Raised This Month: $51 Target: $400
 12% 

[Request] Extension to allow plugins to control subplugins of it.


Post New Thread Reply   
 
Thread Tools Display Modes
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 04-16-2014 , 15:17   Re: [Request] Extension to allow plugins to control subplugins of it.
Reply With Quote #11

Quote:
Originally Posted by WildCard65 View Post
Actually fiagram, from what I see in sourcemod's PluginSys.cpp, it loads any plugin it can open no matter the extension:
Code:
CPlugin *CPlugin::CreatePlugin(const char *file, char *error, size_t maxlength)
{
    char fullpath[PLATFORM_MAX_PATH];
    g_SourceMod.BuildPath(Path_SM, fullpath, sizeof(fullpath), "plugins/%s", file);
    FILE *fp = fopen(fullpath, "rb");

    CPlugin *pPlugin = new CPlugin(file);

    if (!fp)
    {
        if (error)
        {
            UTIL_Format(error, maxlength, "Unable to open file");
        }
        pPlugin->m_status = Plugin_BadLoad;
        return pPlugin;
    }

    fclose(fp);

    return pPlugin;
}
...that's not the autoload code. If it was, you wouldn't have a const char *file argument.

It's called internally by _LoadPlugin, which is itself called internally by LoadPlugin. LoadPlugin is part of SourceMod IPluginManager interface, located in IPluginSys.h. It's one of the interfaces that Extensions can use. Granted, it's also called when a plugin is autoloaded (because _LoadPlugin is)

If you're looking for the autoload code, you should be looking at SourceModBase::DoGlobalPluginLoads() and the functions it calls for auto-loading plugins (CPluginManager::LoadAll_FirstPass, which calls CPluginManager::LoadPluginsFromDir, which has a
Code:
        } else if (dir->IsEntryFile()) {
            const char *name = dir->GetEntryName();
            size_t len = strlen(name);
            if (len >= 4
                && strcmp(&name[len-4], ".smx") == 0)
in it)

Incidentally, I found out just a few minutes ago that the optional/ directory under plugins isn't autoloaded, just like disabled/ isn't.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 04-16-2014 at 15:27.
Powerlord is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 04-16-2014 , 16:30   Re: [Request] Extension to allow plugins to control subplugins of it.
Reply With Quote #12

Quote:
Originally Posted by Powerlord View Post
...that's not the autoload code. If it was, you wouldn't have a const char *file argument.

It's called internally by _LoadPlugin, which is itself called internally by LoadPlugin. LoadPlugin is part of SourceMod IPluginManager interface, located in IPluginSys.h. It's one of the interfaces that Extensions can use. Granted, it's also called when a plugin is autoloaded (because _LoadPlugin is)

If you're looking for the autoload code, you should be looking at SourceModBase:oGlobalPluginLoads() and the functions it calls for auto-loading plugins (CPluginManager::LoadAll_FirstPass, which calls CPluginManager::LoadPluginsFromDir, which has a
Code:
        } else if (dir->IsEntryFile()) {
            const char *name = dir->GetEntryName();
            size_t len = strlen(name);
            if (len >= 4
                && strcmp(&name[len-4], ".smx") == 0)
in it)

Incidentally, I found out just a few minutes ago that the optional/ directory under plugins isn't autoloaded, just like disabled/ isn't.
The code I posted is just to show fiagram that sourcemod will still "compile" the plugin no matter if it has .smx or not.
WildCard65 is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 04-16-2014 , 16:43   Re: [Request] Extension to allow plugins to control subplugins of it.
Reply With Quote #13

He never claimed that Sourcemod cannot open "smx" files with a changed extension. He correctly claimed that Sourcemod will not auto-load these plugins, and that you can manually load them later.
__________________
ddhoward is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 04-18-2014 , 18:32   Re: [Request] Extension to allow plugins to control subplugins of it.
Reply With Quote #14

@ddhoward, I tried your suggestion of using forwards and it was a total failure D: replacement Edit: Got to work but it won't be useful if sm plugins unload is called on the sub plugins.

Last edited by WildCard65; 04-19-2014 at 20:23.
WildCard65 is offline
Cookies.net
Senior Member
Join Date: Jan 2011
Old 04-18-2014 , 19:43   Re: [Request] Extension to allow plugins to control subplugins of it.
Reply With Quote #15

Just wondering, why do you need such control of plugins? Is it really too expensive to have them running in the background? Not sure what the impact of many plugins will be as long as they're written in a sensible manner, but I doubt it'd be much.
Cookies.net is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 04-19-2014 , 09:31   Re: [Request] Extension to allow plugins to control subplugins of it.
Reply With Quote #16

