Hey Guys,
This is my chat manager from my old fishbot.
it works like a "event" driven code. exept back then i didnt know how to do events. and still dont to this day haha 
basicly. it pulses Pulse(), the first time it runs it just runs to get the new _seq,
so its a INIT. so it loops threw all and knows where we are up to, it DOESNT call Event_NewMessage so it doesn't spam.
anything after INIT, will be called Event_NewMessage, this is and was my "event" as i dont know events. and having a new chat was basicly a event in my eyes.
so you really shouldnt need to touch anything in there at all.
only thing u should worry about is Event_NewMessage calling CHAT.
chat is where you should have your own code. mine was purely so it would wake me up when noobs where whispering me while i was asleep.
enjoy,
chatmanager.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SwInYFisher.Managers;
namespace SwInYFisher.Managers
{
static class ChatManager
{
// Public Declair
private static bool _Init = false;
private static int _LastSeq;
private static List<cChatMessages> lMessages = new List<cChatMessages>();
// THIS IS WHERE IT CALLS CHAT FUNCTION
// THIS IS WHERE IT ACTS AS A EVENT
private static void Event_NewMessage(cChatMessages Obj)
{
Chat.Event_NewMessage(Obj);
}
#region "Main Code"
/// <summary>
/// Refreshes list, Checks if chat is updated.
/// </summary>
public static void Pulse()
{
PulseList();
CheckNewChat();
}
/// <summary>
/// Refresh's the Chat List, and sorts by _Seq
/// </summary>
private static void PulseList()
{
// Declair
uint CurObj;
// Clear List
lMessages.Clear();
// Get all the chat messages
for (int i = 0; i < 60; i++)
{
// Get current object were at
CurObj = (uint)Addresses.ChatBuffer.ChatBuffer_Start + (uint)Addresses.ChatBuffer.ChatBuffer_Next * (uint)i;
// Create a new class
cChatMessages NewMessage = new cChatMessages();
NewMessage._Seq = GetSequence(CurObj);
NewMessage._Time = GetTime(CurObj);
NewMessage._PureText = GetPureText(CurObj);
NewMessage._FormattedMessage = GetFormattedMessage(CurObj);
// Add Class to the list
lMessages.Add(NewMessage);
}
// Sort
lMessages.Sort();
}
/// <summary>
/// Goes threw list and looks for new chat
/// </summary>
private static void CheckNewChat()
{
foreach (cChatMessages Messages in lMessages)
{
// If theres a new message, Hey lets update.
if (Messages._Seq > _LastSeq)
{
// Call the New Message Event if INIT has been done
if (_Init) Event_NewMessage(Messages);
// Lets make new Seq our last
_LastSeq = Messages._Seq;
}
}
// Lets say we have done INIT
if (_Init == false) _Init = true;
}
#endregion
#region "Memory Reads"
private static long GetTime(uint CurObj)
{
return ProcessManager.WoWProcess.ReadInt64((uint)CurObj + (uint)Addresses.ChatBuffer.Time);
}
private static int GetSequence(uint CurObj)
{
return ProcessManager.WoWProcess.ReadInt((uint)CurObj + (uint)Addresses.ChatBuffer.Sequence);
}
private static string GetPureText(uint CurObj)
{
return ProcessManager.WoWProcess.ReadASCIIString((uint)CurObj + (uint)Addresses.ChatBuffer.PureText,255);
}
private static string GetFormattedMessage(uint CurObj)
{
return ProcessManager.WoWProcess.ReadASCIIString((uint)CurObj + (uint)Addresses.ChatBuffer.FormattedMessage, 400);
}
#endregion
}
public class cChatMessages : IComparable<cChatMessages>
{
// Public Declair
public string _FormattedMessage;
public string _PureText;
public long _Time;
public int _Seq;
public int CompareTo(cChatMessages Obj)
{
return _Seq.CompareTo(Obj._Seq);
}
}
}
this was my chat.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using SwInYFisher.Managers;
using System.Windows.Forms;
namespace SwInYFisher
{
static class Chat
{
// Declair our Notify Icon
private static NotifyIcon _Icon;
/// <summary>
/// Init, Pass our Notify Icon so we can bubble text
/// </summary>
/// <param name="Value"></param>
public static void Init(NotifyIcon Value)
{
_Icon = Value;
}
public static void Event_NewMessage(cChatMessages Obj)
{
int Type;
string Chanel;
string PlayerName;
int pos1 = Obj._FormattedMessage.IndexOf("Type: [") + 7;
int pos2 = Obj._FormattedMessage.IndexOf("]", pos1);
Type = Int32.Parse(Obj._FormattedMessage.Substring(pos1, pos2 - pos1));
pos1 = Obj._FormattedMessage.IndexOf("Channel: [") + 10;
pos2 = Obj._FormattedMessage.IndexOf("]", pos1);
Chanel = Obj._FormattedMessage.Substring(pos1, pos2 - pos1);
pos1 = Obj._FormattedMessage.IndexOf("Player Name: [") + 14;
pos2 = Obj._FormattedMessage.IndexOf("]", pos1);
PlayerName = Obj._FormattedMessage.Substring(pos1, pos2 - pos1);
if (Type == 7)
{
IncomingWhisper(PlayerName, Obj);
}
}
private static void IncomingWhisper(String PlayerName, cChatMessages Obj)
{
_Icon.ShowBalloonTip(15000,
"SwInY Fisher - Incoming Whisper",
PlayerName + ": " + Obj._PureText.ToString(),
ToolTipIcon.Error);
MessageSound();
}
private static void MessageSound()
{
System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
myPlayer.SoundLocation = appPath + "\\nudge.wav";
myPlayer.Play();
}
}
}
oh in my main form i had a timer set to 400ms
just to keep the chat fresh and pulsing
Code:
private static Thread ChatPulse = new Thread(new ThreadStart(ChatManager.Pulse));
private void tmrChat_Tick(object sender, EventArgs e)
{
if (Main.ChatPulse.IsAlive) return;
Main.ChatPulse = null;
Main.ChatPulse = new Thread(new ThreadStart(ChatManager.Pulse));
ChatPulse.Start();
}
#endregion