This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Using Game DLL Functions Safely


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
showdax
Senior Member
Join Date: Dec 2004
Old 12-07-2005 , 02:23   Using Game DLL Functions Safely
Reply With Quote #1

I think the following would be a better way to use DLL-related functions like things in CBaseEntity.

First, a forward declaration:
Code:
class CBasePlayer;
A handy typedef for casting a void pointer to our function pointer:
Code:
typedef void (*ShowViewPortPanel_Function)(CBasePlayer *, char const *, bool, KeyValues *);
The global variable for the function pointer:
Code:
void (*ShowViewPortPanel)(CBasePlayer *, char const *, bool, KeyValues *) = NULL;
And then we find the memory address to the function (signature scanning):
Code:
ShowViewPortPanel = (ShowViewPortPanel_Function) someScanFunctionThatReturnsAVoidPointer();
And finally:
Code:
CBasePlayer *player = (CBasePlayer *) entity->GetUnknown()->GetBaseEntity();

if (player)
{
	ShowViewPortPanel(player, "info", shown, panel);
}
This works fine for me under Linux. According to BAILOPAN, it isn't as simple as giving member function pointers the instance as the first argument under Windows. I think all plugins that use these kinds of functions should use a method like this, with it gracefully disabling commands when it can't find functions.

But then you have things like inline functions which access member variables (like CBaseEntity::AddEFlags) and then you're fucked. For this I was thinking of reverse-engineering the current CBaseEntity/whatever definitions from what's in the CS:S and DOD:S binaries. Then the plugin would have a cvar that enables or disables functionality that uses member variables so one can avoid crashes when Valve updates it again.

The only thing is I'm not really sure how classes are defined in ELF or PE binaries. We'd really only need a definition for the member variables, but I don't know where to start.
showdax is offline
Send a message via MSN to showdax
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:19.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode