inline BOOL WINAPI Load() { TCHAR tzPath[MAX_PATH]; TCHAR tzTemp[MAX_PATH * 2]; GetSystemDirectory(tzPath, MAX_PATH); lstrcat(tzPath, TEXT("\\msimg32.dll")); hModule = LoadLibrary(tzPath); if (hModule == NULL) { wsprintf(tzTemp, TEXT("Failed to load %s\n"), tzPath); OutputDebugText(tzTemp); ExitProcess(1); } GetModuleFileName(NULL, tzTemp, sizeof(tzTemp)); wsprintf(tzTemp, TEXT("%s is loading msimg32.dll\n"), tzTemp); OutputDebugText(tzTemp); vSetDdrawflagAddr = GetFuncAddress("vSetDdrawflag"); AlphaBlendAddr = GetFuncAddress("AlphaBlend"); DllInitializeAddr = GetFuncAddress("DllInitialize"); GradientFillAddr = GetFuncAddress("GradientFill"); TransparentBltAddr = GetFuncAddress("TransparentBlt"); return TRUE; }
Bool FASTCALL InitFunctionBaseUser32(SFunctionBaseUser32 *f, SFunctionBaseKernel32 *k) { if (!k || !k->GetModuleHandleExW || !k->LoadLibraryExA) return False; HMODULE hUser32; hUser32 = k->LoadStayedLibraryA("USER32.dll", k); GetFuncAddress(f->MessageBoxA, hUser32, "MessageBoxA"); GetFuncAddress(f->MessageBoxW, hUser32, "MessageBoxW"); GetFuncAddress(f->GetMessageA, hUser32, "GetMessageA"); GetFuncAddress(f->GetMessageW, hUser32, "GetMessageW"); GetFuncAddress(f->PeekMessageA, hUser32, "PeekMessageA"); GetFuncAddress(f->PeekMessageW, hUser32, "PeekMessageW"); GetFuncAddress(f->wsprintfA, hUser32, "wsprintfA"); GetFuncAddress(f->wsprintfW, hUser32, "wsprintfW"); GetFuncAddress(f->GetKeyState, hUser32, "GetKeyState"); GetFuncAddress(f->GetAsyncKeyState, hUser32, "GetAsyncKeyState"); return True; }
Bool FASTCALL InitFunctionBaseGdi32(SFunctionBaseGdi32 *f, SFunctionBaseKernel32 *k) { if (!k || !k->GetModuleHandleExW || !k->LoadLibraryExA) return False; HMODULE hGdi32; hGdi32 = k->LoadStayedLibraryA("GDI32.dll", k); GetFuncAddress(f->GetTextMetricsA, hGdi32, "GetTextMetricsA"); GetFuncAddress(f->GetTextMetricsW, hGdi32, "GetTextMetricsW"); GetFuncAddress(f->SelectObject, hGdi32, "SelectObject"); GetFuncAddress(f->CreateFontIndirectA, hGdi32, "CreateFontIndirectA"); GetFuncAddress(f->CreateFontIndirectW, hGdi32, "CreateFontIndirectW"); GetFuncAddress(f->GetGlyphOutlineW, hGdi32, "GetGlyphOutlineW"); return True; }
Void Init() { #if defined(NULL_IAT) if (!InitFunction(&g_func)) DebugException(); #endif CMem::CreateGlobalHeap(); // AddVectoredExceptionHandler(True, VectoredHandler); INTEL_STATIC SPatch p[] = { { 0xB8, 1, 0x3B98C }, // 验证 // { 0x24EB, 2, 0x4B14F }, // 边界 // { 0xD5EB, 2, 0x4B17E }, // 边界 { 0xEB, 1, 0x4B14F }, // 边界 { 0xEB, 1, 0x4B17E }, // 边界 { 0xEB, 1, 0x483D1 }, // 边界 { 0xEB, 1, 0x4AADA }, // 边界 { 0xEB, 1, 0x4AB12 }, // 边界 { SWAP2('【'), 4, 0x49C7B }, { SWAP2('【'), 4, 0x49CA0 }, { SWAP2('】'), 4, 0x49EF6 }, { SWAP2('】'), 4, 0x49F1B }, #if defined (MY_DEBUG) { (UInt32)MyCreateFontIndirectA, 4, 0x5B044 }, { (UInt32)MyGetGlyphOutlineA, 4, 0x5B04C }, #endif }; INTEL_STATIC SFuncPatch f[] = { { CALL, 0x2F2E1, DecodeImage, 0x00 }, { CALL, 0x23EAA, MylstrcmpiA, 0x01 }, // { CALL, 0x2F065, MylstrcmpA, 0x01 }, { CALL, 0x43904, GetSeSize, 0x00 }, { CALL, 0x4392D, ReadSe, 0x00 }, }; WChar szPath[MAX_PATH]; DWORD i; #if defined (MY_DEBUG) PatchMemory(p, countof(p), f, countof(f), MYAPI(GetModuleHandleW)(0)); #else PatchMemoryNoVP(p, countof(p), f, countof(f), MYAPI(GetModuleHandleW)(0)); #endif #if defined(NULL_IAT) HMODULE hVorbisfile = g_func.LoadStayedLibraryA("vorbisfile.dll", &g_func); #else HMODULE hVorbisfile = LoadLibraryExW(L"vorbisfile.dll", NULL, 0); #endif GetFuncAddress(vorbis_func.ov_clear, hVorbisfile, "ov_clear"); GetFuncAddress(vorbis_func.ov_open_callbacks, hVorbisfile, "ov_open_callbacks"); GetFuncAddress(vorbis_func.ov_test_callbacks, hVorbisfile, "ov_test_callbacks"); GetFuncAddress(vorbis_func.ov_pcm_seek, hVorbisfile, "ov_pcm_seek"); GetFuncAddress(vorbis_func.ov_pcm_total, hVorbisfile, "ov_pcm_total"); GetFuncAddress(vorbis_func.ov_read, hVorbisfile, "ov_read"); GetFuncAddress(vorbis_func.ov_time_total, hVorbisfile, "ov_time_total"); i = MYAPI(GetModuleFileNameW)(NULL, szPath, countof(szPath)); while (szPath[--i] != '\\'); ++i; *(PULONG64)&szPath[i] = TAG4W('save'); szPath[i + 4] = 0; MYAPI(CreateDirectoryW)(szPath, NULL); #if defined(USE_CACHE) g_ImageCache.Init(); #endif }
Bool FASTCALL InitFunctionBaseKernel32(SFunctionBaseKernel32 *f) { if (!f) return False; HMODULE hKernel32 = GetKernel32Handle(); f->LoadStayedLibraryA = LoadStayedLibraryA; GetFuncAddress(f->CreateMutexA, hKernel32, "CreateMutexA"); GetFuncAddress(f->CreateMutexW, hKernel32, "CreateMutexW"); GetFuncAddress(f->GlobalAlloc, hKernel32, "GlobalAlloc"); GetFuncAddress(f->GetFileAttributesA, hKernel32, "GetFileAttributesA"); GetFuncAddress(f->GetFileAttributesW, hKernel32, "GetFileAttributesW"); GetFuncAddress(f->CreateFileA, hKernel32, "CreateFileA"); GetFuncAddress(f->CreateFileW, hKernel32, "CreateFileW"); GetFuncAddress(f->SetFilePointer, hKernel32, "SetFilePointer"); GetFuncAddress(f->ReadFile, hKernel32, "ReadFile"); GetFuncAddress(f->CloseHandle, hKernel32, "CloseHandle"); GetFuncAddress(f->GetModuleHandleA, hKernel32, "GetModuleHandleA"); GetFuncAddress(f->GetModuleHandleW, hKernel32, "GetModuleHandleW"); GetFuncAddress(f->GetModuleHandleExA, hKernel32, "GetModuleHandleExA"); GetFuncAddress(f->GetModuleHandleExW, hKernel32, "GetModuleHandleExW"); GetFuncAddress(f->GetModuleFileNameA, hKernel32, "GetModuleFileNameA"); GetFuncAddress(f->GetModuleFileNameW, hKernel32, "GetModuleFileNameW"); GetFuncAddress(f->MultiByteToWideChar, hKernel32, "MultiByteToWideChar"); GetFuncAddress(f->GetLastError, hKernel32, "GetLastError"); GetFuncAddress(f->CreateDirectoryA, hKernel32, "CreateDirectoryA"); GetFuncAddress(f->CreateDirectoryW, hKernel32, "CreateDirectoryW"); GetFuncAddress(f->lstrcpyA, hKernel32, "lstrcpyA"); GetFuncAddress(f->lstrcpyW, hKernel32, "lstrcpyW"); GetFuncAddress(f->lstrlenA, hKernel32, "lStrLengthA"); GetFuncAddress(f->lstrlenW, hKernel32, "lstrlenW"); GetFuncAddress(f->lstrcmpA, hKernel32, "lstrcmpA"); GetFuncAddress(f->lstrcmpW, hKernel32, "lstrcmpW"); GetFuncAddress(f->lstrcmpiA, hKernel32, "lstrcmpiA"); GetFuncAddress(f->lstrcmpiW, hKernel32, "lstrcmpiW"); GetFuncAddress(f->GetProcessHeap, hKernel32, "GetProcessHeap"); GetFuncAddress(f->HeapCreate, hKernel32, "HeapCreate"); GetFuncAddress(f->HeapDestroy, hKernel32, "HeapDestroy"); GetFuncAddress(f->HeapAlloc, hKernel32, "HeapAlloc"); GetFuncAddress(f->HeapReAlloc, hKernel32, "HeapReAlloc"); GetFuncAddress(f->HeapFree, hKernel32, "HeapFree"); GetFuncAddress(f->Sleep, hKernel32, "Sleep"); GetFuncAddress(f->InitializeCriticalSection, hKernel32, "InitializeCriticalSection"); GetFuncAddress(f->EnterCriticalSection, hKernel32, "EnterCriticalSection"); GetFuncAddress(f->LeaveCriticalSection, hKernel32, "LeaveCriticalSection"); GetFuncAddress(f->DeleteCriticalSection, hKernel32, "DeleteCriticalSection"); GetFuncAddress(f->CreateEventA, hKernel32, "CreateEventA"); GetFuncAddress(f->CreateEventW, hKernel32, "CreateEventW"); GetFuncAddress(f->SetEvent, hKernel32, "SetEvent"); GetFuncAddress(f->ResetEvent, hKernel32, "ResetEvent"); GetFuncAddress(f->WaitForSingleObject, hKernel32, "WaitForSingleObject"); GetFuncAddress(f->WaitForSingleObjectEx, hKernel32, "WaitForSingleObjectEx"); GetFuncAddress(f->TerminateThread, hKernel32, "TerminateThread"); // GetFuncAddress(f->InterlockedIncrement, hKernel32, "InterlockedIncrement"); // GetFuncAddress(f->InterlockedDecrement, hKernel32, "InterlockedDecrement"); // GetFuncAddress(f->InterlockedExchange, hKernel32, "InterlockedExchange"); // GetFuncAddress(f->InterlockedCompareExchange, hKernel32, "InterlockedCompareExchange"); GetFuncAddress(f->LoadLibraryW, hKernel32, "LoadLibraryW"); GetFuncAddress(f->LoadLibraryA, hKernel32, "LoadLibraryA"); GetFuncAddress(f->LoadLibraryW, hKernel32, "LoadLibraryW"); GetFuncAddress(f->LoadLibraryExA, hKernel32, "LoadLibraryExA"); GetFuncAddress(f->LoadLibraryExW, hKernel32, "LoadLibraryExW"); GetFuncAddress(f->FreeLibrary, hKernel32, "FreeLibrary"); GetFuncAddress(f->VirtualProtectEx, hKernel32, "VirtualProtectEx"); GetFuncAddress(f->FlushInstructionCache, hKernel32, "FlushInstructionCache"); return True; }
Bool FASTCALL InitFunction(SPianoFunction *f) { if (!InitFunctionBaseKernel32(f) || !InitFunctionBaseGdi32(f, f) || #if defined(USE_CACHE) !InitFunctionBaseUser32(f, f) || #endif 0 ) { return False; } HMODULE hUCIDec = f->LoadStayedLibraryA("ucidec.dll", f); HMODULE hUCADec = f->LoadStayedLibraryA("ucadec.dll", f); HMODULE hBASS = f->LoadStayedLibraryA("bass.dll", f); HMODULE hBASSAAC = f->LoadStayedLibraryA("bass_aac.dll", f); // ucidec.dll GetFuncAddress(f->UCIDecode, hUCIDec, "UCIDecode"); GetFuncAddress(f->UCIFree, hUCIDec, "UCIFree"); // ucadec.dll GetFuncAddress(f->UCADecode, hUCADec, "UCADecode"); GetFuncAddress(f->UCADecode2, hUCADec, "UCADecode2"); GetFuncAddress(f->UCAFree, hUCADec, "UCAFree"); // bass_aac.dll GetFuncAddress(f->BASS_MP4_StreamCreateFile, hBASSAAC, "BASS_MP4_StreamCreateFile"); // bass.dll GetFuncAddress(f->BASS_SetConfig, hBASS, "BASS_SetConfig"); GetFuncAddress(f->BASS_ChannelGetLength, hBASS, "BASS_ChannelGetLength"); GetFuncAddress(f->BASS_StreamFree, hBASS, "BASS_StreamFree"); GetFuncAddress(f->BASS_ChannelBytes2Seconds, hBASS, "BASS_ChannelBytes2Seconds"); GetFuncAddress(f->BASS_ChannelSetPosition, hBASS, "BASS_ChannelSetPosition"); GetFuncAddress(f->BASS_ChannelGetData, hBASS, "BASS_ChannelGetData"); GetFuncAddress(f->BASS_Free, hBASS, "BASS_Free"); GetFuncAddress(f->BASS_ChannelGetInfo, hBASS, "BASS_ChannelGetInfo"); GetFuncAddress(f->BASS_ChannelGetPosition, hBASS, "BASS_ChannelGetPosition"); GetFuncAddress(f->BASS_Init, hBASS, "BASS_Init"); GetFuncAddress(f->BASS_ChannelPause, hBASS, "BASS_ChannelPause"); GetFuncAddress(f->BASS_ChannelPlay, hBASS, "BASS_ChannelPlay"); GetFuncAddress(f->BASS_ChannelStop, hBASS, "BASS_ChannelStop"); GetFuncAddress(f->BASS_ChannelIsActive, hBASS, "BASS_ChannelIsActive"); GetFuncAddress(f->BASS_ErrorGetCode, hBASS, "BASS_ErrorGetCode"); GetFuncAddress(f->BASS_ChannelUpdate, hBASS, "BASS_ChannelUpdate"); GetFuncAddress(f->BASS_ChannelGetAttribute, hBASS, "BASS_ChannelGetAttribute"); GetFuncAddress(f->BASS_ChannelSlideAttribute, hBASS, "BASS_ChannelSlideAttribute"); GetFuncAddress(f->BASS_ChannelSetAttribute, hBASS, "BASS_ChannelSetAttribute"); /* // vorbisfile.dll GetFuncAddress(f->ov_clear, hVorbisfile, "ov_clear"); GetFuncAddress(f->ov_open_callbacks, hVorbisfile, "ov_open_callbacks"); GetFuncAddress(f->ov_test_callbacks, hVorbisfile, "ov_test_callbacks"); GetFuncAddress(f->ov_pcm_seek, hVorbisfile, "ov_pcm_seek"); GetFuncAddress(f->ov_pcm_total, hVorbisfile, "ov_pcm_total"); GetFuncAddress(f->ov_read, hVorbisfile, "ov_read"); GetFuncAddress(f->ov_time_total, hVorbisfile, "ov_time_total"); */ return True; }
// Create rendering window. // Call browser: Core.cpp:EmuThread() > main.cpp:Video_Initialize() bool cInterfaceGLX::Create(void *window_handle) { dpy = XOpenDisplay(nullptr); int screen = DefaultScreen(dpy); // checking glx version int glxMajorVersion, glxMinorVersion; glXQueryVersion(dpy, &glxMajorVersion, &glxMinorVersion); if (glxMajorVersion < 1 || (glxMajorVersion == 1 && glxMinorVersion < 4)) { ERROR_LOG(VIDEO, "glX-Version %d.%d detected, but need at least 1.4", glxMajorVersion, glxMinorVersion); return false; } // loading core context creation function glXCreateContextAttribs = (PFNGLXCREATECONTEXTATTRIBSPROC)GetFuncAddress("glXCreateContextAttribsARB"); if (!glXCreateContextAttribs) { ERROR_LOG(VIDEO, "glXCreateContextAttribsARB not found, do you support GLX_ARB_create_context?"); return false; } // choosing framebuffer int visual_attribs[] = { GLX_X_RENDERABLE , True, GLX_DRAWABLE_TYPE , GLX_WINDOW_BIT, GLX_X_VISUAL_TYPE , GLX_TRUE_COLOR, GLX_RED_SIZE , 8, GLX_GREEN_SIZE , 8, GLX_BLUE_SIZE , 8, GLX_DEPTH_SIZE , 0, GLX_STENCIL_SIZE , 0, GLX_DOUBLEBUFFER , True, None }; int fbcount = 0; GLXFBConfig* fbc = glXChooseFBConfig(dpy, screen, visual_attribs, &fbcount); if (!fbc || !fbcount) { ERROR_LOG(VIDEO, "Failed to retrieve a framebuffer config"); return false; } fbconfig = *fbc; XFree(fbc); // Get an appropriate visual XVisualInfo* vi = glXGetVisualFromFBConfig(dpy, fbconfig); // Create a GLX context. // We try to get a 3.3 core profile, else we try it with anything we get. int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 3, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, None }; s_glxError = false; XErrorHandler oldHandler = XSetErrorHandler(&ctxErrorHandler); ctx = glXCreateContextAttribs(dpy, fbconfig, 0, True, context_attribs); XSync(dpy, False); if (!ctx || s_glxError) { int context_attribs_legacy[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 1, GLX_CONTEXT_MINOR_VERSION_ARB, 0, None }; s_glxError = false; ctx = glXCreateContextAttribs(dpy, fbconfig, 0, True, context_attribs_legacy); XSync(dpy, False); if (!ctx || s_glxError) { ERROR_LOG(VIDEO, "Unable to create GL context."); return false; } } XSetErrorHandler(oldHandler); XWindow.Initialize(dpy); Window parent = (Window)window_handle; XWindowAttributes attribs; if (!XGetWindowAttributes(dpy, parent, &attribs)) { ERROR_LOG(VIDEO, "Window attribute retrieval failed"); return false; } s_backbuffer_width = attribs.width; s_backbuffer_height = attribs.height; win = XWindow.CreateXWindow(parent, vi); XFree(vi); return true; }
bool Interfaces::Init( CreateInterfaceFn pfnAppSystem ) { this->pfnAppSystem = pfnAppSystem; // Grab module handles hmEngine = GetHandleOfModule( "engine" ); #ifndef _LINUX hmTier0 = GetHandleOfModule( "tier0" ); #else hmTier0 = GetHandleOfModule("libtier0"); #endif if ( !hmEngine || !hmTier0 ) return false; // Grab engine CreateInterfaceFn // Note that we can access all interfaces (except client.dll/server.dll ones) through the pfnAppSystem function. pfnEngine = (CreateInterfaceFn) GetFuncAddress( hmEngine, "CreateInterface" ); if ( !pfnEngine ) return false; // Grab the interfaces pEngine = (IVEngineClient*) pfnAppSystem( "VEngineClient013", NULL ); pEvents = (IGameEventManager2*) pfnAppSystem( "GAMEEVENTSMANAGER002", NULL ); pVGUI = (IEngineVGui*) pfnAppSystem( "VEngineVGui001", NULL ); pModelInfo = (IVModelInfoClient*) pfnAppSystem( "VModelInfoClient006", NULL ); pModelRender = (IVModelRender*) pfnAppSystem( "VEngineModel016", NULL ); pOverlay = (IVDebugOverlay*) pfnAppSystem( "VDebugOverlay003", NULL ); pRenderView = (IVRenderView*) pfnAppSystem( "VEngineRenderView013", NULL ); pMaterial = (IMaterialSystem*) pfnAppSystem( "VMaterialSystem080", NULL ); pCvar = (ICvar*) pfnAppSystem( "VEngineCvar004", NULL ); pSurface = (ISurface*) pfnAppSystem( "VGUI_Surface030", NULL ); // Grab client module handle #ifndef _LINUX hmClient = GetHandleOfModule( "client" ); #else const char* szGameDir = pEngine->GetGameDirectory(); char szClientBinaryPath[FILENAME_MAX]; snprintf(szClientBinaryPath, sizeof(szClientBinaryPath), "%s/bin/client.so", szGameDir); hmClient = dlopen(szClientBinaryPath, RTLD_NOLOAD); #endif if(!hmClient) return false; // Grab client CreateInterfaceFn pfnClient = (CreateInterfaceFn) GetFuncAddress( hmClient, "CreateInterface" ); if(!pfnClient) return false; pClient = (IBaseClientDLL*) pfnClient( "VClient017", NULL ); pEntityList = (IClientEntityList*) pfnClient( "VClientEntityList003", NULL ); #ifndef _LINUX if ( char* p = (char*)SigScan( hmClient, "\xA1\x00\x00\x00\x00\x85\xC0\x74\x06\x05", "\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF" ) ) #else if ( char* p = (char*)SigScan( (void*)pfnClient, "\xA1\x00\x00\x00\x00\x55\x89\xE5\x85\xC0\x74\x0C", "\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF" ) ) #endif { pfnGameResources = (GameResourcesFn)p; ppGameRes = *(TFPlayerResource***)( p+1 ); } #ifndef _LINUX if ( char* p = (char*)SigScan( hmClient, "\x55" "\x8B\xEC" "\xE8\x00\x00\x00\x00" "\x85\xC0" "\x75\x06" "\x32\xC0", "\xFF" "\xFF\xFF" "\xFF\x00\x00\x00\x00" "\xFF\xFF" "\xFF\xFF" "\xFF\xFF" ) ) { // Signature ends up in IGameResources::IsLocalPlayer() pfnGetLocalPlayer = reinterpret_cast<GetLocalPlayerFn>( *(unsigned int*)( p+4 ) + (unsigned int)p + 0x8 ); } #else if ( char* p = (char*)SigScan( (void*)pfnClient, "\x55" "\x89\xE5" "\x83\xEC\x18" "\xE8\x00\x00\x00\x00" "\x89\xC2" "\x31\xC0" "\x85\xD2" "\x74\x11", "\xFF" "\xFF\xFF" "\xFF\xFF\xFF" "\xFF\x00\x00\x00\x00" "\xFF\xFF" "\xFF\xFF" "\xFF\xFF" "\xFF\xFF") ) { // Signature ends up in IGameResources::IsLocalPlayer() pfnGetLocalPlayer = reinterpret_cast<GetLocalPlayerFn>( *(unsigned int*)( p+7 ) + (unsigned int)p + 0xB ); } #endif // FIXME! Test all the above for NULL ptrs... return true; }