From 3004006783a18745348a1d0cf34a89ea9327e7cd Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Mon, 15 May 2023 19:45:35 +0200 Subject: [PATCH] Cleanup notifies component --- deps/extra/gsc-tool/interface.cpp | 30 ---------- deps/extra/gsc-tool/interface.hpp | 9 --- src/client/component/gsc/script_extension.cpp | 1 + src/client/component/notifies.cpp | 56 +++++++++---------- 4 files changed, 26 insertions(+), 70 deletions(-) delete mode 100644 deps/extra/gsc-tool/interface.cpp delete mode 100644 deps/extra/gsc-tool/interface.hpp diff --git a/deps/extra/gsc-tool/interface.cpp b/deps/extra/gsc-tool/interface.cpp deleted file mode 100644 index 218ed650..00000000 --- a/deps/extra/gsc-tool/interface.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "stdafx.hpp" - -#include - -#include "interface.hpp" - -namespace gsc -{ - std::unique_ptr compiler() - { - auto compiler = std::make_unique(); - compiler->mode(xsk::gsc::build::prod); - return compiler; - } - - std::unique_ptr decompiler() - { - return std::make_unique(); - } - - std::unique_ptr assembler() - { - return std::make_unique(); - } - - std::unique_ptr disassembler() - { - return std::make_unique(); - } -} diff --git a/deps/extra/gsc-tool/interface.hpp b/deps/extra/gsc-tool/interface.hpp deleted file mode 100644 index 133e6ae2..00000000 --- a/deps/extra/gsc-tool/interface.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -namespace gsc -{ - std::unique_ptr compiler(); - std::unique_ptr decompiler(); - std::unique_ptr assembler(); - std::unique_ptr disassembler(); -} diff --git a/src/client/component/gsc/script_extension.cpp b/src/client/component/gsc/script_extension.cpp index a5a7e86d..c5b35981 100644 --- a/src/client/component/gsc/script_extension.cpp +++ b/src/client/component/gsc/script_extension.cpp @@ -268,6 +268,7 @@ namespace gsc { utils::hook::set(0x1405BC7BC, FUNC_TABLE_SIZE); // change builtin func count + utils::hook::set(0x1405BCB6C + 2, sizeof(func_table)); utils::hook::set(0x1405BC7C2 + 4, RVA(&func_table)); utils::hook::inject(0x1405BCB78 + 3, &func_table); utils::hook::set(0x1405CA678 + 4, RVA(&func_table)); diff --git a/src/client/component/notifies.cpp b/src/client/component/notifies.cpp index 376915d9..3c6156de 100644 --- a/src/client/component/notifies.cpp +++ b/src/client/component/notifies.cpp @@ -31,15 +31,16 @@ namespace notifies char empty_function[2] = {0x32, 0x34}; // CHECK_CLEAR_PARAMS, END const char* target_function = nullptr; - unsigned int local_id_to_entity(unsigned int local_id) + scripting::entity local_id_to_entity(unsigned int local_id) { - const auto variable = game::scr_VarGlob->objectVariableValue[local_id]; - return variable.u.f.next; + return game::scr_VarGlob->objectVariableValue[local_id].u.f.next; } bool execute_vm_hook(const char* pos) { - if (vm_execute_hooks.find(pos) == vm_execute_hooks.end()) + const auto start = std::chrono::high_resolution_clock::now(); + const auto iter = vm_execute_hooks.find(pos); + if (iter == vm_execute_hooks.end()) { hook_enabled = true; return false; @@ -51,18 +52,16 @@ namespace notifies return false; } - const auto& hook = vm_execute_hooks[pos]; + const auto& hook = iter->second; if (hook.is_lua_hook) { const auto& function = hook.lua_function; const auto state = function.lua_state(); - const scripting::entity self = local_id_to_entity(game::scr_VmPub->function_frame->fs.localId); - + const auto self = local_id_to_entity(game::scr_VmPub->function_frame->fs.localId); std::vector args; const auto top = game::scr_function_stack->top; - for (auto* value = top; value->type != game::SCRIPT_END; --value) { args.push_back(scripting::lua::convert(state, *value)); @@ -119,16 +118,14 @@ namespace notifies return {}; } - const auto player = scripting::call("getentbynum", {ent->s.entityNum}); - - return scripting::lua::convert(state, player); + const scripting::entity entity{game::scr_entref_t(ent->s.entityNum, 0)}; + return scripting::lua::convert(state, entity); } std::string get_weapon_name(unsigned int weapon, bool isAlternate) { char output[1024] = {0}; game::BG_GetWeaponNameComplete(weapon, isAlternate, output, 1024); - return output; } @@ -139,37 +136,34 @@ namespace notifies return {}; } - const auto _vec = scripting::vector(vec); - - return scripting::lua::convert(state, _vec); + return scripting::lua::convert(state, scripting::vector(vec)); } std::string convert_mod(const int meansOfDeath) { const auto value = reinterpret_cast(0x140BF49B0)[meansOfDeath]; - const auto string = game::SL_ConvertToString(*value); - - return string; + return game::SL_ConvertToString(*value); } - void scr_entity_damage_stub(game::gentity_s* self, game::gentity_s* inflictor, game::gentity_s* attacker, const float* vDir, const float* vPoint, - int damage, int dflags, const unsigned int meansOfDeath, const unsigned int weapon, bool isAlternate, unsigned int a11, const int hitLoc, unsigned int a13, unsigned int a14) + void scr_entity_damage_stub(game::gentity_s* self, game::gentity_s* inflictor, game::gentity_s* attacker, const float* v_dir, const float* v_point, + int damage, int dflags, const unsigned int means_of_death, const unsigned int weapon, bool is_alternate, + unsigned int a11, const int hit_loc, unsigned int a13, unsigned int a14) { { - const std::string _hitLoc = reinterpret_cast(0x140BF4AA0)[hitLoc]; - const auto _mod = convert_mod(meansOfDeath); - const auto _weapon = get_weapon_name(weapon, isAlternate); + const std::string hit_loc_str = reinterpret_cast(0x140BF4AA0)[hit_loc]; + const auto mod_str = convert_mod(means_of_death); + const auto weapon_str = get_weapon_name(weapon, is_alternate); for (const auto& callback : entity_damage_callbacks) { const auto state = callback.lua_state(); - const auto _self = convert_entity(state, self); - const auto _inflictor = convert_entity(state, inflictor); - const auto _attacker = convert_entity(state, attacker); - const auto _vDir = convert_vector(state, vDir); + const auto self_ent = convert_entity(state, self); + const auto inflictor_ent = convert_entity(state, inflictor); + const auto attacker_ent = convert_entity(state, attacker); + const auto v_dir_vec = convert_vector(state, v_dir); - const auto result = callback(_self, _inflictor, _attacker, damage, _mod, _weapon, _vDir, _hitLoc); + const auto result = callback(self_ent, inflictor_ent, attacker_ent, damage, mod_str, weapon_str, v_dir_vec, hit_loc_str); scripting::lua::handle_error(result); if (result.valid()) @@ -188,8 +182,8 @@ namespace notifies } } - scr_entity_damage_hook.invoke(self,inflictor, attacker, vDir, vPoint, damage, dflags, - meansOfDeath, weapon, isAlternate, a11, hitLoc, a13, a14); + scr_entity_damage_hook.invoke(self, inflictor, attacker, v_dir, v_point, damage, dflags, + means_of_death, weapon, is_alternate, a11, hit_loc, a13, a14); } } @@ -261,4 +255,4 @@ namespace notifies }; } -REGISTER_COMPONENT(notifies::component) \ No newline at end of file +REGISTER_COMPONENT(notifies::component)