Correctly handle fov

This commit is contained in:
momo5502 2019-01-26 12:30:19 +01:00
parent c439240ecd
commit 70a7467105
4 changed files with 73 additions and 1 deletions

View File

@ -13,6 +13,8 @@ namespace game
DB_LoadXAssets_t DB_LoadXAssets;
Dvar_SetFromStringByName_t Dvar_SetFromStringByName;
G_RunFrame_t G_RunFrame;
MSG_ReadData_t MSG_ReadData;
@ -298,6 +300,8 @@ namespace game
native::DB_LoadXAssets = native::DB_LoadXAssets_t(SELECT_VALUE(0x48A8E0, 0x4CD020, 0x44F770));
native::Dvar_SetFromStringByName = native::Dvar_SetFromStringByName_t(SELECT_VALUE(0x4DD090, 0x5BF740, 0x518DF0));
native::G_RunFrame = native::G_RunFrame_t(SELECT_VALUE(0x52EAA0, 0x50CB70, 0x48AD60));
native::MSG_ReadData = native::MSG_ReadData_t(SELECT_VALUE(0, 0x5592A0, 0));

View File

@ -21,6 +21,9 @@ namespace game
typedef void (*DB_LoadXAssets_t)(XZoneInfo* zoneInfo, unsigned int zoneCount, int sync);
extern DB_LoadXAssets_t DB_LoadXAssets;
typedef void (*Dvar_SetFromStringByName_t)(const char *dvarName, const char *string);
extern Dvar_SetFromStringByName_t Dvar_SetFromStringByName;
typedef int (*G_RunFrame_t)(int, int);
extern G_RunFrame_t G_RunFrame;

View File

@ -495,5 +495,56 @@ namespace game
char charId;
const char* name;
};
union DvarValue
{
bool enabled;
int integer;
unsigned int unsignedInt;
float value;
float vector[4];
const char* string;
char color[4];
};
struct enum_limit
{
int stringCount;
const char** strings;
};
struct int_limit
{
int min;
int max;
};
struct float_limit
{
float min;
float max;
};
union DvarLimits
{
enum_limit enumeration;
int_limit integer;
float_limit value;
float_limit vector;
};
struct dvar_t
{
const char* name;
unsigned int flags;
char type;
bool modified;
DvarValue current;
DvarValue latched;
DvarValue reset;
DvarLimits domain;
bool (__cdecl *domainFunc)(dvar_t*, DvarValue);
dvar_t* hashNext;
};
}
}

View File

@ -10,12 +10,26 @@ public:
{
if (game::is_dedi()) return;
utils::hook::set<BYTE>(SELECT_VALUE(0x4302C5, 0x455155, 0), 0x41);
// Set dvar flag
utils::hook::set<BYTE>(SELECT_VALUE(0x4302C5, 0x455155, 0), 0x1 | (game::is_mp() ? 0x40 : 0));
if (game::is_mp())
{
// Set dvar limit
static const auto cg_fov_limit = 90.0f;
utils::hook::set(0x455148, &cg_fov_limit);
// Prevent value change via internal scripts
utils::hook(0x4698BA, &set_server_command_dvar_stub, HOOK_CALL).install()->quick();
}
}
private:
static void set_server_command_dvar_stub(const char* dvar, const char* value)
{
if (strcmp(dvar, "cg_fov") != 0 || strcmp(value, "65") != 0)
{
game::native::Dvar_SetFromStringByName(dvar, value);
}
}
};