Jump to content
V3ct0r

Mod loading system for server and client (PKOdev.NET mod loader)

Recommended Posts

Mod loading system for server and client (PKOdev.NET mod loader)

 

screenshot_1.png

 

 

The Problem


Many developers and administrators of Tales of Pirates servers in our community know that the functionality of the client and server can be changed by mods (addons, plugins, patches). 


Some examples of mods:
1) The fix of SQL Injections in AccountServer.exe and GroupServer.exe;
2) Increasing the limits for .txt / .bin files (ItemInfo, CharacterInfo, SkillInfo, etc.);
3) Local chat message handling using the lua function HandleChat();
4) Character transformation using the lua function TransformCha();
5) Character effects panel;
6) Displaying the levels of HP and SP under characters and monsters.


Thus, with the help of mods, you can fix critical bugs and vulnerabilities, change settings, add new functionality and features.
Initially, the appearance of mods was caused by the lack of open access to the source codes of the client and the server: the developers had no choice but to edit executable .exe files, developing and applying reverse engineering skills. After the publication of the source codes, the popularity of mods still remains at a high level. This is due to a few reasons:
1) Low quality of the received source codes, lack of experience in their use. To use them, the administrator needs to have an extensive knowledge of the C++ programming language, understand the client-server architecture, and understand how the server and the client work. In addition, the source codes require a long study and research for bugs and vulnerabilities, including the testing process;
2) The existing official builds of the server and client fully satisfy the requirements of most administrators and players, in addition, their performance and reliability have been confirmed by years of use. Many programs, scripts and mods were written for them, which may be incompatible with the server and client executable files compiled from the source codes;
3) The source code researching allows you to better understand the structure of the server and client executables (GameServer.exe, Game.exe). The knowledge gained makes it possible to create mods of increased complexity.

 

When implementing their projects, administrators and developers can go in two ways: use the old, official builds of the server and client, and change their functionality using mods, or go towards the development of source codes. As it should already be clear, this topic supports the first way.


At the moment, mod development is associated with some problems:
1) Our community lacks a clear standard and culture for writing mods. Someone injects the code directly into the executable file ("patching"), others prefer to write DLL. Some mods can conflict with each other, which leads to errors and subtle bugs;
2) Installing mods involves certain difficulties: for example, how to transfer a mod from one GameServer.exe to another one? Each time you need to do editing (patching) .exe file, and for this you need to have special knowledge and skills. If the mods are made in the form of DLL libraries, then each mod must be manually added into the import table of the executable file. All this is inconvenient, time-consuming and creates the possibility of errors and bugs during the installation process; 
3) There are many versions of GameServer.exe and Game.exe (the rest of the server .exe's are not taken into account), which have a different binary structure. In other words, the developed mod for GameServer.exe version 1.36 will not work with GameServer.exe version 1.38 - you need to develop the mod for a specific .exe file. As a result, there is confusion about the versions of the executable files. A shining example is the addresses of the limits for .txt/.bin tables, I think many have noticed that they are different for different .exe.


Based on the above, it was decided to create a system that would solve the current state of affairs in regards to mods and simplify their usage.

 

 

The Mod Loader


The mod loader performs several tasks:
1) Determining the type and version of the executable file (.exe) to be modified;
2) Searching for mods, determining their version, attaching to the process of the executable file;
3) Unification of the process of creating, installing and uninstalling mods.


It is a DLL library that attaches one-time to the executable file of the server or client. Mods are also DLL libraries that are placed in a specific directory and are automatically launched by the loader when the server or client executable file starts.


Before running the executable file, control is transferred to the loader. The loader determines the type and version of the .exe file to which it is attached and starts the process of searching for DLL libraries in the "mods" directory from the server or client root folder. The DLLs found are dynamically attached to the server or client process after which the loader requests the library information regarding the mod name, type, version of the executable target file, name and the author of the mod. If the type and version of the .exe file with attached loader matches the type and version of the .exe file obtained from the mod's library, then the loader gives the mod a command to start. Furthermore, changes to the code of the process of the executable file, thereby carrying out the modification. Before terminating the server or client process, control is again gained to the loader, which in turn detaches all mods from the process.

 

The current version of the mod loader can work with the official 1.3x versions of GameServer.exe (server) and Game.exe (client).
The type of executable file (GameServer.exe or Game.exe) and its version is determined by the build timestamp (linker timestamp), which is written in the COFF header of each executable.

 