Quote:
Originally Posted by Cookies.net View Post
Just wondering, why do you need such control of plugins? Is it really too expensive to have them running in the background? Not sure what the impact of many plugins will be as long as they're written in a sensible manner, but I doubt it'd be much.
You have no idea how FF2 works with it's subplugins:
PHP Code:
EnableSubPlugins(bool:force=false)
{
    if(
areSubPluginsEnabled && !force)
    {
        return;
    }

    
areSubPluginsEnabled=true;
    
decl String:path[PLATFORM_MAX_PATH], String:filename[PLATFORM_MAX_PATH], String:filename_old[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMpathPLATFORM_MAX_PATH"plugins/freaks");
    
decl FileType:filetype;
    new 
Handle:directory=OpenDirectory(path);
    while(
ReadDirEntry(directoryfilenamePLATFORM_MAX_PATHfiletype))
    {
        if(
filetype==FileType_File && StrContains(filename".smx"false)!=-1)
        {
            
Format(filename_oldPLATFORM_MAX_PATH"%s/%s"pathfilename);
            
ReplaceString(filenamePLATFORM_MAX_PATH".smx"".ff2"false);
            
Format(filenamePLATFORM_MAX_PATH"%s/%s"pathfilename);
            
DeleteFile(filename);
            
RenameFile(filenamefilename_old);
        }
    }

    
directory=OpenDirectory(path);
    while(
ReadDirEntry(directoryfilenamePLATFORM_MAX_PATHfiletype))
    {
        if(
filetype==FileType_File && StrContains(filename".ff2"false)!=-1)
        {
            
ServerCommand("sm plugins load freaks/%s"filename);
        }
    }
}

DisableSubPlugins(bool:force=false)
{
    if(!
areSubPluginsEnabled && !force)
    {
        return;
    }

    
decl String:path[PLATFORM_MAX_PATH], String:filename[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMpathPLATFORM_MAX_PATH"plugins/freaks");
    
decl FileType:filetype;
    new 
Handle:directory=OpenDirectory(path);
    while(
ReadDirEntry(directoryfilenamePLATFORM_MAX_PATHfiletype))
    {
        if(
filetype==FileType_File && StrContains(filename".ff2"false)!=-1)
        {
            
InsertServerCommand("sm plugins unload freaks/%s"filename);
        }
    }
    
ServerExecute();
    
areSubPluginsEnabled=false;

WildCard65 is offline
Cookies.net
Senior Member
Join Date: Jan 2011
Old 04-19-2014 , 11:49   Re: [Request] Extension to allow plugins to control subplugins of it.
Reply With Quote #17

Quote:
Originally Posted by WildCard65 View Post
You have no idea how FF2 works with it's subplugins:
Weren't you going to rewrite the FF2 base anyway? Why can't you just change how it works, instead of trying to create an exact clone, that might be cleaner in the code (who knows), instead of trying to find a better approach? I'm personally working on an alternative for VSH/FF2 myself which will use a completely different approach, by using the game mode manager I wrote (Gamma, it can be found in the Snippets and Tutorials section as I thought it wouldn't be usable for some time, but it got to a pretty usable state much faster than anticipated).

Last edited by Cookies.net; 04-19-2014 at 11:52.
Cookies.net is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 04-19-2014 , 11:52   Re: [Request] Extension to allow plugins to control subplugins of it.
Reply With Quote #18

Quote:
Originally Posted by Cookies.net View Post
Weren't you going to rewrite the FF2 base anyway? Why can't you just change how it works, instead of trying to create an exact clone, that might be cleaner in the code, who knows, instead of trying to find a better approach? I'm personally working on an alternative for VSH/FF2 myself which will use a completely different approach, by using the game mode manager I wrote (Gamma, it can be found in the Snippets and Tutorials section as I thought it wouldn't be usable for some time, but it got to a pretty usable state much faster than anticipated).
code I posted is not from the rewrite start me doing.
WildCard65 is offline
Cookies.net
Senior Member
Join Date: Jan 2011
Old 04-19-2014 , 11:57   Re: [Request] Extension to allow plugins to control subplugins of it.
Reply With Quote #19

Quote:
Originally Posted by WildCard65 View Post
code I posted is not from the rewrite start me doing.
Wasn't this extension request for the rewrite? Or was it just in general? No matter what, searching for a more proper solution would be better, instead of relying on loading and unloading plugins.
Cookies.net is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 04-19-2014 , 13:19   Re: [Request] Extension to allow plugins to control subplugins of it.
Reply With Quote #20

Quote:
Originally Posted by Cookies.net View Post
Wasn't this extension request for the rewrite? Or was it just in general? No matter what, searching for a more proper solution would be better, instead of relying on loading and unloading plugins.
for the rewrite because I want to be able to not have to keep using the commands "sm plugins load" and "sm plugins unload"
WildCard65 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode