From 1e67fadc42ab5cf5fde8030d15e01bd9e5692d89 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Thu, 30 Jun 2022 17:07:39 +0200 Subject: [PATCH] [Chat] Isolate stack --- src/Components/Modules/Chat.cpp | 1 + src/Game/Scripting/StackIsolation.cpp | 26 ++++++++++++++++++++++++++ src/Game/Scripting/StackIsolation.hpp | 24 ++++++++++++++++++++++++ src/STDInclude.hpp | 1 + 4 files changed, 52 insertions(+) create mode 100644 src/Game/Scripting/StackIsolation.cpp create mode 100644 src/Game/Scripting/StackIsolation.hpp diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp index beb95f0b..ead9e87b 100644 --- a/src/Components/Modules/Chat.cpp +++ b/src/Components/Modules/Chat.cpp @@ -369,6 +369,7 @@ namespace Components { const auto entityId = Game::Scr_GetEntityId(self->s.number, 0); + Scripting::StackIsolation _; Game::Scr_AddInt(mode); Game::Scr_AddString(message); diff --git a/src/Game/Scripting/StackIsolation.cpp b/src/Game/Scripting/StackIsolation.cpp new file mode 100644 index 00000000..feed4e07 --- /dev/null +++ b/src/Game/Scripting/StackIsolation.cpp @@ -0,0 +1,26 @@ +#include + +namespace Scripting +{ + StackIsolation::StackIsolation() + { + this->inParamCount_ = Game::scrVmPub->inparamcount; + this->outParamCount_ = Game::scrVmPub->outparamcount; + this->top_ = Game::scrVmPub->top; + this->maxStack_ = Game::scrVmPub->maxStack; + + Game::scrVmPub->top = this->stack_; + Game::scrVmPub->maxStack = &this->stack_[ARRAYSIZE(this->stack_) - 1]; + Game::scrVmPub->inparamcount = 0; + Game::scrVmPub->outparamcount = 0; + } + + StackIsolation::~StackIsolation() + { + Game::Scr_ClearOutParams(); + Game::scrVmPub->inparamcount = this->inParamCount_; + Game::scrVmPub->outparamcount = this->outParamCount_; + Game::scrVmPub->top = this->top_; + Game::scrVmPub->maxStack = this->maxStack_; + } +} diff --git a/src/Game/Scripting/StackIsolation.hpp b/src/Game/Scripting/StackIsolation.hpp new file mode 100644 index 00000000..dfe6bd4a --- /dev/null +++ b/src/Game/Scripting/StackIsolation.hpp @@ -0,0 +1,24 @@ +#pragma once + +namespace Scripting +{ + class StackIsolation final + { + public: + StackIsolation(); + ~StackIsolation(); + + StackIsolation(StackIsolation&&) = delete; + StackIsolation(const StackIsolation&) = delete; + StackIsolation& operator=(StackIsolation&&) = delete; + StackIsolation& operator=(const StackIsolation&) = delete; + + private: + Game::VariableValue stack_[512]{}; + + Game::VariableValue* maxStack_; + Game::VariableValue* top_; + unsigned int inParamCount_; + unsigned int outParamCount_; + }; +} diff --git a/src/STDInclude.hpp b/src/STDInclude.hpp index d2deaa11..4ea171d8 100644 --- a/src/STDInclude.hpp +++ b/src/STDInclude.hpp @@ -141,6 +141,7 @@ using namespace std::literals; #include "Game/Structs.hpp" #include "Game/Functions.hpp" #include +#include #include "Utils/Stream.hpp" // Breaks order on purpose