Supported GameServer.exe and Game.exe

---------------------+----+----------------+--------------  
Name                 | ID |   Designation  | Time stamp
---------------------+----+----------------+--------------
GameServer.exe  1.36 |  1 | GAMESERVER_136 | 1204708785
---------------------+----+----------------+--------------
GameServer.exe  1.38 |  2 | GAMESERVER_138 | 1204708785
---------------------+----+----------------+--------------
Game.exe             |  3 | GAME_13X_0     | 1222073761
---------------------+----+----------------+--------------
Game.exe             |  4 | GAME_13X_1     | 1243412597
---------------------+----+----------------+--------------
Game.exe             |  5 | GAME_13X_2     | 1252912474
---------------------+----+----------------+--------------
Game.exe             |  6 | GAME_13X_3     | 1244511158
---------------------+----+----------------+--------------
Game.exe             |  7 | GAME_13X_4     | 1585009030
---------------------+----+----------------+--------------
Game.exe             |  8 | GAME_13X_5     | 1207214236
---------------------+----+----------------+--------------
GateServer.exe 1.38  | 101| GATESERVER_138 | 1224838480
---------------------+----+----------------+--------------

 


Installing the Mod Loader

 

screenshot_2.png


1) In the root directory of the executable file, create a folder called "mods*. This folder will store DLL libraries of mods;
2) Open the executable file in CFF Explorer. Go to the "Import adder" tab (1);
3) Click the "Add" button (2) and select the pkodev.mod.loader.dll file (see the attachments at the end of this post);
4) In the "Exported functions" list, select "ExportedFunction" (3);
5) Click the "Import By Name" button (4);
6) Uncheck the "Rebuild OFTs" checkbox (5);
7) Click the "Rebuild Import Table" button (6);
8 ) Save the file (7).
9) Run the executable file. You should see the following message in the console window: 

[pkodev.mod.loader] -----------------------------------------------
[pkodev.mod.loader]    PKOdev.NET mod loader ver. 1.0 by V3ct0r
[pkodev.mod.loader] -----------------------------------------------

If the executable file does not have a console window, for example, Game.exe, then run it as follows:

system\Game.exe startgame > output.txt

The console output will now be redirected to the text file output.txt.


* Note: for Game.exe, the mods folder must be in the client's root directory, not in the "system" folder.

 

 

Installing mods


To install a mod, just place its DLL library in the "mods" folder. For convenience, each mod can be placed in a separate folder.

 

An example of a folder structure for GameServer.exe:

GameServer
|
-> Mods
   |
   -> .disabled
   |
   -> .priority
   |
   -> pkodev.mod.example1.server.138.dll
   |
   -> pkodev.mod.example2
      | 
      -> pkodev.mod.example2.server.138.dll
   |
   -> pkodev.mod.example3
      | 
      -> pkodev.mod.example3.server.138.dll

After launching the executable file, you should see the new mod in the list of loaded mods:

screenshot_3.png

 

 

Uninstalling mods 


To uninstall a mod, you need to delete its DLL library from the "mods" folder.

 

 

Temporary disabling of mods

 

To disable the loading of certain mods, create a ".disabled" file in the root directory with mods ("mods" folder) and write the names of the mods that you want to temporarily disable into it from a new line. For example:

// File: mods\.disabled
// Write here the names of mods that do not need to be loaded
pkodev.mod.fullmap
pkodev.mod.tablelimit

Thus, mods "pkodev.mod.fullmap" and "pkodev.mod.tablelimit" will be ignored by the loader.

 

 

Mod loading priority

 

The mod loader allows you to load certain mods in the specified order. To do this, create a ".priority" file in the root directory with mods ("mods" folder) and write down the names of mods in it in descending order of priority. Mods not listed in this file will be loaded after mods with priority, in random order. For example:

// File mods\.priority
// Write down mods loading priority in descending order here
pkodev.mod.power
pkodev.mod.tablelimit
pkodev.mod.fullmap

 

Mods will be loaded in the following order:

1. pkodev.mod.power;

2. pkodev.mod.tablelimit;

3. pkodev.mod.fullmap;

4. Next - all other mods found in the "mods" folder in random order.

 


Creating a mod


In order for a mod to be loaded by the mod loader, it must meet the following requirements:
1) The name of the DLL library of the mod should be like:

pkodev.mod.<mod name>.<client or server>.<.exe designation >.dll

Examples:

