Restore timescale dvars

This commit is contained in:
Diavolo 2022-06-28 11:56:21 +02:00
parent 6b69fb6357
commit ac19219bf0
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
8 changed files with 98 additions and 15 deletions

View File

@ -15,12 +15,12 @@ namespace demonware
buffer.read_bool(&more_data); buffer.read_bool(&more_data);
buffer.set_use_data_types(true); buffer.set_use_data_types(true);
uint32_t seed, title_id, ticket_size; uint32_t seed, title_id;
buffer.read_uint32(&seed); buffer.read_uint32(&seed);
buffer.read_uint32(&title_id); buffer.read_uint32(&title_id);
uint8_t ticket[1024]; uint8_t ticket[1024];
buffer.read_bytes(std::min(ticket_size, static_cast<uint32_t>(sizeof(ticket))), ticket); buffer.read_bytes(sizeof(ticket), ticket);
game::native::bdAuthTicket auth_ticket{}; game::native::bdAuthTicket auth_ticket{};
std::memset(&auth_ticket, 0xA, sizeof auth_ticket); std::memset(&auth_ticket, 0xA, sizeof auth_ticket);

View File

@ -15,7 +15,7 @@ namespace demonware
buffer.read_bool(&more_data); buffer.read_bool(&more_data);
buffer.set_use_data_types(true); buffer.set_use_data_types(true);
uint32_t seed, title_id, ticket_size; uint32_t seed, title_id;
buffer.read_uint32(&seed); buffer.read_uint32(&seed);
buffer.read_uint32(&title_id); buffer.read_uint32(&title_id);
@ -23,7 +23,7 @@ namespace demonware
buffer.read_bytes(sizeof(rsa_key), rsa_key); buffer.read_bytes(sizeof(rsa_key), rsa_key);
uint8_t ticket[1024]; uint8_t ticket[1024];
buffer.read_bytes(std::min(ticket_size, static_cast<uint32_t>(sizeof(ticket))), ticket); buffer.read_bytes(sizeof(ticket), ticket);
game::native::bdAuthTicket auth_ticket{}; game::native::bdAuthTicket auth_ticket{};
std::memset(&auth_ticket, 0xA, sizeof auth_ticket); std::memset(&auth_ticket, 0xA, sizeof auth_ticket);

View File

@ -105,6 +105,8 @@ namespace game
DeferredQueue* deferredQueue; DeferredQueue* deferredQueue;
float* com_codeTimeScale;
namespace mp namespace mp
{ {
SV_GetGuid_t SV_GetGuid; SV_GetGuid_t SV_GetGuid;
@ -306,7 +308,7 @@ namespace game
dvar_value.value = value; dvar_value.value = value;
return dvar_register_variant_dedicated(dvarName, dvar_type::DVAR_TYPE_FLOAT, return dvar_register_variant_dedicated(dvarName, DVAR_TYPE_FLOAT,
flags, dvar_value, domain, description); flags, dvar_value, domain, description);
} }
@ -819,5 +821,7 @@ namespace game
native::level = reinterpret_cast<native::level_locals_t*>(SELECT_VALUE(0x0, 0x1C6D4D8, 0x1B21A20)); native::level = reinterpret_cast<native::level_locals_t*>(SELECT_VALUE(0x0, 0x1C6D4D8, 0x1B21A20));
native::deferredQueue = reinterpret_cast<native::DeferredQueue*>(SELECT_VALUE(0x0, 0x1D55438, 0x0)); native::deferredQueue = reinterpret_cast<native::DeferredQueue*>(SELECT_VALUE(0x0, 0x1D55438, 0x0));
native::com_codeTimeScale = reinterpret_cast<float*>(SELECT_VALUE(0x1769F1C, 0x1CEF554, 0x1B9CEC0));
} }
} }

View File

@ -186,6 +186,8 @@ namespace game
extern DeferredQueue* deferredQueue; extern DeferredQueue* deferredQueue;
extern float* com_codeTimeScale;
// PM Global Definitions & Functions // PM Global Definitions & Functions
constexpr auto JUMP_LAND_SLOWDOWN_TIME = 1800; constexpr auto JUMP_LAND_SLOWDOWN_TIME = 1800;

View File

@ -610,9 +610,10 @@ namespace game
DVAR_CHEAT = 1 << 2, DVAR_CHEAT = 1 << 2,
DVAR_CODINFO = 1 << 3, DVAR_CODINFO = 1 << 3,
DVAR_SCRIPTINFO = 1 << 4, DVAR_SCRIPTINFO = 1 << 4,
DVAR_SAVED = 1 << 6,
DVAR_SERVERINFO = 1 << 10, DVAR_SERVERINFO = 1 << 10,
DVAR_WRITEPROTECTED = 1 << 11, DVAR_INIT = 1 << 11,
DVAR_READONLY = 1 << 13, DVAR_ROM = 1 << 13,
DVAR_AUTOEXEC = 1 << 15, DVAR_AUTOEXEC = 1 << 15,
}; // Incomplete }; // Incomplete

View File

