From c947f269176f361de3f42b1c5010323db6962edb Mon Sep 17 00:00:00 2001 From: Leonid Pospelov Date: Fri, 1 Dec 2023 00:43:35 +0600 Subject: [PATCH] fix(skymp5-server): handle non-object self in callPapyrusFunction (#1752) --- skymp5-server/cpp/addon/ScampServer.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/skymp5-server/cpp/addon/ScampServer.cpp b/skymp5-server/cpp/addon/ScampServer.cpp index a526962ff4..c8368ebcce 100644 --- a/skymp5-server/cpp/addon/ScampServer.cpp +++ b/skymp5-server/cpp/addon/ScampServer.cpp @@ -1040,8 +1040,14 @@ Napi::Value ScampServer::CallPapyrusFunction(const Napi::CallbackInfo& info) auto& vm = partOne->worldState.GetPapyrusVm(); if (callType == "method") { - res = vm.CallMethod(static_cast(self), functionName.data(), - args); + if (self.GetType() == VarValue::Type::kType_Object) { + res = vm.CallMethod(static_cast(self), + functionName.data(), args); + } else { + throw std::runtime_error( + "Can't call Papyrus method on non-object self '" + self.ToString() + + "'"); + } } else if (callType == "global") { res = vm.CallStatic(className, functionName, args); } else {