pkodev.mod.tablelimit.client.13x_0.dll
pkodev.mod.mobspawn.server.138.dll

2) DLL library of the mod should export 3 functions:


__declspec(dllexport) void __cdecl GetModInformation(mod_info& info)


Fill in the structure of type mod_info. This structure contains basic information about the mod: its name, version, author name, executable file ID for which the mod is intended.

// Mod information structure
struct mod_info
{
    // Mod name
    char name[128];
    
    // Mod version
    char version[64];
    
    // Author’s name
    char author[64];
    
    // Type and version of the target .exe file (see the table)
    unsigned int exe_version;
};

 

__declspec(dllexport) void __cdecl Start(const char* path)

 

Enable the mod and modify the process of the executable file. The path variable contains the path to the root directory of the mod. In this function, the mod must perform its initialization, load the necessary settings and modify the process of the executable file.


__declspec(dllexport) void __cdecl Stop()


Disable the mod. In this function, the mod must save its settings, roll back the process modification (optional) and free resources.


3) The type and version of the executable file specified in the DLL library of the mod (structure modinfo, field exe_version) must match the type and version of the executable file for which it is intended. If the loader has defined the type and version of the executable file as GameServer.exe 1.38 (GAMESERVER_138) with ID 2, then the mod's DLL library should write the value 2 in the exe_version field, otherwise the mod  will be determined as unsuitable.

 

 

Mod development example


Any programming language can be used to develop the mod which supports creating DLLs. I will use the C++ as programming language and the Visual Studio 2019 Community as development environment.


As an example, let's create a mod for GameServer.exe version 1.38 that will display the "Hello world!" message in its window.


1) Let's define the name of the mod, let it be: 

pkodev.mod.helloworld

Then the name of the DLL library of the mod will be:

pkodev.mod.helloworld.server.138.dll

2) Create a Dynamic-Link Library (DLL) project;
3) Add the loader.h file to the project (see the attachments at the end of this post);

4) Implement the function GetModInformation():

void GetModInformation(mod_info& info)
{
    strcpy_s(info.name, "pkodev.mod.helloworld");
    strcpy_s(info.version, "1.0");
    strcpy_s(info.author, "V3ct0r");
    info.exe_version = GAMESERVER_138;
}

5) Implement the function Start()

void Start(const char* path)
{
    std::cout << "Hello world!" << std::endl;
    std::cout << "path = " << path << std::endl << std::endl;
}

6) Implement the function Stop()

void Stop()
{

}

7) Compile the project. As a result, we’ll get the file pkodev.mod.helloworld.server.138.dll;
8 ) Install and test the mod. In the GameServer.exe window, we should see the message "Hello world!" and the path to the root directory of the mod.

screenshot_4.png
 
The sample mod project can be found in the attachments.

 


Download

 

1) The mod loader;

2) Source code of the mod loader (C++);

3) Interface for creating mods (file loader.h);

4) The project of the sample mod "Hello world!" for Visual Studio 2019 Community (C++);

5) Samples of client and server executables from the table (7.3 MB);

6) PKOdev .NET mod loader project template for Visual Studio 2019 Community (C++).

 

 

Available mods

 

1) Connecting Game.exe to Stall Server ("offline" stalls server connector);

2) Fixing instant respawn of killed monsters after GameServer restart;

3) Editing the limits of .txt tables;

4) Player rating system;

5) System of daily rewards for entering the game;

6) Automatically connect to the server / enter the game (Client modification that allows you to automatically connect to the server);

7) Displaying coordinates under the NPC;

8 ) Displaying additional parameters on the form with character characteristics (frmState);

9) Displaying the cooldown of skills;

10) Displaying the player's character level next to its name;

11) Antibot;

12) Displaying the name of the item in the apparel;

13) Displaying the level of items on their icons ("smart icons");

14) Change the size of the monsters;

15) Server time;

16) Social buttons (Discord, Youtube, Twitch and etc);

17) Medals (necklaces) with titles;

18) Displaying servers response time ("ping") on the server selection form;

19) Contract system;

20) Disabling error messages when compiling .txt tables (table_bin);

21) Colored GM messages (GM notice);

22) Fixing the resetting character professions when reconnecting to the server;

23) Cleaning up chats;

24) Disabling password verification when entering into the in-game shop (IGS);

25) 60 frames per second (60 FPS);

26) Flying effect for wings;

27) Full area map for the region;

