Jump to content

  • Log In with Google      Sign In   
  • Create Account

Loading Dlls as mods (Similar to idtech and source)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 ill   Members   -  Reputation: 320

Like
0Likes
Like

Posted 05 August 2012 - 12:25 PM

I was thinking about how to make my engine moddable. I could use lua and scripting of some sort, but I just don't feel like going through the trouble of learning lua and adding yet another random feature to my engine.

Something that seems pretty doable is to just load dlls like idTech engines do. On windows, a mod might come with gamex86.dll. I'm a bit fuzzy on the details though. If I have a mod that overrides a tiny thing in the base game, does the gamex86.dll need to be completely recompiled from the source of the original game's dll or can I layer the mod dlls on top of each other some how? Knowing what I know now about dlls, I'm pretty sure that's impossible.

I could still easily let other things be moddable, like weapon stats, graphics, sounds, etc... if it's data driven and not compiled into the dll.

Sponsor:

#2 Aiive   GDNet+   -  Reputation: 1020

Like
1Likes
Like

Posted 06 August 2012 - 12:22 PM

In my opinion it depends on the type of changes you are planning to allow the end user to make.


For example, instead of having all the particles float up, I write a mod which makes them float down.

You make an interface to the particle system which has a virtual function called OnUpdate(). I write my DLL using your interface and change the OnUpdate to my own custom particle update.

When starting the editor it reads the file names of a specific directory, loads my mod using LoadLibrary, and gets a pointer to the virtual function OnUpdate. When the particle update loop comes around if you have a valid pointer to an external OnUpdate method you use that one. If not, you simply update particles as normal.

This way the original compilation is already configured to accept mods and no changes to the original source are needed.

Of course it would need to be refined to a system that works to your needs, but you have to decide what exactly you want the end user to be able to change. If you wanted them to be able to add their own networking code the above would work. The user would just give the plugin to their friends/users along with the game.

However if you are looking for a more 100% ability to change anything I think a scripting language would work best.

Edited by iheartyyouxo, 06 August 2012 - 12:24 PM.


#3 6677   Members   -  Reputation: 1058

Like
1Likes
Like

Posted 06 August 2012 - 04:29 PM

A scripting engines main advantages I think are ease of implementation (supposedly, I have no hands on experience here) and that a new script can be rewritten on the fly. In game even you could well have the debug console linking straight into the scripting engine.

#4 wolfscaptain   Members   -  Reputation: 200

Like
0Likes
Like

Posted 07 August 2012 - 02:15 AM

To replace data files, I'd go with with something like PhysicsFS.
They have this exact example on their main page I believe.

#5 ill   Members   -  Reputation: 320

Like
0Likes
Like

Posted 09 August 2012 - 04:28 AM

Yeah I already use PhsyicsFS. It's wonderful and makes life easier. I have some data driven configuration that is easily overriden by mods.

I'm not sure how easy it is to integrate a game engine with something like Lua.

Quake and Halflife Modding seems to have been working just fine for those games by relying mostly on C/C++ written mod dlls. I'm just fuzzy on the details of what's possible.

Like can I load gamex86.dll from mod 1, then load gamex86.dll from mod 2 and have a class like Soldier that was defined in mod 1 be overriden by mod 2's implementation of Soldier without too much work on my part? Or does mod 2's dll have to be a complete recompile of the whole base game dll and include everything, and have only 1 dll loaded at once?

#6 Aldacron   GDNet+   -  Reputation: 3279

Like
1Likes
Like

Posted 09 August 2012 - 08:42 AM

I'm not sure how easy it is to integrate a game engine with something like Lua.


Once you learn Lua and its C interface, it's very easy.

Quake and Halflife Modding seems to have been working just fine for those games by relying mostly on C/C++ written mod dlls. I'm just fuzzy on the details of what's possible.

Like can I load gamex86.dll from mod 1, then load gamex86.dll from mod 2 and have a class like Soldier that was defined in mod 1 be overriden by mod 2's implementation of Soldier without too much work on my part? Or does mod 2's dll have to be a complete recompile of the whole base game dll and include everything, and have only 1 dll loaded at once?


Not quite. The approach id used with Quake is not amenable to making minor modifications. The gamex86.dll is the game and only one instance of it will ever be loaded at a time. In this case, the executable file is the game engine (renderer, audio system, resource loaders, etc...). It loads the game DLL at runtime, then hands control over to it. Engine functions are called by the DLL via function pointers in a struct instance that the engine passes to the DLL at load time. This approach is fine if you want to allow total rewrites of your game. But for minor modifications, like a new soldier type, it's quite a bit of overkill.

If you want to use DLLs for minor mods, then you would be better off taking a plugin approach. In this case, you can put the core game code in your executable and just define an interface that mod DLLs can use. At runtime, you can scan a designated mod directory for DLLs and load them in, looking for specific functions in each one and responding appropriately to what you find.

I'm guessing that this probably gives you more questions. And it's a bit too complex to describe in a forum post if you don't already understand what's going on under the hood. So if you do want to go either way with a DLL mod system, what you need to study up on is how to dynamically load DLLs at runtime and how to implement a plugin system. Google should be able to point you in the right direction.

A much more sane approach is to use a scripting language like Lua. The advantages over using DLLs are big. For one, it doesn't require modders to already know C or C++. For another, mods can be compiled and executed at runtime from within the game, without having to compile a C codebase and restarting the game each time. And a really big one is that they are safer, as you can prevent mods from having access to system calls. This is a big deal. It would suck for a player to download a DLL mod for your game that, when initialized, downloads and installs a backdoor, or erases the harddrive. Guess who's going to get a good portion the blame when that happens.

I highly recommend using a scripting language instead of a DLL-based mod system. Getting up and going with Lua isn't difficult and there are plenty of resources online that show you how to get it to interoperate with your program. Spend a some time experimenting with just that and you should be able to learn most of what you need to know relatively quickly.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS