Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/NickHugi/PyKotor into Nic…
Browse files Browse the repository at this point in the history
…kHugi/master
  • Loading branch information
th3w1zard1 committed Apr 16, 2024
2 parents 540a53f + 7bd63c2 commit b366457
Show file tree
Hide file tree
Showing 100 changed files with 492 additions and 555 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
K1_PATH="C:\Program Files (x86)\Steam\steamapps\common\swkotor"
K2_PATH="C:\Program Files (x86)\Steam\steamapps\common\Knights of the Old Republic II"
PYTHONPATH="${env:PYTHONPATH};Libraries\PyKotor\src;Libraries\PyKotorGL\src;Libraries\PyKotorFont\src;Libraries\Utility\src"
NWNNSSCOMP_PATH="C:/Program Files (x86)/KotOR Scripting Tool/nwnnsscomp.exe"
NWNNSSCOMP_PATH="C:/Program Files (x86)/KotOR Scripting Tool/nwnnsscomp.exe"
MYPYPATH="Libraries\PyKotor\src;Libraries\PyKotorGL\src;Libraries\PyKotorFont\src;Libraries\Utility\src;Tools\HoloPatcher\src;Tools\HolocronToolset\src;Tools\BatchPatcher\src;Tools\GUIDuplicator\src;Tools\MDLDecompile\src"
18 changes: 9 additions & 9 deletions .github/workflows/publish_pykotor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ jobs:
if (-not (Test-Path -Path "upx-dir")) {
New-Item -ItemType Directory -Path "upx-dir"
}
Get-ChildItem -Path "temp_folder_upx/$fileNameWithoutExtension" -Recurse | Move-Item -Destination "upx-dir"
Get-ChildItem -LiteralPath "temp_folder_upx/$fileNameWithoutExtension" -Recurse | Move-Item -Destination "upx-dir"
Remove-Item "temp_folder_upx" -Recurse -Force -ErrorAction SilentlyContinue
} else {
tar -xvf $archiveName --strip-components=1 -C "upx-dir"
Expand Down Expand Up @@ -318,13 +318,13 @@ jobs:
Write-Host "Virtual environment path: $venvPath"
# Dynamically find the Python version directory inside the venv
$pythonLibPath = Get-ChildItem -Path "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$pythonLibPath = Get-ChildItem -LiteralPath "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$sitePackagesPath = Join-Path -Path $pythonLibPath.FullName -ChildPath "site-packages"
Write-Host "Site-packages path: $sitePackagesPath"
# Use patchelf to adjust RPATH for all shared libraries in the virtual environment
Get-ChildItem -Path $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
Get-ChildItem -LiteralPath $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
$libPath = $_.FullName
Write-Host "Patching $libPath"
sudo patchelf --set-rpath '$ORIGIN' $libPath
Expand All @@ -337,7 +337,7 @@ jobs:
Get-PSDrive -PSProvider FileSystem | ForEach-Object {
$drive = $_.Root
Write-Host "Searching in $drive"
Get-ChildItem -Path $drive -Filter 'api-ms-win-crt-*.dll' -Recurse -ErrorAction SilentlyContinue -Force | ForEach-Object {
Get-ChildItem -LiteralPath $drive -Filter 'api-ms-win-crt-*.dll' -Recurse -ErrorAction SilentlyContinue -Force | ForEach-Object {
Write-Host $_.FullName
}
}
Expand Down Expand Up @@ -467,13 +467,13 @@ jobs:
Write-Host "Virtual environment path: $venvPath"
# Dynamically find the Python version directory inside the venv
$pythonLibPath = Get-ChildItem -Path "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$pythonLibPath = Get-ChildItem -LiteralPath "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$sitePackagesPath = Join-Path -Path $pythonLibPath.FullName -ChildPath "site-packages"
Write-Host "Site-packages path: $sitePackagesPath"
# Use patchelf to adjust RPATH for all shared libraries in the virtual environment
Get-ChildItem -Path $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
Get-ChildItem -LiteralPath $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
$libPath = $_.FullName
Write-Host "Patching $libPath"
sudo patchelf --set-rpath '$ORIGIN' $libPath
Expand Down Expand Up @@ -604,13 +604,13 @@ jobs:
Write-Host "Virtual environment path: $venvPath"
# Dynamically find the Python version directory inside the venv
$pythonLibPath = Get-ChildItem -Path "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$pythonLibPath = Get-ChildItem -LiteralPath "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$sitePackagesPath = Join-Path -Path $pythonLibPath.FullName -ChildPath "site-packages"
Write-Host "Site-packages path: $sitePackagesPath"
# Use patchelf to adjust RPATH for all shared libraries in the virtual environment
Get-ChildItem -Path $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
Get-ChildItem -LiteralPath $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
$libPath = $_.FullName
Write-Host "Patching $libPath"
sudo patchelf --set-rpath '$ORIGIN' $libPath
Expand Down Expand Up @@ -882,7 +882,7 @@ jobs:
}
# Iterate through each tool in the folder
Get-ChildItem -Path $matrixPackagePath | ForEach-Object {
Get-ChildItem -LiteralPath $matrixPackagePath | ForEach-Object {
$toolExePath = $_.FullName
$toolFileName = $_.Name
$fileBaseName = [IO.Path]::GetFileNameWithoutExtension($_.Name)
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release_holopatcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ jobs:
if (-not (Test-Path -Path "upx-dir")) {
New-Item -ItemType Directory -Path "upx-dir"
}
Get-ChildItem -Path "temp_folder_upx/$fileNameWithoutExtension" -Recurse | Move-Item -Destination "upx-dir"
Get-ChildItem -LiteralPath "temp_folder_upx/$fileNameWithoutExtension" -Recurse | Move-Item -Destination "upx-dir"
Remove-Item "temp_folder_upx" -Recurse -Force -ErrorAction SilentlyContinue
} else {
tar -xvf $archiveName --strip-components=1 -C "upx-dir"
Expand Down Expand Up @@ -322,13 +322,13 @@ jobs:
Write-Host "Virtual environment path: $venvPath"
# Dynamically find the Python version directory inside the venv
$pythonLibPath = Get-ChildItem -Path "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$pythonLibPath = Get-ChildItem -LiteralPath "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$sitePackagesPath = Join-Path -Path $pythonLibPath.FullName -ChildPath "site-packages"
Write-Host "Site-packages path: $sitePackagesPath"
# Use patchelf to adjust RPATH for all shared libraries in the virtual environment
Get-ChildItem -Path $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
Get-ChildItem -LiteralPath $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
$libPath = $_.FullName
Write-Host "Patching $libPath"
sudo patchelf --set-rpath '$ORIGIN' $libPath
Expand Down Expand Up @@ -451,7 +451,7 @@ jobs:
$originalDir = Get-Location
$sourceFolder = Join-Path -Path $originalDir -ChildPath "published_workflow_builds"
Set-Location $sourceFolder
Get-ChildItem -Path "." -Directory | ForEach-Object {
Get-ChildItem -LiteralPath "." -Directory | ForEach-Object {
$folderName = $_.Name
$archiveName = "$folderName.zip"
zip -r -9 $archiveName $folderName
Expand Down Expand Up @@ -530,7 +530,7 @@ jobs:
$archivePath = "published_workflow_builds/*.zip"
$releaseId = $env:RELEASE_ID
$token = "${{ secrets.GITHUB_TOKEN }}""
Get-ChildItem -Path $archivePath | ForEach-Object {
Get-ChildItem -LiteralPath $archivePath | ForEach-Object {
$filePath = $_.FullName
$fileName = $_.Name
$uploadUrl = "https://uploads.github.com/repos/$env:GITHUB_REPOSITORY/releases/$releaseId/assets?name=$fileName&label=$fileName"
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release_toolset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ jobs:
if (-not (Test-Path -Path "upx-dir")) {
New-Item -ItemType Directory -Path "upx-dir"
}
Get-ChildItem -Path "temp_folder_upx/$fileNameWithoutExtension" -Recurse | Move-Item -Destination "upx-dir"
Get-ChildItem -LiteralPath "temp_folder_upx/$fileNameWithoutExtension" -Recurse | Move-Item -Destination "upx-dir"
Remove-Item "temp_folder_upx" -Recurse -Force -ErrorAction SilentlyContinue
} else {
tar -xvf $archiveName --strip-components=1 -C "upx-dir"
Expand Down Expand Up @@ -341,13 +341,13 @@ jobs:
Write-Host "Virtual environment path: $venvPath"
# Dynamically find the Python version directory inside the venv
$pythonLibPath = Get-ChildItem -Path "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$pythonLibPath = Get-ChildItem -LiteralPath "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$sitePackagesPath = Join-Path -Path $pythonLibPath.FullName -ChildPath "site-packages"
Write-Host "Site-packages path: $sitePackagesPath"
# Use patchelf to adjust RPATH for all shared libraries in the virtual environment
Get-ChildItem -Path $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
Get-ChildItem -LiteralPath $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
$libPath = $_.FullName
Write-Host "Patching $libPath"
sudo patchelf --set-rpath '$ORIGIN' $libPath
Expand Down Expand Up @@ -473,7 +473,7 @@ jobs:
$originalDir = Get-Location
$sourceFolder = Join-Path -Path $originalDir -ChildPath "published_workflow_builds"
Set-Location $sourceFolder
Get-ChildItem -Path "." -Directory | ForEach-Object {
Get-ChildItem -LiteralPath "." -Directory | ForEach-Object {
$folderName = $_.Name
$archiveName = "$folderName.zip"
zip -r -9 $archiveName $folderName
Expand Down Expand Up @@ -552,7 +552,7 @@ jobs:
$archivePath = "published_workflow_builds/*.zip"
$releaseId = $env:RELEASE_ID
$token = "${{ secrets.GITHUB_TOKEN }}""
Get-ChildItem -Path $archivePath | ForEach-Object {
Get-ChildItem -LiteralPath $archivePath | ForEach-Object {
$filePath = $_.FullName
$fileName = $_.Name
$uploadUrl = "https://uploads.github.com/repos/$env:GITHUB_REPOSITORY/releases/$releaseId/assets?name=$fileName&label=$fileName"
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release_translator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ jobs:
if (-not (Test-Path -Path "upx-dir")) {
New-Item -ItemType Directory -Path "upx-dir"
}
Get-ChildItem -Path "temp_folder_upx/$fileNameWithoutExtension" -Recurse | Move-Item -Destination "upx-dir"
Get-ChildItem -LiteralPath "temp_folder_upx/$fileNameWithoutExtension" -Recurse | Move-Item -Destination "upx-dir"
Remove-Item "temp_folder_upx" -Recurse -Force -ErrorAction SilentlyContinue
} else {
tar -xvf $archiveName --strip-components=1 -C "upx-dir"
Expand Down Expand Up @@ -321,13 +321,13 @@ jobs:
Write-Host "Virtual environment path: $venvPath"
# Dynamically find the Python version directory inside the venv
$pythonLibPath = Get-ChildItem -Path "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$pythonLibPath = Get-ChildItem -LiteralPath "$venvPath/lib" | Where-Object { $_.PSIsContainer } | Select-Object -First 1
$sitePackagesPath = Join-Path -Path $pythonLibPath.FullName -ChildPath "site-packages"
Write-Host "Site-packages path: $sitePackagesPath"
# Use patchelf to adjust RPATH for all shared libraries in the virtual environment
Get-ChildItem -Path $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
Get-ChildItem -LiteralPath $sitePackagesPath -Filter *.so -Recurse | ForEach-Object {
$libPath = $_.FullName
Write-Host "Patching $libPath"
sudo patchelf --set-rpath '$ORIGIN' $libPath
Expand Down Expand Up @@ -449,7 +449,7 @@ jobs:
$originalDir = Get-Location
$sourceFolder = Join-Path -Path $originalDir -ChildPath "published_workflow_builds"
Set-Location $sourceFolder
Get-ChildItem -Path "." -Directory | ForEach-Object {
Get-ChildItem -LiteralPath "." -Directory | ForEach-Object {
$folderName = $_.Name
$archiveName = "$folderName.zip"
zip -r -9 $archiveName $folderName
Expand Down Expand Up @@ -528,7 +528,7 @@ jobs:
$archivePath = "published_workflow_builds/*.zip"
$releaseId = $env:RELEASE_ID
$token = "${{ secrets.GITHUB_TOKEN }}""
Get-ChildItem -Path $archivePath | ForEach-Object {
Get-ChildItem -LiteralPath $archivePath | ForEach-Object {
$filePath = $_.FullName
$fileName = $_.Name
$uploadUrl = "https://uploads.github.com/repos/$env:GITHUB_REPOSITORY/releases/$releaseId/assets?name=$fileName&label=$fileName"
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"name": "Run HoloPatcher",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}${pathSeparator}Tools${pathSeparator}HoloPatcher${pathSeparator}src${pathSeparator}__main__.py",
"cwd": "${workspaceFolder}/Tools/HoloPatcher/src/",
"module": "holopatcher",
"console": "integratedTerminal",
"env": {"PYTHONPATH": "${workspaceFolder}/Libraries/PyKotor/src;${workspaceFolder}/Libraries/Utility/src;${env:PYTHONPATH}"},
"justMyCode": true,
Expand All @@ -66,7 +66,7 @@
"name": "Run BatchPatcher",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}${pathSeparator}Tools${pathSeparator}BatchPatcher${pathSeparator}src${pathSeparator}__main__.py",
"module": "batchpatcher",
"cwd": "${workspaceFolder}/Tools/BatchPatcher/src/",
"console": "integratedTerminal",
"env": {"PYTHONPATH": "${workspaceFolder}/Libraries/PyKotor/src;${workspaceFolder}/Libraries/Utility/src;${env:PYTHONPATH}"},
Expand Down
23 changes: 14 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,25 @@
"reportCallIssue": "warning", // doesn't handle NamedTuple correctly.
"reportAssignmentType": "warning",
"reportArgumentType": "warning",
"reportPrivateImportUsage": "warning",
},
"mypy-type-checker.args": [
"--check-untyped-defs" // Ignores issues with defs that can optionally be None.
],
"python.analysis.autoFormatStrings": true,
"mypy.targets": [
"Libraries",
"Tools"
],
"mypy.extraArguments": [
"--exclude='./.venv'",
"--exclude='tests/results'"
"--exclude=./.venv",
"--exclude=tests/results",
"--check-untyped-defs",
"-v",
"--explicit-package-bases"
],
"github-actions.workflows.pinned.workflows": [
".github/workflows/publish_and_test_pykotor.yml"
],
"mypy-type-checker.args": [
"--check-untyped-defs",
"--explicit-package-bases"
],
"mypy.runUsingActiveInterpreter": true,
"mypy-type-checker.preferDaemon": true,
"mypy-type-checker.reportingScope": "workspace",
"mypy-type-checker.importStrategy": "fromEnvironment",
}
9 changes: 7 additions & 2 deletions Libraries/PyKotor/src/pykotor/resource/formats/tpc/io_tga.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,15 @@ def load(

def _load_with_pillow(
self,
) -> TPC | None:
):
if self._tpc is None:
raise ValueError("Call load() instead of this directly.")
# Use Pillow to handle the TGA file
print("Loading with pillow")
with Image.open(self._reader._stream) as img: # type: ignore[reportArgumentType] their static type is incorrect, it supports any stream/byte/filepath-like object.

# Their static type is incorrect, it supports any stream/byte/filepath-like object.
with Image.open(self._reader._stream) as img: # type: ignore[reportArgumentType]

# Determine the appropriate texture format based on the image mode
if img.mode == "L":
texture_format = TPCTextureFormat.Greyscale
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ If powershell is not an option for you, you can install Python manually from htt
Once 'install_python_venv.ps1' finishes, you can run any of the provided tools, such as HoloPatcher, KotorDiff, or the Toolset, like this:
```commandline
pip install -r Tools/HoloPatcher/requirements.txt --prefer-binary
python ./Tools/HoloPatcher/src/__main__.py
python Tools/HoloPatcher/src/holopatcher/__main__.py
pip install -r Tools/HolocronToolset/requirements.txt --prefer-binary
python Tools/HolocronToolset/src/toolset/__main__.py
python Tools/KotorDiff/__main__.py
python Tools/KotorDiff/src/kotordiff/__main__.py
```

see [HoloPatcher's readme](https://github.com/NickHugi/PyKotor/tree/master/Tools/HoloPatcher#readme) for more information
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def add_sys_path(path: pathlib.Path):
add_sys_path(utility_path.parent)


from batchpatcher.translate.language_translator import TranslationOption, Translator
from pykotor.common.language import Language, LocalizedString
from pykotor.common.stream import BinaryReader, BinaryWriter
from pykotor.extract.capsule import Capsule
Expand All @@ -65,7 +66,6 @@ def add_sys_path(path: pathlib.Path):
from pykotor.tools.misc import is_any_erf_type_file, is_capsule_file
from pykotor.tools.path import CaseAwarePath, find_kotor_paths_from_default
from pykotor.tslpatcher.logger import LogType, PatchLog, PatchLogger
from translate.language_translator import TranslationOption, Translator
from utility.system.path import Path, PurePath

if TYPE_CHECKING:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def update_sys_path(path):
update_sys_path(utility_path.parent)


from config import CURRENT_VERSION, getRemoteHolopatcherUpdateInfo, remoteVersionNewer
from holopatcher.config import CURRENT_VERSION, getRemoteHolopatcherUpdateInfo, remoteVersionNewer
from pykotor.common.misc import Game
from pykotor.common.stream import BinaryReader
from pykotor.extract.file import ResourceIdentifier
Expand All @@ -70,7 +70,7 @@ def update_sys_path(path):
from utility.error_handling import format_exception_with_variables, universal_simplify_exception
from utility.misc import ProcessorArchitecture
from utility.string_util import striprtf
from utility.system.os_helper import win_get_system32_dir
from utility.system.os_helper import kill_self_pid, win_get_system32_dir
from utility.system.path import Path
from utility.tkinter.tooltip import ToolTip
from utility.tkinter.updater import TkProgressDialog
Expand Down Expand Up @@ -295,7 +295,11 @@ def initialize_ui_controls(self):
self.gamepaths = ttk.Combobox(top_frame, style="TCombobox")
self.gamepaths.set("Select your KOTOR directory path")
self.gamepaths.grid(row=1, column=0, padx=5, pady=2, sticky="ew")
self.gamepaths["values"] = [str(path) for game in find_kotor_paths_from_default().values() for path in game]
self.gamepaths["values"] = [
str(path)
for game in find_kotor_paths_from_default().values()
for path in game
]
self.gamepaths.bind("<<ComboboxSelected>>", self.on_gamepaths_chosen)
# Browse for a KOTOR path
self.gamepaths_browse_button = ttk.Button(top_frame, text="Browse", command=self.open_kotor)
Expand Down Expand Up @@ -1264,6 +1268,7 @@ def task():

def set_state(
self,
*,
state: bool,
):
"""Sets the active thread task state. Disables UI controls until this function is called again with run=False.
Expand Down Expand Up @@ -1325,7 +1330,15 @@ def _execute_mod_install(
8. If CLI, exit regardless of success or error.
"""
confirm_msg: str = installer.config().confirm_message.strip()
if confirm_msg and not self.one_shot and confirm_msg != "N/A" and not messagebox.askokcancel("This mod requires confirmation", confirm_msg):
if (
confirm_msg
and not self.one_shot
and confirm_msg != "N/A"
and not messagebox.askokcancel(
"This mod requires confirmation",
confirm_msg,
)
):
return
if progress_update_func is not None:
self.progress_bar["maximum"] = len(
Expand Down Expand Up @@ -1556,9 +1569,9 @@ def onAppCrash(

def my_cleanup_function(app: App):
"""Prevents the patcher from running in the background after sys.exit is called."""
#print("Fully shutting down Holo Patcher...")
#kill_self_pid()
#app.root.destroy()
print("Fully shutting down HoloPatcher...")
kill_self_pid()
app.root.destroy()


def main():
Expand Down
Loading

0 comments on commit b366457

Please sign in to comment.