28) Highlight friends and enemies with color.

 

(updated on 02/18/2022)

 

 

If you have any questions or have problems, then feel free to write in this thread.

  • Like 5
  • Thanks 1

Share this post


Link to post
Share on other sites

Added the samples of server and client executables shown in the table for mod developers.

 

Download (7.3 MB)


Share this post


Link to post
Share on other sites
On 12/16/2021 at 3:37 AM, RafaelaMartins said:

Hi V3ct0r, if you have a mod for State +time for buffs etc please share with us ❤️

Hello @RafaelaMartins!

 

Unfortunately, I do not have this mod.

  • Thanks 1

Share this post


Link to post
Share on other sites

i get this error here directiopn of the mods is correct, but when i try start it i get this error!!system\Game.exe startgame > output.txt awsome realase btw thkx for the mods...

Namnlös.png

Share this post


Link to post
Share on other sites

Hello @Mesut!

 

Make sure pkodev.mod.loader.dll is in the same folder as Game.exe

  • Like 1

Share this post


Link to post
Share on other sites
39 minutes ago, flamyman1412 said:

I've tried system\Game.exe startgame > output.txt but it's not supported.
don't see version Game.exe

Use system\Game.exe avaatoppi > output.txt

  • Thanks 1

Share this post


Link to post
Share on other sites

Well, it's time to sleep, just check the version of the game.exe if it's 1.36 or 1.38, if it doesn't work for you, you'll have to replace the game.exe

https://mega.nz/file/9AFFnSYT#pgeoUZyRdYVtGZNanH-9eXswqlQz25TfDjKtF97m7Xo

45 minutes ago, flamyman1412 said:

program as game program, Unable to run directly, Please launch the game correctly!

  • Thanks 1

Share this post


Link to post
Share on other sites
51 minutes ago, dragontechi said:

Well, it's time to sleep, just check the version of the game.exe if it's 1.36 or 1.38, if it doesn't work for you, you'll have to replace the game.exe

https://mega.nz/file/9AFFnSYT#pgeoUZyRdYVtGZNanH-9eXswqlQz25TfDjKtF97m7Xo

Thanks for all the help What you did to me, all the problems are because of my Game.exe and I can't change it because of language problems inside Game.exe.

Share this post


Link to post
Share on other sites
On 12/30/2021 at 6:54 PM, RafaelaMartins said:

Hi V3ctor, you have a mod for show the server time? near minimap

Hello! I will release it soon.

 

On 12/31/2021 at 9:30 AM, flamyman1412 said:

My game is not supported Can I modify my game to support mods?

You don't need to modify your Game.exe, but you need to modify mod loader and all mods to make them support your Game.exe. You have to find out the build timestamp of your Game.exe and add it into the file loader.h, thereby registering the Game.exe in the loader. Then you need to add support for this version of Game.exe to each mod, find the addresses of the required functions from the new Game.exe.

 

On 12/31/2021 at 12:48 PM, dragontechi said:

if your version is 1.36 or 1.38 it is compatible

Not all versions of 1.3x Game.exe are compatible. I took only 6 of the most common Game.exe versions.

 

On 12/31/2021 at 1:25 PM, flamyman1412 said:

I've tried system\Game.exe startgame > output.txt but it's not supported.
don't see version Game.exe

Any logs from the file output.txt?

 

On 12/31/2021 at 2:11 PM, flamyman1412 said:

program as game program, Unable to run directly, Please launch the game correctly!

This is because wrong startup parameter ("avaatoppi")

 

 

 


Share this post


Link to post
Share on other sites
4 hours ago, V3ct0r said:

Hello! I will release it soon.

 

You don't need to modify your Game.exe, but you need to modify mod loader and all mods to make them support your Game.exe. You have to find out the build timestamp of your Game.exe and add it into the file loader.h, thereby registering the Game.exe in the loader. Then you need to add support for this version of Game.exe to each mod, find the addresses of the required functions from the new Game.exe.

 

Not all versions of 1.3x Game.exe are compatible. I took only 6 of the most common Game.exe versions.

 

Any logs from the file output.txt?

 

This is because wrong startup parameter ("avaatoppi")

 

 

 

I don't know where I can look for build timestamp Game.exe, I don't have the ability to do this.

Share this post


Link to post
Share on other sites
On 1/1/2022 at 17:52, V3ct0r said:

¡Hola! Lo lanzaré pronto.

 

