From 947c8440268d7a94d93f0a5a7479b8b80c215f47 Mon Sep 17 00:00:00 2001 From: Kenzzer Date: Thu, 25 Jul 2024 18:37:41 +0200 Subject: [PATCH 1/2] Disallow cloning of entity factories --- extension/natives/entityfactory.cpp | 9 +++++++++ extension/pluginentityfactory.cpp | 5 +++++ scripting/include/cbasenpc/entityfactory.inc | 4 +++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/extension/natives/entityfactory.cpp b/extension/natives/entityfactory.cpp index 5a27663..c153fc2 100644 --- a/extension/natives/entityfactory.cpp +++ b/extension/natives/entityfactory.cpp @@ -42,6 +42,15 @@ cell_t CPluginEntityFactory_Ctor(IPluginContext * context, const cell_t * params IPluginFunction *postConstructor = context->GetFunctionById(params[2]); IPluginFunction *onRemove = context->GetFunctionById(params[3]); + if (params[0] >= 4 && params[4] != 0) { + // This factory needs to be created for another plugin + HandleError error = HandleError_None; + plugin = plsys->PluginFromHandle(static_cast(params[4]), &error); + if (error != HandleError_None || plugin == nullptr) { + return context->ThrowNativeError("Could not create entity factory with the given plugin handle %d (error %d)", params[4], error); + } + } + CPluginEntityFactory* factory = new CPluginEntityFactory(plugin, classname, postConstructor, onRemove); return factory->m_Handle; } diff --git a/extension/pluginentityfactory.cpp b/extension/pluginentityfactory.cpp index caad1df..c2d834d 100644 --- a/extension/pluginentityfactory.cpp +++ b/extension/pluginentityfactory.cpp @@ -200,6 +200,11 @@ bool CPluginEntityFactories::Init( IGameConfig* config, char* error, size_t maxl m_hookIds.push_back(SH_ADD_HOOK(IEntityFactoryDictionary, GetCannonicalName, factoryDictionary, SH_MEMBER(this, &CPluginEntityFactories::Hook_GetCannonicalName), false)); } + HandleAccess security; + handlesys->InitAccessDefaults(nullptr, &security); + // Disallow this handle type from being cloned + security.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY; + m_FactoryType = g_PluginEntityFactoryHandle = handlesys->CreateType( "PluginEntityFactory", this, 0, nullptr, nullptr, myself->GetIdentity(), nullptr ); if ( !m_FactoryType ) { diff --git a/scripting/include/cbasenpc/entityfactory.inc b/scripting/include/cbasenpc/entityfactory.inc index ab9d0ee..5a772aa 100644 --- a/scripting/include/cbasenpc/entityfactory.inc +++ b/scripting/include/cbasenpc/entityfactory.inc @@ -87,8 +87,10 @@ methodmap CEntityFactory < Handle * Perform any needed cleanup for your entity here. * @param error Invalid handle, classname is NULL or empty, or out of * memory. + * @param plugin Optional Handle to another plugin to mark as the owner. + * If no owner is passed, the owner is the calling plugin. */ - public native CEntityFactory(const char[] classname, CEntityFactoryPostConstructor postConstructor=INVALID_FUNCTION, CEntityFactoryOnRemoveCallback onRemove=INVALID_FUNCTION); + public native CEntityFactory(const char[] classname, CEntityFactoryPostConstructor postConstructor=INVALID_FUNCTION, CEntityFactoryOnRemoveCallback onRemove=INVALID_FUNCTION, Handle plugin = INVALID_HANDLE); /** * Instructs the factory to use CBaseNPC (NextBot) as the base class. From 925fbac6d13d2db1c25a96d2bc3ff0c9720dfeca Mon Sep 17 00:00:00 2001 From: Kenzzer Date: Thu, 25 Jul 2024 18:38:40 +0200 Subject: [PATCH 2/2] update product version --- product.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/product.version b/product.version index ca71766..1b1bfae 100644 --- a/product.version +++ b/product.version @@ -1 +1 @@ -1.11.2 +1.11.3 \ No newline at end of file