Hello, i have been trying to get CastSpellById to work but i keep getting an error: Injection failed for some reason.
Code:
Code:
public bool CastSpellByID(uint id)
{
Console.WriteLine("Castspell");
uint codeCave = wow.AllocateMemory();
const uint CastSpellID = 0x007735F0;
wow.Asm.Clear();
wow.Asm.AddLine("fs mov eax, [0x2C]");
wow.Asm.AddLine("mov eax, [eax]");
wow.Asm.AddLine("add eax, 8");
wow.Asm.AddLine("mov dword [eax], {0}", CurMgr);
wow.Asm.AddLine("push 0");
wow.Asm.AddLine("push 0");
wow.Asm.AddLine("push 0");
wow.Asm.AddLine("push {0}", id);
wow.Asm.AddLine("call {0}", CastSpellID);
wow.Asm.AddLine("add esp,16");
wow.Asm.AddLine("retn");
wow.Asm.InjectAndExecute(codeCave); //<-- This line makes the error
wow.FreeMemory(codeCave);
return true;
}
The code that calls the function:
Code:
BlackMagic wow;
UInt32 g_clientConnection, clientConnection, CurMgr, CurMgrOffset;
private const string PATTERN_CLIENT_CONNECTION = "EB 02 33 C0 8B D 00 00 00 00 64 8B 15 00 00 00 00 8B 34 8A 8B D 00 00 00 00 89 81 00 00 00 00";
private const string MASK_CLIENT_CONNECTION = "xxxxxx????xxx????xxxxx????xx????";
Public go()
{
uint dwCodeLoc;
wow = new BlackMagic();
if (wow.OpenProcessAndThread(SProcess.GetProcessFromProcessName("wow")))
{
dwCodeLoc = SPattern.FindPattern(wow.ProcessHandle, wow.MainModule, PATTERN_CLIENT_CONNECTION, MASK_CLIENT_CONNECTION, ' ');
g_clientConnection = wow.ReadUInt(dwCodeLoc + 0x16);
clientConnection = wow.ReadUInt(g_clientConnection);
CurMgrOffset = wow.ReadUInt(dwCodeLoc + 0x1C);
CurMgr = wow.ReadUInt(clientConnection + CurMgrOffset);
Console.WriteLine("CLIENT_CONNECTION: 0x{0:X08}", clientConnection);
Console.WriteLine("CURMGR_OFFSET: 0x{0:X08}", CurMgrOffset);
Console.WriteLine("CurMgr: 0x{0:X08}", CurMgr);
Console.ReadLine();
CastSpellByID(2050); //Lesser Heal rank 1
}
else
{
Console.WriteLine("World of Warcraft could not be opened for read/write.");
}
}
I am rather new to ASM and memory programming.