Raised This Month: $51 Target: $400
 12% 

[Solved] Like "Meta Mod" Code From Windows to Linux


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 12-01-2012 , 13:49   [Solved] Like "Meta Mod" Code From Windows to Linux
Reply With Quote #1

I want to make this for Linux, if possible in this mode. Otherwise, other type of building would be greatly appreciated.

PHP Code:
// Big thanks to jim_yang and Meta Mod 1.19 author(s)
// https://forums.alliedmods.net/member.php?u=19661

#define WIN !defined( __linux__ )

#if WIN
    #include < extdll.h >
#else
    #include "extdll.h"
#endif

#if WIN
    #define DLL_EXP extern "C" __declspec ( dllexport )
#else
    #define DLL_EXP /* */
#endif

#if WIN
    #define LINK_ENT( EntityClassName ) DLL_EXP void EntityClassName( entvars_t * pVars ) { ENTITY_FN Entity = ( ENTITY_FN ) GetProcAddress( hGameDll, #EntityClassName ); ( * Entity ) ( pVars ); }
#else
    /* ????????????? */
#endif

#if WIN
    
HMODULE hGameDll;
#else
    /* ????????????? */
#endif

enginefuncs_t g_engfuncs;
globalvars_t gpGlobals;
DLL_FUNCTIONS g_dllfuncs;

#if WIN
    
typedef void WINAPI ENGINE_API_FN ) ( enginefuncs_t *, globalvars_t * );
#else
    
typedef void ( * ENGINE_API_FN ) ( enginefuncs_t *, globalvars_t * );
#endif

typedef int ( * ENTITY_API_FN ) ( DLL_FUNCTIONS *, int );
typedef void ( * ENTITY_FN ) ( entvars_t * );

#if WIN
    
DLL_EXP void WINAPI GiveFnptrsToDllenginefuncs_t pFuncsglobalvars_t pGlobals ) {
#else
    
DLL_EXP void GiveFnptrsToDllenginefuncs_t pFuncsglobalvars_t pGlobals ) {
#endif
    
memcpy( &g_engfuncspFuncssizeofg_engfuncs ) );
    
gpGlobals pGlobals;
#if WIN
    
hGameDll LoadLibraryL"cstrike\\dlls\\mp.dll" );
    
ENGINE_API_FN Call = ( ENGINE_API_FN GetProcAddresshGameDll"GiveFnptrsToDll" );
    
CallpFuncspGlobals );
#else
    /* ????????????? */
#endif
    
printf"Loading \"Hattrick Main Admin Plugin\" by Hattrick\n" );
}

DLL_EXP int GetEntityAPIDLL_FUNCTIONS pFuncsint Vers ) {
#if WIN
    
ENTITY_API_FN Call = ( ENTITY_API_FN GetProcAddresshGameDll"GetEntityAPI" );
    
Call( &g_dllfuncsVers );
    
CallpFuncsVers );
#else
    /* ????????????? */
#endif
    
return 1;
}

LINK_ENTAngleIMatrix );
LINK_ENTAngleMatrix );
LINK_ENTBALLS_airball );
// and so on... 
__________________

Last edited by claudiuhks; 12-01-2012 at 13:53.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-01-2012 , 14:55   Re: Like "Meta Mod" code from Windows to Linux
Reply With Quote #2

For LoadLibrary, see dlopen.
For GetProcAddress, see, dlsym.
__________________

Last edited by Arkshine; 12-01-2012 at 14:57.
Arkshine is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 12-13-2012 , 18:16   Re: Like "Meta Mod" code from Windows to Linux
Reply With Quote #3

I prepared the next code for Linux but it doesn't load on Linux due to the next error:

Quote:
Couldn't get GiveFnptrsToDll from ../dlls/hmap_i386.so
Couldn't get GetEntityAPI from ../dlls/hmap_i386.so
Part of my code is:

PHP Code:
#include "extdll.h"

#if WINDOWS
#pragma comment ( linker, "/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1" )
#pragma comment ( linker, "/SECTION:.data,RW" )
#endif

typedef int ( * ENTITY_API_FN ) ( DLL_FUNCTIONS *, int );

#if WINDOWS
HMODULE g_Module;

typedef void WINAPI ENGINE_API_FN ) ( enginefuncs_t *, globalvars_t * );
#else
void g_pModule NULL;

typedef void ( * ENGINE_API_FN ) ( enginefuncs_t *, globalvars_t * );
#endif

#if WINDOWS
extern "C" __declspec dllexport void WINAPI GiveFnptrsToDllenginefuncs_t pEngine_Functionsglobalvars_t pGlobal_Variables ) {
#else
void GiveFnptrsToDllenginefuncs_t pEngine_Functionsglobalvars_t pGlobal_Variables ) {
#endif

#if WINDOWS
    
g_Module LoadLibraryL"cstrike\\dlls\\mp.dll" );

    
ENGINE_API_FN Address = ( ENGINE_API_FN GetProcAddressg_Module"GiveFnptrsToDll" );
#else
    
