[Chat]: Fix script vars leaking (#776)
This commit is contained in:
parent
58781bd8ef
commit
d1f6f1db8b
@ -560,23 +560,27 @@ namespace Components
|
||||
|
||||
int Chat::ChatCallback(Game::gentity_s* self, const char* codePos, const char* message, int mode)
|
||||
{
|
||||
const auto entityId = Game::Scr_GetEntityId(self - Game::g_entities, 0);
|
||||
constexpr auto paramcount = 2;
|
||||
|
||||
Scripting::StackIsolation _;
|
||||
Game::Scr_AddInt(mode);
|
||||
Game::Scr_AddString(message);
|
||||
|
||||
Game::VariableValue value;
|
||||
value.type = Game::VAR_OBJECT;
|
||||
value.u.uintValue = entityId;
|
||||
const auto objId = Game::Scr_GetEntityId(self - Game::g_entities, 0);
|
||||
Game::AddRefToObject(objId);
|
||||
const auto id = Game::VM_Execute_0(Game::AllocThread(objId), codePos, paramcount);
|
||||
|
||||
Game::AddRefToValue(value.type, value.u);
|
||||
const auto localId = Game::AllocThread(entityId);
|
||||
const auto result = GetCallbackReturn();
|
||||
|
||||
const auto result = Game::VM_Execute_0(localId, codePos, 2);
|
||||
Game::RemoveRefToObject(result);
|
||||
Game::RemoveRefToValue(Game::scrVmPub->top->type, Game::scrVmPub->top->u);
|
||||
|
||||
return GetCallbackReturn();
|
||||
Game::scrVmPub->top->type = Game::VAR_UNDEFINED;
|
||||
--Game::scrVmPub->top;
|
||||
--Game::scrVmPub->inparamcount;
|
||||
|
||||
Game::Scr_FreeThread(static_cast<std::uint16_t>(id));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Chat::AddScriptFunctions()
|
||||
|
@ -4,6 +4,7 @@ namespace Game
|
||||
{
|
||||
AddRefToObject_t AddRefToObject = AddRefToObject_t(0x61C360);
|
||||
RemoveRefToObject_t RemoveRefToObject = RemoveRefToObject_t(0x437190);
|
||||
RemoveRefToValue_t RemoveRefToValue = RemoveRefToValue_t(0x48E170);
|
||||
AllocObject_t AllocObject = AllocObject_t(0x434320);
|
||||
AddRefToValue_t AddRefToValue = AddRefToValue_t(0x482740);
|
||||
FindVariable_t FindVariable = FindVariable_t(0x4AB650);
|
||||
|
@ -8,6 +8,9 @@ namespace Game
|
||||
typedef void(*RemoveRefToObject_t)(unsigned int id);
|
||||
extern RemoveRefToObject_t RemoveRefToObject;
|
||||
|
||||
typedef void(*RemoveRefToValue_t)(int type, VariableUnion u);
|
||||
extern RemoveRefToValue_t RemoveRefToValue;
|
||||
|
||||
typedef unsigned int(*AllocObject_t)();
|
||||
extern AllocObject_t AllocObject;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user