I just checked what I did actually different in my version and the only relevant change is in main.cpp:
PHP Code:
#include "main.h"
#include <stdio.h>
#include "include/functions.h"
#include "include/cracking.h"
#include "include/gsc.h"
DWORD WINAPI MyThread(LPVOID);
DWORD g_threadID;
HMODULE g_hModule;
static int isStarted = 0;
DWORD WINAPI MyThread(LPVOID)
{
if (isStarted) {
Com_Printf("Already started!\n");
return NULL;
}
isStarted = 1;
Com_Printf("[PLUGIN LOADED]\n");
#if COD_VERSION == COD2_1_3
cracking_hook_call(0x46E7BF, (int)Scr_GetCustomFunction);
cracking_hook_call(0x46EA03, (int)Scr_GetCustomMethod);
#endif
return 0;
}
extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
Com_Printf("DllMain()\n");
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
g_hModule = hinstDLL;
DisableThreadLibraryCalls(hinstDLL);
CloseHandle(CreateThread(NULL, 0, &MyThread, NULL, 0, &g_threadID));
MyThread(NULL);
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_PROCESS_DETACH:
Com_Printf("[PLUGIN UNLOADED]\n");
FreeLibraryAndExitThread(g_hModule, 0);
break;
case DLL_THREAD_DETACH:
Com_Printf("[THREAD DETACH]\n");
break;
}
return TRUE; // succesful
}
That's were I had all my problems as well: server crashed or just didn't work at all.
Changes in SmartGit:
I guess the CloseHandle(CreateThread()) is just not doing anything and could be commented out also. I call MyThread() without threading, since it is just hooking the two functions nonetheless.
When it still doesn't work, check the Com_Printf() to figure out to what point the code actually did something:
File: functions.h
PHP Code:
#if COD_VERSION == COD2_1_3
#if 0
static Com_Printf_t Com_Printf = (Com_Printf_t)0x0431EE0;
#else
static FILE *f = NULL;
static int Com_Printf(const char *format, ...) {
if (f == NULL) {
f = fopen("libcod.txt", "a+");
//fclose(f);
}
fprintf(f, "%s", format);
fflush(f);
}
#endif
#else
static Com_Printf_t Com_Printf = (Com_Printf_t)NULL;
#warning Com_Printf_t Com_Printf = NULL;
#endif