Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow factory clone #55

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions extension/natives/entityfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Handle_t>(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;
}
Expand Down
5 changes: 5 additions & 0 deletions extension/pluginentityfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion product.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.2
1.11.3
4 changes: 3 additions & 1 deletion scripting/include/cbasenpc/entityfactory.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading