|
8 | 8 | from collections.abc import Iterator |
9 | 9 | from functools import cache |
10 | 10 | from io import BytesIO |
11 | | -from os import path |
12 | 11 | from pathlib import Path |
13 | 12 | from zipfile import ZIP_DEFLATED, ZipFile |
14 | 13 |
|
|
20 | 19 | ZIP_SETTINGS_FOLDER = ZIP_MODS_FOLDER / "settings" |
21 | 20 | ZIP_EXECUTABLE_FOLDER = Path("Binaries") |
22 | 21 | ZIP_PLUGINS_FOLDER = ZIP_EXECUTABLE_FOLDER / "Plugins" |
| 22 | +ZIP_PROXY_INIT_SCRIPT_FOLDERS = [ |
| 23 | + ZIP_EXECUTABLE_FOLDER / ZIP_MODS_FOLDER, |
| 24 | +] |
23 | 25 |
|
24 | 26 | # The base CMake directories - these need the preset added after |
25 | 27 | BUILD_DIR_BASE = THIS_FOLDER / "out" / "build" |
|
36 | 38 |
|
37 | 39 | # And there are a few extra files which we want which aren't matched by the above |
38 | 40 | INIT_SCRIPT = MODS_FOLDER / "__main__.py" |
| 41 | +PROXY_INIT_SCRIPT = MODS_FOLDER / "proxy__main__.py" |
39 | 42 | SETTINGS_GITIGNORE = MODS_FOLDER / "settings" / ".gitignore" |
40 | 43 | STUBS_DIR = THIS_FOLDER / "libs" / "pyunrealsdk" / "stubs" |
41 | 44 | STUBS_LICENSE = THIS_FOLDER / "libs" / "pyunrealsdk" / "LICENSE" |
@@ -217,10 +220,17 @@ def zip_config_file(zip_file: ZipFile) -> None: |
217 | 220 | Args: |
218 | 221 | zip_file: The zip file to add the config file to. |
219 | 222 | """ |
220 | | - # Path.relative_to doesn't work when where's no common base, need to use os.path |
221 | | - # While the file goes in the plugins folder, this path is relative to *the executable* |
222 | | - init_script_path = path.relpath(ZIP_MODS_FOLDER / INIT_SCRIPT.name, ZIP_EXECUTABLE_FOLDER) |
223 | | - pyexec_root = path.relpath(ZIP_MODS_FOLDER, ZIP_EXECUTABLE_FOLDER) |
| 223 | + # When launching via Steam, the CWD is (sometimes) `<steam>\Borderlands`. When launching via Mod |
| 224 | + # Organiser, or by running the exe directly, it's `Borderlands\Binaries`. |
| 225 | + # Stick with Steam as the default, since if we're not using Steam, the path this checks will |
| 226 | + # still be inside the game folder. |
| 227 | + init_script_path = str(ZIP_MODS_FOLDER / INIT_SCRIPT.name) |
| 228 | + pyexec_root = str(ZIP_MODS_FOLDER) |
| 229 | + |
| 230 | + # Copy the proxy script to all the spots the relative path might otherwise end up |
| 231 | + for path in ZIP_PROXY_INIT_SCRIPT_FOLDERS: |
| 232 | + zip_file.write(PROXY_INIT_SCRIPT, path / INIT_SCRIPT.name) |
| 233 | + zip_file.writestr(str(path / "Wrong folder, you cannot place sdk mods here!.txt"), "") |
224 | 234 |
|
225 | 235 | version_number = tomllib.loads(MANAGER_PYPROJECT.read_text())["project"]["version"] |
226 | 236 | git_version = get_git_repo_version() |
|
0 commit comments