Hi all,
I have a question for those of you who are injecting and hosting the .NET CLR inside WoW. I've been encountering crashes in my own solution whilst attempting to call any WoW object virtual function (GetName being the primary one I have been trying to get working).
I haven't had the chance to debug it too much yet and obviously I will keep looking into it, trying to solve it myself. However, I thought I'd ask here in the meantime just to make sure I wasn't doing something obviously wrong with setting up / registering delegates etc.
The relevant code for the relevant objects:
WoWObject:
Code:
// CGObject_C
class WoWObject
{
...
public enum VTable
{
GetBag = 9,
GetPosition = 11,
GetFacing = 13,
GetScale = 14,
GetModel = 23,
Interact = 42,
GetName = 52,
}
...
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate string GetNameDelegate(IntPtr instance);
...
public IntPtr BaseAddress { get; protected set; }
...
public virtual string Name
{
get
{
return "";
}
}
...
}
WoWUnit:
Code:
class WoWUnit : WoWObject
{
...
private GetNameDelegate _getName;
public override string Name
{
get
{
if (_getName == null)
{
_getName = Memory.RegisterDelegate<GetNameDelegate>(Memory.GetObjectVTableFunctionPointer(BaseAddress, (int)VTable.GetName));
}
return _getName(BaseAddress);
}
}
...
}
Firstly, is this the correct way to set up / call a virtual function for an object deriving from CGObject_C? From the bits and pieces I've put together from searching this seems to be the general approach, although most people seem to either use C++ or BlackMagic ASM injection.
The object list is pulsed from an EndScene hook (hooking mostly credits to WhiteMagic by Apoc, rewritten into my framework, and object stuff mostly based off Apoc's thread on object management, credits once again). This all works fine - I can spit out objects' GUIDs and any other properties that are read from the descriptors etc. However, the moment I make a call to WoWUnit.Name, the program crashes (crash dump: NoMorePasting.com).
I've tried a few different methods of debugging but admittedly given the minimal time I've had to spend on it and my still limited knowledge of ASM etc, that hasn't found me a solution yet. I've tried putting a breakpoint in Olly on 0x006BD710 (CGUnit_C__GetUnitName according to info dump) both with clean WoW and with my code injected. It appears that the code follows a different path when I call it than when the game calls it.
Code:
.text:006BD729 test byte ptr [esi+0F42h], 80h
.text:006BD730 jz loc_6BD7ED
My call appears to fail that test, causing it to proceed and eventually enter the loop beginning at loc_6BD753. The crash eventually occurs attempting to read invalid memory at loc_6BD787, but according to debugging it appears to go through about 10 iterations of the loop before it fails. This much I've been able to determine from debugging, and as I've said I haven't been able to put that much time into it; also, my knowledge of ASM is somewhat limited making it more difficult to understand what the function / loop is actually doing and thus why it might be crashing. However, I thought I'd at least check if there was anything glaringly obvious.
Any help / pointers / comments appreciated. Constructive ridicule would also be appreciated
.
Cheers!