This commit is contained in:
Federico Cecchetto 2021-05-29 23:17:24 +02:00
parent dc2d8135cd
commit d2c9e8c2e8
2 changed files with 53 additions and 32 deletions

View File

@ -60,17 +60,35 @@ namespace gsc
return args;
}
void return_value(const scripting::script_value& value)
{
if (game::scr_VmPub->outparamcount)
{
game::Scr_ClearOutParams();
}
scripting::push_value(value);
}
auto function_map_start = 0x200;
auto method_map_start = 0x8400;
void call_function(unsigned int id)
{
if (id >= 0x200)
if (id < 0x200)
{
return reinterpret_cast<builtin_function*>(0x1D6EB34)[id]();
}
try
{
const auto result = functions[id](get_arguments());
scripting::push_value(result);
const auto type = result.get_raw().type;
if (type)
{
return_value(result);
}
}
catch (std::exception e)
{
@ -79,22 +97,24 @@ namespace gsc
printf("%s\n", e.what());
printf("****************************************************\n");
}
}
else
{
reinterpret_cast<builtin_function*>(0x1D6EB34)[id]();
}
}
void call_method(game::scr_entref_t ent, unsigned int id)
{
if (id >= 0x8400)
if (id < 0x8400)
{
return reinterpret_cast<builtin_method*>(0x1D4F258)[id](ent);
}
try
{
const auto result = methods[id](ent, get_arguments());
scripting::push_value(result);
const auto type = result.get_raw().type;
if (type)
{
return_value(result);
}
}
catch (std::exception e)
{
@ -103,12 +123,6 @@ namespace gsc
printf("%s\n", e.what());
printf("****************************************************\n");
}
}
else
{
reinterpret_cast<builtin_method*>(0x1D4F258)[id](ent);
}
}
__declspec(naked) void call_builtin_stub()

View File

@ -51,6 +51,13 @@ namespace scripting
throw std::runtime_error("Invalid type");
}
const auto value = this->get<int>();
if (!value)
{
throw std::runtime_error("Null pointer");
}
return reinterpret_cast<T*>(this->get<int>());
}