...I'm doing this in current YaPB:
Code:
#ifdef _WIN32
#ifdef __BORLANDC__
extern "C" DLLEXPORT void WINAPI GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals)
#else
void WINAPI GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals )
#endif
#else
extern "C" DLLEXPORT void GiveFnptrsToDll( enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals )
#endif
{
// get the engine functions from the engine...
memcpy(&g_engfuncs, pengfuncsFromEngine, sizeof(enginefuncs_t));
gpGlobals = pGlobals;
if (g_bIsMMPlugin)
return; // we needn't load the game DLL if we're running in Metamod
char szGameDLLName[256];
GetGameDirectory(szGameDLLName);
// load the actual Counter-Strike Game DLL
#ifdef _WIN32
strcat(szGameDLLName, "/dlls/mp.dll");
h_Library = LoadLibrary(szGameDLLName);
#else
strcat(szGameDLLName, "/dlls/cs_i386.so");
h_Library = dlopen(szGameDLLName, RTLD_NOW);
#endif
if (!h_Library)
{
// try to extract the game DLL out of the Steam cache
int size;
#ifdef _WIN32
unsigned char *filebuf = LOAD_FILE_FOR_ME("dlls/mp.dll", &size);
#else
unsigned char *filebuf = LOAD_FILE_FOR_ME("dlls/cs_i386.so", &size);
#endif
if (filebuf)
{
CreatePath(szGameDLLName);
FILE *fp = fopen(szGameDLLName, "wb");
if (fp)
{
// dump the file and close it
fwrite(filebuf, size, 1, fp);
fclose(fp);
}
FREE_FILE(filebuf);
}
#ifdef _WIN32
h_Library = LoadLibrary(szGameDLLName);
#else
h_Library = dlopen(szGameDLLName, RTLD_NOW);
#endif
}
if (!h_Library)
TerminateOnError("Fail to load game DLL !");
other_GetEntityAPI = (GETENTITYAPI)GetProcAddress(h_Library, "GetEntityAPI");
other_GetNewDLLFunctions = (GETNEWDLLFUNCTIONS)GetProcAddress(h_Library, "GetNewDLLFunctions");
other_GiveFnptrsToDll = (GIVEFNPTRSTODLL)GetProcAddress(h_Library, "GiveFnptrsToDll");
GetEngineFunctions(pengfuncsFromEngine, NULL);
#ifdef _WIN32
LoadSymbols(szGameDLLName); // Load exported symbol table
pengfuncsFromEngine->pfnFunctionFromName = FunctionFromName;
pengfuncsFromEngine->pfnNameForFunction = NameForFunction;
#endif
// give the engine functions to the other DLL...
(*other_GiveFnptrsToDll)(pengfuncsFromEngine, pGlobals);
}