Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: warz on May 29, 2006, 08:20 PM

Title: Errors with declspec(naked) and fastcall function
Post by: warz on May 29, 2006, 08:20 PM
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..

(http://www.rafm.org/files/error.png)

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.
Title: Re: Errors with declspec(naked) and fastcall function
Post by: MyndFyre on May 29, 2006, 09:00 PM
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.
Title: Re: Errors with declspec(naked) and fastcall function
Post by: 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.
Title: Re: Errors with declspec(naked) and fastcall function
Post by: Maddox on June 05, 2006, 04:53 AM
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, ...);
Title: Re: Errors with declspec(naked) and fastcall function
Post by: Maddox on June 05, 2006, 04:55 AM
Hey warz, what is your AIM/MSN now? Is it still dotslashwarz?