@ -12,7 +12,7 @@ public:
if (game::is_dedi()) return; if (game::is_dedi()) return;
// Set dvar flag // Set dvar flag
utils::hook::set<BYTE>(SELECT_VALUE(0x4302C5, 0x455155, 0), 0x1 | (game::is_mp() ? 0x40 : 0)); utils::hook::set<BYTE>(SELECT_VALUE(0x4302C5, 0x455155, 0), game::native::DVAR_ARCHIVE | (game::is_mp() ? game::native::DVAR_SAVED : 0));
if (game::is_mp()) if (game::is_mp())
{ {
@ -26,12 +26,16 @@ public:
} }
private: private:
static void set_server_command_dvar_stub(const char* dvar, const char* value) static void set_server_command_dvar_stub(const char* dvar_name, const char* value)
{ {
if (strcmp(dvar, "cg_fov") != 0) const auto* dvar = game::native::Dvar_FindVar(dvar_name);
if (dvar != nullptr && ((dvar->flags & game::native::DVAR_ARCHIVE) != 0))
{ {
game::native::Dvar_SetFromStringByName(dvar, value); printf("Not allowing server to override archive dvar '%s'\n", dvar_name);
return;
} }
game::native::Dvar_SetFromStringByName(dvar_name, value);
} }
}; };

74
src/module/gameplay.cpp Normal file
View File

@ -0,0 +1,74 @@
#include <std_include.hpp>
#include <loader/module_loader.hpp>
#include <utils/hook.hpp>
#include "game/game.hpp"
static const game::native::dvar_t** com_fixedtime = nullptr;
static const game::native::dvar_t* com_timescale = nullptr;
static const game::native::dvar_t* dev_timescale = nullptr;
static const game::native::dvar_t* dvar_register_com_timescale(const char* dvar_name, float value,
float min, float max, unsigned __int16 /*flags*/, const char* description)
{
// Remove DVAR_ROM & DVAR_CHEAT
com_timescale = game::native::Dvar_RegisterFloat(dvar_name, value,
min, max, game::native::DVAR_CODINFO | game::native::DVAR_SAVED, description);
return com_timescale;
}
static const game::native::dvar_t* dvar_register_dev_timescale(const char* dvar_name, float value,
float min, float max, unsigned __int16 /*flags*/, const char* description)
{
// Remove DVAR_CHEAT
dev_timescale = game::native::Dvar_RegisterFloat(dvar_name, value,
min, max, game::native::DVAR_CODINFO, description);
return dev_timescale;
}
static float com_get_timescale_for_snd()
{
const auto fixed_time = (*com_fixedtime)->current.integer;
if (fixed_time != 0)
{
return static_cast<float>(fixed_time);
}
return dev_timescale->current.value * com_timescale->current.value;
}
static float com_get_timescale_for_sv()
{
assert(com_timescale != nullptr);
if (dev_timescale->current.value == 1.0f && com_timescale->current.value == 1.0f
&& *game::native::com_codeTimeScale == 1.0f)
{
return 1.0f;
}
return dev_timescale->current.value * com_timescale->current.value * (*game::native::com_codeTimeScale);
}
class gameplay final : public module
{
public:
void post_load() override
{
// com_timescale && timescale are already implemented on SP
if (game::is_mp())
{
com_fixedtime = reinterpret_cast<const game::native::dvar_t**>(0x1CEF568);
utils::hook(0x55419F, &dvar_register_com_timescale, HOOK_CALL).install()->quick();
utils::hook(0x5541CF, &dvar_register_dev_timescale, HOOK_CALL).install()->quick();
utils::hook(0x6C66CB, &com_get_timescale_for_snd, HOOK_CALL).install()->quick();
utils::hook(0x6A71E0, &com_get_timescale_for_sv, HOOK_JUMP).install()->quick();
}
}
};
REGISTER_MODULE(gameplay)

View File

@ -316,9 +316,7 @@ void player_movement::pm_project_velocity_stub(const float* vel_in, const float*
if (std::fabsf(normal[2]) < 0.001f || length_squared_2d == 0.0f) if (std::fabsf(normal[2]) < 0.001f || length_squared_2d == 0.0f)
{ {
vel_out[0] = vel_in[0]; std::memcpy(vel_out, vel_in, sizeof(std::float_t[3]));
vel_out[1] = vel_in[1];
vel_out[2] = vel_in[2];
return; return;
} }
@ -590,7 +588,7 @@ void player_movement::patch_sp()
void player_movement::register_common_dvars() void player_movement::register_common_dvars()
{ {
// Pm dvars // pm dvars
pm_bounces = game::native::Dvar_RegisterBool("pm_bounces", false, pm_bounces = game::native::Dvar_RegisterBool("pm_bounces", false,
game::native::DVAR_CODINFO, "CoD4 Bounces"); game::native::DVAR_CODINFO, "CoD4 Bounces");
pm_bouncesAllAngles = game::native::Dvar_RegisterBool("pm_bouncesAllAngles", false, pm_bouncesAllAngles = game::native::Dvar_RegisterBool("pm_bouncesAllAngles", false,