iw5-mod/src/game/game.cpp

123 lines
3.3 KiB
C++
Raw Normal View History

2018-12-24 23:22:56 +01:00
#include <std_include.hpp>
#include "game.hpp"
namespace game
{
namespace native
{
2018-12-28 12:50:34 +01:00
Cmd_AddCommand_t Cmd_AddCommand;
2019-01-16 16:19:21 +01:00
Com_Error_t Com_Error;
Conbuf_AppendText_t Conbuf_AppendText;
2018-12-28 13:59:44 +01:00
DB_LoadXAssets_t DB_LoadXAssets;
MSG_ReadData_t MSG_ReadData;
2019-01-13 19:03:46 +01:00
RemoveRefToValue_t RemoveRefToValue;
2018-12-24 23:22:56 +01:00
Sys_ShowConsole_t Sys_ShowConsole;
2018-12-28 12:50:34 +01:00
2019-01-13 19:03:46 +01:00
VM_Notify_t VM_Notify;
2018-12-28 12:50:34 +01:00
int* cmd_args;
int* cmd_argc;
const char*** cmd_argv;
2018-12-24 23:22:56 +01:00
2019-01-13 19:03:46 +01:00
short* scrVarGlob;
char** scrMemTreePub;
2019-01-16 16:19:21 +01:00
unsigned int* levelEntityId;
2019-01-13 19:03:46 +01:00
void AddRefToValue(VariableValue* value)
{
if (value->type == SCRIPT_OBJECT)
{
++scrVarGlob[4 * value->u.entityId];
}
2019-01-13 21:28:05 +01:00
else if ((value->type & ~1) == SCRIPT_STRING)
2019-01-13 19:03:46 +01:00
{
static const auto size = is_sp() ? 16 : 12;
const auto ref_count = reinterpret_cast<unsigned volatile *>(*scrMemTreePub + size * value
->u.stringValue);
InterlockedIncrement(ref_count);
}
else if (value->type == SCRIPT_VECTOR)
{
if (!*PBYTE(value->u.vectorValue - 1))
{
++*PWORD(value->u.vectorValue - 4);
}
}
}
scr_entref_t Scr_GetEntityIdRef(const unsigned int id)
{
static auto class_array = reinterpret_cast<DWORD*>(SELECT_VALUE(0x19AFC84, 0x1E72184, 0x1D3C804));
static auto ent_array = reinterpret_cast<WORD*>(SELECT_VALUE(0x19AFC82, 0x1E72182, 0x1D3C802));
scr_entref_t result{};
result.raw.classnum = static_cast<unsigned short>(class_array[2 * id]) >> 8;
result.raw.entnum = ent_array[4 * id];
return result;
}
const char* SL_ConvertToString(unsigned int stringValue)
{
if (!stringValue) return nullptr;
static const auto size = is_sp() ? 16 : 12;
return *scrMemTreePub + size * stringValue + 4;
}
}
2018-12-24 23:22:56 +01:00
2018-12-26 16:28:16 +01:00
launcher::mode mode = launcher::mode::none;
2018-12-24 23:22:56 +01:00
bool is_mp()
{
2018-12-26 16:28:16 +01:00
return mode == launcher::mode::multiplayer;
2018-12-24 23:22:56 +01:00
}
bool is_sp()
{
2018-12-26 16:28:16 +01:00
return mode == launcher::mode::singleplayer;
2018-12-24 23:22:56 +01:00
}
bool is_dedi()
{
2018-12-26 16:28:16 +01:00
return mode == launcher::mode::server;
2018-12-24 23:22:56 +01:00
}
void initialize(const launcher::mode _mode)
{
mode = _mode;
2018-12-28 12:50:34 +01:00
native::Cmd_AddCommand = native::Cmd_AddCommand_t(SELECT_VALUE(0x558820, 0x545DF0, 0));
2019-01-16 16:19:21 +01:00
native::Com_Error = native::Com_Error_t(SELECT_VALUE(0x425540, 0x555450, 0x4D93F0));
native::Conbuf_AppendText = native::Conbuf_AppendText_t(SELECT_VALUE(0x4C84E0, 0x5CF610, 0x53C790));
2018-12-28 13:59:44 +01:00
native::DB_LoadXAssets = native::DB_LoadXAssets_t(SELECT_VALUE(0x48A8E0, 0x4CD020, 0x44F770));
native::MSG_ReadData = native::MSG_ReadData_t(SELECT_VALUE(0, 0x5592A0, 0));
2019-01-13 19:03:46 +01:00
native::RemoveRefToValue = native::RemoveRefToValue_t(SELECT_VALUE(0x477EA0, 0x565730, 0x4E8A40));
2018-12-24 23:22:56 +01:00
native::Sys_ShowConsole = native::Sys_ShowConsole_t(SELECT_VALUE(0x470AF0, 0x5CF590, 0));
2018-12-28 12:50:34 +01:00
2019-01-13 19:03:46 +01:00
native::VM_Notify = native::VM_Notify_t(SELECT_VALUE(0x610200, 0x569720, 0x4EF450));
2018-12-28 12:50:34 +01:00
native::cmd_args = reinterpret_cast<int*>(SELECT_VALUE(0x1750750, 0x1C978D0, 0x1B455F8));
native::cmd_argc = reinterpret_cast<int*>(SELECT_VALUE(0x1750794, 0x1C97914, 0x1B4563C));
native::cmd_argv = reinterpret_cast<const char***>(SELECT_VALUE(0x17507B4, 0x1C97934, 0x1B4565C));
2019-01-13 19:03:46 +01:00
native::scrVarGlob = reinterpret_cast<short*>(SELECT_VALUE(0x19AFC80, 0x1E72180, 0x1D3C800));
native::scrMemTreePub = reinterpret_cast<char**>(SELECT_VALUE(0x196FB00, 0x1E32000, 0x1C152A4));
2019-01-16 16:19:21 +01:00
native::levelEntityId = reinterpret_cast<unsigned int*>(SELECT_VALUE(0x1BCBCA4, 0x208E1A4, 0x1CD873C));
2018-12-24 23:22:56 +01:00
}
}