From d2c9e8c2e8bd0821a0a304ef670285ddc043a607 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sat, 29 May 2021 23:17:24 +0200 Subject: [PATCH] Fixes --- src/component/gsc.cpp | 78 +++++++++++++++++------------ src/game/scripting/script_value.hpp | 7 +++ 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/component/gsc.cpp b/src/component/gsc.cpp index ef365c5..4a440e1 100644 --- a/src/component/gsc.cpp +++ b/src/component/gsc.cpp @@ -60,54 +60,68 @@ 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) { - try - { - 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"); - } - + return reinterpret_cast(0x1D6EB34)[id](); } - else + + try { - reinterpret_cast(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) { - if (id >= 0x8400) + if (id < 0x8400) { - try - { - 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"); - } - + return reinterpret_cast(0x1D4F258)[id](ent); } - else + + try { - reinterpret_cast(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"); } } diff --git a/src/game/scripting/script_value.hpp b/src/game/scripting/script_value.hpp index 6b86f76..e53d2a6 100644 --- a/src/game/scripting/script_value.hpp +++ b/src/game/scripting/script_value.hpp @@ -51,6 +51,13 @@ namespace scripting throw std::runtime_error("Invalid type"); } + const auto value = this->get(); + + if (!value) + { + throw std::runtime_error("Null pointer"); + } + return reinterpret_cast(this->get()); }