Skip to content
Electric26 edited this page Aug 29, 2017 · 3 revisions

Some basic information

World Of Tanks python scripts are inside

  • res
  • res_bw

However, res_bw contains BigWorld engine's stuff so most likely you will only use res.
I'm not even sure you can override things inside res_bw.

At the origin, all game modifications were overriding original files in res folder and so corrupting the client.
In order to avoid this situation, Wargaming created res_mods folder where all content is dynamically loaded instead of the original files.

This is obtained by adding res_mods in paths.xml before res declaration, so that class loader look inside res_mods before res:

<root>
  <Paths>
    <Path>./res_mods/0.9.10</Path>
     ...
     ...
     ...
    <Path>./res</Path>
    <Path>./res_bw</Path>
  </Paths>
</root>

However there was another problem: since each modification was made by overriding original python script files with files of same name, it was not possible to use multiple mods which would have altered same files.

As an example, let's suppose a player want install a mod X that overrides original Avatar.py from res with a new one in res_mods.
After a while he also wants to install a mod Y that also replaces the same Avatar.py in res_mods.
As result only the latest mod (Y) is working and the previous mod (X) was overridden and not working anymore.

Then a mod loader was introduced by modders. It's composed of:

  1. res_mods/<version>/scripts/client/mods/__init__.pyc (empty file)
  2. res_mods/<version>/scripts/client/CameraNode.pyc (the loader)

The loader looks inside res_mods/<version>/scripts/client/mods for any .pyc file and loads those at runtime instead of using old way of replacing the "startup replacing method". This is a great way, since every mod can override a lot of original functions and with a chain system like this in place, other mods keeps on working.

There are mainly 3 steps to modding python files:

  1. Locate the code
  2. Create the mod file
  3. Compile it

1. Locate the code

You need to find a function that you can override with your code.
At least you should know when and from where the function is called.
There is no correct tutorial for this, but if you understand the game's file structure it's easier to find what you need just with file names.

Otherwise you can:

  1. Use global search on wotsources for some text, for example if you want find code that manage the sixthsense icon then search for "sixthsense" :)
  2. Iterate over results, check what functions do
  3. Repeat global search for named variables or named functions

In Eclipse, to make a global search, select the project wotsources then use the search feature.

2. Create the mod file

Let's suppose there is an original file called tank.py:

# tank.py
class TankGun:
    def shoot(self):
        # ... some code here!

Now if you would like to create a mod to change its behavior, doesn't matter the file name you choose.
For example, in case you would like to write a message to python.log when you shoot, you could do following:

# myawesomemod.py
def new_shoot(self):
    print "i'm going to shoot!"
    return old_shoot(self)

old_shoot = TankGun.shoot
TankGun.shoot = new_shoot

The code is pretty simple:

  1. define a new function new_shoot with the same signature as the original, and log "i'm going to shoot!".
  2. save the original function code in old_shoot.
  3. inject the new function code.
3. Compile it

Compile the mod back in to .pyc and move it to res_mods/<version>/scripts/client/mods/, don't forget the mod loader!