#Modding support

1 messages · Page 1 of 1 (latest)

unique dragon
#

Hi all,
I'd like to add modding support to my game via dll (aka it would load the dlls on start). Here's my solution right now:

The user will inherit one, and only one IMod class, where it contains an initialization method, the Mod Loader will find the only class that has inherited IMod, and use Activator.CreateInstance(obj) to create that object and box it to an IMod class, then call the Initialization method. The initialization will then pass classes that are inherited from interfaces to the Mod Loader, and it would run the mods.

Is there a better way to approach it, or is it a good method? Thanks everyone ;)

woven lintel
#

That is a typical approach, and nothing wrong with it. It's ugly, but reflection always is. And when you're dealing with something like this there is no avoiding it

#

In fact this is how I've done mod loaders in the past

unique dragon
#

Oh, okay thanks a lot ;)

woven lintel
#

The only other conceivable way I could think of would be to use IL emitting. That'd boost performance but it's a whole can of worms that would require a lot of work to do so I wouldn't recommend it

#

Your solution is fine

#

will find the only class that inherited IMod
However another way to do this would be to have modders include a manifest file of some kind, which could specify which class is the main mod class

#

If you've ever created plugins for a Bukkit minecraft server, for example, they have a manifest file called plugin.yml which has a main property
Example from https://www.spigotmc.org/wiki/plugin-yml/:

main: org.spigotmc.testplugin.Test

So the mod developer tells the loader which class it is, rather than the loader trying to figure it out

#

But y'know, swings and roundabouts shrug

unique dragon
#

Thankyou so much, appreciate it