So I've come to the point where I need to interact with units, so I got a hold of the interact asm function and freshed it up, however it does crash at:
Code:
Core.WBM.Asm.InjectAndExecute(codecave);
with the simple and explaning error:
Code:
Injection failed for some reason.
The Interact() function:
Code:
public void Interact()
{
Core.WBM.Asm.Clear();
Core.WBM.Asm.AddLine("fs mov eax, [0x2C]");
Core.WBM.Asm.AddLine("mov eax, [eax]");
Core.WBM.Asm.AddLine("add eax, 0x10");
Core.WBM.Asm.AddLine("mov dword [eax], {0}", new object[] { CurMgr });
Core.WBM.Asm.AddLine("mov ecx, {0}", new object[] { BaseAddress });
Core.WBM.Asm.AddLine("call {0}", new object[] { VMTPtr(VMT_Interact) });
UIntPtr smsg = Imports.GetProcAddress(LoadLibrary("User32.dll"), "SendMessageA");
Core.WBM.Asm.AddLine("push {0}", Core.WBM.ProcessId);
Core.WBM.Asm.AddLine("push {0}", Core.WBM.ProcessId);
Core.WBM.Asm.AddLine("push {0}", 0xBEEF);
Core.WBM.Asm.AddLine("push {0}", (IntPtr)Core.hWnd);
Core.WBM.Asm.AddLine("mov eax, {0}", smsg);
Core.WBM.Asm.AddLine("call eax");
Core.WBM.Asm.AddLine("retn");
uint codecave = Core.WBM.AllocateMemory();
Core.WBM.Asm.InjectAndExecute(codecave);
Core.WBM.FreeMemory(codecave);
}
uint VMTPtr(uint offset)
{
return Core.WBM.ReadUInt(Core.WBM.ReadUInt(BaseAddress) + offset);
}
and where I call it:
Code:
if (curObj.Type == 3) // NPC
{
NPCObject NPCO = new NPCObject(curObj.BaseAddress);
NPCObjectList.Add(curObj.GUID, NPCO);
NPCDump.WriteLine("[Name: " + NPCO.Name + "] [GUID: " + NPCO.GUID + "] [Health: " + NPCO.Health.ToString() + "/" + NPCO.MaxHealth.ToString() + " (" + NPCO.HealthPercent.ToString() + "%)] [Position: " + NPCO.Location.ToString() + "]");
if (NPCO.Location.DistanceToSelf <= 15)
{
NPCO.Interact();
}
}