diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ee6391..725d845 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -214,7 +214,7 @@ elseif( COMPILER_MSVC ) endif() if ( PLATFORM_LINUX ) - add_compile_definitions(linux __linux__) + add_compile_definitions(linux __linux__ POSIX) endif() #----------------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d3e62b5..e7e2de4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,6 +28,8 @@ add_sources( wpnmod_main.cpp wpnmod_memory.cpp wpnmod_memory.h + wpnmod_memory_engine.cpp + wpnmod_memory_gamedll.cpp wpnmod_natives.cpp wpnmod_parse.cpp wpnmod_parse.h diff --git a/src/wpnmod_memory.cpp b/src/wpnmod_memory.cpp index 1f4c989..30a8df6 100644 --- a/src/wpnmod_memory.cpp +++ b/src/wpnmod_memory.cpp @@ -90,971 +90,62 @@ bool CMemory::Init(void) m_bSuccess = true; - Parse_GetDispatch(); - Parse_CallGameEntity(); - Parse_WorldPrecache(); - Parse_InfoArrays(); - Parse_ClearMultiDamage(); - Parse_ApplyMultiDamage(); - Parse_GiveNamedItem(); - Parse_SetAnimation(); - Parse_SubRemove(); - Parse_FallThink(); - Parse_AmmoSpawn(); - Parse_ItemSpawn(); - - if (!m_bSuccess) - { - UnsetHooks(); - } - else - { - WPNMOD_LOG(" Memory initialization ended.\n"); - } - - return m_bSuccess; -} - -void CMemory::UnsetHooks(void) -{ - UnsetHook(&g_fh_GiveNamedItem); - UnsetHook(&g_fh_FallThink); - UnsetHook(&g_fh_AmmoSpawn); - UnsetHook(&g_fh_ItemSpawn); - UnsetHook(&g_fh_GetDispatch); - UnsetHook(&g_fh_CallGameEntity); - UnsetHook(&g_fh_WorldPrecache); -} - -void CMemory::Parse_ClearMultiDamage(void) -{ - char funcname[] = "ClearMultiDamage (gamedll)"; - -#ifdef __linux__ - - size_t pAdress = FindAdressInDLL(&m_GameDllModule, "ClearMultiDamage__Fv"); - - if (!pAdress) - { - m_bIsNewGCC = true; - pAdress = FindAdressInDLL(&m_GameDllModule, "_Z16ClearMultiDamagev"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); - m_bSuccess = false; - return; - } - - WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); - -#else - size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?ClearMultiDamage@@YAXXZ"); - - if (pAdress) - { - m_pClearMultiDamage = (void *)pAdress; - return; - } - - pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?SuperBounceTouch@CSqueakGrenade@@AAEXPAVCBaseEntity@@@Z"); - - char mask[] = "x?????x?????x"; - unsigned char pattern[] = "\x3B\x00\x00\x00\x00\x00\x0F\x00\x00\x00\x00\x00\xE8"; - size_t BytesOffset = 13; - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); - m_bSuccess = false; - return; - } - - pAdress = ParseFunc(pAdress, pAdress + 300, funcname, pattern, mask, BytesOffset); - - if (!pAdress) - { - m_bSuccess = false; - return; - } - -#endif - - m_pClearMultiDamage = (void*)pAdress; -} - -void CMemory::Parse_ApplyMultiDamage(void) -{ - char funcname[] = "ApplyMultiDamage (gamedll)"; - -#ifdef __linux__ - - size_t pAdress = FindAdressInDLL(&m_GameDllModule, "ApplyMultiDamage__FP9entvars_sT0"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(&m_GameDllModule, "_Z16ApplyMultiDamageP9entvars_sS0_"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); - m_bSuccess = false; - return; - } - - WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); - -#else - - size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?ApplyMultiDamage@@YAXPAUentvars_s@@0@Z"); - - if (pAdress) - { - m_pApplyMultiDamage = (void *)pAdress; - return; - } - - pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?SuperBounceTouch@CSqueakGrenade@@AAEXPAVCBaseEntity@@@Z"); - - char mask[] = "xxx????x"; - unsigned char pattern[] = "\x50\x50\xE8\x00\x00\x00\x00\x8B"; - size_t BytesOffset = 3; - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); - m_bSuccess = false; - return; - } - - pAdress = ParseFunc(pAdress, pAdress + 700, funcname, pattern, mask, BytesOffset); - - if (!pAdress) - { - m_bSuccess = false; - return; - } - -#endif - - m_pApplyMultiDamage = (void*)pAdress; -} - -void CMemory::Parse_GiveNamedItem(void) -{ - char funcname[] = "CBasePlayer::GiveNamedItem (gamedll)"; - -#ifdef __linux__ - - size_t pAdress = FindAdressInDLL(&m_GameDllModule, "GiveNamedItem__11CBasePlayerPCc"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN11CBasePlayer13GiveNamedItemEPKc"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); - m_bSuccess = false; - return; - } - - WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); - -#else - - size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?GiveNamedItem@CBasePlayer@@QAEXPBD@Z"); - - if (!pAdress) - { - char string[] = "weapon_crowbar"; - char mask[] = "xxxxxx?x"; - unsigned char pattern[] = "\x68\x00\x00\x00\x00\x8B\x00\xE8"; - size_t BytesOffset = 8; - - pAdress = ParseFunc(m_start_gamedll, m_end_gamedll, funcname, string, pattern, mask, BytesOffset); - - if (!pAdress) - { - m_bSuccess = false; - return; - } - } - -#endif - - g_fh_GiveNamedItem.address = (void*)pAdress; - - if (!CreateFunctionHook(&g_fh_GiveNamedItem)) - { - WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); - m_bSuccess = false; - return; - } - - SetHook(&g_fh_GiveNamedItem); -} - -size_t Parse_StringInModule(module *lib, unsigned char* pattern, const char *string) -{ - int i = 0; - unsigned char *ptr = &pattern[0]; - while (*(ptr++)) - { - //++ptr; - ++i; - } - -// printf2("!!!!!!!!!!!!!!!! Parse_StringInModule %d\n", i); - - return NULL; -} - -void CMemory::Parse_SetAnimation(void) -{ - char funcname[] = "CBasePlayer::SetAnimation (gamedll)"; - -#ifdef __linux__ - - size_t pAdress = FindAdressInDLL(&m_GameDllModule, "SetAnimation__11CBasePlayer11PLAYER_ANIM"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN11CBasePlayer12SetAnimationE11PLAYER_ANIM"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); - m_bSuccess = false; - return; - } - - WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); - -#else - - size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?SetAnimation@CBasePlayer@@QAEXW4PLAYER_ANIM@@@Z"); - - if (pAdress) - { - m_pPlayerSetAnimation = (void *)pAdress; - return; - } - - char string[] = "models/v_satchel_radio.mdl"; - char mask[] = "xxxxx"; - unsigned char pattern[] = "\xB9\x00\x00\x00\x00"; - - char mask2[] = "xx?xxx"; - unsigned char pattern2[] = "\x8B\x4E\x00\x6A\x05\xE8"; - size_t BytesOffset = 6; - - int count = 0; - - size_t pCurrent = NULL; - size_t pCandidate = NULL; - - pCurrent = FindStringInDLL(m_start_gamedll, m_end_gamedll, string); - - //Parse_StringInModule(GetModule_GameDll(), pattern, string); - - while (pCurrent) - { - *(size_t*)(pattern + 1) = (size_t)pCurrent; - - if ((pCandidate = FindAdressInDLL(m_start_gamedll, m_end_gamedll, pattern, mask)) != NULL) - { - count++; - pAdress = pCandidate; - } - - pCurrent = FindStringInDLL(pCurrent + 1, m_end_gamedll, string); - } - - if (!count) - { - WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); - m_bSuccess = false; - return; - } - else if (count > 1) - { - WPNMOD_LOG(" Error: \"%s\" not found [1]\n", funcname); - m_bSuccess = false; - return; - } - - pAdress = ParseFunc(pAdress, pAdress + 150, funcname, pattern2, mask2, BytesOffset); - - if (!pAdress) - { - m_bSuccess = false; - return; - } - -#endif - - m_pPlayerSetAnimation = (void*)pAdress; -} - -void CMemory::Parse_SubRemove(void) -{ - char funcname[] = "CBaseEntity::SUB_Remove (gamedll)"; - -#ifdef WIN32 - - void* pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "?SUB_Remove@CBaseEntity@@QAEXXZ"); - -#else - - void* pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "SUB_Remove__11CBaseEntity"); - - if (!pAdress) - { - pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "_ZN11CBaseEntity10SUB_RemoveEv"); - } - -#endif - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); - m_bSuccess = false; - return; - } - - m_pSubRemove = pAdress; - - WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); -} - -void CMemory::Parse_FallThink(void) -{ - char funcname[] = "CBasePlayerItem::FallThink (gamedll)"; - -#ifdef WIN32 - - void* pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "?FallThink@CBasePlayerItem@@QAEXXZ"); - -#else - - void* pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "FallThink__15CBasePlayerItem"); - - if (!pAdress) - { - pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "_ZN15CBasePlayerItem9FallThinkEv"); - } - -#endif - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); - m_bSuccess = false; - return; - } - - WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); - - g_fh_FallThink.address = (void*)pAdress; - - if (!CreateFunctionHook(&g_fh_FallThink)) - { - WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); - m_bSuccess = false; - return; - } - - SetHook(&g_fh_FallThink); -} - -void CMemory::Parse_AmmoSpawn(void) -{ - char* funcname = "CBasePlayerAmmo::Spawn (gamedll)"; - -#ifdef __linux__ - - size_t pAdress = FindAdressInDLL(&m_GameDllModule, "Spawn__15CBasePlayerAmmo"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN15CBasePlayerAmmo5SpawnEv"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); - m_bSuccess = false; - return; - } - -#else - - size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?Spawn@CBasePlayerAmmo@@UAEXXZ"); - - if (!pAdress) - { - int count = 0; - - size_t pAdress = NULL; - size_t pCurrent = NULL; - size_t pCandidate = NULL; - - // - // 68 10 88 0C 10 push offset aModelsW_argren ; "models/w_ARgrenade.mdl" - // - - char string[] = "models/w_ARgrenade.mdl"; - char mask[] = "xxxxxx"; - unsigned char pattern[] = "\x04\x68\x00\x00\x00\x00"; - - pCurrent = FindStringInDLL(m_start_gamedll, m_end_gamedll, string); - - while (pCurrent) - { - *(size_t *)(pattern + 2) = (size_t)pCurrent; - - if ((pCandidate = FindAdressInDLL(m_start_gamedll, m_end_gamedll, pattern, mask))) - { - count++; - pAdress = pCandidate; - } - - pCurrent = FindStringInDLL(pCurrent + 1, m_end_gamedll, string); - } - - if (!count) - { - WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); - m_bSuccess = false; - return; - } - else if (count > 1) - { - WPNMOD_LOG(" Error: \"%s\" not found [1]\n", funcname); - m_bSuccess = false; - return; - } - - size_t start = pAdress; - size_t end = pAdress + 32; - - pAdress = FindAdressInDLL(start, end, (unsigned char *)"\xE9", "x"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(start, end, (unsigned char *)"\xE8", "x"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found [2]\n", funcname); - m_bSuccess = false; - return; - } - - pAdress += 1; - pAdress = *(size_t *)pAdress + pAdress + 4; - } - -#endif - - WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); - - g_fh_AmmoSpawn.address = (void*)pAdress; - - if (!CreateFunctionHook(&g_fh_AmmoSpawn)) - { - WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); - m_bSuccess = false; - return; - } - - SetHook(&g_fh_AmmoSpawn); -} - -void CMemory::Parse_ItemSpawn(void) -{ - char* funcname = "CItem::Spawn (gamedll)"; - -#ifdef __linux__ - - size_t pAdress = FindAdressInDLL(&m_GameDllModule, "Spawn__5CItem"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN5CItem5SpawnEv"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); - m_bSuccess = false; - return; - } - -#else - - size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?Spawn@CItem@@UAEXXZ"); - - if (!pAdress) - { - int count = 0; - - size_t pAdress = NULL; - size_t pCurrent = NULL; - size_t pCandidate = NULL; - - // - // 8B 46 04 mov eax, [esi+4] - // 68 A4 62 0C 10 push offset aModelsW_batter; "models/w_battery.mdl" - // - - char string[] = "models/w_battery.mdl"; - char mask[] = "xxxxxx"; - unsigned char pattern[] = "\x04\x68\x00\x00\x00\x00"; - - pCurrent = FindStringInDLL(m_start_gamedll, m_end_gamedll, string); - - while (pCurrent) - { - *(size_t *)(pattern + 2) = (size_t)pCurrent; - - if ((pCandidate = FindAdressInDLL(m_start_gamedll, m_end_gamedll, pattern, mask))) - { - count++; - pAdress = pCandidate; - } - - pCurrent = FindStringInDLL(pCurrent + 1, m_end_gamedll, string); - } - - if (!count) - { - WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); - m_bSuccess = false; - return; - } - else if (count > 1) - { - WPNMOD_LOG(" Error: \"%s\" not found [1]\n", funcname); - m_bSuccess = false; - return; - } - - size_t start = pAdress; - size_t end = pAdress + 32; - - pAdress = FindAdressInDLL(start, end, (unsigned char *)"\xE9", "x"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(start, end, (unsigned char *)"\xE8", "x"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found [2]\n", funcname); - m_bSuccess = false; - return; - } - - pAdress += 1; - pAdress = *(size_t *)pAdress + pAdress + 4; - } - -#endif - - WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); - - g_fh_ItemSpawn.address = (void*)pAdress; - - if (!CreateFunctionHook(&g_fh_ItemSpawn)) - { - WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); - m_bSuccess = false; - return; - } - - SetHook(&g_fh_ItemSpawn); -} - -void CMemory::Parse_WorldPrecache(void) -{ - char* funcname = "W_Precache (gamedll)"; - -#ifdef __linux__ - - size_t pAdress = FindAdressInDLL(&m_GameDllModule, "W_Precache__Fv"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(&m_GameDllModule, "_Z10W_Precachev"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); - m_bSuccess = false; - return; - } + // Metamod + Parse_CallGameEntity(); -#else + // Engine + FindReHldsApi(); + Parse_GetDispatch(); - size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?W_Precache@@YAXXZ"); + // GameDLL + Parse_WorldPrecache(); + Parse_InfoArrays(); + Parse_ClearMultiDamage(); + Parse_ApplyMultiDamage(); + Parse_GiveNamedItem(); + Parse_SetAnimation(); + Parse_SubRemove(); + Parse_FallThink(); + Parse_AmmoSpawn(); + Parse_ItemSpawn(); - if (!pAdress) + if (!m_bSuccess) { - int count = 0; - - size_t pCurrent = NULL; - size_t pCandidate = NULL; - - // 85 C0 test eax, eax - // 75 10 jnz short loc_100EC92C - // 68 0C D4 14 10 push offset aCouldNotCreate; "**COULD NOT CREATE SOUNDENT**\n" - // 6A 01 push 1; _DWORD - // FF 15 DC 15 15 10 call dword_101515DC - // 83 C4 08 add esp, 8 - // E8 7F 03 00 00 call sub_100ECCB0 - // E8 6A FB FD FF call sub_100CC4A0 - // E8 A5 01 FE FF call sub_100CCAE0 - // E8 70 D5 FF FF call sub_100E9EB0 - // E8 3B F6 F2 FF call W_Precache - - char string[] = "**COULD NOT CREATE SOUNDENT**\n"; - char mask[] = "xxxxxx"; - unsigned char pattern[] = "\x10\x68\x00\x00\x00\x00"; - - pCurrent = FindStringInDLL(m_start_gamedll, m_end_gamedll, string); - - while (pCurrent) - { - *(size_t *)(pattern + 2) = (size_t)pCurrent; - - if ((pCandidate = FindAdressInDLL(m_start_gamedll, m_end_gamedll, pattern, mask))) - { - count++; - pAdress = pCandidate; - } - - pCurrent = FindStringInDLL(pCurrent + 1, m_end_gamedll, string); - } - - if (!count) - { - WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); - m_bSuccess = false; - return; - } - else if (count > 1) - { - WPNMOD_LOG(" Error: \"%s\" not found [1]\n", funcname); - m_bSuccess = false; - return; - } - - count = 0; - - size_t end = pAdress + 50; - unsigned char opcode[] = "\xE8"; - - pCurrent = FindAdressInDLL(pAdress + 4, end, opcode, "x"); - - // Find fourth call. - while (pCurrent && count != 4) - { - count++; - pAdress = pCurrent; - pCurrent = FindAdressInDLL(pCurrent + 1, end, opcode, "x"); - } - - if (count != 4) - { - WPNMOD_LOG(" Error: \"%s\" not found [2]\n", funcname); - m_bSuccess = false; - return; - } - - pAdress += 1; - pAdress = *(size_t *)pAdress + pAdress + 4; + UnsetHooks(); } -#endif - - WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); - - g_fh_WorldPrecache.address = m_pWorldPrecache = (void*)pAdress; - - if (!CreateFunctionHook(&g_fh_WorldPrecache)) + else { - WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); - m_bSuccess = false; - return; + WPNMOD_LOG(" Memory initialization ended.\n"); } - SetHook(&g_fh_WorldPrecache); + return m_bSuccess; } -void CMemory::Parse_InfoArrays(void) +void CMemory::UnsetHooks(void) { - // - // Let's find "ItemInfo CBasePlayerItem::ItemInfoArray[MAX_WEAPONS]" in gamedll - // - -#ifdef __linux__ - - size_t pAdress = FindAdressInDLL(&m_GameDllModule, "_15CBasePlayerItem.ItemInfoArray"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN15CBasePlayerItem13ItemInfoArrayE"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"ItemInfoArray (gamedll)\" not found [0]\n"); - WPNMOD_LOG(" Error: \"AmmoInfoArray (gamedll)\" not found [0]\n"); - m_bSuccess = false; - return; - } - - g_Items.m_pItemInfoArray = (ItemInfo*)(pAdress); - -#else - - if (!m_pWorldPrecache) - { - // Nothing to do here! - WPNMOD_LOG(" Error: \"ItemInfoArray (gamedll)\" not found [0]\n"); - WPNMOD_LOG(" Error: \"AmmoInfoArray (gamedll)\" not found [0]\n"); - m_bSuccess = false; - return; - } - - size_t pAdress = FindAdressInDLL(&m_GameDllModule, "?ItemInfoArray@CBasePlayerItem@@2PAUItemInfo@@A"); - - if (pAdress) - { - g_Items.m_pItemInfoArray = (ItemInfo *)pAdress; - } - else - { - // Win1 - // void W_Precache(void) - // 68 80 05 00 00 push 10110000000b - // 6A 00 push 0 - // 68 28 D8 10 10 push offset ItemInfoArray - // E8 8F 4D 00 00 call sub_1009E5E0 - // 68 00 01 00 00 push 100000000b - // 6A 00 push 0 - // 68 A8 DD 10 10 push offset AmmoInfoArray - - // Win2 - // void W_Precache(void) - // 57 push edi - // B9 60 01 00 00 mov ecx, 160h - // 33 C0 xor eax, eax - // BF 48 15 16 10 mov edi, offset ItemInfoArray - // F3 AB rep stosd - // B9 40 00 00 00 mov ecx, 40h - // BF 40 14 16 10 mov edi, offset AmmoInfoArray - // F3 AB rep stosd - - size_t start = (size_t)m_pWorldPrecache; - size_t end = (size_t)m_pWorldPrecache + 15; - - pAdress = FindAdressInDLL(start, end, (unsigned char *)"\x6A\x00\x68", "xxx"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(start, end, (unsigned char *)"\x33\xC0\xBF", "xxx"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"ItemInfoArray (gamedll)\" not found [1]\n"); - WPNMOD_LOG(" Error: \"AmmoInfoArray (gamedll)\" not found [1]\n"); - m_bSuccess = false; - return; - } - - pAdress += 3; - g_Items.m_pItemInfoArray = (ItemInfo *)*(size_t *)(pAdress); - } - -#endif - - // Success! - WPNMOD_LOG_ONLY(" Found \"ItemInfoArray (gamedll)\" at %p\n", pAdress); - - // - // Now let's find "AmmoInfo CBasePlayerItem::AmmoInfoArray[MAX_AMMO_SLOTS]"; - // - -#ifdef __linux__ - - pAdress = FindAdressInDLL(&m_GameDllModule, "_15CBasePlayerItem.AmmoInfoArray"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN15CBasePlayerItem13AmmoInfoArrayE"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"AmmoInfoArray (gamedll)\" not found [1]\n"); - m_bSuccess = false; - return; - } - - g_Items.m_pAmmoInfoArray = (AmmoInfo*)(pAdress); - -#else - - pAdress = FindAdressInDLL(&m_GameDllModule, "?AmmoInfoArray@CBasePlayerItem@@2PAUAmmoInfo@@A"); - - if (pAdress) - { - g_Items.m_pAmmoInfoArray = (AmmoInfo *)pAdress; - } - else - { - size_t start = pAdress; - size_t end = pAdress + 25; - - pAdress = FindAdressInDLL(start, end, (unsigned char *)"\x6A\x00\x68", "xxx"); - - if (!pAdress) - { - pAdress = FindAdressInDLL(start, end, (unsigned char *)"\xBF", "x"); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"AmmoInfoArray (gamedll)\" not found [2]\n"); - m_bSuccess = false; - return; - } - - unsigned char *bytes = (unsigned char *)&(*(size_t *)pAdress); - - if (bytes[0] == 0x6A) - { - pAdress += 3; - } - else if (bytes[0] == 0xBF) - { - pAdress += 1; - } - - g_Items.m_pAmmoInfoArray = (AmmoInfo *)*(size_t *)(pAdress); - } - -#endif - - // Success! - WPNMOD_LOG_ONLY(" Found \"AmmoInfoArray (gamedll)\" at %p\n", pAdress); + UnsetReHldsHooks(); + UnsetHook(&g_fh_GiveNamedItem); + UnsetHook(&g_fh_FallThink); + UnsetHook(&g_fh_AmmoSpawn); + UnsetHook(&g_fh_ItemSpawn); + UnsetHook(&g_fh_GetDispatch); + UnsetHook(&g_fh_CallGameEntity); + UnsetHook(&g_fh_WorldPrecache); } -void CMemory::Parse_GetDispatch(void) +size_t Parse_StringInModule(module *lib, unsigned char* pattern, const char *string) { - char* funcname = "GetDispatch (engine)"; - -#ifdef __linux__ - - size_t pAdress = FindAdressInDLL(&m_EngineModule, "GetDispatch"); - - if (!pAdress) - { - //pAdress = FindAdressInDLL(&m_GameDllModule, ""); - } - - if (!pAdress) - { - WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); - m_bSuccess = false; - return; - } - -#else - - int count = 0; - - size_t pAdress = NULL; - size_t pCurrent = NULL; - size_t pCandidate = NULL; - - // - // 68 30 B1 E4 01 push offset aGetentityapi2; "GetEntityAPI2" - // E8 09 F7 FF FF call GetDispatch - // - - char string[] = "GetEntityAPI2"; - char mask[] = "xxxxx"; - unsigned char pattern[] = "\x68\x00\x00\x00\x00"; - - pCurrent = FindStringInDLL(m_start_engine, m_end_engine, string); - - while (pCurrent) - { - *(size_t*)(pattern + 1) = (size_t)pCurrent; - - if ((pCandidate = FindAdressInDLL(m_start_engine, m_end_engine, pattern, mask))) - { - count++; - pAdress = pCandidate; - } - - pCurrent = FindStringInDLL(pCurrent + 1, m_end_engine, string); - } - - if (!count) - { - WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); - m_bSuccess = false; - return; - } - else if (count > 1) - { - WPNMOD_LOG(" Error: \"%s\" not found [1]\n", funcname); - m_bSuccess = false; - return; - } - - // Find first call. - size_t end = pAdress + 10; - unsigned char opcode[] = "\xE8"; - - pAdress = FindAdressInDLL(pAdress, end, opcode, "x"); - - if (!pAdress) + int i = 0; + unsigned char *ptr = &pattern[0]; + while (*(ptr++)) { - WPNMOD_LOG(" Error: \"%s\" not found [2]\n", funcname); - m_bSuccess = false; - return; + //++ptr; + ++i; } - pAdress += 1; - pAdress = *(size_t*)pAdress + pAdress + 4; - -#endif - - WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); - - g_fh_GetDispatch.address = (void*)pAdress; - - if (!CreateFunctionHook(&g_fh_GetDispatch)) - { - WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); - m_bSuccess = false; - return; - } +// printf2("!!!!!!!!!!!!!!!! Parse_StringInModule %d\n", i); - SetHook(&g_fh_GetDispatch); + return NULL; } void CMemory::Parse_CallGameEntity(void) @@ -1158,9 +249,6 @@ char* CMemory::GetDllNameByModule(void* base, char* lp, size_t bufSize) return (ptr ? ptr + 1 : lp); } - - - size_t CMemory::ParseFunc(size_t start, size_t end, char* funcname, unsigned char* pattern, char* mask, size_t bytes) { int count = 0; @@ -1237,4 +325,3 @@ size_t CMemory::ParseFunc(size_t start, size_t end, char* funcname, char* string return pAdress; } - diff --git a/src/wpnmod_memory.h b/src/wpnmod_memory.h index e8864a4..063819e 100644 --- a/src/wpnmod_memory.h +++ b/src/wpnmod_memory.h @@ -52,7 +52,7 @@ - +class IRehldsApi; class CMemory { @@ -70,6 +70,8 @@ class CMemory bool m_bSuccess; bool m_bIsNewGCC; + IRehldsApi* m_pRehldsApi = nullptr; + public: CMemory(); @@ -90,11 +92,15 @@ class CMemory void Parse_ApplyMultiDamage(void); void Parse_AmmoSpawn(void); void Parse_ItemSpawn(void); - void Parse_GetDispatch(void); void Parse_CallGameEntity(void); void Parse_WorldPrecache(void); void Parse_InfoArrays(void); + // Engine + void FindReHldsApi(); + void UnsetReHldsHooks(); + void Parse_GetDispatch(void); + void EnableShieldHitboxTracing(void); bool IsNewGCC(void) { return m_bIsNewGCC; }; diff --git a/src/wpnmod_memory_engine.cpp b/src/wpnmod_memory_engine.cpp new file mode 100644 index 0000000..9f57b9b --- /dev/null +++ b/src/wpnmod_memory_engine.cpp @@ -0,0 +1,188 @@ +/* + * Half-Life Weapon Mod + * Copyright (c) 2012 - 2014 AGHL.RU Dev Team + * + * http://aghl.ru/forum/ - Russian Half-Life and Adrenaline Gamer Community + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, the author gives permission to + * link the code of this program with the Half-Life Game Engine ("HL + * Engine") and Modified Game Libraries ("MODs") developed by Valve, + * L.L.C ("Valve"). You must obey the GNU General Public License in all + * respects for all of the code used other than the HL Engine and MODs + * from Valve. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. + * + */ + +#include +#include +#include "wpnmod_memory.h" +#include "wpnmod_hooks.h" +#include "wpnmod_items.h" + +void* WpnMod_GetDispatch(char* pname); + +static DISPATCHFUNCTION ReHldsGetDispatch(IRehldsHook_GetDispatch* pHook, char* pszName) +{ + if (g_Config.IsInited()) + { + auto pDispatch = (DISPATCHFUNCTION)WpnMod_GetDispatch(pszName); + + if (pDispatch) + return pDispatch; + } + + return pHook->callNext(pszName); +} + +void CMemory::FindReHldsApi() +{ + CreateInterfaceFn pfnEngineFactory = Sys_GetFactory((CSysModule*)m_EngineModule.base); + if (!pfnEngineFactory) + return; + + m_pRehldsApi = static_cast(pfnEngineFactory(VREHLDS_HLDS_API_VERSION, nullptr)); + if (!m_pRehldsApi) + return; + + int major = m_pRehldsApi->GetMajorVersion(); + int minor = m_pRehldsApi->GetMinorVersion(); + WPNMOD_LOG(" Found ReHLDS API v%d.%d\n", m_pRehldsApi->GetMajorVersion(), m_pRehldsApi->GetMinorVersion()); + + // Check version + if (major != REHLDS_API_VERSION_MAJOR || minor < REHLDS_API_VERSION_MINOR) + { + WPNMOD_LOG(" Unsupported ReHLDS API version. Minimum: v%d.%d\n", REHLDS_API_VERSION_MAJOR, REHLDS_API_VERSION_MINOR); + m_pRehldsApi = nullptr; + } +} + +void CMemory::UnsetReHldsHooks() +{ + if (m_pRehldsApi) + { + m_pRehldsApi->GetHookchains()->GetDispatch()->unregisterHook(ReHldsGetDispatch); + } +} + +void CMemory::Parse_GetDispatch(void) +{ + char* funcname = "GetDispatch (engine)"; + + if (m_pRehldsApi) + { + // Use ReHLDS hookchain system + m_pRehldsApi->GetHookchains()->GetDispatch()->registerHook(ReHldsGetDispatch); + return; + } + +#ifdef __linux__ + + size_t pAdress = FindAdressInDLL(&m_EngineModule, "GetDispatch"); + + if (!pAdress) + { + //pAdress = FindAdressInDLL(&m_GameDllModule, ""); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); + m_bSuccess = false; + return; + } + +#else + + int count = 0; + + size_t pAdress = NULL; + size_t pCurrent = NULL; + size_t pCandidate = NULL; + + // + // 68 30 B1 E4 01 push offset aGetentityapi2; "GetEntityAPI2" + // E8 09 F7 FF FF call GetDispatch + // + + char string[] = "GetEntityAPI2"; + char mask[] = "xxxxx"; + unsigned char pattern[] = "\x68\x00\x00\x00\x00"; + + pCurrent = FindStringInDLL(m_start_engine, m_end_engine, string); + + while (pCurrent) + { + *(size_t*)(pattern + 1) = (size_t)pCurrent; + + if ((pCandidate = FindAdressInDLL(m_start_engine, m_end_engine, pattern, mask))) + { + count++; + pAdress = pCandidate; + } + + pCurrent = FindStringInDLL(pCurrent + 1, m_end_engine, string); + } + + if (!count) + { + WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); + m_bSuccess = false; + return; + } + else if (count > 1) + { + WPNMOD_LOG(" Error: \"%s\" not found [1]\n", funcname); + m_bSuccess = false; + return; + } + + // Find first call. + size_t end = pAdress + 10; + unsigned char opcode[] = "\xE8"; + + pAdress = FindAdressInDLL(pAdress, end, opcode, "x"); + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found [2]\n", funcname); + m_bSuccess = false; + return; + } + + pAdress += 1; + pAdress = *(size_t*)pAdress + pAdress + 4; + +#endif + + WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); + + g_fh_GetDispatch.address = (void*)pAdress; + + if (!CreateFunctionHook(&g_fh_GetDispatch)) + { + WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); + m_bSuccess = false; + return; + } + + SetHook(&g_fh_GetDispatch); +} + diff --git a/src/wpnmod_memory_gamedll.cpp b/src/wpnmod_memory_gamedll.cpp new file mode 100644 index 0000000..9c0ab60 --- /dev/null +++ b/src/wpnmod_memory_gamedll.cpp @@ -0,0 +1,855 @@ +/* + * Half-Life Weapon Mod + * Copyright (c) 2012 - 2014 AGHL.RU Dev Team + * + * http://aghl.ru/forum/ - Russian Half-Life and Adrenaline Gamer Community + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, the author gives permission to + * link the code of this program with the Half-Life Game Engine ("HL + * Engine") and Modified Game Libraries ("MODs") developed by Valve, + * L.L.C ("Valve"). You must obey the GNU General Public License in all + * respects for all of the code used other than the HL Engine and MODs + * from Valve. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. + * + */ + +#include "wpnmod_memory.h" +#include "wpnmod_hooks.h" +#include "wpnmod_items.h" + +void CMemory::Parse_ClearMultiDamage(void) +{ + char funcname[] = "ClearMultiDamage (gamedll)"; + +#ifdef __linux__ + + size_t pAdress = FindAdressInDLL(&m_GameDllModule, "ClearMultiDamage__Fv"); + + if (!pAdress) + { + m_bIsNewGCC = true; + pAdress = FindAdressInDLL(&m_GameDllModule, "_Z16ClearMultiDamagev"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); + m_bSuccess = false; + return; + } + + WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); + +#else + size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?ClearMultiDamage@@YAXXZ"); + + if (pAdress) + { + m_pClearMultiDamage = (void*)pAdress; + return; + } + + pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?SuperBounceTouch@CSqueakGrenade@@AAEXPAVCBaseEntity@@@Z"); + + char mask[] = "x?????x?????x"; + unsigned char pattern[] = "\x3B\x00\x00\x00\x00\x00\x0F\x00\x00\x00\x00\x00\xE8"; + size_t BytesOffset = 13; + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); + m_bSuccess = false; + return; + } + + pAdress = ParseFunc(pAdress, pAdress + 300, funcname, pattern, mask, BytesOffset); + + if (!pAdress) + { + m_bSuccess = false; + return; + } + +#endif + + m_pClearMultiDamage = (void*)pAdress; +} + +void CMemory::Parse_ApplyMultiDamage(void) +{ + char funcname[] = "ApplyMultiDamage (gamedll)"; + +#ifdef __linux__ + + size_t pAdress = FindAdressInDLL(&m_GameDllModule, "ApplyMultiDamage__FP9entvars_sT0"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(&m_GameDllModule, "_Z16ApplyMultiDamageP9entvars_sS0_"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); + m_bSuccess = false; + return; + } + + WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); + +#else + + size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?ApplyMultiDamage@@YAXPAUentvars_s@@0@Z"); + + if (pAdress) + { + m_pApplyMultiDamage = (void*)pAdress; + return; + } + + pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?SuperBounceTouch@CSqueakGrenade@@AAEXPAVCBaseEntity@@@Z"); + + char mask[] = "xxx????x"; + unsigned char pattern[] = "\x50\x50\xE8\x00\x00\x00\x00\x8B"; + size_t BytesOffset = 3; + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); + m_bSuccess = false; + return; + } + + pAdress = ParseFunc(pAdress, pAdress + 700, funcname, pattern, mask, BytesOffset); + + if (!pAdress) + { + m_bSuccess = false; + return; + } + +#endif + + m_pApplyMultiDamage = (void*)pAdress; +} + +void CMemory::Parse_GiveNamedItem(void) +{ + char funcname[] = "CBasePlayer::GiveNamedItem (gamedll)"; + +#ifdef __linux__ + + size_t pAdress = FindAdressInDLL(&m_GameDllModule, "GiveNamedItem__11CBasePlayerPCc"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN11CBasePlayer13GiveNamedItemEPKc"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); + m_bSuccess = false; + return; + } + + WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); + +#else + + size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?GiveNamedItem@CBasePlayer@@QAEXPBD@Z"); + + if (!pAdress) + { + char string[] = "weapon_crowbar"; + char mask[] = "xxxxxx?x"; + unsigned char pattern[] = "\x68\x00\x00\x00\x00\x8B\x00\xE8"; + size_t BytesOffset = 8; + + pAdress = ParseFunc(m_start_gamedll, m_end_gamedll, funcname, string, pattern, mask, BytesOffset); + + if (!pAdress) + { + m_bSuccess = false; + return; + } + } + +#endif + + g_fh_GiveNamedItem.address = (void*)pAdress; + + if (!CreateFunctionHook(&g_fh_GiveNamedItem)) + { + WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); + m_bSuccess = false; + return; + } + + SetHook(&g_fh_GiveNamedItem); +} + +void CMemory::Parse_SetAnimation(void) +{ + char funcname[] = "CBasePlayer::SetAnimation (gamedll)"; + +#ifdef __linux__ + + size_t pAdress = FindAdressInDLL(&m_GameDllModule, "SetAnimation__11CBasePlayer11PLAYER_ANIM"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN11CBasePlayer12SetAnimationE11PLAYER_ANIM"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); + m_bSuccess = false; + return; + } + + WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); + +#else + + size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?SetAnimation@CBasePlayer@@QAEXW4PLAYER_ANIM@@@Z"); + + if (pAdress) + { + m_pPlayerSetAnimation = (void*)pAdress; + return; + } + + char string[] = "models/v_satchel_radio.mdl"; + char mask[] = "xxxxx"; + unsigned char pattern[] = "\xB9\x00\x00\x00\x00"; + + char mask2[] = "xx?xxx"; + unsigned char pattern2[] = "\x8B\x4E\x00\x6A\x05\xE8"; + size_t BytesOffset = 6; + + int count = 0; + + size_t pCurrent = NULL; + size_t pCandidate = NULL; + + pCurrent = FindStringInDLL(m_start_gamedll, m_end_gamedll, string); + + //Parse_StringInModule(GetModule_GameDll(), pattern, string); + + while (pCurrent) + { + *(size_t*)(pattern + 1) = (size_t)pCurrent; + + if ((pCandidate = FindAdressInDLL(m_start_gamedll, m_end_gamedll, pattern, mask)) != NULL) + { + count++; + pAdress = pCandidate; + } + + pCurrent = FindStringInDLL(pCurrent + 1, m_end_gamedll, string); + } + + if (!count) + { + WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); + m_bSuccess = false; + return; + } + else if (count > 1) + { + WPNMOD_LOG(" Error: \"%s\" not found [1]\n", funcname); + m_bSuccess = false; + return; + } + + pAdress = ParseFunc(pAdress, pAdress + 150, funcname, pattern2, mask2, BytesOffset); + + if (!pAdress) + { + m_bSuccess = false; + return; + } + +#endif + + m_pPlayerSetAnimation = (void*)pAdress; +} + +void CMemory::Parse_SubRemove(void) +{ + char funcname[] = "CBaseEntity::SUB_Remove (gamedll)"; + +#ifdef WIN32 + + void* pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "?SUB_Remove@CBaseEntity@@QAEXXZ"); + +#else + + void* pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "SUB_Remove__11CBaseEntity"); + + if (!pAdress) + { + pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "_ZN11CBaseEntity10SUB_RemoveEv"); + } + +#endif + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); + m_bSuccess = false; + return; + } + + m_pSubRemove = pAdress; + + WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); +} + +void CMemory::Parse_FallThink(void) +{ + char funcname[] = "CBasePlayerItem::FallThink (gamedll)"; + +#ifdef WIN32 + + void* pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "?FallThink@CBasePlayerItem@@QAEXXZ"); + +#else + + void* pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "FallThink__15CBasePlayerItem"); + + if (!pAdress) + { + pAdress = (void*)FindAdressInDLL(&m_GameDllModule, "_ZN15CBasePlayerItem9FallThinkEv"); + } + +#endif + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); + m_bSuccess = false; + return; + } + + WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); + + g_fh_FallThink.address = (void*)pAdress; + + if (!CreateFunctionHook(&g_fh_FallThink)) + { + WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); + m_bSuccess = false; + return; + } + + SetHook(&g_fh_FallThink); +} + +void CMemory::Parse_AmmoSpawn(void) +{ + char* funcname = "CBasePlayerAmmo::Spawn (gamedll)"; + +#ifdef __linux__ + + size_t pAdress = FindAdressInDLL(&m_GameDllModule, "Spawn__15CBasePlayerAmmo"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN15CBasePlayerAmmo5SpawnEv"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); + m_bSuccess = false; + return; + } + +#else + + size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?Spawn@CBasePlayerAmmo@@UAEXXZ"); + + if (!pAdress) + { + int count = 0; + + size_t pAdress = NULL; + size_t pCurrent = NULL; + size_t pCandidate = NULL; + + // + // 68 10 88 0C 10 push offset aModelsW_argren ; "models/w_ARgrenade.mdl" + // + + char string[] = "models/w_ARgrenade.mdl"; + char mask[] = "xxxxxx"; + unsigned char pattern[] = "\x04\x68\x00\x00\x00\x00"; + + pCurrent = FindStringInDLL(m_start_gamedll, m_end_gamedll, string); + + while (pCurrent) + { + *(size_t*)(pattern + 2) = (size_t)pCurrent; + + if ((pCandidate = FindAdressInDLL(m_start_gamedll, m_end_gamedll, pattern, mask))) + { + count++; + pAdress = pCandidate; + } + + pCurrent = FindStringInDLL(pCurrent + 1, m_end_gamedll, string); + } + + if (!count) + { + WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); + m_bSuccess = false; + return; + } + else if (count > 1) + { + WPNMOD_LOG(" Error: \"%s\" not found [1]\n", funcname); + m_bSuccess = false; + return; + } + + size_t start = pAdress; + size_t end = pAdress + 32; + + pAdress = FindAdressInDLL(start, end, (unsigned char*)"\xE9", "x"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(start, end, (unsigned char*)"\xE8", "x"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found [2]\n", funcname); + m_bSuccess = false; + return; + } + + pAdress += 1; + pAdress = *(size_t*)pAdress + pAdress + 4; + } + +#endif + + WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); + + g_fh_AmmoSpawn.address = (void*)pAdress; + + if (!CreateFunctionHook(&g_fh_AmmoSpawn)) + { + WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); + m_bSuccess = false; + return; + } + + SetHook(&g_fh_AmmoSpawn); +} + +void CMemory::Parse_ItemSpawn(void) +{ + char* funcname = "CItem::Spawn (gamedll)"; + +#ifdef __linux__ + + size_t pAdress = FindAdressInDLL(&m_GameDllModule, "Spawn__5CItem"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN5CItem5SpawnEv"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); + m_bSuccess = false; + return; + } + +#else + + size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?Spawn@CItem@@UAEXXZ"); + + if (!pAdress) + { + int count = 0; + + size_t pAdress = NULL; + size_t pCurrent = NULL; + size_t pCandidate = NULL; + + // + // 8B 46 04 mov eax, [esi+4] + // 68 A4 62 0C 10 push offset aModelsW_batter; "models/w_battery.mdl" + // + + char string[] = "models/w_battery.mdl"; + char mask[] = "xxxxxx"; + unsigned char pattern[] = "\x04\x68\x00\x00\x00\x00"; + + pCurrent = FindStringInDLL(m_start_gamedll, m_end_gamedll, string); + + while (pCurrent) + { + *(size_t*)(pattern + 2) = (size_t)pCurrent; + + if ((pCandidate = FindAdressInDLL(m_start_gamedll, m_end_gamedll, pattern, mask))) + { + count++; + pAdress = pCandidate; + } + + pCurrent = FindStringInDLL(pCurrent + 1, m_end_gamedll, string); + } + + if (!count) + { + WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); + m_bSuccess = false; + return; + } + else if (count > 1) + { + WPNMOD_LOG(" Error: \"%s\" not found [1]\n", funcname); + m_bSuccess = false; + return; + } + + size_t start = pAdress; + size_t end = pAdress + 32; + + pAdress = FindAdressInDLL(start, end, (unsigned char*)"\xE9", "x"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(start, end, (unsigned char*)"\xE8", "x"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found [2]\n", funcname); + m_bSuccess = false; + return; + } + + pAdress += 1; + pAdress = *(size_t*)pAdress + pAdress + 4; + } + +#endif + + WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); + + g_fh_ItemSpawn.address = (void*)pAdress; + + if (!CreateFunctionHook(&g_fh_ItemSpawn)) + { + WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); + m_bSuccess = false; + return; + } + + SetHook(&g_fh_ItemSpawn); +} + +void CMemory::Parse_WorldPrecache(void) +{ + char* funcname = "W_Precache (gamedll)"; + +#ifdef __linux__ + + size_t pAdress = FindAdressInDLL(&m_GameDllModule, "W_Precache__Fv"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(&m_GameDllModule, "_Z10W_Precachev"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"%s\" not found\n", funcname); + m_bSuccess = false; + return; + } + +#else + + size_t pAdress = (size_t)FindAdressInDLL(&m_GameDllModule, "?W_Precache@@YAXXZ"); + + if (!pAdress) + { + int count = 0; + + size_t pCurrent = NULL; + size_t pCandidate = NULL; + + // 85 C0 test eax, eax + // 75 10 jnz short loc_100EC92C + // 68 0C D4 14 10 push offset aCouldNotCreate; "**COULD NOT CREATE SOUNDENT**\n" + // 6A 01 push 1; _DWORD + // FF 15 DC 15 15 10 call dword_101515DC + // 83 C4 08 add esp, 8 + // E8 7F 03 00 00 call sub_100ECCB0 + // E8 6A FB FD FF call sub_100CC4A0 + // E8 A5 01 FE FF call sub_100CCAE0 + // E8 70 D5 FF FF call sub_100E9EB0 + // E8 3B F6 F2 FF call W_Precache + + char string[] = "**COULD NOT CREATE SOUNDENT**\n"; + char mask[] = "xxxxxx"; + unsigned char pattern[] = "\x10\x68\x00\x00\x00\x00"; + + pCurrent = FindStringInDLL(m_start_gamedll, m_end_gamedll, string); + + while (pCurrent) + { + *(size_t*)(pattern + 2) = (size_t)pCurrent; + + if ((pCandidate = FindAdressInDLL(m_start_gamedll, m_end_gamedll, pattern, mask))) + { + count++; + pAdress = pCandidate; + } + + pCurrent = FindStringInDLL(pCurrent + 1, m_end_gamedll, string); + } + + if (!count) + { + WPNMOD_LOG(" Error: \"%s\" not found [0]\n", funcname); + m_bSuccess = false; + return; + } + else if (count > 1) + { + WPNMOD_LOG(" Error: \"%s\" not found [1]\n", funcname); + m_bSuccess = false; + return; + } + + count = 0; + + size_t end = pAdress + 50; + unsigned char opcode[] = "\xE8"; + + pCurrent = FindAdressInDLL(pAdress + 4, end, opcode, "x"); + + // Find fourth call. + while (pCurrent && count != 4) + { + count++; + pAdress = pCurrent; + pCurrent = FindAdressInDLL(pCurrent + 1, end, opcode, "x"); + } + + if (count != 4) + { + WPNMOD_LOG(" Error: \"%s\" not found [2]\n", funcname); + m_bSuccess = false; + return; + } + + pAdress += 1; + pAdress = *(size_t*)pAdress + pAdress + 4; + } +#endif + + WPNMOD_LOG_ONLY(" Found \"%s\" at %p\n", funcname, pAdress); + + g_fh_WorldPrecache.address = m_pWorldPrecache = (void*)pAdress; + + if (!CreateFunctionHook(&g_fh_WorldPrecache)) + { + WPNMOD_LOG(" Error: failed to hook \"%s\"\n", funcname); + m_bSuccess = false; + return; + } + + SetHook(&g_fh_WorldPrecache); +} + +void CMemory::Parse_InfoArrays(void) +{ + // + // Let's find "ItemInfo CBasePlayerItem::ItemInfoArray[MAX_WEAPONS]" in gamedll + // + +#ifdef __linux__ + + size_t pAdress = FindAdressInDLL(&m_GameDllModule, "_15CBasePlayerItem.ItemInfoArray"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN15CBasePlayerItem13ItemInfoArrayE"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"ItemInfoArray (gamedll)\" not found [0]\n"); + WPNMOD_LOG(" Error: \"AmmoInfoArray (gamedll)\" not found [0]\n"); + m_bSuccess = false; + return; + } + + g_Items.m_pItemInfoArray = (ItemInfo*)(pAdress); + +#else + + if (!m_pWorldPrecache) + { + // Nothing to do here! + WPNMOD_LOG(" Error: \"ItemInfoArray (gamedll)\" not found [0]\n"); + WPNMOD_LOG(" Error: \"AmmoInfoArray (gamedll)\" not found [0]\n"); + m_bSuccess = false; + return; + } + + size_t pAdress = FindAdressInDLL(&m_GameDllModule, "?ItemInfoArray@CBasePlayerItem@@2PAUItemInfo@@A"); + + if (pAdress) + { + g_Items.m_pItemInfoArray = (ItemInfo*)pAdress; + } + else + { + // Win1 + // void W_Precache(void) + // 68 80 05 00 00 push 10110000000b + // 6A 00 push 0 + // 68 28 D8 10 10 push offset ItemInfoArray + // E8 8F 4D 00 00 call sub_1009E5E0 + // 68 00 01 00 00 push 100000000b + // 6A 00 push 0 + // 68 A8 DD 10 10 push offset AmmoInfoArray + + // Win2 + // void W_Precache(void) + // 57 push edi + // B9 60 01 00 00 mov ecx, 160h + // 33 C0 xor eax, eax + // BF 48 15 16 10 mov edi, offset ItemInfoArray + // F3 AB rep stosd + // B9 40 00 00 00 mov ecx, 40h + // BF 40 14 16 10 mov edi, offset AmmoInfoArray + // F3 AB rep stosd + + size_t start = (size_t)m_pWorldPrecache; + size_t end = (size_t)m_pWorldPrecache + 15; + + pAdress = FindAdressInDLL(start, end, (unsigned char*)"\x6A\x00\x68", "xxx"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(start, end, (unsigned char*)"\x33\xC0\xBF", "xxx"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"ItemInfoArray (gamedll)\" not found [1]\n"); + WPNMOD_LOG(" Error: \"AmmoInfoArray (gamedll)\" not found [1]\n"); + m_bSuccess = false; + return; + } + + pAdress += 3; + g_Items.m_pItemInfoArray = (ItemInfo*)*(size_t*)(pAdress); + } + +#endif + + // Success! + WPNMOD_LOG_ONLY(" Found \"ItemInfoArray (gamedll)\" at %p\n", pAdress); + + // + // Now let's find "AmmoInfo CBasePlayerItem::AmmoInfoArray[MAX_AMMO_SLOTS]"; + // + +#ifdef __linux__ + + pAdress = FindAdressInDLL(&m_GameDllModule, "_15CBasePlayerItem.AmmoInfoArray"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(&m_GameDllModule, "_ZN15CBasePlayerItem13AmmoInfoArrayE"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"AmmoInfoArray (gamedll)\" not found [1]\n"); + m_bSuccess = false; + return; + } + + g_Items.m_pAmmoInfoArray = (AmmoInfo*)(pAdress); + +#else + + pAdress = FindAdressInDLL(&m_GameDllModule, "?AmmoInfoArray@CBasePlayerItem@@2PAUAmmoInfo@@A"); + + if (pAdress) + { + g_Items.m_pAmmoInfoArray = (AmmoInfo*)pAdress; + } + else + { + size_t start = pAdress; + size_t end = pAdress + 25; + + pAdress = FindAdressInDLL(start, end, (unsigned char*)"\x6A\x00\x68", "xxx"); + + if (!pAdress) + { + pAdress = FindAdressInDLL(start, end, (unsigned char*)"\xBF", "x"); + } + + if (!pAdress) + { + WPNMOD_LOG(" Error: \"AmmoInfoArray (gamedll)\" not found [2]\n"); + m_bSuccess = false; + return; + } + + unsigned char* bytes = (unsigned char*)&(*(size_t*)pAdress); + + if (bytes[0] == 0x6A) + { + pAdress += 3; + } + else if (bytes[0] == 0xBF) + { + pAdress += 1; + } + + g_Items.m_pAmmoInfoArray = (AmmoInfo*)*(size_t*)(pAdress); + } + +#endif + + // Success! + WPNMOD_LOG_ONLY(" Found \"AmmoInfoArray (gamedll)\" at %p\n", pAdress); +} diff --git a/thirdparty/hlsdk/CMakeLists.txt b/thirdparty/hlsdk/CMakeLists.txt index 2512c0b..061b066 100644 --- a/thirdparty/hlsdk/CMakeLists.txt +++ b/thirdparty/hlsdk/CMakeLists.txt @@ -20,7 +20,6 @@ add_sources( common/event_flags.h common/exefuncs.h common/hltv.h - common/interface.h common/in_buttons.h common/ivoicetweak.h common/mathlib.h @@ -97,6 +96,19 @@ add_sources( pm_shared/pm_movevars.h pm_shared/pm_shared.h + public/rehlds/cmd_rehlds.h + public/rehlds/common_rehlds.h + public/rehlds/FlightRecorder.h + public/rehlds/hookchains.h + public/rehlds/pr_dlls.h + public/rehlds/qlimits.h + public/rehlds/rehlds_api.h + public/rehlds/rehlds_interfaces.h + public/rehlds/userid_rehlds.h + + public/tier1/interface.cpp + public/tier1/interface.h + Dummy.cpp ) @@ -105,11 +117,12 @@ add_library( hlsdk STATIC ${PREP_SRCS} ) check_winxp_support( hlsdk ) target_include_directories( hlsdk PUBLIC - # TODO: Only leave common and . + # TODO: Only leave common, public and . common dlls engine pm_shared + public ) create_source_groups( "${CMAKE_SOURCE_DIR}" ) diff --git a/thirdparty/hlsdk/common/interface.h b/thirdparty/hlsdk/common/interface.h deleted file mode 100644 index b49d087..0000000 --- a/thirdparty/hlsdk/common/interface.h +++ /dev/null @@ -1,129 +0,0 @@ -//========= Copyright © 1996-2002, Valve LLC, All rights reserved. ============ -// -// Purpose: -// -// $NoKeywords: $ -//============================================================================= - -// This header defines the interface convention used in the valve engine. -// To make an interface and expose it: -// 1. Derive from IBaseInterface. -// 2. The interface must be ALL pure virtuals, and have no data members. -// 3. Define a name for it. -// 4. In its implementation file, use EXPOSE_INTERFACE or EXPOSE_SINGLE_INTERFACE. - -// Versioning -// There are two versioning cases that are handled by this: -// 1. You add functions to the end of an interface, so it is binary compatible with the previous interface. In this case, -// you need two EXPOSE_INTERFACEs: one to expose your class as the old interface and one to expose it as the new interface. -// 2. You update an interface so it's not compatible anymore (but you still want to be able to expose the old interface -// for legacy code). In this case, you need to make a new version name for your new interface, and make a wrapper interface and -// expose it for the old interface. - -#ifndef INTERFACE_H -#define INTERFACE_H - -#ifdef __cplusplus - -// All interfaces derive from this. -class IBaseInterface -{ -public: - - virtual ~IBaseInterface() {} -}; - - -#define CREATEINTERFACE_PROCNAME "CreateInterface" -typedef IBaseInterface* (*CreateInterfaceFn)(const char *pName, int *pReturnCode); - - -typedef IBaseInterface* (*InstantiateInterfaceFn)(); - - -// Used internally to register classes. -class InterfaceReg -{ -public: - InterfaceReg(InstantiateInterfaceFn fn, const char *pName); - -public: - - InstantiateInterfaceFn m_CreateFn; - const char *m_pName; - - InterfaceReg *m_pNext; // For the global list. - static InterfaceReg *s_pInterfaceRegs; -}; - - -// Use this to expose an interface that can have multiple instances. -// e.g.: -// EXPOSE_INTERFACE( CInterfaceImp, IInterface, "MyInterface001" ) -// This will expose a class called CInterfaceImp that implements IInterface (a pure class) -// clients can receive a pointer to this class by calling CreateInterface( "MyInterface001" ) -// -// In practice, the shared header file defines the interface (IInterface) and version name ("MyInterface001") -// so that each component can use these names/vtables to communicate -// -// A single class can support multiple interfaces through multiple inheritance -// -#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \ - static InterfaceReg __g_Create##className##_reg(functionName, versionName); - -#define EXPOSE_INTERFACE(className, interfaceName, versionName) \ - static IBaseInterface* __Create##className##_interface() {return (interfaceName *)new className;}\ - static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); - -// Use this to expose a singleton interface with a global variable you've created. -#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \ - static IBaseInterface* __Create##className##interfaceName##_interface() {return (interfaceName *)&globalVarName;}\ - static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); - -// Use this to expose a singleton interface. This creates the global variable for you automatically. -#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \ - static className __g_##className##_singleton;\ - EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton) - - -#ifdef WIN32 - #define EXPORT_FUNCTION __declspec(dllexport) -#else - #define EXPORT_FUNCTION -#endif - - -// This function is automatically exported and allows you to access any interfaces exposed with the above macros. -// if pReturnCode is set, it will return one of the following values -// extend this for other error conditions/code -enum -{ - IFACE_OK = 0, - IFACE_FAILED -}; - - -extern "C" -{ - EXPORT_FUNCTION IBaseInterface* CreateInterface(const char *pName, int *pReturnCode); -}; - - -// Handle to an interface (HInterfaceModule_t* is just there for type safety). -typedef struct HInterfaceModule_t* HINTERFACEMODULE; - - -// Use these to load and unload a module. -extern HINTERFACEMODULE Sys_LoadModule(const char *pModuleName); -extern void Sys_FreeModule(HINTERFACEMODULE hModule); - -// Use these to get the factory function from either a loaded module or the current module. -extern CreateInterfaceFn Sys_GetFactory( HINTERFACEMODULE hModule ); -extern CreateInterfaceFn Sys_GetFactoryThis( void ); - -#endif // __cplusplus - -#endif - - - diff --git a/thirdparty/hlsdk/common/mathlib.h b/thirdparty/hlsdk/common/mathlib.h index 908e631..e227a08 100644 --- a/thirdparty/hlsdk/common/mathlib.h +++ b/thirdparty/hlsdk/common/mathlib.h @@ -13,6 +13,7 @@ * ****/ // mathlib.h +#pragma once typedef float vec_t; typedef vec_t vec3_t[3]; @@ -40,7 +41,7 @@ extern int nanmask; #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) #ifndef VECTOR_H - #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]) + // #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]) #endif #define VectorSubtract(a,b,c) {(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];} diff --git a/thirdparty/hlsdk/public/FileSystem.h b/thirdparty/hlsdk/public/FileSystem.h new file mode 100644 index 0000000..ddd812b --- /dev/null +++ b/thirdparty/hlsdk/public/FileSystem.h @@ -0,0 +1,203 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#pragma once + +#include "tier1/interface.h" +#include +#include + +// There is only one instance of the IFileSystem interface, +// located in the filesystem_stdio library (filesystem_steam is obsolete). +#ifdef _WIN32 + #define STDIO_FILESYSTEM_LIB "filesystem_stdio.dll" + #define STEAM_FILESYSTEM_LIB "filesystem_steam.dll" +#else + #define STDIO_FILESYSTEM_LIB "filesystem_stdio.so" + #define STEAM_FILESYSTEM_LIB "filesystem_steam.so" +#endif // _WIN32 + +// Forward declarations +typedef FILE *FileHandle_t; +typedef int FileFindHandle_t; +typedef int WaitForResourcesHandle_t; +typedef void (*WarningFunc_t)(const char *fmt, ...); + +// Enums used by the interface +#ifndef FILESYSTEM_INTERNAL_H +typedef enum +{ + FILESYSTEM_SEEK_HEAD = 0, + FILESYSTEM_SEEK_CURRENT, + FILESYSTEM_SEEK_TAIL, +} FileSystemSeek_t; + +enum +{ + FILESYSTEM_INVALID_FIND_HANDLE = -1 +}; + +typedef enum +{ + FILESYSTEM_WARNING = -1, // A problem! + FILESYSTEM_WARNING_QUIET = 0, // Don't print anything + FILESYSTEM_WARNING_REPORTUNCLOSED, // On shutdown, report names of files left unclosed + FILESYSTEM_WARNING_REPORTUSAGE, // Report number of times a file was opened, closed + FILESYSTEM_WARNING_REPORTALLACCESSES // Report all open/close events to console (!slow!) +} FileWarningLevel_t; + +const FileHandle_t FILESYSTEM_INVALID_HANDLE = nullptr; + +#endif // FILESYSTEM_INTERNAL_H + +// turn off any windows defines +#undef GetCurrentDirectory + +// Purpose: Main file system interface +class IFileSystem: public IBaseInterface +{ +public: + // Mount and unmount the filesystem + virtual void Mount() = 0; + virtual void Unmount() = 0; + + // Remove all search paths (including write path?) + virtual void RemoveAllSearchPaths() = 0; + + // Add paths in priority order (mod dir, game dir, ....) + // If one or more .pak files are in the specified directory, then they are + // added after the file system path + // If the path is the relative path to a .bsp file, then any previous .bsp file + // override is cleared and the current .bsp is searched for an embedded PAK file + // and this file becomes the highest priority search path (i.e., it's looked at first + // even before the mod's file system path). + virtual void AddSearchPath(const char *pPath, const char *pathID) = 0; + virtual bool RemoveSearchPath(const char *pPath) = 0; + + // Deletes a file + virtual void RemoveFile(const char *pRelativePath, const char *pathID) = 0; + + // this isn't implementable on STEAM as is. + virtual void CreateDirHierarchy(const char *path, const char *pathID) = 0; + + // File I/O and info + virtual bool FileExists(const char *pFileName) = 0; + virtual bool IsDirectory(const char *pFileName) = 0; + + // opens a file + // if pathID is NULL, all paths will be searched for the file + virtual FileHandle_t Open(const char *pFileName, const char *pOptions, const char *pathID = 0L) = 0; + + virtual void Close(FileHandle_t file) = 0; + + virtual void Seek(FileHandle_t file, int pos, FileSystemSeek_t seekType) = 0; + virtual size_t Tell(FileHandle_t file) = 0; + + virtual size_t Size(FileHandle_t file) = 0; + virtual size_t Size(const char *pFileName) = 0; + + virtual long GetFileTime(const char *pFileName) = 0; + virtual void FileTimeToString(char *pStrip, int maxCharsIncludingTerminator, long fileTime) = 0; + + virtual bool IsOk(FileHandle_t file) = 0; + + virtual void Flush(FileHandle_t file) = 0; + virtual bool EndOfFile(FileHandle_t file) = 0; + + virtual int Read(void *pOutput, int size, FileHandle_t file) = 0; + virtual int Write(void const *pInput, int size, FileHandle_t file) = 0; + virtual char *ReadLine(char *pOutput, int maxChars, FileHandle_t file) = 0; + virtual int FPrintf(FileHandle_t file, const char *fmt, ...) = 0; + + // direct filesystem buffer access + // returns a handle to a buffer containing the file data + // this is the optimal way to access the complete data for a file, + // since the file preloader has probably already got it in memory + virtual void *GetReadBuffer(FileHandle_t file, int *outBufferSize, bool failIfNotInCache) = 0; + virtual void ReleaseReadBuffer(FileHandle_t file, void *readBuffer) = 0; + + // FindFirst/FindNext + virtual const char *FindFirst(const char *pWildCard, FileFindHandle_t *pHandle, const char *pathID = 0L) = 0; + virtual const char *FindNext(FileFindHandle_t handle) = 0; + virtual bool FindIsDirectory(FileFindHandle_t handle) = 0; + virtual void FindClose(FileFindHandle_t handle) = 0; + + virtual void GetLocalCopy(const char *pFileName) = 0; + + virtual const char *GetLocalPath(const char *pFileName, char *pLocalPath, int localPathBufferSize) = 0; + + // Note: This is sort of a secondary feature; but it's really useful to have it here + virtual char *ParseFile(char *pFileBytes, char *pToken, bool *pWasQuoted) = 0; + + // Returns true on success (based on current list of search paths, otherwise false if it can't be resolved) + virtual bool FullPathToRelativePath(const char *pFullpath, char *pRelative) = 0; + + // Gets the current working directory + virtual bool GetCurrentDirectory(char *pDirectory, int maxlen) = 0; + + // Dump to printf/OutputDebugString the list of files that have not been closed + virtual void PrintOpenedFiles() = 0; + + virtual void SetWarningFunc(WarningFunc_t pfnWarning) = 0; + virtual void SetWarningLevel(FileWarningLevel_t level) = 0; + + virtual void LogLevelLoadStarted(const char *name) = 0; + virtual void LogLevelLoadFinished(const char *name) = 0; + virtual int HintResourceNeed(const char *hintlist, int forgetEverything) = 0; + virtual int PauseResourcePreloading() = 0; + virtual int ResumeResourcePreloading() = 0; + virtual int SetVBuf(FileHandle_t stream, char *buffer, int mode, long size) = 0; + virtual void GetInterfaceVersion(char *p, int maxlen) = 0; + virtual bool IsFileImmediatelyAvailable(const char *pFileName) = 0; + + // starts waiting for resources to be available + // returns FILESYSTEM_INVALID_HANDLE if there is nothing to wait on + virtual WaitForResourcesHandle_t WaitForResources(const char *resourcelist) = 0; + + // get progress on waiting for resources; progress is a float [0, 1], complete is true on the waiting being done + // returns false if no progress is available + // any calls after complete is true or on an invalid handle will return false, 0.0f, true + virtual bool GetWaitForResourcesProgress(WaitForResourcesHandle_t handle, float *progress /* out */ , bool *complete /* out */) = 0; + + // cancels a progress call + virtual void CancelWaitForResources(WaitForResourcesHandle_t handle) = 0; + // returns true if the appID has all its caches fully preloaded + virtual bool IsAppReadyForOfflinePlay(int appID) = 0; + + // interface for custom pack files > 4Gb + virtual bool AddPackFile(const char *fullpath, const char *pathID) = 0; + + // open a file but force the data to come from the steam cache, NOT from disk + virtual FileHandle_t OpenFromCacheForRead(const char *pFileName, const char *pOptions, const char *pathID = 0L) = 0; + virtual void AddSearchPathNoWrite(const char *pPath, const char *pathID) = 0; +}; + +// Steam3/Src compat +#define IBaseFileSystem IFileSystem + +#define FILESYSTEM_INTERFACE_VERSION "VFileSystem009" diff --git a/thirdparty/hlsdk/public/rehlds/FlightRecorder.h b/thirdparty/hlsdk/public/rehlds/FlightRecorder.h new file mode 100644 index 0000000..ff58c1d --- /dev/null +++ b/thirdparty/hlsdk/public/rehlds/FlightRecorder.h @@ -0,0 +1,61 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#include "archtypes.h" + +class IRehldsFlightRecorder +{ +public: + virtual ~IRehldsFlightRecorder() { } + + virtual uint16 RegisterMessage(const char* module, const char *message, unsigned int version, bool inOut) = 0; + + virtual void StartMessage(uint16 msg, bool entrance) = 0; + virtual void EndMessage(uint16 msg, bool entrance) = 0; + + virtual void WriteInt8(int8_t v) = 0; + virtual void WriteUInt8(uint8_t v) = 0; + + virtual void WriteInt16(int16 v) = 0; + virtual void WriteUInt16(uint16 v) = 0; + + virtual void WriteInt32(int32 v) = 0; + virtual void WriteUInt32(uint32 v) = 0; + + virtual void WriteInt64(int64 v) = 0; + virtual void WriteUInt64(uint64 v) = 0; + + virtual void WriteFloat(float v) = 0; + virtual void WriteDouble(double v) = 0; + + virtual void WriteString(const char* s) = 0; + + virtual void WriteBuffer(const void* data ,unsigned int len) = 0; + +}; diff --git a/thirdparty/hlsdk/public/rehlds/cmd_rehlds.h b/thirdparty/hlsdk/public/rehlds/cmd_rehlds.h new file mode 100644 index 0000000..003cb60 --- /dev/null +++ b/thirdparty/hlsdk/public/rehlds/cmd_rehlds.h @@ -0,0 +1,49 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#include "archtypes.h" + +typedef void(*xcommand_t)(void); +typedef struct cmd_function_s +{ + struct cmd_function_s *next; + const char *name; + xcommand_t function; + int flags; +} cmd_function_t; + +typedef enum cmd_source_s +{ + src_client = 0, // came in over a net connection as a clc_stringcmd. host_client will be valid during this state. + src_command = 1, // from the command buffer. +} cmd_source_t; + +#define FCMD_HUD_COMMAND BIT(0) +#define FCMD_GAME_COMMAND BIT(1) +#define FCMD_WRAPPER_COMMAND BIT(2) diff --git a/thirdparty/hlsdk/public/rehlds/common_rehlds.h b/thirdparty/hlsdk/public/rehlds/common_rehlds.h new file mode 100644 index 0000000..64a5d18 --- /dev/null +++ b/thirdparty/hlsdk/public/rehlds/common_rehlds.h @@ -0,0 +1,78 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#include "const.h" +#include "qlimits.h" + +#ifdef REHLDS_FIXES +#define COM_TOKEN_LEN 2048 +#else +#define COM_TOKEN_LEN 1024 +#endif + +// Don't allow overflow +#define SIZEBUF_CHECK_OVERFLOW 0 +#define SIZEBUF_ALLOW_OVERFLOW BIT(0) +#define SIZEBUF_OVERFLOWED BIT(1) + +#define MAX_NUM_ARGVS 50 +#define NUM_SAFE_ARGVS 7 + +#define COM_COPY_CHUNK_SIZE 1024 +#define COM_MAX_CMD_LINE 256 + +typedef struct sizebuf_s +{ + const char *buffername; + uint16 flags; + byte *data; + int maxsize; + int cursize; +} sizebuf_t; + +typedef struct downloadtime_s +{ + qboolean bUsed; + float fTime; + int nBytesRemaining; +} downloadtime_t; + +typedef struct incomingtransfer_s +{ + qboolean doneregistering; + int percent; + qboolean downloadrequested; + downloadtime_t rgStats[8]; + int nCurStat; + int nTotalSize; + int nTotalToTransfer; + int nRemainingToTransfer; + float fLastStatusUpdate; + qboolean custom; +} incomingtransfer_t; diff --git a/thirdparty/hlsdk/public/rehlds/hookchains.h b/thirdparty/hlsdk/public/rehlds/hookchains.h new file mode 100644 index 0000000..197b8a3 --- /dev/null +++ b/thirdparty/hlsdk/public/rehlds/hookchains.h @@ -0,0 +1,80 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +template +class IHookChain { +protected: + virtual ~IHookChain() {} + +public: + virtual t_ret callNext(t_args... args) = 0; + virtual t_ret callOriginal(t_args... args) = 0; +}; + +template +class IVoidHookChain +{ +protected: + virtual ~IVoidHookChain() {} + +public: + virtual void callNext(t_args... args) = 0; + virtual void callOriginal(t_args... args) = 0; +}; + +// Specifies priorities for hooks call order in the chain. +// For equal priorities first registered hook will be called first. +enum HookChainPriority +{ + HC_PRIORITY_UNINTERRUPTABLE = 255, // Hook will be called before other hooks. + HC_PRIORITY_HIGH = 192, // Hook will be called before hooks with default priority. + HC_PRIORITY_DEFAULT = 128, // Default hook call priority. + HC_PRIORITY_MEDIUM = 64, // Hook will be called after hooks with default priority. + HC_PRIORITY_LOW = 0, // Hook will be called after all other hooks. +}; + +// Hook chain registry(for hooks [un]registration) +template +class IHookChainRegistry { +public: + typedef t_ret(*hookfunc_t)(IHookChain*, t_args...); + + virtual void registerHook(hookfunc_t hook, int priority = HC_PRIORITY_DEFAULT) = 0; + virtual void unregisterHook(hookfunc_t hook) = 0; +}; + +// Hook chain registry(for hooks [un]registration) +template +class IVoidHookChainRegistry { +public: + typedef void(*hookfunc_t)(IVoidHookChain*, t_args...); + + virtual void registerHook(hookfunc_t hook, int priority = HC_PRIORITY_DEFAULT) = 0; + virtual void unregisterHook(hookfunc_t hook) = 0; +}; diff --git a/thirdparty/hlsdk/public/rehlds/pr_dlls.h b/thirdparty/hlsdk/public/rehlds/pr_dlls.h new file mode 100644 index 0000000..e03c69b --- /dev/null +++ b/thirdparty/hlsdk/public/rehlds/pr_dlls.h @@ -0,0 +1,51 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ + +#pragma once + +// #include "maintypes.h" +#include "eiface.h" + +const int MAX_EXTENSION_DLL = 50; + +typedef struct functiontable_s +{ + uint32 pFunction; + char *pFunctionName; +} functiontable_t; + +typedef struct extensiondll_s +{ + void *lDLLHandle; + functiontable_t *functionTable; + int functionCount; +} extensiondll_t; + +typedef void(*ENTITYINIT)(struct entvars_s *); +typedef void(*DISPATCHFUNCTION)(struct entvars_s *, void *); +typedef void(*FIELDIOFUNCTION)(SAVERESTOREDATA *, const char *, void *, TYPEDESCRIPTION *, int); diff --git a/thirdparty/hlsdk/public/rehlds/qlimits.h b/thirdparty/hlsdk/public/rehlds/qlimits.h new file mode 100644 index 0000000..1a67bd5 --- /dev/null +++ b/thirdparty/hlsdk/public/rehlds/qlimits.h @@ -0,0 +1,44 @@ +//========= Copyright (c) 1996-2002, Valve LLC, All rights reserved. ========== +// +// Purpose: +// +// $NoKeywords: $ +//============================================================================= + +#ifndef QLIMITS_H +#define QLIMITS_H + +#if defined( _WIN32 ) +#pragma once +#endif + +// DATA STRUCTURE INFO + +#define MAX_NUM_ARGVS 50 + +// SYSTEM INFO +#define MAX_QPATH 64 // max length of a game pathname +#define MAX_OSPATH 260 // max length of a filesystem pathname + +#define ON_EPSILON 0.1 // point on plane side epsilon + +#define MAX_LIGHTSTYLE_INDEX_BITS 6 +#define MAX_LIGHTSTYLES (1< IRehldsHook_Steam_NotifyClientConnect; +typedef IHookChainRegistry IRehldsHookRegistry_Steam_NotifyClientConnect; + +//SV_ConnectClient hook +typedef IVoidHookChain<> IRehldsHook_SV_ConnectClient; +typedef IVoidHookChainRegistry<> IRehldsHookRegistry_SV_ConnectClient; + +//SV_GetIDString hook +typedef IHookChain IRehldsHook_SV_GetIDString; +typedef IHookChainRegistry IRehldsHookRegistry_SV_GetIDString; + +//SV_SendServerinfo hook +typedef IVoidHookChain IRehldsHook_SV_SendServerinfo; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_SendServerinfo; + +//SV_CheckProtocol hook +typedef IHookChain IRehldsHook_SV_CheckProtocol; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CheckProtocol; + +//SVC_GetChallenge_mod hook +typedef IVoidHookChain IRehldsHook_SVC_GetChallenge_mod; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SVC_GetChallenge_mod; + +//SV_CheckKeyInfo hook +typedef IHookChain IRehldsHook_SV_CheckKeyInfo; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CheckKeyInfo; + +//SV_CheckIPRestrictions hook +typedef IHookChain IRehldsHook_SV_CheckIPRestrictions; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CheckIPRestrictions; + +//SV_FinishCertificateCheck hook +typedef IHookChain IRehldsHook_SV_FinishCertificateCheck; +typedef IHookChainRegistry IRehldsHookRegistry_SV_FinishCertificateCheck; + +//Steam_NotifyBotConnect hook +typedef IHookChain IRehldsHook_Steam_NotifyBotConnect; +typedef IHookChainRegistry IRehldsHookRegistry_Steam_NotifyBotConnect; + +//SerializeSteamId +typedef IVoidHookChain IRehldsHook_SerializeSteamId; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SerializeSteamId; + +//SV_CompareUserID hook +typedef IHookChain IRehldsHook_SV_CompareUserID; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CompareUserID; + +//Steam_NotifyClientDisconnect +typedef IVoidHookChain IRehldsHook_Steam_NotifyClientDisconnect; +typedef IVoidHookChainRegistry IRehldsHookRegistry_Steam_NotifyClientDisconnect; + +//PreProcessPacket +typedef IHookChain IRehldsHook_PreprocessPacket; +typedef IHookChainRegistry IRehldsHookRegistry_PreprocessPacket; + +//ValidateCommand +typedef IHookChain IRehldsHook_ValidateCommand; +typedef IHookChainRegistry IRehldsHookRegistry_ValidateCommand; + +//ExecuteServerStringCmd +typedef IVoidHookChain IRehldsHook_ExecuteServerStringCmd; +typedef IVoidHookChainRegistry IRehldsHookRegistry_ExecuteServerStringCmd; + +//ClientConnected +typedef IVoidHookChain IRehldsHook_ClientConnected; +typedef IVoidHookChainRegistry IRehldsHookRegistry_ClientConnected; + +//HandleNetCommand +typedef IVoidHookChain IRehldsHook_HandleNetCommand; +typedef IVoidHookChainRegistry IRehldsHookRegistry_HandleNetCommand; + +//Mod_LoadBrushModel +typedef IVoidHookChain IRehldsHook_Mod_LoadBrushModel; +typedef IVoidHookChainRegistry IRehldsHookRegistry_Mod_LoadBrushModel; + +//Mod_LoadStudioModel +typedef IVoidHookChain IRehldsHook_Mod_LoadStudioModel; +typedef IVoidHookChainRegistry IRehldsHookRegistry_Mod_LoadStudioModel; + +//SV_EmitEvents hook +typedef IVoidHookChain IRehldsHook_SV_EmitEvents; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_EmitEvents; + +//EV_PlayReliableEvent hook +typedef IVoidHookChain IRehldsHook_EV_PlayReliableEvent; +typedef IVoidHookChainRegistry IRehldsHookRegistry_EV_PlayReliableEvent; + +//SV_StartSound hook +typedef IVoidHookChain IRehldsHook_SV_StartSound; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_StartSound; + +//PF_Remove_I hook +typedef IVoidHookChain IRehldsHook_PF_Remove_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_Remove_I; + +//PF_BuildSoundMsg_I hook +typedef IVoidHookChain IRehldsHook_PF_BuildSoundMsg_I; +typedef IVoidHookChainRegistry IRehldsHookRegistry_PF_BuildSoundMsg_I; + +//SV_WriteFullClientUpdate hook +typedef IVoidHookChain IRehldsHook_SV_WriteFullClientUpdate; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_WriteFullClientUpdate; + +//SV_CheckConsistencyResponse hook +typedef IHookChain IRehldsHook_SV_CheckConsistencyResponse; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CheckConsistencyResponse; + +//SV_DropClient hook +typedef IVoidHookChain IRehldsHook_SV_DropClient; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_DropClient; + +//SV_ActivateServer hook +typedef IVoidHookChain IRehldsHook_SV_ActivateServer; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_ActivateServer; + +//SV_WriteVoiceCodec hook +typedef IVoidHookChain IRehldsHook_SV_WriteVoiceCodec; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_WriteVoiceCodec; + +//Steam_GSGetSteamID hook +typedef IHookChain IRehldsHook_Steam_GSGetSteamID; +typedef IHookChainRegistry IRehldsHookRegistry_Steam_GSGetSteamID; + +//SV_TransferConsistencyInfo hook +typedef IHookChain IRehldsHook_SV_TransferConsistencyInfo; +typedef IHookChainRegistry IRehldsHookRegistry_SV_TransferConsistencyInfo; + +//Steam_GSBUpdateUserData hook +typedef IHookChain IRehldsHook_Steam_GSBUpdateUserData; +typedef IHookChainRegistry IRehldsHookRegistry_Steam_GSBUpdateUserData; + +//Cvar_DirectSet hook +typedef IVoidHookChain IRehldsHook_Cvar_DirectSet; +typedef IVoidHookChainRegistry IRehldsHookRegistry_Cvar_DirectSet; + +//SV_EstablishTimeBase hook +typedef IVoidHookChain IRehldsHook_SV_EstablishTimeBase; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_EstablishTimeBase; + +//SV_Spawn_f hook +typedef IVoidHookChain<> IRehldsHook_SV_Spawn_f; +typedef IVoidHookChainRegistry<> IRehldsHookRegistry_SV_Spawn_f; + +//SV_CreatePacketEntities hook +typedef IHookChain IRehldsHook_SV_CreatePacketEntities; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CreatePacketEntities; + +//SV_EmitSound2 hook +typedef IHookChain IRehldsHook_SV_EmitSound2; +typedef IHookChainRegistry IRehldsHookRegistry_SV_EmitSound2; + +//CreateFakeClient hook +typedef IHookChain IRehldsHook_CreateFakeClient; +typedef IHookChainRegistry IRehldsHookRegistry_CreateFakeClient; + +//SV_CheckConnectionLessRateLimits +typedef IHookChain IRehldsHook_SV_CheckConnectionLessRateLimits; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CheckConnectionLessRateLimits; + +//SV_Frame hook +typedef IVoidHookChain<> IRehldsHook_SV_Frame; +typedef IVoidHookChainRegistry<> IRehldsHookRegistry_SV_Frame; + +//SV_ShouldSendConsistencyList hook +typedef IHookChain IRehldsHook_SV_ShouldSendConsistencyList; +typedef IHookChainRegistry IRehldsHookRegistry_SV_ShouldSendConsistencyList; + +//GetEntityInit hook +typedef IHookChain IRehldsHook_GetEntityInit; +typedef IHookChainRegistry IRehldsHookRegistry_GetEntityInit; + +//SV_EmitPings hook +typedef IHookChain IRehldsHook_SV_EmitPings; +typedef IHookChainRegistry IRehldsHookRegistry_SV_EmitPings; + +//ED_Alloc hook +typedef IHookChain IRehldsHook_ED_Alloc; +typedef IHookChainRegistry IRehldsHookRegistry_ED_Alloc; + +//ED_Free hook +typedef IVoidHookChain IRehldsHook_ED_Free; +typedef IVoidHookChainRegistry IRehldsHookRegistry_ED_Free; + +//Con_Printf hook +typedef IHookChain IRehldsHook_Con_Printf; +typedef IHookChainRegistry IRehldsHookRegistry_Con_Printf; + +//SV_CheckUserInfo hook +typedef IHookChain IRehldsHook_SV_CheckUserInfo; +typedef IHookChainRegistry IRehldsHookRegistry_SV_CheckUserInfo; + +//PF_precache_generic_I hook +typedef IHookChain IRehldsHook_PF_precache_generic_I; +typedef IHookChainRegistry IRehldsHookRegistry_PF_precache_generic_I; + +//PF_precache_model_I hook +typedef IHookChain IRehldsHook_PF_precache_model_I; +typedef IHookChainRegistry IRehldsHookRegistry_PF_precache_model_I; + +//PF_precache_sound_I hook +typedef IHookChain IRehldsHook_PF_precache_sound_I; +typedef IHookChainRegistry IRehldsHookRegistry_PF_precache_sound_I; + +//EV_Precache hook +typedef IHookChain IRehldsHook_EV_Precache; +typedef IHookChainRegistry IRehldsHookRegistry_EV_Precache; + +//SV_AddResource hook +typedef IVoidHookChain IRehldsHook_SV_AddResource; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_AddResource; + +//SV_ClientPrintf hook +typedef IVoidHookChain IRehldsHook_SV_ClientPrintf; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_ClientPrintf; + +//SV_AllowPhysent hook +typedef IHookChain IRehldsHook_SV_AllowPhysent; +typedef IHookChainRegistry IRehldsHookRegistry_SV_AllowPhysent; + +//GetDispatch hook +typedef IHookChain IRehldsHook_GetDispatch; +typedef IHookChainRegistry IRehldsHookRegistry_GetDispatch; + +class IRehldsHookchains { +public: + virtual ~IRehldsHookchains() { } + + virtual IRehldsHookRegistry_Steam_NotifyClientConnect* Steam_NotifyClientConnect() = 0; + virtual IRehldsHookRegistry_SV_ConnectClient* SV_ConnectClient() = 0; + virtual IRehldsHookRegistry_SV_GetIDString* SV_GetIDString() = 0; + virtual IRehldsHookRegistry_SV_SendServerinfo* SV_SendServerinfo() = 0; + virtual IRehldsHookRegistry_SV_CheckProtocol* SV_CheckProtocol() = 0; + virtual IRehldsHookRegistry_SVC_GetChallenge_mod* SVC_GetChallenge_mod() = 0; + virtual IRehldsHookRegistry_SV_CheckKeyInfo* SV_CheckKeyInfo() = 0; + virtual IRehldsHookRegistry_SV_CheckIPRestrictions* SV_CheckIPRestrictions() = 0; + virtual IRehldsHookRegistry_SV_FinishCertificateCheck* SV_FinishCertificateCheck() = 0; + virtual IRehldsHookRegistry_Steam_NotifyBotConnect* Steam_NotifyBotConnect() = 0; + virtual IRehldsHookRegistry_SerializeSteamId* SerializeSteamId() = 0; + virtual IRehldsHookRegistry_SV_CompareUserID* SV_CompareUserID() = 0; + virtual IRehldsHookRegistry_Steam_NotifyClientDisconnect* Steam_NotifyClientDisconnect() = 0; + virtual IRehldsHookRegistry_PreprocessPacket* PreprocessPacket() = 0; + virtual IRehldsHookRegistry_ValidateCommand* ValidateCommand() = 0; + virtual IRehldsHookRegistry_ClientConnected* ClientConnected() = 0; + virtual IRehldsHookRegistry_HandleNetCommand* HandleNetCommand() = 0; + virtual IRehldsHookRegistry_Mod_LoadBrushModel* Mod_LoadBrushModel() = 0; + virtual IRehldsHookRegistry_Mod_LoadStudioModel* Mod_LoadStudioModel() = 0; + virtual IRehldsHookRegistry_ExecuteServerStringCmd* ExecuteServerStringCmd() = 0; + virtual IRehldsHookRegistry_SV_EmitEvents* SV_EmitEvents() = 0; + virtual IRehldsHookRegistry_EV_PlayReliableEvent* EV_PlayReliableEvent() = 0; + virtual IRehldsHookRegistry_SV_StartSound* SV_StartSound() = 0; + virtual IRehldsHookRegistry_PF_Remove_I* PF_Remove_I() = 0; + virtual IRehldsHookRegistry_PF_BuildSoundMsg_I* PF_BuildSoundMsg_I() = 0; + virtual IRehldsHookRegistry_SV_WriteFullClientUpdate* SV_WriteFullClientUpdate() = 0; + virtual IRehldsHookRegistry_SV_CheckConsistencyResponse* SV_CheckConsistencyResponse() = 0; + virtual IRehldsHookRegistry_SV_DropClient* SV_DropClient() = 0; + virtual IRehldsHookRegistry_SV_ActivateServer* SV_ActivateServer() = 0; + virtual IRehldsHookRegistry_SV_WriteVoiceCodec* SV_WriteVoiceCodec() = 0; + virtual IRehldsHookRegistry_Steam_GSGetSteamID* Steam_GSGetSteamID() = 0; + virtual IRehldsHookRegistry_SV_TransferConsistencyInfo* SV_TransferConsistencyInfo() = 0; + virtual IRehldsHookRegistry_Steam_GSBUpdateUserData* Steam_GSBUpdateUserData() = 0; + virtual IRehldsHookRegistry_Cvar_DirectSet* Cvar_DirectSet() = 0; + virtual IRehldsHookRegistry_SV_EstablishTimeBase* SV_EstablishTimeBase() = 0; + virtual IRehldsHookRegistry_SV_Spawn_f* SV_Spawn_f() = 0; + virtual IRehldsHookRegistry_SV_CreatePacketEntities* SV_CreatePacketEntities() = 0; + virtual IRehldsHookRegistry_SV_EmitSound2* SV_EmitSound2() = 0; + virtual IRehldsHookRegistry_CreateFakeClient* CreateFakeClient() = 0; + virtual IRehldsHookRegistry_SV_CheckConnectionLessRateLimits* SV_CheckConnectionLessRateLimits() = 0; + virtual IRehldsHookRegistry_SV_Frame* SV_Frame() = 0; + virtual IRehldsHookRegistry_SV_ShouldSendConsistencyList* SV_ShouldSendConsistencyList() = 0; + virtual IRehldsHookRegistry_GetEntityInit* GetEntityInit() = 0; + virtual IRehldsHookRegistry_SV_EmitPings* SV_EmitPings() = 0; + virtual IRehldsHookRegistry_ED_Alloc* ED_Alloc() = 0; + virtual IRehldsHookRegistry_ED_Free* ED_Free() = 0; + virtual IRehldsHookRegistry_Con_Printf* Con_Printf() = 0; + virtual IRehldsHookRegistry_SV_CheckUserInfo* SV_CheckUserInfo() = 0; + virtual IRehldsHookRegistry_PF_precache_generic_I* PF_precache_generic_I() = 0; + virtual IRehldsHookRegistry_PF_precache_model_I* PF_precache_model_I() = 0; + virtual IRehldsHookRegistry_PF_precache_sound_I* PF_precache_sound_I() = 0; + virtual IRehldsHookRegistry_EV_Precache* EV_Precache() = 0; + virtual IRehldsHookRegistry_SV_AddResource* SV_AddResource() = 0; + virtual IRehldsHookRegistry_SV_ClientPrintf* SV_ClientPrintf() = 0; + virtual IRehldsHookRegistry_SV_AllowPhysent* SV_AllowPhysent() = 0; + virtual IRehldsHookRegistry_GetDispatch* GetDispatch() = 0; +}; + +struct RehldsFuncs_t { + void(*DropClient)(IGameClient* cl, bool crash, const char* fmt, ...); + void(*RejectConnection)(netadr_t *adr, char *fmt, ...); + qboolean(*SteamNotifyBotConnect)(IGameClient* cl); + sizebuf_t*(*GetNetMessage)(); + IGameClient*(*GetHostClient)(); + int*(*GetMsgReadCount)(); + qboolean(*FilterUser)(USERID_t*); + void(*NET_SendPacket)(unsigned int length, void *data, const netadr_t &to); + void(*TokenizeString)(char* s); + bool(*CheckChallenge)(const netadr_t& adr, int challenge); + void(*SendUserReg)(sizebuf_t* msg); + void(*WriteDeltaDescriptionsToClient)(sizebuf_t* msg); + void(*SetMoveVars)(); + void(*WriteMovevarsToClient)(sizebuf_t* msg); + char*(*GetClientFallback)(); + int*(*GetAllowCheats)(); + bool(*GSBSecure)(); + int(*GetBuildNumber)(); + double(*GetRealTime)(); + int*(*GetMsgBadRead)(); + cmd_source_t*(*GetCmdSource)(); + void(*Log)(const char* prefix, const char* msg); + DLL_FUNCTIONS *(*GetEntityInterface)(); + void(*EV_PlayReliableEvent)(IGameClient *cl, int entindex, unsigned short eventindex, float delay, struct event_args_s *pargs); + int(*SV_LookupSoundIndex)(const char *sample); + void(*MSG_StartBitWriting)(sizebuf_t *buf); + void(*MSG_WriteBits)(uint32 data, int numbits); + void(*MSG_WriteBitVec3Coord)(const float *fa); + void(*MSG_EndBitWriting)(sizebuf_t *buf); + void*(*SZ_GetSpace)(sizebuf_t *buf, int length); + cvar_t*(*GetCvarVars)(); + int (*SV_GetChallenge)(const netadr_t& adr); + void (*SV_AddResource)(resourcetype_t type, const char *name, int size, unsigned char flags, int index); + int(*MSG_ReadShort)(); + int(*MSG_ReadBuf)(int iSize, void *pbuf); + void(*MSG_WriteBuf)(sizebuf_t *sb, int iSize, void *buf); + void(*MSG_WriteByte)(sizebuf_t *sb, int c); + void(*MSG_WriteShort)(sizebuf_t *sb, int c); + void(*MSG_WriteString)(sizebuf_t *sb, const char *s); + void*(*GetPluginApi)(const char *name); + void(*RegisterPluginApi)(const char *name, void *impl); + qboolean(*SV_FileInConsistencyList)(const char *filename, struct consistency_s **ppconsist); + qboolean(*Steam_NotifyClientConnect)(IGameClient *cl, const void *pvSteam2Key, unsigned int ucbSteam2Key); + void(*Steam_NotifyClientDisconnect)(IGameClient* cl); + void(*SV_StartSound)(int recipients, edict_t *entity, int channel, const char *sample, int volume, float attenuation, int flags, int pitch); + bool(*SV_EmitSound2)(edict_t *entity, IGameClient *receiver, int channel, const char *sample, float volume, float attenuation, int flags, int pitch, int emitFlags, const float *pOrigin); + void(*SV_UpdateUserInfo)(IGameClient *pGameClient); + bool(*StripUnprintableAndSpace)(char *pch); + void(*Cmd_RemoveCmd)(const char *cmd_name); + void(*GetCommandMatches)(const char *string, ObjectList *pMatchList); + bool(*AddExtDll)(void *hModule); + void(*AddCvarListener)(const char *var_name, cvar_callback_t func); + void(*RemoveExtDll)(void *hModule); + void(*RemoveCvarListener)(const char *var_name, cvar_callback_t func); + ENTITYINIT(*GetEntityInit)(char *pszClassName); + + // Read functions + int(*MSG_ReadChar)(); + int(*MSG_ReadByte)(); + int(*MSG_ReadLong)(); + float(*MSG_ReadFloat)(); + char*(*MSG_ReadString)(); + char*(*MSG_ReadStringLine)(); + float(*MSG_ReadAngle)(); + float(*MSG_ReadHiresAngle)(); + void(*MSG_ReadUsercmd)(struct usercmd_s *to, struct usercmd_s *from); + float(*MSG_ReadCoord)(); + void(*MSG_ReadVec3Coord)(sizebuf_t *sb, vec3_t fa); + + // Read bit functions + bool(*MSG_IsBitReading)(); + void(*MSG_StartBitReading)(sizebuf_t *buf); + void(*MSG_EndBitReading)(sizebuf_t *buf); + uint32(*MSG_PeekBits)(int numbits); + int(*MSG_ReadOneBit)(); + uint32(*MSG_ReadBits)(int numbits); + int(*MSG_ReadSBits)(int numbits); + float(*MSG_ReadBitCoord)(); + void(*MSG_ReadBitVec3Coord)(vec_t *fa); + float(*MSG_ReadBitAngle)(int numbits); + int(*MSG_ReadBitData)(void *dest, int length); + char*(*MSG_ReadBitString)(); + int(*MSG_CurrentBit)(); + + // Write functions + void(*MSG_WriteLong)(sizebuf_t *sb, int c); + void(*MSG_WriteFloat)(sizebuf_t *sb, float f); + void(*MSG_WriteAngle)(sizebuf_t *sb, float f); + void(*MSG_WriteHiresAngle)(sizebuf_t *sb, float f); + void(*MSG_WriteUsercmd)(sizebuf_t *sb, struct usercmd_s *to, struct usercmd_s *from); + void(*MSG_WriteCoord)(sizebuf_t *sb, float f); + void(*MSG_WriteVec3Coord)(sizebuf_t *sb, const vec3_t fa); + + // Write bit functions + bool(*MSG_IsBitWriting)(); + void(*MSG_WriteOneBit)(int nValue); + void(*MSG_WriteSBits)(uint32 data, int numbits); + void(*MSG_WriteBitCoord)(float f); + void(*MSG_WriteBitAngle)(float fAngle, int numbits); + void(*MSG_WriteBitData)(void *src, int length); + void(*MSG_WriteBitString)(const char *p); + void(*SZ_Write)(sizebuf_t *buf, const void *data, int length); + void(*SZ_Print)(sizebuf_t *buf, const char *data); + void(*SZ_Clear)(sizebuf_t *buf); + void(*MSG_BeginReading)(); + double(*GetHostFrameTime)(); + struct cmd_function_s *(*GetFirstCmdFunctionHandle)(); +}; + +class IRehldsApi { +public: + virtual ~IRehldsApi() { } + + virtual int GetMajorVersion() = 0; + virtual int GetMinorVersion() = 0; + virtual const RehldsFuncs_t* GetFuncs() = 0; + virtual IRehldsHookchains* GetHookchains() = 0; + virtual IRehldsServerStatic* GetServerStatic() = 0; + virtual IRehldsServerData* GetServerData() = 0; + virtual IRehldsFlightRecorder* GetFlightRecorder() = 0; +}; + +#define VREHLDS_HLDS_API_VERSION "VREHLDS_HLDS_API_VERSION001" diff --git a/thirdparty/hlsdk/public/rehlds/rehlds_interfaces.h b/thirdparty/hlsdk/public/rehlds/rehlds_interfaces.h new file mode 100644 index 0000000..52fd6be --- /dev/null +++ b/thirdparty/hlsdk/public/rehlds/rehlds_interfaces.h @@ -0,0 +1,333 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +class INetChan; +class IGameClient; + +#include +#include "archtypes.h" +#include "const.h" +#include "netadr.h" +#include "custom.h" +#include "FileSystem.h" + +#include "common_rehlds.h" +#include "userid_rehlds.h" + +#ifdef REHLDS_SELF +#include "server.h" +#endif + +class INetChan; +class IGameClient; + +typedef enum server_state_e +{ +} server_state_t; + +class IGameClient { +public: + virtual int GetId() = 0; + + // false = client is free + virtual bool IsActive() = 0; + virtual void SetActive(bool active) = 0; + + // false = don't send datagrams + virtual bool IsSpawned() = 0; + virtual void SetSpawned(bool spawned) = 0; + + // The client's net connection + virtual INetChan* GetNetChan() = 0; + + // The datagram is written to after every frame, but only cleared + // when it is sent out to the client. It can be harmlessly overflowed + virtual sizebuf_t* GetDatagram() = 0; + + // EDICT_NUM(clientnum + 1) + virtual edict_t* GetEdict() = 0; + + virtual USERID_t* GetNetworkUserID() = 0; + + virtual const char* GetName() = 0; + + virtual bool IsConnected() = 0; + virtual void SetConnected(bool connected) = 0; + + // Which other clients does this guy's voice stream go to? + virtual uint32 GetVoiceStream(int stream_id) = 0; + virtual void SetLastVoiceTime(double time) = 0; + virtual double GetLastVoiceTime() = 0; + + // Does this client want to hear his own voice? + virtual bool GetLoopback() = 0; + virtual struct usercmd_s *GetLastCmd() = 0; + + // This is spectator proxy (hltv) + virtual bool IsProxy() = 0; + virtual void SetProxy(bool proxy) = 0; + + // This client is a fake player controlled by the game DLL + virtual bool IsFakeClient() = 0; + virtual void SetFakeClient(bool state) = 0; + + // On server, getting data + virtual bool IsFullyConnected() = 0; + virtual void SetFullyConnected(bool state) = 0; + + virtual bool IsUploading() = 0; + virtual void SetUploading(bool state) = 0; + + virtual bool IsHasUserMsgs() = 0; + virtual void SetHasUserMsgs(bool value) = 0; + + virtual bool HasForceUnmodified() = 0; + virtual void SetHasForceUnmodified(bool value) = 0; + + // Number of packets choked at the server because the client - server network channel + // is backlogged with too much data + virtual int GetChokeCount() = 0; + virtual void SetChokeCount(int count) = 0; + + // -1 = no compression. This is where the server is creating the compressed info from + virtual int GetDeltaSequence() = 0; + virtual void SetDeltaSequence(int value) = 0; + + // For filling in big drops + virtual void SetLastCmd(struct usercmd_s *ucmd) = 0; + + virtual double GetConnectTime() = 0; + virtual void SetConnectTime(double time) = 0; + + virtual double GetCmdTime() = 0; + virtual void SetCmdTime(double time) = 0; + + virtual double GetIgnoreCmdTime() = 0; + virtual void SetIgnoreCmdTime(double time) = 0; + + virtual float GetLatency() = 0; + virtual void SetLatency(float latency) = 0; + + virtual float GetPacketLoss() = 0; + virtual void SetPacketLoss(float packetLoss) = 0; + + virtual double GetLocalTime() = 0; + virtual void SetLocalTime(double time) = 0; + + virtual double GetSvTimeBase() = 0; + virtual void SetSvTimeBase(double time) = 0; + + // Or time of disconnect for zombies + virtual double GetConnectionStartedTime() = 0; + virtual void SetConnectionStartedTime(double time) = 0; + + // Time when we should send next world state update (datagram) + virtual double GetNextMessageTime() = 0; + virtual void SetNextMessageTime(double time) = 0; + + // Default time to wait for next message + virtual double GetNextMessageIntervalTime() = 0; + virtual void SetNextMessageIntervalTime(double time_interval) = 0; + + // false - only send messages if the client has sent one and the bandwidth is not choked + virtual bool GetSendMessageState() = 0; + virtual void SetSendMessageState(bool state) = 0; + + virtual bool GetSkipMessageState() = 0; + virtual void SetSkipMessageState(bool state) = 0; + + virtual bool GetSendInfoState() = 0; + virtual void SetSendInfoState(bool state) = 0; + + virtual float GetSendInfoTime() = 0; + virtual void SetSendInfoTime(float time) = 0; + + // updates can be deltad from here + virtual struct client_frame_s *GetFrames() = 0; + + // Per edict events + virtual struct event_state_s *GetEvents() = 0; + + // View Entity (camera or the client itself) svc_setview + virtual const edict_t *GetViewEntity() = 0; + virtual void SetViewEntity(const edict_t *entity) = 0; + + // Identifying number on server + virtual int GetUserID() = 0; + virtual void SetUserID(int iUserID) = 0; + + // name, etc (received from client) + virtual char *GetUserInfo() = 0; + + // MD5 hash is 32 hex #'s, plus trailing 0 + // Hashed CD Key (32 hex alphabetic chars + 0 terminator) + virtual char *GetHashedCDKey() = 0; + + virtual int GetTopColor() = 0; + virtual void SetTopColor(int color) = 0; + + virtual int GetBottomColor() = 0; + virtual void SetBottomColor(int color) = 0; + + virtual resource_t *GetResourcesOnHand() = 0; + virtual resource_t *GetResourcesNeeded() = 0; + + virtual FileHandle_t GetUploadFileHandle() = 0; + virtual void SetUploadFileHandle(FileHandle_t fhFile) = 0; + + virtual bool IsUploadDoneRegistering() = 0; + virtual void SetUploadDoneRegistering(bool state) = 0; + + virtual customization_t *GetCustomizationData() = 0; + + virtual int GetCRC32MapValue() = 0; + virtual void SetCRC32MapValue(int crcMapValue) = 0; + + // Perform client side prediction of weapon effects + // Determines that the client enabled prediction weapons and will be handled pfnGetWeaponData + virtual bool IsClientPredictingWeapons() = 0; + virtual void SetClientPredictingWeapons(bool state) = 0; + + // Perform server side lag compensation of player movement + // Determines that the client is requesting lag compensation + virtual bool IsClientLagCompensation() = 0; + virtual void SetClientLagCompensation(bool state) = 0; + + // Set on server (transmit to client) + virtual char *GetPhysInfo() = 0; + + virtual void SetVoiceStream(int stream_id, int value) = 0; + + virtual int GetSendResourceCount() = 0; + virtual void SetSendResourceCount(int count) = 0; + + virtual bool IsSentNewResponse() = 0; + virtual void SetSentNewResponse(bool state) = 0; + + // this must be the last virtual function in class +#ifdef REHLDS_SELF + virtual client_t* GetClient() = 0; +#endif +}; + +class INetChan { +public: + virtual const netadr_t* GetRemoteAdr() = 0; + virtual sizebuf_t* GetMessageBuf() = 0; + + + // this must be the last virtual function in class +#ifdef REHLDS_SELF + virtual netchan_t* GetChan() = 0; +#endif +}; + +#ifndef REHLDS_SELF +struct client_t; +#endif + +class IRehldsServerStatic { +public: + virtual ~IRehldsServerStatic() { } + + virtual int GetMaxClients() = 0; + virtual bool IsLogActive() = 0; + virtual IGameClient* GetClient(int id) = 0; + virtual client_t* GetClient_t(int id) = 0; + virtual int GetIndexOfClient_t(client_t* client) = 0; + virtual int GetMaxClientsLimit() = 0; + virtual client_t *GetNextClient_t(client_t *client) = 0; + virtual int GetSpawnCount() = 0; + virtual void SetSpawnCount(int count) = 0; + virtual struct server_log_s *GetLog() = 0; + virtual bool IsSecure() = 0; + virtual void SetSecure(bool value) = 0; +}; + +class IRehldsServerData { +public: + virtual ~IRehldsServerData() { } + + virtual const char* GetModelName() = 0; + virtual const char* GetName() = 0; + virtual uint32 GetWorldmapCrc() = 0; + virtual uint8_t* GetClientDllMd5() = 0; + virtual sizebuf_t* GetDatagram() = 0; + virtual sizebuf_t* GetReliableDatagram() = 0; + + virtual void SetModelName(const char* modelname) = 0; + virtual void SetConsistencyNum(int num) = 0; + virtual int GetConsistencyNum() = 0; + virtual int GetResourcesNum() = 0; + virtual int GetDecalNameNum() = 0; + + virtual double GetTime() = 0; + virtual void SetResourcesNum(int num) = 0; + virtual struct resource_s *GetResource(int index) = 0; + virtual void SetName(const char* name) = 0; + virtual class ISteamGameServer *GetSteamGameServer() = 0; + virtual struct netadr_s *GetNetFrom() = 0; + virtual double GetOldTime() = 0; + + virtual void SetNetFrom(struct netadr_s *from) = 0; + virtual void SetWorldmapCrc(uint32 crcValue) = 0; + virtual void SetDecalNameNum(int num) = 0; + + virtual bool IsActive() = 0; + virtual void SetActive(bool state) = 0; + virtual bool IsPaused() = 0; + virtual void SetPaused(bool state) = 0; + virtual int GetLastIndexCheckInPVS() = 0; + virtual void SetLastIndexCheckInPVS(int id) = 0; + virtual double GetLastIndexCheckTimeInPVS() = 0; + virtual void SetLastIndexCheckTimeInPVS(double time) = 0; + virtual const char *GetOldName() = 0; + virtual void SetOldName(const char *name) = 0; + virtual const char *GetStartSpotName() = 0; + virtual void SetStartSpotName(const char *startspot) = 0; + virtual struct model_s *GetWorldModel() = 0; + virtual void SetWorldModel(struct model_s *model) = 0; + virtual struct consistency_s *GetConsistency(int index) = 0; + virtual struct model_s *GetModel(int index) = 0; + virtual struct event_s *GetEventPrecache(int index) = 0; + virtual struct entity_state_s *GetEntityBaseline(int index) = 0; + virtual struct extra_baselines_s *GetEntityInstanceBaselines() = 0; + virtual int GetNumGenericNames() = 0; + virtual void SetNumGenericNames(int num) = 0; + virtual int GetNumEdicts() = 0; + virtual void SetNumEdicts(int num_edicts) = 0; + virtual int GetMaxEdicts() = 0; + virtual void SetMaxEdicts(int max_edicts) = 0; + virtual edict_t *GetEdict(int index) = 0; + virtual server_state_t GetState() = 0; + virtual void SetState(server_state_t st) = 0; + virtual sizebuf_t *GetMulticastBuf() = 0; + virtual sizebuf_t *GetSpectatorBuf() = 0; + virtual sizebuf_t *GetSignonBuf() = 0; +}; diff --git a/thirdparty/hlsdk/public/rehlds/userid_rehlds.h b/thirdparty/hlsdk/public/rehlds/userid_rehlds.h new file mode 100644 index 0000000..53b76f4 --- /dev/null +++ b/thirdparty/hlsdk/public/rehlds/userid_rehlds.h @@ -0,0 +1,46 @@ +/* +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* In addition, as a special exception, the author gives permission to +* link the code of this program with the Half-Life Game Engine ("HL +* Engine") and Modified Game Libraries ("MODs") developed by Valve, +* L.L.C ("Valve"). You must obey the GNU General Public License in all +* respects for all of the code used other than the HL Engine and MODs +* from Valve. If you modify this file, you may extend this exception +* to your version of the file, but you are not obligated to do so. If +* you do not wish to do so, delete this exception statement from your +* version. +* +*/ +#pragma once + +#include "archtypes.h" + +// Authentication types +enum AUTH_IDTYPE +{ + AUTH_IDTYPE_UNKNOWN = 0, + AUTH_IDTYPE_STEAM = 1, + AUTH_IDTYPE_VALVE = 2, + AUTH_IDTYPE_LOCAL = 3 +}; + +typedef struct USERID_s +{ + int idtype; + uint64 m_SteamID; + unsigned int clientip; +} USERID_t; diff --git a/thirdparty/hlsdk/public/tier1/interface.cpp b/thirdparty/hlsdk/public/tier1/interface.cpp new file mode 100644 index 0000000..2027e62 --- /dev/null +++ b/thirdparty/hlsdk/public/tier1/interface.cpp @@ -0,0 +1,238 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// +#if defined( _WIN32 ) && !defined( _X360 ) +#include +#endif + +#if !defined( DONT_PROTECT_FILEIO_FUNCTIONS ) +#define DONT_PROTECT_FILEIO_FUNCTIONS // for protected_things.h +#endif + +#if defined( PROTECTED_THINGS_ENABLE ) +#undef PROTECTED_THINGS_ENABLE // from protected_things.h +#endif + +#include +#include "interface.h" +#include +#include +#ifdef _WIN32 +#include // getcwd +#elif POSIX +#include +#include +#define _getcwd getcwd +#endif + +#ifdef POSIX +using HMODULE = void*; +#endif + +// ------------------------------------------------------------------------------------ // +// InterfaceReg. +// ------------------------------------------------------------------------------------ // +InterfaceReg *InterfaceReg::s_pInterfaceRegs = NULL; + +InterfaceReg::InterfaceReg( InstantiateInterfaceFn fn, const char *pName ) : + m_pName(pName) +{ + m_CreateFn = fn; + m_pNext = s_pInterfaceRegs; + s_pInterfaceRegs = this; +} + +// ------------------------------------------------------------------------------------ // +// CreateInterface. +// This is the primary exported function by a dll, referenced by name via dynamic binding +// that exposes an opqaue function pointer to the interface. +// +// We have the Internal variant so Sys_GetFactoryThis() returns the correct internal +// symbol under GCC/Linux/Mac as CreateInterface is DLL_EXPORT so its global so the loaders +// on those OS's pick exactly 1 of the CreateInterface symbols to be the one that is process wide and +// all Sys_GetFactoryThis() calls find that one, which doesn't work. Using the internal walkthrough here +// makes sure Sys_GetFactoryThis() has the dll specific symbol and GetProcAddress() returns the module specific +// function for CreateInterface again getting the dll specific symbol we need. +// ------------------------------------------------------------------------------------ // +void* CreateInterfaceInternal( const char *pName, int *pReturnCode ) +{ + InterfaceReg *pCur; + + for (pCur=InterfaceReg::s_pInterfaceRegs; pCur; pCur=pCur->m_pNext) + { + if (strcmp(pCur->m_pName, pName) == 0) + { + if (pReturnCode) + { + *pReturnCode = IFACE_OK; + } + return pCur->m_CreateFn(); + } + } + + if (pReturnCode) + { + *pReturnCode = IFACE_FAILED; + } + return NULL; +} + +void* CreateInterface( const char *pName, int *pReturnCode ) +{ + return CreateInterfaceInternal( pName, pReturnCode ); +} + + + +#ifdef POSIX +// Linux doesn't have this function so this emulates its functionality +void *GetModuleHandle(const char *name) +{ + void *handle; + + if( name == NULL ) + { + // hmm, how can this be handled under linux.... + // is it even needed? + return NULL; + } + + if( (handle=dlopen(name, RTLD_NOW))==NULL) + { + printf("DLOPEN Error:%s\n",dlerror()); + // couldn't open this file + return NULL; + } + + // read "man dlopen" for details + // in short dlopen() inc a ref count + // so dec the ref count by performing the close + dlclose(handle); + return handle; +} +#endif + +#if defined( _WIN32 ) && !defined( _X360 ) +#define WIN32_LEAN_AND_MEAN +#include "windows.h" +#endif + +//----------------------------------------------------------------------------- +// Purpose: returns a pointer to a function, given a module +// Input : pModuleName - module name +// *pName - proc name +//----------------------------------------------------------------------------- +static void *Sys_GetProcAddress( const char *pModuleName, const char *pName ) +{ + HMODULE hModule = (HMODULE)GetModuleHandle( pModuleName ); +#ifdef WIN32 + return (void *)GetProcAddress( hModule, pName ); +#else + return (void *)dlsym( (void *)hModule, pName ); +#endif +} + +#if !defined(LINUX) +static void *Sys_GetProcAddress( HMODULE hModule, const char *pName ) +{ +#ifdef WIN32 + return (void *)GetProcAddress( hModule, pName ); +#else + return (void *)dlsym( (void *)hModule, pName ); +#endif +} +#endif + +//----------------------------------------------------------------------------- +// Purpose: Unloads a DLL/component from +// Input : *pModuleName - filename of the component +// Output : opaque handle to the module (hides system dependency) +//----------------------------------------------------------------------------- +void Sys_UnloadModule( CSysModule *pModule ) +{ + if ( !pModule ) + return; + + HMODULE hDLL = reinterpret_cast(pModule); + +#ifdef _WIN32 + FreeLibrary( hDLL ); +#elif defined(POSIX) + dlclose((void *)hDLL); +#endif +} + +//----------------------------------------------------------------------------- +// Purpose: returns a pointer to a function, given a module +// Input : module - windows HMODULE from Sys_LoadModule() +// *pName - proc name +// Output : factory for this module +//----------------------------------------------------------------------------- +CreateInterfaceFn Sys_GetFactory( CSysModule *pModule ) +{ + if ( !pModule ) + return NULL; + + HMODULE hDLL = reinterpret_cast(pModule); +#ifdef _WIN32 + return reinterpret_cast(GetProcAddress( hDLL, CREATEINTERFACE_PROCNAME )); +#elif defined(POSIX) + // Linux gives this error: + //../public/interface.cpp: In function `IBaseInterface *(*Sys_GetFactory + //(CSysModule *)) (const char *, int *)': + //../public/interface.cpp:154: ISO C++ forbids casting between + //pointer-to-function and pointer-to-object + // + // so lets get around it :) + return (CreateInterfaceFn)(Sys_GetProcAddress( (void *)hDLL, CREATEINTERFACE_PROCNAME )); +#endif +} + +//----------------------------------------------------------------------------- +// Purpose: returns the instance of this module +// Output : interface_instance_t +//----------------------------------------------------------------------------- +CreateInterfaceFn Sys_GetFactoryThis( void ) +{ + return &CreateInterfaceInternal; +} + +//----------------------------------------------------------------------------- +// Purpose: returns the instance of the named module +// Input : *pModuleName - name of the module +// Output : interface_instance_t - instance of that module +//----------------------------------------------------------------------------- +CreateInterfaceFn Sys_GetFactory( const char *pModuleName ) +{ +#ifdef _WIN32 + return static_cast( Sys_GetProcAddress( pModuleName, CREATEINTERFACE_PROCNAME ) ); +#elif defined(POSIX) + // see Sys_GetFactory( CSysModule *pModule ) for an explanation + return (CreateInterfaceFn)( Sys_GetProcAddress( pModuleName, CREATEINTERFACE_PROCNAME ) ); +#endif +} + +#if defined( STAGING_ONLY ) && defined( _WIN32 ) + +typedef USHORT( WINAPI RtlCaptureStackBackTrace_FUNC )( + ULONG frames_to_skip, + ULONG frames_to_capture, + PVOID *backtrace, + PULONG backtrace_hash ); + +extern "C" int backtrace( void **buffer, int size ) +{ + HMODULE hNTDll = GetModuleHandleA( "ntdll.dll" ); + static RtlCaptureStackBackTrace_FUNC * const pfnRtlCaptureStackBackTrace = + ( RtlCaptureStackBackTrace_FUNC * )GetProcAddress( hNTDll, "RtlCaptureStackBackTrace" ); + + if ( !pfnRtlCaptureStackBackTrace ) + return 0; + + return (int)pfnRtlCaptureStackBackTrace( 2, size, buffer, 0 ); +} + +#endif // STAGING_ONLY && _WIN32 + diff --git a/thirdparty/hlsdk/public/tier1/interface.h b/thirdparty/hlsdk/public/tier1/interface.h new file mode 100644 index 0000000..c87e7b0 --- /dev/null +++ b/thirdparty/hlsdk/public/tier1/interface.h @@ -0,0 +1,173 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +// This header defines the interface convention used in the valve engine. +// To make an interface and expose it: +// 1. The interface must be ALL pure virtuals, and have no data members. +// 2. Define a name for it. +// 3. In its implementation file, use EXPOSE_INTERFACE or EXPOSE_SINGLE_INTERFACE. + +// Versioning +// There are two versioning cases that are handled by this: +// 1. You add functions to the end of an interface, so it is binary compatible with the previous interface. In this case, +// you need two EXPOSE_INTERFACEs: one to expose your class as the old interface and one to expose it as the new interface. +// 2. You update an interface so it's not compatible anymore (but you still want to be able to expose the old interface +// for legacy code). In this case, you need to make a new version name for your new interface, and make a wrapper interface and +// expose it for the old interface. + +// Static Linking: +// Must mimic unique seperate class 'InterfaceReg' constructors per subsystem. +// Each subsystem can then import and export interfaces as expected. +// This is achieved through unique namespacing 'InterfaceReg' via symbol _SUBSYSTEM. +// Static Linking also needs to generate unique symbols per interface so as to +// provide a 'stitching' method whereby these interface symbols can be referenced +// via the lib's primary module (usually the lib's interface exposure) +// therby stitching all of that lib's code/data together for eventual final exe link inclusion. + +#ifndef INTERFACE_H +#define INTERFACE_H + +#ifdef _WIN32 +#pragma once +#endif + +#ifdef _LINUX +#include // dlopen,dlclose, et al +#include + +#define GetProcAddress dlsym + +#ifdef _snprintf +#undef _snprintf +#endif +#define _snprintf snprintf +#endif + +// All interfaces derive from this. +class IBaseInterface +{ +public: + virtual ~IBaseInterface() {} +}; + +#if !defined( _X360 ) +#define CREATEINTERFACE_PROCNAME "CreateInterface" +#else +// x360 only allows ordinal exports, .def files export "CreateInterface" at 1 +#define CREATEINTERFACE_PROCNAME ((const char*)1) +#endif + +typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode); +typedef void* (*InstantiateInterfaceFn)(); + +// Used internally to register classes. +class InterfaceReg +{ +public: + InterfaceReg(InstantiateInterfaceFn fn, const char *pName); + +public: + InstantiateInterfaceFn m_CreateFn; + const char *m_pName; + + InterfaceReg *m_pNext; // For the global list. + static InterfaceReg *s_pInterfaceRegs; +}; + +// Use this to expose an interface that can have multiple instances. +// e.g.: +// EXPOSE_INTERFACE( CInterfaceImp, IInterface, "MyInterface001" ) +// This will expose a class called CInterfaceImp that implements IInterface (a pure class) +// clients can receive a pointer to this class by calling CreateInterface( "MyInterface001" ) +// +// In practice, the shared header file defines the interface (IInterface) and version name ("MyInterface001") +// so that each component can use these names/vtables to communicate +// +// A single class can support multiple interfaces through multiple inheritance +// +// Use this if you want to write the factory function. +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \ + static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName); +#else +#define EXPOSE_INTERFACE_FN(functionName, interfaceName, versionName) \ + namespace _SUBSYSTEM \ + { \ + static InterfaceReg __g_Create##interfaceName##_reg(functionName, versionName); \ + } +#endif + +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_INTERFACE(className, interfaceName, versionName) \ + static void* __Create##className##_interface() {return static_cast( new className );} \ + static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); +#else +#define EXPOSE_INTERFACE(className, interfaceName, versionName) \ + namespace _SUBSYSTEM \ + { \ + static void* __Create##className##_interface() {return static_cast( new className );} \ + static InterfaceReg __g_Create##className##_reg(__Create##className##_interface, versionName ); \ + } +#endif + +// Use this to expose a singleton interface with a global variable you've created. +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR_WITH_NAMESPACE(className, interfaceNamespace, interfaceName, versionName, globalVarName) \ + static void* __Create##className##interfaceName##_interface() {return static_cast( &globalVarName );} \ + static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); +#else +#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR_WITH_NAMESPACE(className, interfaceNamespace, interfaceName, versionName, globalVarName) \ + namespace _SUBSYSTEM \ + { \ + static void* __Create##className##interfaceName##_interface() {return static_cast( &globalVarName );} \ + static InterfaceReg __g_Create##className##interfaceName##_reg(__Create##className##interfaceName##_interface, versionName); \ + } +#endif + +#define EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, globalVarName) \ + EXPOSE_SINGLE_INTERFACE_GLOBALVAR_WITH_NAMESPACE(className, , interfaceName, versionName, globalVarName) + +// Use this to expose a singleton interface. This creates the global variable for you automatically. +#if !defined(_STATIC_LINKED) || !defined(_SUBSYSTEM) +#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \ + static className __g_##className##_singleton; \ + EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton) +#else +#define EXPOSE_SINGLE_INTERFACE(className, interfaceName, versionName) \ + namespace _SUBSYSTEM \ + { \ + static className __g_##className##_singleton; \ + } \ + EXPOSE_SINGLE_INTERFACE_GLOBALVAR(className, interfaceName, versionName, __g_##className##_singleton) +#endif + +// load/unload components +class CSysModule; + +// interface return status +enum +{ + IFACE_OK = 0, + IFACE_FAILED +}; + + +//----------------------------------------------------------------------------- +// UNDONE: This is obsolete, use the module load/unload/get instead!!! +//----------------------------------------------------------------------------- +extern CreateInterfaceFn Sys_GetFactory( CSysModule *pModule ); +extern CreateInterfaceFn Sys_GetFactory( const char *pModuleName ); +extern CreateInterfaceFn Sys_GetFactoryThis( void ); + +enum Sys_Flags +{ + SYS_NOFLAGS = 0x00, + SYS_NOLOAD = 0x01 // no loading, no ref-counting, only returns handle if lib is loaded. +}; + +#endif