Added dvars loaded scheduler event, fixed issues with new dvars resetting on match load, fixed issue with blackjack not being available at restart of the game

This commit is contained in:
Jari van der Kaap 2023-02-11 20:40:26 +01:00
parent 52005ab43f
commit a045200523
6 changed files with 48 additions and 24 deletions

View File

@ -25,6 +25,10 @@ DataSources.MPStatsSettings = DataSourceHelpers.ListSetup( "MPStatsSettings", fu
return optionsTable return optionsTable
end) end)
if Dvar.cg_unlockall_loot:get() == true then
Engine.SetDvar( "ui_enableAllHeroes", 1 )
end
LUI.createMenu.MPStatsMenu = function ( controller ) LUI.createMenu.MPStatsMenu = function ( controller )
local self = CoD.Menu.NewForUIEditor( "MPStatsMenu" ) local self = CoD.Menu.NewForUIEditor( "MPStatsMenu" )
if PreLoadFunc then if PreLoadFunc then

View File

@ -35,7 +35,7 @@ namespace dvars
{ {
const auto* dvar = reinterpret_cast<const game::dvar_t*>(&game::s_dvarPool[160 * i]); const auto* dvar = reinterpret_cast<const game::dvar_t*>(&game::s_dvarPool[160 * i]);
if (!dvar->debugName || (game::dvarFlags_e::DVAR_SAVED & dvar->flags) == 0) if (!dvar->debugName)
continue; continue;
auto name = dvar->debugName; auto name = dvar->debugName;
@ -54,7 +54,7 @@ namespace dvars
{ {
dvar_set_variant_hook.invoke(dvar, value, source); dvar_set_variant_hook.invoke(dvar, value, source);
if (initial_config_read && (game::dvarFlags_e::DVAR_SAVED & dvar->flags) != 0 && dvar->debugName) if (initial_config_read && dvar->debugName)
{ {
write_archive_dvars(); write_archive_dvars();
} }
@ -72,6 +72,7 @@ namespace dvars
game::Cbuf_ExecuteBuffer(0, game::ControllerIndex_t::CONTROLLER_INDEX_0, filedata.c_str()); game::Cbuf_ExecuteBuffer(0, game::ControllerIndex_t::CONTROLLER_INDEX_0, filedata.c_str());
initial_config_read = true; initial_config_read = true;
scheduler::execute(scheduler::pipeline::dvars_loaded);
} }
game::dvar_t* dvar_register_new_stub(game::dvarStrHash_t hash, const char* dvar_name, game::dvarType_t type, unsigned int flags, game::dvar_t* dvar_register_new_stub(game::dvarStrHash_t hash, const char* dvar_name, game::dvarType_t type, unsigned int flags,
@ -90,7 +91,7 @@ namespace dvars
public: public:
void post_unpack() override void post_unpack() override
{ {
scheduler::once(read_archive_dvars, scheduler::pipeline::renderer); scheduler::once(read_archive_dvars, scheduler::pipeline::main);
//dvar_register_new_hook.create(0x1422C5330_g, dvar_register_new_stub); //dvar_register_new_hook.create(0x1422C5330_g, dvar_register_new_stub);
dvar_set_variant_hook.create(0x1422C9A90_g, dvar_set_variant_stub); dvar_set_variant_hook.create(0x1422C9A90_g, dvar_set_variant_stub);

View File

@ -59,12 +59,19 @@ namespace loot
{ {
void post_unpack() override void post_unpack() override
{ {
dvar_cg_unlockall_loot = game::Dvar_RegisterBool(game::Dvar_GenerateHash("cg_unlockall_loot"), "cg_unlockall_loot", false, (game::dvarFlags_e)0x40, "Unlocks blackmarket loot"); dvar_cg_unlockall_loot = game::Dvar_RegisterBool(game::Dvar_GenerateHash("cg_unlockall_loot"), "cg_unlockall_loot", false, (game::dvarFlags_e)0x0, "Unlocks blackmarket loot");
dvar_cg_unlockall_loot->debugName = "cg_unlockall_loot"; dvar_cg_unlockall_loot->debugName = "cg_unlockall_loot";
loot_getitemquantity_hook.create(0x141E82C90_g, loot_getitemquantity_stub); loot_getitemquantity_hook.create(0x141E82C90_g, loot_getitemquantity_stub);
liveinventory_getitemquantity_hook.create(0x141E090C0_g, liveinventory_getitemquantity_stub); liveinventory_getitemquantity_hook.create(0x141E090C0_g, liveinventory_getitemquantity_stub);
liveinventory_areextraslotspurchased_hook.create(0x141E089E0_g, liveinventory_areextraslotspurchased_stub); liveinventory_areextraslotspurchased_hook.create(0x141E089E0_g, liveinventory_areextraslotspurchased_stub);
scheduler::once([]() {
if (dvar_cg_unlockall_loot->current.enabled)
{
game::Dvar_SetFromStringByName("ui_enableAllHeroes", "1", true);
}
}, scheduler::pipeline::dvars_loaded);
} }
}; };
}; };

View File

@ -91,11 +91,6 @@ namespace scheduler
utils::hook::detour g_run_frame_hook; utils::hook::detour g_run_frame_hook;
utils::hook::detour main_frame_hook; utils::hook::detour main_frame_hook;
void execute(const pipeline type)
{
assert(type >= 0 && type < pipeline::count);
pipelines[type].execute();
}
void r_end_frame_stub() void r_end_frame_stub()
{ {
@ -116,6 +111,12 @@ namespace scheduler
} }
} }
void execute(const pipeline type)
{
assert(type >= 0 && type < pipeline::count);
pipelines[type].execute();
}
void schedule(const std::function<bool()>& callback, const pipeline type, void schedule(const std::function<bool()>& callback, const pipeline type,
const std::chrono::milliseconds delay) const std::chrono::milliseconds delay)
{ {

View File

@ -16,12 +16,17 @@ namespace scheduler
// The game's main thread // The game's main thread
main, main,
// Dvars are done loading from the config file
dvars_loaded,
count, count,
}; };
static const bool cond_continue = false; static const bool cond_continue = false;
static const bool cond_end = true; static const bool cond_end = true;
void execute(const pipeline type);
void schedule(const std::function<bool()>& callback, pipeline type = pipeline::async, void schedule(const std::function<bool()>& callback, pipeline type = pipeline::async,
std::chrono::milliseconds delay = 0ms); std::chrono::milliseconds delay = 0ms);
void loop(const std::function<void()>& callback, pipeline type = pipeline::async, void loop(const std::function<void()>& callback, pipeline type = pipeline::async,

View File

@ -24,7 +24,7 @@ namespace ui_scripting
utils::hook::detour lua_cod_getrawfile_hook; utils::hook::detour lua_cod_getrawfile_hook;
game::dvar_t* dvar_cg_enable_unsafe_lua_functions; game::dvar_t* dvar_cg_enable_unsafe_lua_functions;
static bool unsafe_function_called_message_show = false; static bool unsafe_function_called_message_shown = false;
struct globals_t struct globals_t
{ {
@ -309,12 +309,12 @@ namespace ui_scripting
int lua_unsafe_function_stub([[maybe_unused]] game::hks::lua_State* l) int lua_unsafe_function_stub([[maybe_unused]] game::hks::lua_State* l)
{ {
if (!unsafe_function_called_message_show) if (!unsafe_function_called_message_shown)
{ {
auto state = get_globals(); auto state = get_globals();
// TODO: Is it possible to do this with a confirm dialog? Doing this in LUI seems unsafe to me because mods will be able to change this aswell // TODO: Is it possible to do this with a confirm dialog? Doing this in LUI seems unsafe to me because mods will be able to change this aswell
state["LuaUtils"]["ShowMessageDialog"](0, 0, "The map/mod you are playing tried to run code that can be unsafe. This can include writing or reading files on your system, accessing environment variables, running system commands or loading a dll. These are usually used for storing data across games, integrating third party software like Discord or fetching data from a server to make the gameplay for dynamic.\nThis can also cause a lot of harm by the wrong people.\n\nIf you trust this map/mod and want to enable these features, open the following file in your Black Ops 3 installation: players/user/config.cfg.\nIn this file change 'set cg_enable_unsafe_lua_functions 0' to 'set cg_enable_unsafe_lua_functions 1' and restart Black Ops 3.", "Unsafe lua function called"); state["LuaUtils"]["ShowMessageDialog"](0, 0, "The map/mod you are playing tried to run code that can be unsafe. This can include writing or reading files on your system, accessing environment variables, running system commands or loading a dll. These are usually used for storing data across games, integrating third party software like Discord or fetching data from a server to make the gameplay for dynamic.\nThis can also cause a lot of harm by the wrong people.\n\nIf you trust this map/mod and want to enable these features, open the following file in your Black Ops 3 installation: players/user/config.cfg.\nIn this file change 'set cg_enable_unsafe_lua_functions 0' to 'set cg_enable_unsafe_lua_functions 1' and restart Black Ops 3.", "Unsafe lua function called");
unsafe_function_called_message_show = true; unsafe_function_called_message_shown = true;
} }
return 0; return 0;
@ -379,12 +379,26 @@ namespace ui_scripting
ui_shutdown_hook.create(0x14270E9C0_g, ui_shutdown_stub); ui_shutdown_hook.create(0x14270E9C0_g, ui_shutdown_stub);
lua_cod_getrawfile_hook.create(0x141F0F880_g, lua_cod_getrawfile_stub); lua_cod_getrawfile_hook.create(0x141F0F880_g, lua_cod_getrawfile_stub);
dvar_cg_enable_unsafe_lua_functions = game::Dvar_RegisterBool(game::Dvar_GenerateHash("cg_enable_unsafe_lua_functions"), "cg_enable_unsafe_lua_functions", false, (game::dvarFlags_e)0x1040, "Enables the use of unsafe lua functions"); dvar_cg_enable_unsafe_lua_functions = game::Dvar_RegisterBool(game::Dvar_GenerateHash("cg_enable_unsafe_lua_functions"), "cg_enable_unsafe_lua_functions", false, (game::dvarFlags_e)0x1000, "Enables the use of unsafe lua functions");
dvar_cg_enable_unsafe_lua_functions->debugName = "cg_enable_unsafe_lua_functions"; dvar_cg_enable_unsafe_lua_functions->debugName = "cg_enable_unsafe_lua_functions";
scheduler::once([]() { scheduler::once([]() {
game::dvar_t* dvar_callstack_ship = game::Dvar_FindVar("ui_error_callstack_ship");
dvar_callstack_ship->flags = (game::dvarFlags_e)0;
game::dvar_t* dvar_report_delay= game::Dvar_FindVar("ui_error_report_delay");
dvar_report_delay->flags = (game::dvarFlags_e)0;
game::Dvar_SetFromStringByName("ui_error_callstack_ship", "1", true);
game::Dvar_SetFromStringByName("ui_error_report_delay", "0", true);
}, scheduler::pipeline::renderer);
scheduler::once([]() {
printf("dvar_cg_enable_unsafe_lua_functions scheduler %s", game::Dvar_DisplayableValue(dvar_cg_enable_unsafe_lua_functions));
if (!dvar_cg_enable_unsafe_lua_functions->current.enabled) if (!dvar_cg_enable_unsafe_lua_functions->current.enabled)
{ {
printf("dvar_cg_enable_unsafe_lua_functions add jumps");
// Do not allow the HKS vm to open LUA's libraries // Do not allow the HKS vm to open LUA's libraries
// Disable unsafe functions // Disable unsafe functions
utils::hook::jump(0x141D34190_g, luaopen_stub); // debug utils::hook::jump(0x141D34190_g, luaopen_stub); // debug
@ -435,15 +449,7 @@ namespace ui_scripting
utils::hook::jump(0x141D299C0_g, lua_unsafe_function_stub); // package_loadlib utils::hook::jump(0x141D299C0_g, lua_unsafe_function_stub); // package_loadlib
} }
}, scheduler::pipeline::dvars_loaded);
game::dvar_t* dvar_callstack_ship = game::Dvar_FindVar("ui_error_callstack_ship");
dvar_callstack_ship->flags = (game::dvarFlags_e)0;
game::dvar_t* dvar_report_delay= game::Dvar_FindVar("ui_error_report_delay");
dvar_report_delay->flags = (game::dvarFlags_e)0;
game::Dvar_SetFromStringByName("ui_error_callstack_ship", "1", true);
game::Dvar_SetFromStringByName("ui_error_report_delay", "0", true);
}, scheduler::pipeline::renderer);
} }
}; };
} }