Merge pull request #325 from diamante0018/develop

gsc: allow scripts with both handles to load, assert gsc funcs
This commit is contained in:
fed 2022-08-28 14:42:06 +00:00 committed by GitHub
commit 17e573c97d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -146,7 +146,8 @@ namespace gsc
console::info("Loaded '%s::main'\n", name.data());
main_handles[name] = main_handle;
}
else if (init_handle)
if (init_handle)
{
console::info("Loaded '%s::init'\n", name.data());
init_handles[name] = init_handle;
@ -388,6 +389,24 @@ namespace gsc
gsc_error = error;
game::Scr_ErrorInternal();
}
void assert_cmd()
{
const auto expr = get_argument(0).as<int>();
if (!expr)
{
set_gsc_error("assert fail");
}
}
void assertex_cmd()
{
const auto expr = get_argument(0).as<int>();
if (!expr)
{
set_gsc_error(get_argument(1).as<std::string>());
}
}
}
game::ScriptFile* find_script(game::XAssetType /*type*/, const char* name, int /*allow_create_default*/)
@ -450,6 +469,10 @@ namespace gsc
// replace builtin print function
utils::hook::jump(0x1404EC640, gscr_print_stub);
// restore assert
utils::hook::jump(0x1404EC890, assert_cmd);
utils::hook::jump(0x1404EC920, assertex_cmd);
utils::hook::call(0x1405CB94F, vm_error_stub);
utils::hook::call(0x1405BC583, unknown_function_stub);
@ -479,7 +502,7 @@ namespace gsc
if (with.type != game::SCRIPT_FUNCTION)
{
set_gsc_error("replaceFunc: parameter 0 must be a function");
set_gsc_error("replaceFunc: parameter 1 must be a function");
return;
}