Use BaseRuntime instead of IPluginRuntime in PluginSys/ShareSys.

This commit is contained in:
David Anderson
2026-05-17 15:22:58 -07:00
parent 890c7119fe
commit e70cddfe3e
10 changed files with 40 additions and 33 deletions
+2 -1
View File
@@ -34,6 +34,7 @@
#include <stdarg.h>
#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);
}
+3 -4
View File
@@ -31,6 +31,7 @@
#include "NativeOwner.h"
#include "ShareSys.h"
#include "PluginSys.h"
#include <sourcepawn/vm/plugin-runtime.h>
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,
+3 -3
View File
@@ -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;
};
+10 -11
View File
@@ -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; i<num; i++)
{
const sp_native_t *native = pContext->GetRuntime()->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; i<num; i++)
{
const sp_native_t *native = pContext->GetRuntime()->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;
}
+3 -2
View File
@@ -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<IPluginRuntime> m_pRuntime;
std::unique_ptr<sp::BaseRuntime> m_pRuntime;
std::unique_ptr<CPhraseCollection> m_pPhrases;
IPluginContext *m_pContext;
sp_pubvar_t *m_MaxClientsVar;
+10 -7
View File
@@ -39,6 +39,7 @@
#include "common_logic.h"
#include "PluginSys.h"
#include "HandleSys.h"
#include <sourcepawn/vm/plugin-runtime.h>
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<Native> &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);
}
+4 -2
View File
@@ -45,6 +45,7 @@
#include <sourcehook.h>
#include <sh_memory.h>
#include <sourcepawn/vm/plugin-runtime.h>
#if defined PLATFORM_WINDOWS
#include <windows.h>
@@ -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;
}
+2 -1
View File
@@ -36,6 +36,7 @@
#include <IHandleSys.h>
#include <IForwardSys.h>
#include <ISourceMod.h>
#include <sourcepawn/vm/base-runtime.h>
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();
+2 -1
View File
@@ -37,6 +37,7 @@
#include "stringutil.h"
#include "sprintf.h"
#include <am-string.h>
#include <sourcepawn/vm/base-runtime.h>
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<int>(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)