EDIT: I actually solved my own problem - of course, after days of trying this to no avail, I solved it immediately after posting. Typical. The below code should work, I'll leave it up in case anybody can use it as a learning tool
As much as I hate to open another question thread after just having done so a few days ago, I've spent a considerable amount of time on this and searched extensively but haven't found what I'm doing wrong. I'm using Apoc's Lua Wrapper (http://www.mmowned.com/forums/world-...ected-clr.html) from an injected endScene hook and now have DoString working.
I may be completely off, but from what I understand, in order to get return values, we must register our own Lua function. When registering new Lua, the InvalidPtr function checks to see whether the pointer to our new function is within WoW's .text space. Since the pointer to our new function is outside this space, we find an unused space in the .text section and write a JMP to our new Lua pointer. We then try to pass this JMP location to WoW's Registering function.
When I do this, it's still crashing WoW as I call WoW's register function. I've debugged in OllyDbg and it appears that my JMP command is correctly pointing to the new Lua function.
Code:
// LuaRegisterCommand = WoWBase + 0x3AB990
// Pass the pointer to my new Lua function as the argument
public static IntPtr WriteLuaCallback(IntPtr callbackPtr)
{
// Set codeCaveLocation (where my JMP is written) to a location which
// is unused, overwriting only the 0xCC 0xCC 0xCC... used for alignment
IntPtr codeCaveLocation = (IntPtr)Helper.WoWBase + 0x3E5C32;
// Write 0xE9, the opcode for a relative jump
Helper.Magic.Write<byte>(codeCaveLocation, 0xE9);
// Write the relative location of my new Lua pointer to the JMP instruction
Helper.Magic.Write<int>(codeCaveLocation + 1, (int)callbackPtr - (int)codeCaveLocation - 5);
// Return the location of my code cave (JMP instruction) to be used as I
// call WoW's RegisterCommand - RegisterCommand(commandName, codeCaveLocation)
return codeCaveLocation;
}
Any help would be greatly appreciated.
A couple of the main references I've used (not limited to of course)
http://www.mmowned.com/forums/world-...-callback.html
http://www.mmowned.com/forums/world-..._register.html