fix custom func hook

This commit is contained in:
quaK 2024-01-06 20:03:54 +02:00
parent 4c42488ab4
commit 10c54dd3bf

View File

@ -94,8 +94,7 @@ namespace gsc
void vm_call_builtin_function_internal(int specific_function_id) void vm_call_builtin_function_internal(int specific_function_id)
{ {
const auto function_id = get_function_id(); const auto function_id = specific_function_id;
printf("test %d : %d\n", function_id, specific_function_id);
const auto custom = functions.contains(static_cast<std::uint16_t>(function_id)); const auto custom = functions.contains(static_cast<std::uint16_t>(function_id));
if (custom) if (custom)
{ {
@ -106,11 +105,10 @@ namespace gsc
builtin_function func = func_table[function_id]; builtin_function func = func_table[function_id];
if (func == nullptr) if (func == nullptr)
{ {
printf(utils::string::va("builtin function \"%s\" doesn't exist", gsc_ctx->func_name(function_id).data()), true); printf(utils::string::va("builtin function \"%s\" doesn't exist", gsc_ctx->func_name(function_id).data()), true); // scr_error crashes
return; return;
} }
printf("test\n");
func(); func();
} }
@ -119,10 +117,11 @@ namespace gsc
return utils::hook::assemble([](utils::hook::assembler& a) return utils::hook::assemble([](utils::hook::assembler& a)
{ {
a.pushad64(); a.pushad64();
a.push(rdx); a.push(rcx);
a.mov(rdx, rax); // TODO: pass builtin_function or id, but is this the right ID??? a.mov(rcx, rcx); // function id is already in rcx
a.dec(rcx); // -1
a.call_aligned(vm_call_builtin_function_internal); // call with builtin_function a.call_aligned(vm_call_builtin_function_internal); // call with builtin_function
a.pop(rdx); a.pop(rcx);
a.popad64(); a.popad64();
a.jmp(0xC0E8F9_b); a.jmp(0xC0E8F9_b);
@ -160,7 +159,7 @@ namespace gsc
if (meth == nullptr) if (meth == nullptr)
{ {
scr_error(utils::string::va("builtin method \"%s\" doesn't exist", gsc_ctx->meth_name(method_id).data()), true); printf(utils::string::va("builtin method \"%s\" doesn't exist", gsc_ctx->meth_name(method_id).data()), true); // scr_error crashes
return; return;
} }
@ -367,6 +366,7 @@ namespace gsc
function::add("test", [](const function_args& args) function::add("test", [](const function_args& args)
{ {
// return 0 so the game doesn't override the cfg // return 0 so the game doesn't override the cfg
printf("test\n");
console::debug(args[0].as<const char*>()); console::debug(args[0].as<const char*>());
return scripting::script_value{}; return scripting::script_value{};
}); });
@ -496,4 +496,4 @@ namespace gsc
}; };
} }
//REGISTER_COMPONENT(gsc::extension) REGISTER_COMPONENT(gsc::extension)