iw4x-client/src/Game/Functions.cpp

309 lines
11 KiB
C++
Raw Normal View History

#include "STDInclude.hpp"
2015-12-23 08:45:53 -05:00
namespace Game
{
// C-Style casts are fine here, that's where we're doing our dirty stuff anyways...
2016-01-12 08:27:48 -05:00
BG_LoadWeaponDef_LoadObj_t BG_LoadWeaponDef_LoadObj = (BG_LoadWeaponDef_LoadObj_t)0x57B5F0;
2015-12-24 06:30:52 -05:00
Cbuf_AddText_t Cbuf_AddText = (Cbuf_AddText_t)0x404B20;
2016-01-01 11:36:47 -05:00
CL_GetClientName_t CL_GetClientName = (CL_GetClientName_t)0x4563D0;
2015-12-24 06:30:52 -05:00
CL_IsCgameInitialized_t CL_IsCgameInitialized = (CL_IsCgameInitialized_t)0x43EB20;
2015-12-25 15:42:35 -05:00
CL_ConnectFromParty_t CL_ConnectFromParty = (CL_ConnectFromParty_t)0x433D30;
2015-12-24 06:30:52 -05:00
2015-12-23 08:45:53 -05:00
Cmd_AddCommand_t Cmd_AddCommand = (Cmd_AddCommand_t)0x470090;
2015-12-24 06:30:52 -05:00
Cmd_ExecuteSingleCommand_t Cmd_ExecuteSingleCommand = (Cmd_ExecuteSingleCommand_t)0x609540;
2015-12-23 08:45:53 -05:00
2015-12-23 16:21:03 -05:00
Com_Error_t Com_Error = (Com_Error_t)0x4B22D0;
Com_Printf_t Com_Printf = (Com_Printf_t)0x402500;
Com_PrintMessage_t Com_PrintMessage = (Com_PrintMessage_t)0x4AA830;
2015-12-23 16:21:03 -05:00
Com_Milliseconds_t Com_Milliseconds = (Com_Milliseconds_t)0x42A660;
2015-12-28 08:08:46 -05:00
Com_ParseExt_t Com_ParseExt = (Com_ParseExt_t)0x474D60;
2015-12-23 16:21:03 -05:00
2016-01-22 05:59:43 -05:00
DB_EnumXAssets_t DB_EnumXAssets = (DB_EnumXAssets_t)0x4B76D0;
2015-12-23 16:21:03 -05:00
DB_FindXAssetHeader_t DB_FindXAssetHeader = (DB_FindXAssetHeader_t)0x407930;
2015-12-25 20:51:58 -05:00
DB_GetXAssetNameHandler_t* DB_GetXAssetNameHandlers = (DB_GetXAssetNameHandler_t*)0x799328;
2015-12-23 08:45:53 -05:00
DB_GetXAssetSizeHandler_t* DB_GetXAssetSizeHandlers = (DB_GetXAssetSizeHandler_t*)0x799488;
2016-01-05 19:23:43 -05:00
DB_GetXAssetTypeName_t DB_GetXAssetTypeName = (DB_GetXAssetTypeName_t)0x4CFCF0;
2015-12-23 21:26:46 -05:00
DB_LoadXAssets_t DB_LoadXAssets = (DB_LoadXAssets_t)0x4E5930;
2015-12-23 08:45:53 -05:00
Dvar_RegisterBool_t Dvar_RegisterBool = (Dvar_RegisterBool_t)0x4CE1A0;
Dvar_RegisterFloat_t Dvar_RegisterFloat = (Dvar_RegisterFloat_t)0x648440;
2016-01-16 07:11:00 -05:00
Dvar_RegisterVec2_t Dvar_RegisterVec2 = (Dvar_RegisterVec2_t)0x4F6070;
Dvar_RegisterVec3_t Dvar_RegisterVec3 = (Dvar_RegisterVec3_t)0x4EF8E0;
Dvar_RegisterVec4_t Dvar_RegisterVec4 = (Dvar_RegisterVec4_t)0x4F28E0;
2015-12-23 08:45:53 -05:00
Dvar_RegisterInt_t Dvar_RegisterInt = (Dvar_RegisterInt_t)0x479830;
Dvar_RegisterEnum_t Dvar_RegisterEnum = (Dvar_RegisterEnum_t)0x412E40;
Dvar_RegisterString_t Dvar_RegisterString = (Dvar_RegisterString_t)0x4FC7E0;
2016-02-07 20:09:55 -05:00
Dvar_RegisterColor_t Dvar_RegisterColor = (Dvar_RegisterColor_t)0x4F28E0;//0x471500;
2015-12-23 08:45:53 -05:00
2016-02-07 20:09:55 -05:00
Dvar_GetUnpackedColorByName_t Dvar_GetUnpackedColorByName = (Dvar_GetUnpackedColorByName_t)0x406530;
2015-12-23 08:45:53 -05:00
Dvar_FindVar_t Dvar_FindVar = (Dvar_FindVar_t)0x4D5390;
2016-01-07 20:20:55 -05:00
Dvar_InfoString_Big_t Dvar_InfoString_Big = (Dvar_InfoString_Big_t)0x4D98A0;
2015-12-23 08:45:53 -05:00
Dvar_SetCommand_t Dvar_SetCommand = (Dvar_SetCommand_t)0x4EE430;
Field_Clear_t Field_Clear = (Field_Clear_t)0x437EB0;
2015-12-23 21:26:46 -05:00
FreeMemory_t FreeMemory = (FreeMemory_t)0x4D6640;
2015-12-25 15:42:35 -05:00
FS_FileExists_t FS_FileExists = (FS_FileExists_t)0x4DEFA0;
2015-12-23 21:26:46 -05:00
FS_FreeFile_t FS_FreeFile = (FS_FreeFile_t)0x4416B0;
FS_ReadFile_t FS_ReadFile = (FS_ReadFile_t)0x4F4B90;
2015-12-25 15:42:35 -05:00
FS_ListFiles_t FS_ListFiles = (FS_ListFiles_t)0x441BB0;
FS_FreeFileList_t FS_FreeFileList = (FS_FreeFileList_t)0x4A5DE0;
FS_FOpenFileAppend_t FS_FOpenFileAppend = (FS_FOpenFileAppend_t)0x410BB0;
FS_FOpenFileAppend_t FS_FOpenFileWrite = (FS_FOpenFileAppend_t)0x4BA530;
FS_FOpenFileRead_t FS_FOpenFileRead = (FS_FOpenFileRead_t)0x46CBF0;
FS_FCloseFile_t FS_FCloseFile = (FS_FCloseFile_t)0x462000;
FS_WriteFile_t FS_WriteFile = (FS_WriteFile_t)0x426450;
FS_Write_t FS_Write = (FS_Write_t)0x4C06E0;
FS_Read_t FS_Read = (FS_Read_t)0x4A04C0;
FS_Seek_t FS_Seek = (FS_Seek_t)0x4A63D0;
FS_FTell_t FS_FTell = (FS_FTell_t)0x4E6760;
FS_Remove_t FS_Remove = (FS_Remove_t)0x4660F0;
FS_Restart_t FS_Restart = (FS_Restart_t)0x461A50;
FS_BuildPathToFile_t FS_BuildPathToFile = (FS_BuildPathToFile_t)0x4702C0;
2015-12-23 21:26:46 -05:00
Image_LoadFromFileWithReader_t Image_LoadFromFileWithReader = (Image_LoadFromFileWithReader_t)0x53ABF0;
Image_Release_t Image_Release = (Image_Release_t)0x51F010;
2015-12-24 06:30:52 -05:00
Menus_CloseAll_t Menus_CloseAll = (Menus_CloseAll_t)0x4BA5B0;
2015-12-23 21:26:46 -05:00
Menus_OpenByName_t Menus_OpenByName = (Menus_OpenByName_t)0x4CCE60;
2016-01-15 13:23:07 -05:00
Menus_FindByName_t Menus_FindByName = (Menus_FindByName_t)0x487240;
2016-01-14 08:26:29 -05:00
Menu_IsVisible_t Menu_IsVisible = (Menu_IsVisible_t)0x4D77D0;
Menus_MenuIsInStack_t Menus_MenuIsInStack = (Menus_MenuIsInStack_t)0x47ACB0;
2015-12-23 21:26:46 -05:00
2016-01-09 14:56:28 -05:00
MSG_Init_t MSG_Init = (MSG_Init_t)0x45FCA0;
MSG_ReadData_t MSG_ReadData = (MSG_ReadData_t)0x4527C0;
MSG_ReadLong_t MSG_ReadLong = (MSG_ReadLong_t)0x4C9550;
MSG_ReadShort_t MSG_ReadShort = (MSG_ReadShort_t)0x40BDD0;
MSG_ReadInt64_t MSG_ReadInt64 = (MSG_ReadInt64_t)0x4F1850;
MSG_ReadString_t MSG_ReadString = (MSG_ReadString_t)0x60E2B0;
MSG_WriteByte_t MSG_WriteByte = (MSG_WriteByte_t)0x48C520;
MSG_WriteData_t MSG_WriteData = (MSG_WriteData_t)0x4F4120;
MSG_WriteLong_t MSG_WriteLong = (MSG_WriteLong_t)0x41CA20;
MSG_WriteBitsCompress_t MSG_WriteBitsCompress = (MSG_WriteBitsCompress_t)0x4319D0;
MSG_ReadByte_t MSG_ReadByte = (MSG_ReadByte_t)0x4C1C20;
2015-12-24 10:55:38 -05:00
NET_AdrToString_t NET_AdrToString = (NET_AdrToString_t)0x469880;
NET_CompareAdr_t NET_CompareAdr = (NET_CompareAdr_t)0x4D0AA0;
2016-01-03 18:00:07 -05:00
NET_IsLocalAddress_t NET_IsLocalAddress = (NET_IsLocalAddress_t)0x402BD0;
2015-12-24 10:55:38 -05:00
NET_StringToAdr_t NET_StringToAdr = (NET_StringToAdr_t)0x409010;
2016-01-24 10:57:16 -05:00
NET_OutOfBandPrint_t NET_OutOfBandPrint = (NET_OutOfBandPrint_t)0x4AEF00;
NET_OutOfBandData_t NET_OutOfBandData = (NET_OutOfBandData_t)0x49C7E0;
2015-12-24 10:55:38 -05:00
2015-12-26 21:56:00 -05:00
Live_MPAcceptInvite_t Live_MPAcceptInvite = (Live_MPAcceptInvite_t)0x420A6D;
2016-01-01 20:28:09 -05:00
Live_ParsePlaylists_t Live_ParsePlaylists = (Live_ParsePlaylists_t)0x4295A0;
2015-12-26 21:56:00 -05:00
LoadInitialFF_t LoadInitialFF = (LoadInitialFF_t)0x506AC0;
2015-12-23 08:45:53 -05:00
LoadModdableRawfile_t LoadModdableRawfile = (LoadModdableRawfile_t)0x61ABC0;
2015-12-27 22:02:30 -05:00
LocalizeString_t LocalizeString = (LocalizeString_t)0x4FB010;
LocalizeMapString_t LocalizeMapString = (LocalizeMapString_t)0x44BB30;
2016-01-03 09:44:51 -05:00
SE_Load_t SE_Load = (SE_Load_t)0x502A30;
PC_ReadToken_t PC_ReadToken = (PC_ReadToken_t)0x4ACCD0;
2015-12-25 15:42:35 -05:00
PC_ReadTokenHandle_t PC_ReadTokenHandle = (PC_ReadTokenHandle_t)0x4D2060;
PC_SourceError_t PC_SourceError = (PC_SourceError_t)0x467A00;
2016-01-02 14:30:19 -05:00
Party_GetMaxPlayers_t Party_GetMaxPlayers = (Party_GetMaxPlayers_t)0x4F5D60;
PartyHost_CountMembers_t PartyHost_CountMembers = (PartyHost_CountMembers_t)0x497330;
2015-12-26 21:56:00 -05:00
PartyHost_GetMemberAddressBySlot_t PartyHost_GetMemberAddressBySlot = (PartyHost_GetMemberAddressBySlot_t)0x44E100;
2016-01-07 20:20:55 -05:00
PartyHost_GetMemberName_t PartyHost_GetMemberName = (PartyHost_GetMemberName_t)0x44BE90;
2015-12-26 21:56:00 -05:00
2016-01-12 17:42:05 -05:00
R_AddCmdDrawStretchPic_t R_AddCmdDrawStretchPic = (R_AddCmdDrawStretchPic_t)0x509770;
R_RegisterFont_t R_RegisterFont = (R_RegisterFont_t)0x505670;
R_AddCmdDrawText_t R_AddCmdDrawText = (R_AddCmdDrawText_t)0x509D80;
R_TextWidth_t R_TextWidth = (R_TextWidth_t)0x5056C0;
2016-01-16 09:03:09 -05:00
R_TextHeight_t R_TextHeight = (R_TextHeight_t)0x505770;
2016-01-12 17:42:05 -05:00
2015-12-23 21:26:46 -05:00
Script_Alloc_t Script_Alloc = (Script_Alloc_t)0x422E70;
Script_SetupTokens_t Script_SetupTokens = (Script_SetupTokens_t)0x4E6950;
Script_CleanString_t Script_CleanString = (Script_CleanString_t)0x498220;
2015-12-25 15:42:35 -05:00
SetConsole_t SetConsole = (SetConsole_t)0x44F060;
2016-01-05 19:23:43 -05:00
SL_ConvertToString_t SL_ConvertToString = (SL_ConvertToString_t)0x4EC1D0;
2016-01-22 07:18:26 -05:00
SL_GetString_t SL_GetString = (SL_GetString_t)0x4CDC10;
2016-01-05 19:23:43 -05:00
2015-12-26 21:56:00 -05:00
Steam_JoinLobby_t Steam_JoinLobby = (Steam_JoinLobby_t)0x49CF70;
2016-01-07 20:20:55 -05:00
SV_GameClientNum_Score_t SV_GameClientNum_Score = (SV_GameClientNum_Score_t)0x469AC0;
Sys_IsMainThread_t Sys_IsMainThread = (Sys_IsMainThread_t)0x4C37D0;
2016-01-24 10:57:16 -05:00
Sys_SendPacket_t Sys_SendPacket = (Sys_SendPacket_t)0x60FDC0;
2015-12-25 15:42:35 -05:00
UI_AddMenuList_t UI_AddMenuList = (UI_AddMenuList_t)0x4533C0;
2016-01-08 09:03:38 -05:00
UI_LoadMenus_t UI_LoadMenus = (UI_LoadMenus_t)0x641460;
2015-12-30 19:10:15 -05:00
UI_DrawHandlePic_t UI_DrawHandlePic = (UI_DrawHandlePic_t)0x4D0EA0;
2015-12-25 15:42:35 -05:00
2015-12-23 21:26:46 -05:00
Win_GetLanguage_t Win_GetLanguage = (Win_GetLanguage_t)0x45CBA0;
2015-12-23 08:45:53 -05:00
void** DB_XAssetPool = (void**)0x7998A8;
unsigned int* g_poolSize = (unsigned int*)0x7995E8;
DWORD* cmd_id = (DWORD*)0x1AAC5D0;
DWORD* cmd_argc = (DWORD*)0x1AAC614;
char*** cmd_argv = (char***)0x1AAC634;
2015-12-23 21:26:46 -05:00
source_t **sourceFiles = (source_t **)0x7C4A98;
keywordHash_t **menuParseKeywordHash = (keywordHash_t **)0x63AE928;
int* svs_numclients = (int*)0x31D938C;
client_t* svs_clients = (client_t*)0x31D9390;
2015-12-25 16:34:05 -05:00
UiContext *uiContext = (UiContext *)0x62E2858;
2015-12-27 22:02:30 -05:00
int* arenaCount = (int*)0x62E6930;
mapArena_t* arenas = (mapArena_t*)0x62E6934;
int* gameTypeCount = (int*)0x62E50A0;
gameTypeName_t* gameTypes = (gameTypeName_t*)0x62E50A4;
2015-12-28 19:45:04 -05:00
XBlock** g_streamBlocks = (XBlock**)0x16E554C;
2016-01-02 12:36:01 -05:00
bool* g_lobbyCreateInProgress = (bool*)0x66C9BC2;
2016-01-02 14:30:19 -05:00
party_t** partyIngame = (party_t**)0x1081C00;
PartyData_s** partyData = (PartyData_s**)0x107E500;
2016-01-02 12:36:01 -05:00
2016-01-03 18:00:07 -05:00
int* numIP = (int*)0x64A1E68;
netIP_t* localIP = (netIP_t*)0x64A1E28;
2016-01-09 14:56:28 -05:00
int* demoFile = (int*)0xA5EA1C;
int* demoPlaying = (int*)0xA5EA0C;
2016-01-10 09:48:49 -05:00
int* demoRecording = (int*)0xA5EA08;
2016-01-09 14:56:28 -05:00
int* serverMessageSequence = (int*)0xA3E9B4;
2016-01-11 06:09:31 -05:00
gentity_t* g_entities = (gentity_t*)0x18835D8;
2016-02-12 16:23:41 -05:00
SOCKET* ip_socket = (SOCKET*)0x64A3008;
2015-12-23 08:45:53 -05:00
void* ReallocateAssetPool(XAssetType type, unsigned int newSize)
{
int elSize = DB_GetXAssetSizeHandlers[type]();
2016-01-12 13:08:26 -05:00
void* poolEntry = Utils::Memory::Allocate(newSize * elSize);
2015-12-23 08:45:53 -05:00
DB_XAssetPool[type] = poolEntry;
g_poolSize[type] = newSize;
return poolEntry;
}
2015-12-24 06:53:11 -05:00
void Menu_FreeItemMemory(Game::itemDef_t* item)
{
__asm
{
mov edi, item
mov eax, 63D880h
call eax
}
}
2015-12-24 10:55:38 -05:00
2016-01-04 09:43:09 -05:00
const char* TabeLookup(StringTable* stringtable, int row, int column)
{
if (!stringtable || !stringtable->values || row >= stringtable->rowCount || column >= stringtable->columnCount) return "";
const char* value = stringtable->values[row * stringtable->columnCount + column].string;
if (!value) value = "";
return value;
}
2015-12-27 22:02:30 -05:00
const char* UI_LocalizeMapName(const char* mapName)
{
2016-01-24 13:58:13 -05:00
for (int i = 0; i < *arenaCount; ++i)
2015-12-27 22:02:30 -05:00
{
if (!_stricmp(arenas[i].mapName, mapName))
{
char* uiName = &arenas[i].uiName[0];
if ((uiName[0] == 'M' && uiName[1] == 'P') || (uiName[0] == 'P' && uiName[1] == 'A')) // MPUI/PATCH
{
char* name = LocalizeMapString(uiName);
return name;
}
return uiName;
}
}
return mapName;
}
const char* UI_LocalizeGameType(const char* gameType)
{
if (gameType == 0 || *gameType == '\0')
{
return "";
}
2016-01-24 13:58:13 -05:00
for (int i = 0; i < *gameTypeCount; ++i)
2015-12-27 22:02:30 -05:00
{
if (!_stricmp(gameTypes[i].gameType, gameType))
{
char* name = LocalizeMapString(gameTypes[i].uiName);
return name;
}
}
return gameType;
}
2016-01-05 19:23:43 -05:00
const char *DB_GetXAssetName(XAsset *asset)
{
if (!asset) return "";
return DB_GetXAssetNameHandlers[asset->type](&asset->header);
}
XAssetType DB_GetXAssetNameType(const char* name)
{
2016-01-24 13:58:13 -05:00
for (int i = 0; i < ASSET_TYPE_COUNT; ++i)
2016-01-05 19:23:43 -05:00
{
XAssetType type = static_cast<XAssetType>(i);
2016-01-05 19:23:43 -05:00
if (!_stricmp(DB_GetXAssetTypeName(type), name))
{
return type;
}
}
return ASSET_TYPE_INVALID;
}
2016-01-08 09:50:39 -05:00
2016-02-03 16:01:10 -05:00
bool DB_IsZoneLoaded(const char* zone)
{
int zoneCount = Utils::Hook::Get<int>(0x1261BCC);
char* zoneIndices = reinterpret_cast<char*>(0x16B8A34);
char* zoneData = reinterpret_cast<char*>(0x14C0F80);
for (int i = 0; i < zoneCount; ++i)
2016-02-03 16:01:10 -05:00
{
std::string name = zoneData + 4 + 0xA4 * (zoneIndices[i] & 0xFF);
if (name == zone)
{
return true;
}
}
return false;
}
2016-01-08 09:50:39 -05:00
void MessageBox(std::string message, std::string title)
{
SetConsole("com_errorMessage", message.data());
SetConsole("com_errorTitle", title.data());
Cbuf_AddText(0, "openmenu error_popmenu_lobby");
}
unsigned int R_HashString(const char* string)
{
unsigned int hash = 0;
while (*string)
{
hash = (*string | 0x20) ^ (33 * hash);
string++;
}
return hash;
}
2016-01-08 09:50:39 -05:00
}