• Welcome to Valhalla Legends Archive.
 

Errors with declspec(naked) and fastcall function

Started by warz, May 29, 2006, 08:20 PM

Previous topic - Next topic

warz

I've got a function in a class of mine defined like so..


int __fastcall GetMaximumSupply(int playerid, int raceid);
int __declspec(naked) __fastcall NativeClass::GetMaximumSupply(int playerid, int raceid) {}


The first is inside my class definition, and the second is in the relative cpp file for the class.
This function looks like...


const static DWORD offset_maxsupply = 0x00410a90;
int __declspec(naked) __fastcall NativeClass::GetMaximumSupply(int playerid, int raceid) {
     __asm {
jmp [offset_maxsupply]
     }
}


I am calling this function like..


global->native.PrintText(0xBE, (00 + (x * 10)), "%d", global->native.GetMaximumSupply(players[x].id, 0));


I am receiving an error message that states..



my question is pretty straightforward, because I don't know what else to say. :-p
anyways, does anyone know what im doing wrong? ive never attempted to make a declspec(naked), or fastcall function before - but this is calling a native brood war function and expecting an int return value.

MyndFyre

Why are you __declspec(naked)'ing that?

Chances are, the Brood War function is expecting its caller to do something that you're not doing, and whatever's calling you isn't doing it either because you're in a naked context.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

warz

I just made it static, seems to fix it. :-p

Except for the function is only returning the correct max supply value for one player, even when I make everyone zerg and supply 0 for race id in a full game of all zerg players. It returns 0 for everyone else.

Maddox

#3
Quote from: warz on May 29, 2006, 11:16 PM
I just made it static, seems to fix it. :-p

Except for the function is only returning the correct max supply value for one player, even when I make everyone zerg and supply 0 for race id in a full game of all zerg players. It returns 0 for everyone else.

Non-static, native, class functions use __thiscall by default, which is fastcall with the this pointer in ecx and edx unused.  Adding __fastcall to a method probably doesn't do anything unless the method is static.

For reference, if you want to hook a __thiscall function (there are lots in warcraft 3) you should use a function pointer like so:

typedef void (__fastcall * ptrFunc)(void * class, void * dummy, ...);
asdf.

Maddox

Hey warz, what is your AIM/MSN now? Is it still dotslashwarz?
asdf.