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
end)
if Dvar.cg_unlockall_loot:get() == true then
Engine.SetDvar( "ui_enableAllHeroes", 1 )
end
LUI.createMenu.MPStatsMenu = function ( controller )
local self = CoD.Menu.NewForUIEditor( "MPStatsMenu" )
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]);
if (!dvar->debugName || (game::dvarFlags_e::DVAR_SAVED & dvar->flags) == 0)
if (!dvar->debugName)
continue;
auto name = dvar->debugName;
@ -54,7 +54,7 @@ namespace dvars
{
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();
}
@ -72,6 +72,7 @@ namespace dvars
game::Cbuf_ExecuteBuffer(0, game::ControllerIndex_t::CONTROLLER_INDEX_0, filedata.c_str());
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,
@ -90,7 +91,7 @@ namespace dvars
public:
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_set_variant_hook.create(0x1422C9A90_g, dvar_set_variant_stub);

View File

@ -59,12 +59,19 @@ namespace loot
{
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";
loot_getitemquantity_hook.create(0x141E82C90_g, loot_getitemquantity_stub);
liveinventory_getitemquantity_hook.create(0x141E090C0_g, liveinventory_getitemquantity_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 main_frame_hook;
void execute(const pipeline type)
{
assert(type >= 0 && type < pipeline::count);
pipelines[type].execute();
}
void r_end_frame_stub()
{
@ -114,6 +109,12 @@ namespace scheduler
main_frame_hook.invoke<void>();
execute(pipeline::main);
}
}
void execute(const pipeline type)
{
assert(type >= 0 && type < pipeline::count);
pipelines[type].execute();
}
void schedule(const std::function<bool()>& callback, const pipeline type,

View File

@ -14,13 +14,18 @@ namespace scheduler
server,
// The game's main thread
main,
main,
// Dvars are done loading from the config file
dvars_loaded,
count,
};
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,
std::chrono::milliseconds delay = 0ms);

View File

@ -24,7 +24,7 @@ namespace ui_scripting
utils::hook::detour lua_cod_getrawfile_hook;
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
{
@ -309,12 +309,12 @@ namespace ui_scripting
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();
// 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");
unsafe_function_called_message_show = true;
unsafe_function_called_message_shown = true;
}
return 0;
@ -379,12 +379,26 @@ namespace ui_scripting
ui_shutdown_hook.create(0x14270E9C0_g, ui_shutdown_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";
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)
{
printf("dvar_cg_enable_unsafe_lua_functions add jumps");
// Do not allow the HKS vm to open LUA's libraries
// Disable unsafe functions
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
}
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::pipeline::dvars_loaded);
}
};
}