diff --git a/core/logic/DebugReporter.cpp b/core/logic/DebugReporter.cpp index 4490ff9e..3e80eb6f 100644 --- a/core/logic/DebugReporter.cpp +++ b/core/logic/DebugReporter.cpp @@ -34,6 +34,7 @@ #include #include "DebugReporter.h" #include "Logger.h" +#include "sourcepawn/vm/base-runtime.h" #include "sourcepawn/vm/environment.h" DebugReport g_DbgReporter; @@ -87,7 +88,7 @@ void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, { func_idx >>= 1; sp_public_t *function; - if (ctx->GetRuntime()->GetPublicByIndex(func_idx, &function) == SP_ERROR_NONE) + if (ctx->GetBaseRuntime()->GetPublicByIndex(func_idx, &function) == SP_ERROR_NONE) { g_Logger.LogError("[SM] Unable to call function \"%s\" due to above error(s).", function->name); } diff --git a/core/logic/NativeOwner.cpp b/core/logic/NativeOwner.cpp index bdb415f8..b73edc17 100644 --- a/core/logic/NativeOwner.cpp +++ b/core/logic/NativeOwner.cpp @@ -31,6 +31,7 @@ #include "NativeOwner.h" #include "ShareSys.h" #include "PluginSys.h" +#include CNativeOwner::CNativeOwner() : m_nMarkSerial(0) { @@ -67,10 +68,8 @@ void CNativeOwner::AddNatives(const sp_nativeinfo_t *natives) void CNativeOwner::UnbindWeakRef(const WeakNative &ref) { - IPluginContext *pContext; - - pContext = ref.pl->GetBaseContext(); - pContext->GetRuntime()->UpdateNativeBinding( + auto pContext = ref.pl->runtime(); + pContext->UpdateNativeBinding( ref.idx, nullptr, SP_NTVFLAG_OPTIONAL, diff --git a/core/logic/NativeOwner.h b/core/logic/NativeOwner.h index bc25d4b0..5f0339b3 100644 --- a/core/logic/NativeOwner.h +++ b/core/logic/NativeOwner.h @@ -8,7 +8,7 @@ * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, version 3.0, as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more @@ -45,13 +45,13 @@ using namespace SourceMod; struct WeakNative { - WeakNative(IPlugin *plugin, uint32_t index) : + WeakNative(CPlugin *plugin, uint32_t index) : pl(plugin), idx(index) { pl = plugin; idx = index; } - IPlugin *pl; + CPlugin *pl; uint32_t idx; }; diff --git a/core/logic/PluginSys.cpp b/core/logic/PluginSys.cpp index e99cec3a..50091f72 100644 --- a/core/logic/PluginSys.cpp +++ b/core/logic/PluginSys.cpp @@ -99,8 +99,8 @@ void CPlugin::InitIdentity() m_ident = g_ShareSys.CreateIdentity(g_PluginIdent, this); m_handle = handlesys->CreateHandle(g_PluginType, this, g_PluginSys.GetIdentity(), g_PluginSys.GetIdentity(), NULL); - m_pRuntime->GetDefaultContext()->SetKey(1, m_ident); - m_pRuntime->GetDefaultContext()->SetKey(2, (IPlugin *)this); + m_pRuntime->SetKey(1, m_ident); + m_pRuntime->SetKey(2, (IPlugin *)this); } void CPlugin::DestroyIdentity() @@ -1283,7 +1283,7 @@ CPlugin *CPluginManager::CompileAndPrep(const char *path) bool CPluginManager::MalwareCheckPass(CPlugin *pPlugin) { - unsigned char *pCodeHash = pPlugin->GetRuntime()->GetCodeHash(); + unsigned char *pCodeHash = pPlugin->runtime()->GetCodeHash(); char codeHashBuf[40]; ke::SafeStrcpy(codeHashBuf, sizeof(codeHashBuf), "plugin_"); @@ -1323,11 +1323,10 @@ bool CPluginManager::RunSecondPass(CPlugin *pPlugin) g_ShareSys.BindNativesToPlugin(pPlugin, false); // Find any unbound natives. Right now, these are not allowed. - IPluginContext *pContext = pPlugin->GetBaseContext(); - uint32_t num = pContext->GetNativesNum(); + uint32_t num = pPlugin->runtime()->GetNativesNum(); for (unsigned int i=0; iGetRuntime()->GetNative(i); + const sp_native_t *native = pPlugin->runtime()->GetNative(i); if (!native) break; if (native->status == SP_NATIVE_UNBOUND && @@ -1416,11 +1415,10 @@ void CPluginManager::TryRefreshDependencies(CPlugin *pPlugin) /* Find any unbound natives * Right now, these are not allowed */ - IPluginContext *pContext = pPlugin->GetBaseContext(); - uint32_t num = pContext->GetNativesNum(); + uint32_t num = pPlugin->runtime()->GetNativesNum(); for (unsigned int i=0; iGetRuntime()->GetNative(i); + const sp_native_t *native = pPlugin->runtime()->GetNative(i); if (!native) break; if (native->status == SP_NATIVE_UNBOUND && @@ -1969,7 +1967,7 @@ void CPluginManager::OnRootConsoleCommand(const char *cmdname, const ICommandArg rootmenu->ConsolePrint(" Timestamp: %s", pl->GetDateTime()); } - if (IPluginRuntime *runtime = pl->GetRuntime()) { + if (auto runtime = pl->runtime()) { unsigned char *pCodeHash = runtime->GetCodeHash(); unsigned char *pDataHash = runtime->GetDataHash(); @@ -2345,7 +2343,7 @@ public: IPlugin *FindPluginByContext(IPluginContext *ctx) override { - return g_PluginSys.FindPluginByContext(ctx); + return g_PluginSys.FindPluginByContext(ctx->GetBaseRuntime()); } unsigned int GetPluginCount() override @@ -2406,3 +2404,4 @@ IPluginManager *CPluginManager::GetOldAPI() { return &sOldPluginAPI; } + diff --git a/core/logic/PluginSys.h b/core/logic/PluginSys.h index c53e407e..ab3ae2d9 100644 --- a/core/logic/PluginSys.h +++ b/core/logic/PluginSys.h @@ -118,7 +118,8 @@ public: bool SetProperty(const char *prop, void *ptr); bool GetProperty(const char *prop, void **ptr, bool remove=false); void DropEverything(); - SourcePawn::IPluginRuntime *GetRuntime(); + IPluginRuntime *GetRuntime(); + sp::BaseRuntime *runtime() const { return m_pRuntime.get(); } CNativeOwner *ToNativeOwner() { return this; } @@ -268,7 +269,7 @@ private: char m_errormsg[256]; // Internal properties that must by reset if the runtime is evicted. - std::unique_ptr m_pRuntime; + std::unique_ptr m_pRuntime; std::unique_ptr m_pPhrases; IPluginContext *m_pContext; sp_pubvar_t *m_MaxClientsVar; diff --git a/core/logic/ShareSys.cpp b/core/logic/ShareSys.cpp index 60b529fd..9fc2f569 100644 --- a/core/logic/ShareSys.cpp +++ b/core/logic/ShareSys.cpp @@ -39,6 +39,7 @@ #include "common_logic.h" #include "PluginSys.h" #include "HandleSys.h" +#include using namespace ke; @@ -277,14 +278,14 @@ void ShareSystem::BeginBindingFor(CPlugin *pPlugin) void ShareSystem::BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly) { - IPluginContext *pContext = pPlugin->GetBaseContext(); + sp::BaseRuntime *pContext = pPlugin->GetBaseContext()->GetBaseRuntime(); BeginBindingFor(pPlugin); uint32_t native_count = pContext->GetNativesNum(); for (uint32_t i = 0; i < native_count; i++) { - const sp_native_t *native = pContext->GetRuntime()->GetNative(i); + const sp_native_t *native = pContext->GetNative(i); if (!native) continue; @@ -309,13 +310,13 @@ void ShareSystem::BindNativeToPlugin(CPlugin *pPlugin, const RefPtr &ent if (!entry->owner) return; - IPluginContext *pContext = pPlugin->GetBaseContext(); + sp::BaseRuntime *pContext = pPlugin->GetBaseContext()->GetBaseRuntime(); uint32_t i; if (pContext->FindNativeByName(entry->name(), &i) != SP_ERROR_NONE) return; - const sp_native_t *native = pContext->GetRuntime()->GetNative(i); + const sp_native_t *native = pContext->GetNative(i); if (!native) return; @@ -364,7 +365,7 @@ void ShareSystem::BindNativeToPlugin(CPlugin *pPlugin, const sp_native_t *native } } - auto rt = pPlugin->GetRuntime(); + auto rt = pPlugin->runtime(); if (pEntry->fake) rt->UpdateNativeBindingObject(index, pEntry->fake->wrapper, flags, nullptr); else @@ -485,10 +486,11 @@ FeatureStatus ShareSystem::TestFeature(IPluginRuntime *pRuntime, FeatureType fea FeatureStatus ShareSystem::TestNative(IPluginRuntime *pRuntime, const char *name) { uint32_t index; + sp::BaseRuntime *pBase = pRuntime->GetBaseRuntime(); - if (pRuntime->FindNativeByName(name, &index) == SP_ERROR_NONE) + if (pBase->FindNativeByName(name, &index) == SP_ERROR_NONE) { - if (const sp_native_t *native = pRuntime->GetNative(index)) { + if (const sp_native_t *native = pBase->GetNative(index)) { if (native->status == SP_NATIVE_BOUND) return FeatureStatus_Available; else @@ -511,3 +513,4 @@ FeatureStatus ShareSystem::TestCap(const char *name) return r->value.provider->GetFeatureStatus(FeatureType_Capability, name); } + diff --git a/core/logic/smn_core.cpp b/core/logic/smn_core.cpp index 99a4ea69..e36fd3cb 100644 --- a/core/logic/smn_core.cpp +++ b/core/logic/smn_core.cpp @@ -45,6 +45,7 @@ #include #include +#include #if defined PLATFORM_WINDOWS #include @@ -638,15 +639,16 @@ static cell_t MarkNativeAsOptional(IPluginContext *pContext, const cell_t *param { char *name; uint32_t idx; + sp::BaseRuntime *pBase = pContext->GetBaseRuntime(); pContext->LocalToString(params[1], &name); - if (pContext->FindNativeByName(name, &idx) != SP_ERROR_NONE) + if (pBase->FindNativeByName(name, &idx) != SP_ERROR_NONE) { /* Oops! This HAS to silently fail! */ return 0; } - pContext->GetRuntime()->UpdateNativeBinding(idx, nullptr, SP_NTVFLAG_OPTIONAL, nullptr); + pBase->UpdateNativeBinding(idx, nullptr, SP_NTVFLAG_OPTIONAL, nullptr); return 1; } diff --git a/core/logic/smn_functions.cpp b/core/logic/smn_functions.cpp index bcdb31cc..5532107f 100644 --- a/core/logic/smn_functions.cpp +++ b/core/logic/smn_functions.cpp @@ -36,6 +36,7 @@ #include #include #include +#include HandleType_t g_GlobalFwdType = 0; HandleType_t g_PrivateFwdType = 0; @@ -128,7 +129,7 @@ static cell_t sm_GetFunctionByName(IPluginContext *pContext, const cell_t *param pContext->LocalToString(params[2], &name); /* Get public function index */ - if (pPlugin->GetBaseContext()->FindPublicByName(name, &idx) == SP_ERROR_NOT_FOUND) + if (pContext->GetBaseRuntime()->FindPublicByName(name, &idx) == SP_ERROR_NOT_FOUND) { /* Return INVALID_FUNCTION if not found */ return pContext->GetNullFunctionValue(); diff --git a/core/logic/smn_string.cpp b/core/logic/smn_string.cpp index be7488dc..6fb1c1c6 100644 --- a/core/logic/smn_string.cpp +++ b/core/logic/smn_string.cpp @@ -37,6 +37,7 @@ #include "stringutil.h" #include "sprintf.h" #include +#include inline const char *_strstr(const char *str, const char *substr) { @@ -232,7 +233,7 @@ static cell_t sm_vformat(IPluginContext *pContext, const cell_t *params) int vargPos = static_cast(params[4]); /* Get the parent parameter array */ - cell_t *local_params = pContext->GetLocalParams(); + cell_t *local_params = pContext->GetBaseRuntime()->GetLocalParams(); cell_t max = local_params[0]; if (vargPos > (int)max + 1) diff --git a/sourcepawn b/sourcepawn index 286c7c7c..14caafcb 160000 --- a/sourcepawn +++ b/sourcepawn @@ -1 +1 @@ -Subproject commit 286c7c7c2083637f05fc2a3308b897cf86a6e29b +Subproject commit 14caafcbdcf66aa4600bcf890610e459682630ac