my bot is use to select realm and enterworld,move character to somewhere to do something,an addon implement logout,then continue to change another realm and do the same things,loop again and again.
I use blackmagic to hook,and a different GetLocalizedText to get GluxScreen State without character logging,and LuaDoString to do such as login,selectrealm,enterworld etc,the problem is:
when i use F5 it works perfectly,but get problem with CTRL+F5.
when i run it with CTRL+F5,it usually cause client crashed at EnterWorld().
i don't have too much time in bot researching these days,but i need this bot urgently,if someone can point me and help me work out with winform(windows xp sp3,derectx 9.0c),i would like to pay,i accept paypal.
i think it's not against the section rule,but i am going to post some my code here
EnterWold lua
Code:
CharacterSelect_SaveCharacterOrder()
StopGlueAmbience()
EnterWorld()
GetLocalizedText
Code:
public string GetApiReturn(string variable)
{
// Write variable in the allocated memory
uint codeCave = Memory.AllocateMemory(Encoding.UTF8.GetBytes(variable).Length + 1);
Memory.WriteBytes(codeCave, Encoding.UTF8.GetBytes(variable));
String[] asm = new String[]
{
"push 0",
"push -1",
"mov edx, " + codeCave + "",
"push edx",
"call " + Script_GetLocalizedTest,
"add esp, 0Ch",
"retn",
};
// get value
string varResult = Encoding.ASCII.GetString(InjectAndExecute(asm));
Memory.FreeMemory(codeCave);
return varResult;
}
some Main Thread code in Form1 class
Code:
private void MainThread()
{
hook = new FunctionHook(wowPid);
while (true) { TimerExecute(); }
}
private void TimerExecute()
{
hook.LuaDoString(WowOperater.GetGlueFrameValue());
frameName = hook.GetApiReturn("glueFrame");
switch (frameName)
{
case "login":
....
case "charselect":
....
.......
}
Thread.Sleep(500)
}
hook,unhook,luadostring,and GetLocalizedText here,i guess problem might be here
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Magic;
using System.Threading;
namespace FlyingWowAssistant
{
public class FunctionHook
{
public static BlackMagic Memory = new BlackMagic();
private int _processId = 0;
private bool hookedFlag = false;
private static bool injectionFlag = false;
private static uint hookCodeCave = 0;
private static uint addrCodeCave = 0;
private static uint retnCodeCave = 0;
#region Offset
//offset
private bool initNeeded = true;
private static uint wowBaseAddr = 0;
private static uint pEndScene = 0;
private static uint DX_DEVICE = 0xABF2FC;
private static uint DX_DEVICE_IDX = 0x27F8;
private static uint ENDSCENE_IDX = 0xA8;
private static uint FrameScript_ExecuteBuffer = 0x43C010;
private static uint FrameScript__GetLocalizedText = 0x1BB0C0;
private static uint Script_GetLocalizedTest = 0x43D0F0;
private static uint ClntObjMgrGetActivePlayerObj = 0x3410;
private static uint CGPlayer_C__ClickToMove = 0x997E38;
#endregion
public FunctionHook(int processId)
{
_processId = processId;
Hooking();
}
public string ReadUint(uint offset)
{
return Memory.ReadASCIIString(wowBaseAddr+offset, 50);
}
public string GetApiText(string variable)
{
// Write variable in the allocated memory
uint codeCave = Memory.AllocateMemory(Encoding.UTF8.GetBytes(variable).Length + 1);
Memory.WriteBytes(codeCave, Encoding.UTF8.GetBytes(variable));
String[] asm = new String[]
{
"push 0",
"push -1",
"mov edx, " + codeCave + "",
"push edx",
"call " + Script_GetLocalizedTest,
"add esp, 0Ch",
"retn",
};
// get value
string varResult = Encoding.ASCII.GetString(InjectAndExecute(asm));
Memory.FreeMemory(codeCave);
return varResult;
}
public string GetLocalizedText(string variable)
{
// Write variable in the allocated memory
uint codeCave = Memory.AllocateMemory(Encoding.UTF8.GetBytes(variable).Length + 1);
Memory.WriteBytes(codeCave, Encoding.UTF8.GetBytes(variable));
String[] asm = new String[]
{
"call " + ClntObjMgrGetActivePlayerObj,
"mov ecx, eax",
"push -1",
"mov edx, " + codeCave + "",
"push edx",
"call " + FrameScript__GetLocalizedText,
"retn",
};
// get value
string varResult = Encoding.ASCII.GetString(InjectAndExecute(asm));
Memory.FreeMemory(codeCave);
return varResult;
}
public void LuaDoString(string command)
{
// Write value:
uint codeCave = Memory.AllocateMemory(Encoding.UTF8.GetBytes(command).Length + 1);
Memory.WriteBytes(codeCave, Encoding.UTF8.GetBytes(command));
// Write the asm stuff for Lua_DoString
String[] asm = new String[]
{
"mov eax, " + codeCave,
"push 0",
"push eax",
"push eax",
"mov eax, " + (uint)FrameScript_ExecuteBuffer, // Lua_DoString
"call eax",
"add esp, 0xC",
"retn",
};
// Inject
InjectAndExecute(asm);
Memory.FreeMemory(codeCave);
}
public void ClickToMove(float newX, float newY)
{
uint CTM_PUSH = CGPlayer_C__ClickToMove + 0x1C;
uint CTM_X = CGPlayer_C__ClickToMove + 0x8C;
uint CTM_Y = CGPlayer_C__ClickToMove + 0x4;
uint CTM_Z = CGPlayer_C__ClickToMove + 0x4;
Memory.WriteFloat(CTM_X, newX);
Memory.WriteFloat(CTM_Y, newY);
Memory.WriteUInt(CTM_PUSH, 4);
}
//Inir wow BaseAddr;
private static void InitHook()
{
wowBaseAddr = (uint)Memory.MainModule.BaseAddress;
FrameScript_ExecuteBuffer = wowBaseAddr + FrameScript_ExecuteBuffer;
ClntObjMgrGetActivePlayerObj = wowBaseAddr + ClntObjMgrGetActivePlayerObj;
FrameScript__GetLocalizedText = wowBaseAddr + FrameScript__GetLocalizedText;
Script_GetLocalizedTest = wowBaseAddr + Script_GetLocalizedTest;
CGPlayer_C__ClickToMove = wowBaseAddr + CGPlayer_C__ClickToMove;
uint pDevice = Memory.ReadUInt(wowBaseAddr + DX_DEVICE);
uint pEnd = Memory.ReadUInt(pDevice + DX_DEVICE_IDX);
uint pScene = Memory.ReadUInt(pEnd);
pEndScene = Memory.ReadUInt(pScene + ENDSCENE_IDX);
}
public void Hooking()
{
// Process Connect:
if (!Memory.IsProcessOpen)
{
Memory.OpenProcessAndThread(_processId);
}
if (Memory.IsProcessOpen)
{
if (initNeeded)
{
InitHook();
initNeeded = false;
}
if (Memory.ReadByte(pEndScene) == 0xE9 && (hookCodeCave == 0 || addrCodeCave == 0)) // check if wow is already hooked and dispose Hook
{
DisposeHooking();
}
if (Memory.ReadByte(pEndScene) != 0xE9) // check if wow is already hooked
{
try
{
hookedFlag = false;
// allocate memory to store injected code:
hookCodeCave = Memory.AllocateMemory(2048);
// allocate memory the new injection code pointer:
addrCodeCave = Memory.AllocateMemory(0x4);
Memory.WriteInt(addrCodeCave, 0);
// allocate memory the pointer return value:
retnCodeCave = Memory.AllocateMemory(0x4);
Memory.WriteInt(retnCodeCave, 0);
// Generate the STUB to be injected
Memory.Asm.Clear(); // $Asm
// save regs
Memory.Asm.AddLine("pushad");
Memory.Asm.AddLine("pushfd");
// Test if you need launch injected code:
Memory.Asm.AddLine("mov eax, [" + addrCodeCave + "]");
Memory.Asm.AddLine("test eax, eax");
Memory.Asm.AddLine("je @out");
// Launch Fonction:
Memory.Asm.AddLine("mov eax, [" + addrCodeCave + "]");
Memory.Asm.AddLine("call eax");
// Copie pointer return value:
Memory.Asm.AddLine("mov [" + retnCodeCave + "], eax");
// Enter value 0 of addresse func inject
Memory.Asm.AddLine("mov edx, " + addrCodeCave);
Memory.Asm.AddLine("mov ecx, 0");
Memory.Asm.AddLine("mov [edx], ecx");
// Close func
Memory.Asm.AddLine("@out:");
// load reg
Memory.Asm.AddLine("popfd");
Memory.Asm.AddLine("popad");
// injected code
uint sizeAsm = (uint)(Memory.Asm.Assemble().Length);
Memory.Asm.Inject(hookCodeCave);
// Size asm jumpback
int sizeJumpBack = 5;
// copy and save original instructions
Memory.Asm.Clear();
Memory.Asm.AddLine("mov edi, edi");
Memory.Asm.AddLine("push ebp");
Memory.Asm.AddLine("mov ebp, esp");
Memory.Asm.Inject(hookCodeCave + sizeAsm);
// create jump back stub
Memory.Asm.Clear();
Memory.Asm.AddLine("jmp " + (pEndScene + sizeJumpBack));
Memory.Asm.Inject(hookCodeCave + sizeAsm + (uint)sizeJumpBack);
// create hook jump
Memory.Asm.Clear(); // $jmpto
Memory.Asm.AddLine("jmp " + (hookCodeCave));
Memory.Asm.Inject(pEndScene);
}
catch { hookedFlag = false; return; }
}
hookedFlag = true;
}
}
public void DisposeHooking()
{
try
{
if (Memory.ReadByte(pEndScene) == 0xE9) // check if wow is already hooked and dispose Hook
{
// Restore origine endscene:
Memory.Asm.Clear();
Memory.Asm.AddLine("mov edi, edi");
Memory.Asm.AddLine("push ebp");
Memory.Asm.AddLine("mov ebp, esp");
Memory.Asm.Inject(pEndScene);
}
// free memory:
Memory.FreeMemory(hookCodeCave);
Memory.FreeMemory(addrCodeCave);
Memory.FreeMemory(retnCodeCave);
} catch {}
}
public byte[] InjectAndExecute(string[] asm)
{
int returnLength = 0;
Hooking();
while (injectionFlag){ Thread.Sleep(5); }
injectionFlag = true;
byte[] tempsByte = new byte[0];
// reset return value pointer
Memory.WriteInt(retnCodeCave, 0);
if (Memory.IsProcessOpen && hookedFlag)
{
// Write the asm stuff
Memory.Asm.Clear();
foreach (string tempLineAsm in asm)
{
Memory.Asm.AddLine(tempLineAsm);
}
// Allocation Memory
uint codeCave = Memory.AllocateMemory(Memory.Asm.Assemble().Length);
try
{
// Inject
Memory.Asm.Inject(codeCave);
Memory.WriteInt(addrCodeCave, (int)codeCave);
while (Memory.ReadInt(addrCodeCave) > 0) { Thread.Sleep(5); } // Wait to launch code
if (returnLength == 1)
{
tempsByte = Memory.ReadBytes(retnCodeCave, returnLength);
}
if (returnLength > 1)
{
tempsByte = Memory.ReadBytes(Memory.ReadUInt(retnCodeCave), returnLength);
}
if (returnLength == 0)
{
byte Buf = new Byte();
List<byte> retnByte = new List<byte>();
uint dwAddress = Memory.ReadUInt(retnCodeCave);
Buf = Memory.ReadByte(dwAddress);
while (Buf != 0)
{
retnByte.Add(Buf);
dwAddress = dwAddress + 1;
Buf = Memory.ReadByte(dwAddress);
}
tempsByte = retnByte.ToArray();
}
}
catch { }
// Free memory allocated
Memory.FreeMemory(codeCave);
}
injectionFlag = false;
return tempsByte;
}
}
}