g_pModule dlopen"cstrike/dlls/cs_i386.so"RTLD_NOW );

    
ENGINE_API_FN Address = ( ENGINE_API_FN dlsymg_pModule"GiveFnptrsToDll" );
#endif

    
AddresspEngine_FunctionspGlobal_Variables );
}

#if WINDOWS
extern "C" __declspec dllexport int GetEntityAPIDLL_FUNCTIONS pDll_Functionsint ) {
    
ENTITY_API_FN Address = ( ENTITY_API_FN GetProcAddressg_Module"GetEntityAPI" );
#else
int GetEntityAPIDLL_FUNCTIONS pDll_Functionsint ) {
    
ENTITY_API_FN Address = ( ENTITY_API_FN dlsymg_pModule"GetEntityAPI" );
#endif

    
AddresspDll_FunctionsINTERFACE_VERSION );

    return 
1;

Notes:

It doesn't work on Linux but for Windows it works properly.
I think I have to evidence GiveFnptrsToDll for Linux as the first function that should be loaded, but I don't know how.
For Windows, jim_yang and Meta Mod source code helped.

Any help could be greatly appreciated.
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-13-2012 , 18:56   Re: Like "Meta Mod" code from Windows to Linux
Reply With Quote #4

I don't know much and it may an useless comment, but should not you add extern "C" for linux too ? It would make sense to add it.
__________________
Arkshine is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 12-13-2012 , 19:01   Re: Like "Meta Mod" code from Windows to Linux
Reply With Quote #5

Quote:
Originally Posted by Arkshine View Post
I don't know much and it may an useless comment, but should not you add extern "C" for linux too ? It would make sense to add it.
Impressive.

Thanks for your quickly answer, it works perfectly now!
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-13-2012 , 19:22   Re: [Resolved] Like "Meta Mod" code from Windows to Linux
Reply With Quote #6

:. It's mainly because on the project I'm working I had to export something, and when I've read "Couldn't get", it would mean only the symbol has not been found in your lib ; something you see right away in the code.

Will you post your the whole code once finished or you just need that above ? Never tried and it kind of interesting.
__________________
Arkshine is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 12-13-2012 , 19:48   Re: [Resolved] Like "Meta Mod" code from Windows to Linux
Reply With Quote #7

Quote:
Originally Posted by Arkshine View Post
Will you post your the whole code once finished or you just need that above ? Never tried and it kind of interesting.
Of course I will.
Once I'll finish I'll attach the code here.

By the way, I'm not afraid to publish free coded things that others can't use on servers that run plugins that hack the game to allow users without Steam.
__________________

Last edited by claudiuhks; 12-14-2012 at 23:59.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 12-13-2012 , 20:52   Re: [Resolved] Like "Meta Mod" code from Windows to Linux
Reply With Quote #8

You may download it from the link listed below.

Click here.

It doesn't work with de_airstrip, as I tested. As I think, an entity required couldn't be found in Edict.cpp.

As a note, Dlfcn.H is included in Extdll.H.

Any help would be greatly appreciated.

Does anyone know how to retrieve Message Index on RegUserMsg_Post?

For hooking an Engine function, you may check this example.

PHP Code:
enginefuncs_t g_engfuncs;

void MessageBeginint Destinationint Type, const float pOriginedict_t pEdict ) {
  
// Pre execution state.
  // If you want to block the function, the call, you have to not call the function listed below.
  
g_engfuncs.pfnMessageBeginDestinationTypepOriginpEdict );
  
// Post execution state.
}

#if WINDOWS
extern "C" __declspec dllexport void WINAPI GiveFnptrsToDllenginefuncs_t pEngine_Functionsglobalvars_t * ) {
#else
extern "C" void GiveFnptrsToDllenginefuncs_t pEngine_Functionsglobalvars_t * ) {
#endif
  
memcpy( &g_engfuncspEngine_Functionssizeofenginefuncs_t ) );
  
pEngine_Functions -> pfnMessageBegin MessageBegin;

Attached Files
File Type: zip hmap.zip (4.94 MB, 120 views)
__________________

Last edited by claudiuhks; 12-15-2012 at 00:00.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-14-2012 , 07:17   Re: [Awaiting] Like "Meta Mod" code from Windows to Linux
Reply With Quote #9

Quote:
Does anyone know how to retrieve Message Index on RegUserMsg_Post?
Call the original function and get it's returned value ?
__________________
Arkshine is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 12-14-2012 , 10:52   Re: [Awaiting] Like "Meta Mod" code from Windows to Linux
Reply With Quote #10

Quote:
Originally Posted by Arkshine View Post
Call the original function and get it's returned value ?
It works like a charm! As I tested with printf.

Now only the problem with de_airstrip should be solved so the like "Meta Mod" plugin type will be completely done.
__________________

Last edited by claudiuhks; 12-15-2012 at 00:01.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Reply



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:12.


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