Valhalla Legends Forums Archive | C/C++ Programming | Errors with declspec(naked) and fastcall function

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

[code]
int __fastcall GetMaximumSupply(int playerid, int raceid);
int __declspec(naked) __fastcall NativeClass::GetMaximumSupply(int playerid, int raceid) {}
[/code]

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

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

I am calling this function like..

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

I am receiving an error message that states..

[img]http://www.rafm.org/files/error.png[/img]

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.
May 30, 2006, 1:20 AM
Myndfyr
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.
May 30, 2006, 2:00 AM
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.
May 30, 2006, 4:16 AM
Maddox
[quote author=warz link=topic=15089.msg153421#msg153421 date=1148962610]
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.
[/quote]

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:
[code]
typedef void (__fastcall * ptrFunc)(void * class, void * dummy, ...);
[/code]
June 5, 2006, 9:53 AM
Maddox
Hey warz, what is your AIM/MSN now? Is it still dotslashwarz?
June 5, 2006, 9:55 AM

Search