No necesita modificar su Game.exe, pero necesita modificar el cargador de mods y todos los mods para que sean compatibles con su Game.exe. Debe averiguar la marca de tiempo de compilación de su Game.exe y agregarlo al archivo loader.h , registrando así el Game.exe en el cargador. Luego, debe agregar soporte para esta versión de Game.exe a cada mod, busque las direcciones de las funciones requeridas en el nuevo Game.exe.

 

No todas las versiones de 1.3x Game.exe son compatibles. Tomé solo 6 de las versiones más comunes de Game.exe.

 

¿Algún registro del archivo output.txt ?

 

Esto se debe a que el parámetro de inicio es incorrecto ("avaatoppi")

 

 

 

 

How can I edit the folder where the mods load

Share this post


Link to post
Share on other sites
5 hours ago, dragontechi said:

How can I edit the folder where the mods load

Open the file dllmain.cpp and find the following line:

SearchLibraries("mods", arr);

Where "mods" is the path to the folder where the loader will search mods.

 

On 1/2/2022 at 5:27 AM, flamyman1412 said:

I don't know where I can look for build timestamp Game.exe, I don't have the ability to do this.

From the guide:

Quote

The type of executable file (GameServer.exe or Game.exe) and its version is determined by the build timestamp (linker timestamp), which is written in the COFF header of each executable.

 

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, V3ct0r said:

Open the file dllmain.cpp and find the following line:

SearchLibraries("mods", arr);

Where "mods" is the path to the folder where the loader will search mods.

 

From the guide:

 

Wrong link or do you suggest me to study from topic COFF header.

Share this post


Link to post
Share on other sites
On 1/3/2022 at 6:55 PM, flamyman1412 said:

Wrong link or do you suggest me to study from topic COFF header.

Hello! Yes, the link has been removed from the Microsoft website, but information about the COFF header can be found in Google. I would like to suggest you learn about it by yourself, because it is a ton of work to add new Game.exe support to the mod loader and mods.

 

Now you can use this program to view the build timestamp:

 


Share this post


Link to post
Share on other sites
16 hours ago, V3ct0r said:

Hello! Yes, the link has been removed from the Microsoft website, but information about the COFF header can be found in Google. I would like to suggest you learn about it by yourself, because it is a ton of work to add new Game.exe support to the mod loader and mods.

 

Now you can use this program to view the build timestamp:

 

Done. Thank you to everyone who guided me. Thank you very much.
@V3ct0r @dragontechi

 

I made mods support my game but after installing the mod The game cannot be opened.

There is no error notification.

Or do I have to rebuild the game.dll file to support it? my game

Edited by flamyman1412
Update found problems

Share this post


Link to post
Share on other sites

Hello @flamyman1412!

 

I have updated the link to the mod loader source code. Or you can replace the line:

#include <detours\detours.h>

with:

#include <detours.h>

 

On 1/5/2022 at 2:43 AM, flamyman1412 said:

I made mods support my game but after installing the mod The game cannot be opened.

There is no error notification.

Or do I have to rebuild the game.dll file to support it? my game

Can you give a detailed description of what you did?


Share this post


Link to post
Share on other sites
On 1/7/2022 at 5:28 AM, V3ct0r said:

Hello @flamyman1412!

 

I have updated the link to the mod loader source code. Or you can replace the line:

#include <detours\detours.h>

with:

#include <detours.h>

 

Can you give a detailed description of what you did?

i can fix it
But after installing the mod it doesn't show the effect of the mod.

[pkodev.mod.loader] -----------------------------------------------
[pkodev.mod.loader]    PKOdev.NET mod loader ver. 1.2 by V3ct0r    
[pkodev.mod.loader] -----------------------------------------------
[pkodev.mod.loader] Detected .exe file: 'Game.exe 1.3x (ID: 0)'.
[pkodev.mod.loader] Searching mods in 'mods' directory . . .
[pkodev.mod.loader] Done! (2) mods found out: 
+----+--------------------------------+----------+----------------+
|  # |                            Mod |  Version |         Author |
+----+--------------------------------+----------+----------------+
|  1.|            pkodev.mod.cooldown |      1.0 |         V3ct0r |
|  2.|           pkodev.mod.namelevel |      1.0 |         V3ct0r |
+----+--------------------------------+----------+----------------+
[pkodev.mod.loader] Launching mods . . .
[pkodev.mod.loader] All mods launched!

Edited by flamyman1412

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...