Add stats menu

This commit is contained in:
Federico Cecchetto
2022-03-10 01:30:03 +01:00
parent 9e3cd77c6c
commit 373c0fa2bc
4 changed files with 338 additions and 10 deletions

View File

@ -65,11 +65,6 @@ namespace patches
return com_register_dvars_hook.invoke<void>();
}
int is_item_unlocked()
{
return 0; // 0 == yes
}
void set_client_dvar_from_server_stub(void* a1, void* a2, const char* dvar, const char* value)
{
if (dvar == "cg_fov"s || dvar == "cg_fovMin"s)
@ -214,11 +209,6 @@ namespace patches
true);
utils::hook::call(0x14009EE9E, aim_assist_add_to_target_list);
// unlock all items
utils::hook::jump(0x140413E60, is_item_unlocked); // LiveStorage_IsItemUnlockedFromTable_LocalClient
utils::hook::jump(0x140413860, is_item_unlocked); // LiveStorage_IsItemUnlockedFromTable
utils::hook::jump(0x140412B70, is_item_unlocked); // idk ( unlocks loot etc )
// isProfanity
utils::hook::set(0x1402877D0, 0xC3C033);

View File

@ -0,0 +1,75 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
#include "dvars.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include <utils/nt.hpp>
#include <utils/hook.hpp>
#include <utils/flags.hpp>
namespace stats
{
namespace
{
game::dvar_t* cg_unlock_all_items;
utils::hook::detour is_item_unlocked_hook;
utils::hook::detour is_item_unlocked_hook2;
utils::hook::detour is_item_unlocked_hook3;
int is_item_unlocked_stub(void* a1, void* a2, void* a3)
{
if (cg_unlock_all_items->current.enabled)
{
return 0;
}
return is_item_unlocked_hook.invoke<int>(a1, a2, a3);
}
int is_item_unlocked_stub2(void* a1, void* a2, void* a3, void* a4, void* a5, void* a6)
{
if (cg_unlock_all_items->current.enabled)
{
return 0;
}
return is_item_unlocked_hook2.invoke<int>(a1, a2, a3, a4, a5, a6);
}
int is_item_unlocked_stub3(void* a1)
{
if (cg_unlock_all_items->current.enabled)
{
return 0;
}
return is_item_unlocked_hook3.invoke<int>(a1);
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
if (!game::environment::is_mp())
{
return;
}
cg_unlock_all_items = dvars::register_bool("cg_unlockall_items", false, game::DVAR_FLAG_SAVED, true);
dvars::register_bool("cg_unlockall_classes", false, game::DVAR_FLAG_SAVED, true);
is_item_unlocked_hook.create(0x140413E60, is_item_unlocked_stub);
is_item_unlocked_hook2.create(0x140413860, is_item_unlocked_stub2);
is_item_unlocked_hook3.create(0x140412B70, is_item_unlocked_stub3);
}
};
}
REGISTER_COMPONENT(stats::component)

View File

@ -28,6 +28,8 @@ namespace ui_scripting
utils::hook::detour hks_shutdown_hook;
utils::hook::detour hks_allocator_hook;
utils::hook::detour hks_frame_hook;
utils::hook::detour lui_error_hook;
utils::hook::detour hksi_hks_error_hook;
bool error_hook_enabled = false;
@ -52,6 +54,39 @@ namespace ui_scripting
}
}
int hksi_hks_error_stub(game::hks::lua_State* s, int a2)
{
if (!error_hook_enabled)
{
return hksi_hks_error_hook.invoke<int>(s, a2);
}
else
{
throw std::runtime_error("unknown error");
}
}
int lui_error_stub(game::hks::lua_State* s)
{
if (!error_hook_enabled)
{
return lui_error_hook.invoke<int>(s);
}
else
{
const auto count = static_cast<int>(s->m_apistack.top - s->m_apistack.base);
const auto arguments = get_return_values(count);
std::string error_str = "LUI Error";
if (count && arguments[0].is<std::string>())
{
error_str = arguments[0].as<std::string>();
}
throw std::runtime_error(error_str);
}
}
void* hks_start_stub(char a1)
{
const auto _1 = gsl::finally([]()
@ -162,6 +197,8 @@ namespace ui_scripting
hksi_lual_error_hook.create(SELECT_VALUE(0x1400A5EA0, 0x14012F300), hksi_lual_error_stub);
hks_allocator_hook.create(SELECT_VALUE(0x14009B570, 0x14012BAC0), hks_allocator_stub);
hks_frame_hook.create(SELECT_VALUE(0x1400E37F0, 0x1401755B0), hks_frame_stub);
lui_error_hook.create(SELECT_VALUE(0x14007D7D0, 0x14010C9E0), lui_error_stub);
hksi_hks_error_hook.create(SELECT_VALUE(0x14009DD80, 0x14012E390), hksi_hks_error_stub);
if (game::environment::is_mp())
{