A comprehensive Python library that can read and modify most file formats used by the game Knights of the Old Republic and its sequel.
-
Clone the repository:
git clone https://github.com/NickHugi/PyKotor cd PyKotor
-
Install Poetry (if not already installed):
pip install poetry
-
Install the project and its dependencies:
poetry install
-
Activate the virtual environment:
poetry shell
This will install PyKotor and all its subpackages in editable mode.
PyKotor supports Python versions 3.8 and above. All dependencies are managed by Poetry. PyKotor is supported on most (if not all) operating systems, including Mac and other case-sensitive filesystems.
After installation and activating the virtual environment, you can run any of the provided tools, such as HoloPatcher, KotorDiff, or the Toolset, like this:
python Tools/HolocronToolset/src/toolset/__main__.py
python Tools/HoloPatcher/src/holopatcher/__main__.py
python Tools/KotorDiff/src/kotordiff/__main__.py
To install development dependencies, use:
poetry install --with dev
This will install all the development tools like mypy, ruff, pylint, etc.
After installation, you can run any of the provided tools, such as HoloPatcher, KotorDiff, or the Toolset, like this:
python Tools/HoloPatcher/src/holopatcher/__main__.py
python Tools/HolocronToolset/src/toolset/__main__.py
python Tools/KotorDiff/src/kotordiff/__main__.py
See HoloPatcher's readme for more information
See HolocronToolset's readme for more information
After cloning the repo, open any of the powershell scripts in the compile
folder such as compile_holopatcher.ps1
and compile_toolset.ps1
with PowerShell. Run the deps_holopatcher.ps1
or deps_toolset.ps1
first to get the dependencies setup. Doing so will start an automated process that results in a EXE being built/compiled to the PyKotor/dist folder. Specifically, those scripts will:
- Find a compatible Python interpreter, otherwise will install Python 3.8
- Setup the environment (the venv and PYTHONPATH)
- Install the tool's dependencies. This is any pip packages they require from requirements.txt and recommended.txt
- Install PyInstaller
- Compile to executable binary, as one file, to the dist folder in the root level of this repository.
Simple example of loading data from a game directory, searching for a specific texture, and exporting it to the TGA format.
from pykotor.resource.type import ResourceType
from pykotor.extract.installation import Installation
from pykotor.resource.formats.tpc import write_tpc
inst = Installation("C:/Program Files (x86)/Steam/steamapps/common/swkotor")
tex = inst.texture("C_Gammorean01")
write_tpc(tex, "./C_Gammorean01.tga", ResourceType.TGA)
As shown, this will save C_Gammorean01.tga
to the current directory.
More examples
These represent the currently passing/failing python versions/operating system combinations. Each badge is hyperlinked and permalinked to the full test report. Pick and choose any commit and see how far we have come.
This repository falls under the LGPL-3.0-or-later License.