/////////////////////////////////////////////////////////////////////////////// #define WIN32_LEAN_AND_MEAN #include #define PLUGIN_EXPORTS #include "test.h" #define SYS_PLATFORM_WIN32_PLUGIN #include extern int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ); int plugin_width; int plugin_height; const char *plugin_ServerName = 0; const char *plugin_Path = 0; const char *plugin_PageName = 0; const char *plugin_Src = 0; const char *plugin_Params = 0; HINSTANCE plugin_instance = 0; CReadHookModule *plugin_readhook = 0; typedef int (*ReadHookPtr)(char * curFilename, int totalbytes, int totalfiles, int percentcomplete, void *userPtr ); HWND hWND = NULL; extern HWND hWndMain; DWORD WINAPI EngineThreadFunction( LPVOID lpParameter // thread data ) { if( plugin_ServerName != 0 ) { if( strlen(plugin_ServerName) > 0 ) // webserver { llfile_current_stream = llfile_OpenStream(LLFILE_STREAM_HTTP,plugin_ServerName); if( llfile_current_stream == (llfile_eSTREAM)0 ) { MsgBox("l3lib: unable to connect to %d", plugin_ServerName); } if( plugin_Path ){ if( strlen(plugin_Path) > 0 ) llfile_IoCtlStream(llfile_current_stream,"BASEPATH",(void*)plugin_Path); } } } // Jedes Plugin bekommt ein ReadHookModule plugin_readhook = new CReadHookModule( 15000, 0, 0); llfile_PushModule(llfile_current_stream,plugin_readhook,HEAD); int l = 0; if( plugin_Path ) l += strlen(plugin_Path); if( plugin_Src ) l += strlen(plugin_Src); if( plugin_Params ) l += strlen(plugin_Params); l += 2; char * Arg = (char*)malloc(l); strcpy(Arg,plugin_Path); strcat(Arg,plugin_Src); strcat(Arg," "); strcat(Arg,plugin_Params); try { WinMain( plugin_instance, NULL, Arg, 0 ); } catch(...) { DebugOutLn("Exception catched, winmain"); } /* int xpos =0; int ypos =0; llgfx_SetDisplayMode(plugin_width,plugin_height,32,0,0); llirq_ResetTime(); while(osmain_endgame==false){ float delta = llirq_GetDeltaTime(); llgfx_DrawText("l3lib v1.0 - August 2006, Win32 PLUGIN Driver",BLIT_SRC_CKEY); llgfx_FlipScreen(0); llsound_Update(delta); llinput_Update(); } */ return 0; } HANDLE enginethreadhandle = 0; DWORD engineThreadId = 0; void StartEngine(HWND mainframewindow) { // llgfx_Init(mainframewindow); // llsound_Init(mainframewindow); // llinput_Init(mainframewindow); hWndMain = mainframewindow; enginethreadhandle = (HANDLE) CreateThread( 0, 0, &EngineThreadFunction, 0, 0, &engineThreadId ); } /* ** DLL Init ** ** */ BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls((HINSTANCE)hModule); plugin_instance = (HINSTANCE)hModule; DebugOutLn("DllMain ProcessAttach hInstance=%x\n", hModule); break; case DLL_THREAD_ATTACH: DebugOutLn("DllMain ThreadAttach %x\n", hModule ); break; case DLL_THREAD_DETACH: DebugOutLn("DllMain ThreadDetach %x\n", hModule ); break; case DLL_PROCESS_DETACH: DebugOutLn("DllMain ProcessDetach %x\n", hModule ); if( enginethreadhandle > 0 ) { osmain_endgame = true; // warten auf frame ende DWORD rc = WaitForSingleObject(enginethreadhandle,1000); if( rc == WAIT_TIMEOUT ) { // mehr als 100ms sollte ein frame nicht dauern bis // auf osmain_endgame reagiert wird TerminateThread(enginethreadhandle,0); } CloseHandle(enginethreadhandle); enginethreadhandle = NULL; plugin_instance = NULL; } break; } return TRUE; } PLUGIN_API int StartGame( HWND windowhandle, int width, int height, const char * ServerName, // domain/ip bzw "" wenn lokal const char * Path, // Pfad zur htmlseite const char * PageName, // htmlseite const char * Src, // optional const char * Params) // optional { plugin_width = width; plugin_height = height; plugin_ServerName = ServerName; plugin_Path = Path; plugin_PageName = PageName; plugin_Src = Src; plugin_Params = Params; /* localtest plugin_ServerName = "levelone.alfahosting.org"; plugin_Path = "/test/nebulastars/"; plugin_PageName = "testforff.html"; plugin_Src = "test.dll"; */ StartEngine(windowhandle); return 0; } PLUGIN_API int StopGame( HWND windowhandle ) { if( enginethreadhandle > 0 ) { osmain_endgame = true; // warten auf frame ende DWORD rc = WaitForSingleObject(enginethreadhandle,200); if( rc == WAIT_TIMEOUT ) { // mehr als 100ms sollte ein frame nicht dauern bis // auf osmain_endgame reagiert wird TerminateThread(enginethreadhandle,0); } CloseHandle(enginethreadhandle); enginethreadhandle = NULL; } return 0; }