How do mods work?

How exactly do people get mods for work, for example, in a game? By mods, I mean additions to the final executable.

If I were to create a game (using a compiled language), can I allow myself or others to make additions to it without having to create some kind of scripting language.

My idea: (will this work?)

  • In the most basic program, create a stack or FIFO or even a linked list.
  • Then, outside the program, the loader will download the database and any mods, and then pass the mods address to the base program.
  • Finally, the base program does its work, then switches the execution to mods (possibly with some kind of callback mechanism like [gasp!] Goto). When everything is ready, the code will return to the database, where it can do its job.
+3
source share
3 answers

Usually you will find some of your applications (games?) Of internal interfaces and objects for mod authors. The mod developer will create a dll that uses these objects and interfaces to do something useful. Then the application will dynamically load mod dll and, if necessary, invoke the mod implementation.

Another way to think about your game is the operating system (Windows), and your mod is the application (Word). The OS provides some APIs for creating and managing windows; the application uses them where necessary.

So, as a game, you can create and distribute the following interface:

//mod.h
class Mod {
    //takes suggested damage as an arg and returns modified damage
    virtual int takeDamage(int damage);
};

And ask users to provide exported functions for creating and deleting mod objects.

Deploy it:

//godmod.h
class GodMod : public Mod {
    int takeDamage(int damage) { return 0; } // god mode!!
}

__declspec(dllexport) Mod *create_mod() { return new GodMode(); }
__declspec(dllexport) void delete_mod(Mod *mod) { delete mod; }

DLL (LoadLibrary API Windows), create_mod delete_mod GetProcAddress API. - create_mod , :

int damage = 100; //original damage
for (int i = 0; i < mods_count; i++) {
    damage = mods[i]->tageDamage(damage);
}
decrease_health(damage);

delete_mod DLL.

+3

, . Windows , (DLL), Linux , (SO).

( ) . , , , , , .

, .

. , mysql , , "LOAD PLUGIN".

+4

, , .

. , , , .

, :

  • ++ , , , ++ .
  • ( , , , , ).
  • Using built-in callbacks, it’s hard to define (and provide) an interface between your game and mods

If you do not want to create your own scripting language, using some off-the-shelf (LUA is quite popular for games) is relatively simple.

+3
source

Source: https://habr.com/ru/post/1791680/


All Articles