New MetaEng, Part 2

With core2, many object types have been shifted around, phased out, or renamed. One of the most important types that has arisen in new form is “IUnloadable”. Since SourceMod allows you to remove plugins at any time, nightmares would ensue if things like cvars and console commands were not properly removed on plugin unload.

An IUnloadable defines an object that, at any point in time, could be unloaded from memory. Back in core1, an Unloadable was the opposite – something that couldn’t be unloaded. Slight mistake.

So, now what can be unloaded? The core types essential to SourceMod – IModule and IScript – are both IUnloadables. An Unloadable must also have a parent Unloadable – that is, if it is attached to a related piece of unloadable memory, it must specify this through its GetOwner() property.

In this manner, an IScript is an IUnloadable whose owner is the IUnloadable of the IModule who loaded it. Furthermore, any ICallable from that IScript will be an IUnloadable owned by the script. When the base module is uploaded to CVS, classes like ITimer and IMenu will also be IUnloadables.

So, how does this solve anything? PluginManager and ModuleManager will define two new interfaces: IPluginListener and IModuleListener. A manager class, such as CMenuManager or CTimerManager, can implement these interfaces and register themselves with both the Plugin and Module managers. The manager will then be notified of every plugin and module that is loaded and unloaded.

When the unload event is called (OnScriptUnload or OnModuleUnload). the manager can check all of its internal structures. Since an IMenu is an IUnloadable, it should have a valid parent, which can be compared to the pointer of the module or script. If they match, the manager must remove the callbacks from its internal lists, which will prevent it from accessing deleted memory.

With this design, SourceMod now has complete plugin/module/metaeng control. Everything will be dynamically loadable and unloadable at runtime, and unloading the root object will cause a chain reaction of unloading everything.

2 Responses to “New MetaEng, Part 2”

  1. Schreck says:

    Sounds great man…keepup the good work.

    Ww are rooting for you guys here at SeXy-GaMiNg…We want this program and are looking forward to the same (if not better) admin abilities as AMX/AMXmodX.

    BTW, If Valve/Steam want to call this a hack…They can buzz off since they cant make anything that the public likes except for the game…Valve, leave the scripting to these guys and quit f***ing up the code for them. They have enough bugs to deal with on their own without you changing it all the time.

    Sincerly,

    (–{[sXy-Schreck]}—:HMFIC:

  2. BigDog says:

    Woot woot, yay, cant wait for your awesome system to come out, i am not satisfied with others ones including Mani!!

Leave a Reply

You must be logged in to post a comment.