These are just some things I've worked out while coding and figured I'd share. I don't know asm and have been learning as I go along (thanks to Nesox for your help); please feel free to critique if there's something I should know, or that I've missed.
ClickToMove (remember, unused fields can be left 0)
Code:
uint pMe = 0, pInteractGuid = 0, pClickPos = 0;
try {
pMe = Allocate(4);
Memory.WriteUInt(pMe, Me);
pInteractGuid = Allocate(8);
Memory.WriteUInt64(pInteractGuid, interactGuid);
pClickPos = Allocate(pointSize);
Memory.WriteObject(pClickPos, clickPos);
ClearAndExecute(
"push "+precision,
"push "+pClickPos,
"push "+pInteractGuid,
"push "+(uint)clickType,
"mov ecx, ["+pMe+"]",
"call "+p_ClickToMove,
"retn"
);
} catch(MemoryReadFailedException) {
} finally {
if(pMe!=0)
Memory.FreeMemory(pMe);
if(pInteractGuid!=0)
Memory.FreeMemory(pInteractGuid);
if(pClickPos!=0)
Memory.FreeMemory(pClickPos);
}
GetLocalizedText
Code:
uint lpLua = 0, pReturnBlock = 0;
string szReturn = null;
try {
lpLua = Allocate(szLuaVariable.Length);
Memory.WriteASCIIString(lpLua, szLuaVariable);
pReturnBlock = Allocate(255);
if(pReturnBlock==0) return null;
ClearAndExecute(
"push -1",
"push " + lpLua,
"mov ecx, " + pMe,
"call " + lua_getlocalizedtext,
"mov ["+pReturnBlock+"], eax",
"retn"
);
var pReturn = Memory.ReadUInt(pReturnBlock);
if(pReturn!=0) szReturn = Memory.ReadASCIIString(pReturn, 255);
} catch(MemoryReadFailedException) {
} finally {
if(lpLua != 0)
Memory.FreeMemory(lpLua);
if(pReturnBlock != 0)
Memory.FreeMemory(pReturnBlock);
}
DoString (mostly copypasta from Nesox's aHook wrapper example)
Code:
uint lpLua = 0;
try {
lpLua = Allocate(szLua.Length + szLuaFile.Length + 4);
var lpLuaFile = lpLua + (uint)szLua.Length + 2;
Memory.WriteASCIIString(lpLua, szLua);
Memory.WriteASCIIString(lpLuaFile, szLuaFile);
ClearAndExecute(
"push " + pState,
"push " + lpLuaFile,
"push " + lpLua,
"call " + lua_dostring,
"add esp, 0xC",
"retn"
);
} catch(MemoryReadFailedException) {
} finally {
if(lpLua != 0)
Memory.FreeMemory(lpLua);
}
UpdateHardwareEvent
Code:
ClearAndExecute(
"call "+p_GetTimestamp,
"mov ["+p_LastHardwareAction+"], eax",
"retn"
);