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,54 +60,68 @@ namespace gsc
return args; 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 function_map_start = 0x200;
auto method_map_start = 0x8400; auto method_map_start = 0x8400;
void call_function(unsigned int id) void call_function(unsigned int id)
{ {
if (id >= 0x200) if (id < 0x200)
{ {
try return reinterpret_cast<builtin_function*>(0x1D6EB34)[id]();
{
const auto result = functions[id](get_arguments());
scripting::push_value(result);
}
catch (std::exception e)
{
printf("************** Script execution error **************\n");
printf("Error executing function %s\n", function_name(id).data());
printf("%s\n", e.what());
printf("****************************************************\n");
}
} }
else
try
{ {
reinterpret_cast<builtin_function*>(0x1D6EB34)[id](); const auto result = functions[id](get_arguments());
const auto type = result.get_raw().type;
if (type)
{
return_value(result);
}
}
catch (std::exception e)
{
printf("************** Script execution error **************\n");
printf("Error executing function %s\n", function_name(id).data());
printf("%s\n", e.what());
printf("****************************************************\n");
} }
} }
void call_method(game::scr_entref_t ent, unsigned int id) void call_method(game::scr_entref_t ent, unsigned int id)
{ {
if (id >= 0x8400) if (id < 0x8400)
{ {
try return reinterpret_cast<builtin_method*>(0x1D4F258)[id](ent);
{
const auto result = methods[id](ent, get_arguments());
scripting::push_value(result);
}
catch (std::exception e)
{
printf("************** Script execution error **************\n");
printf("Error executing method %s\n", method_name(id).data());
printf("%s\n", e.what());
printf("****************************************************\n");
}
} }
else
try
{ {
reinterpret_cast<builtin_method*>(0x1D4F258)[id](ent); const auto result = methods[id](ent, get_arguments());
const auto type = result.get_raw().type;
if (type)
{
return_value(result);
}
}
catch (std::exception e)
{
printf("************** Script execution error **************\n");
printf("Error executing method %s\n", method_name(id).data());
printf("%s\n", e.what());
printf("****************************************************\n");
} }
} }

View File

@ -51,6 +51,13 @@ namespace scripting
throw std::runtime_error("Invalid type"); 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>()); return reinterpret_cast<T*>(this->get<int>());
} }