Jump to content


Starting client modding

wot mod python programming client

  • Please log in to reply
2 replies to this topic

Jupiter000 #1 Posted 20 August 2019 - 06:41 PM

    Private

  • Player
  • 11848 battles
  • 5
  • [RONCS] RONCS
  • Member since:
    12-08-2012

Hello!

 

I would like to start writing client mods. I can programming in Python (and I read that mods are written in Python).

Where can I find the library for WoT?

I'd like to create a mod that writes something on the screen.

Thanks in advance!



jhakonen #2 Posted 25 August 2019 - 03:13 PM

    Corporal

  • Player
  • 1729 battles
  • 193
  • [T-BAD] T-BAD
  • Member since:
    06-16-2013

Hi,

 

For writing mods there is no library. The game has not been designed modding in mind. What you do instead is that you monkey patch any internal Python modules that you need to access.

To see what modules there are and what they contain you need to reverse engineer the Python byte code files (*.pyc) that WoT contains. This is easier than what it sounds like :)

 

The byte code files are within res/packages/scripts.pkg file. It is just a zip-file with just a different extension. Extract the files from it to somewhere on your disk. Then use a Python decompiler to convert pyc files to py source files. I've used Uncompyle6. I have also my own tools for extracting the sources, if you wish to use them instead (or to just see how they work) here: https://github.com/jhakonen/wot-sources-extract-tool

 

You can also apply the decompiler to mods created by others, to see how they work. Note though, that some authors obfuscate their byte code files to make decompiling impossible. So the decompiling might not always work.

 

For further examples try searching popular source code platforms for WoT mods, Here's a few examples:

 

Once you have some code done you wish to test in the game you need to compile the code back to a pyc file. You will need Python 2.7.x for that. Using any other Python minor or major version will produce incompatible pyc files, and the game will not load them. And, no, it doesn't load py files either. See e.g.: https://askubuntu.com/questions/324871/how-to-compile-a-python-file

 

To make the game load your file you need to either:

  • Replace an existing pyc file that contains your modifications, place the file to res_mods/<version>/ under same folder path that the decompiled source file has (although you might need to update the file whenever a game update is released, so you don't want use this method with a production ready mod), or
  • Create a pyc file to res_mods/<version>/scripts/client/gui/mods/ with prefix mod_, this gets loaded automatically by a built-in mod-loader (see scripts/client/gui/mods/__init__.py to see how it works once you have the decompiled sources)

 

To distribute your mod you can package your compiled pyc files into an archive file and instruct user to extract them under the res_mods folder. Do note that this is an old way of doing this and Wargaming might drop support for this at some point.

 

The newer, and more future proof way, is to package your mod into a wotmod file that you place to mods/<version> folder instead. You can find the wotmod specification document from here:

https://koreanrandom.com/forum/topic/36987-mod-packages-пакеты-модов/page/28

 

For my own mod I have created a separate setuptools based command that does the wotmod file creation. You can use it yourself if you want to:

https://github.com/jhakonen/setuptools-wotmod/

There's also the mandatory hello-world example mod that shows how to use it. :)

 

 



Jupiter000 #3 Posted 02 September 2019 - 11:53 AM

    Private

  • Player
  • 11848 battles
  • 5
  • [RONCS] RONCS
  • Member since:
    12-08-2012

View Postjhakonen, on 25 August 2019 - 02:13 PM, said:

Hi,

 

For writing mods there is no library. The game has not been designed modding in mind. What you do instead is that you monkey patch any internal Python modules that you need to access.

To see what modules there are and what they contain you need to reverse engineer the Python byte code files (*.pyc) that WoT contains. This is easier than what it sounds like :)

 

The byte code files are within res/packages/scripts.pkg file. It is just a zip-file with just a different extension. Extract the files from it to somewhere on your disk. Then use a Python decompiler to convert pyc files to py source files. I've used Uncompyle6. I have also my own tools for extracting the sources, if you wish to use them instead (or to just see how they work) here: https://github.com/jhakonen/wot-sources-extract-tool

 

You can also apply the decompiler to mods created by others, to see how they work. Note though, that some authors obfuscate their byte code files to make decompiling impossible. So the decompiling might not always work.

 

For further examples try searching popular source code platforms for WoT mods, Here's a few examples:

 

Once you have some code done you wish to test in the game you need to compile the code back to a pyc file. You will need Python 2.7.x for that. Using any other Python minor or major version will produce incompatible pyc files, and the game will not load them. And, no, it doesn't load py files either. See e.g.: https://askubuntu.com/questions/324871/how-to-compile-a-python-file

 

To make the game load your file you need to either:

  • Replace an existing pyc file that contains your modifications, place the file to res_mods/<version>/ under same folder path that the decompiled source file has (although you might need to update the file whenever a game update is released, so you don't want use this method with a production ready mod), or
  • Create a pyc file to res_mods/<version>/scripts/client/gui/mods/ with prefix mod_, this gets loaded automatically by a built-in mod-loader (see scripts/client/gui/mods/__init__.py to see how it works once you have the decompiled sources)

 

To distribute your mod you can package your compiled pyc files into an archive file and instruct user to extract them under the res_mods folder. Do note that this is an old way of doing this and Wargaming might drop support for this at some point.

 

The newer, and more future proof way, is to package your mod into a wotmod file that you place to mods/<version> folder instead. You can find the wotmod specification document from here:

https://koreanrandom.com/forum/topic/36987-mod-packages-пакеты-модов/page/28

 

For my own mod I have created a separate setuptools based command that does the wotmod file creation. You can use it yourself if you want to:

https://github.com/jhakonen/setuptools-wotmod/

There's also the mandatory hello-world example mod that shows how to use it. :)

 

 

 

Thank you so much!







Also tagged with wot, mod, python, programming, client

1 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users