diff --git a/Readme.md b/Readme.md index 09f9597..fb6144a 100644 --- a/Readme.md +++ b/Readme.md @@ -35,13 +35,14 @@ accept arguments into `sys.argv`. ## Initialization Script If you want to make more permanent mods, you'll want to use the initialization script. By default -this is `__main__.py` in the game's cwd. The initialization script is automatically run after sdk -initialization, so you can use it to import other files and generally perform all your setup. +this is `__main__.py` in the same folder as the `pyunrealsdk.dll`. The initialization script is +automatically run after sdk initialization, so you can use it to import other files and generally +perform all your setup. You can swap to a different initialization script by using setting `pyunrealsdk.init_script` in the [unrealsdk configuration file](https://github.com/bl-sdk/unrealsdk/#configuration). If you do this you may also want to set `pyunrealsdk.pyexec_root`, so that `pyexec` commands work from the same -folder. +folder. These are relative to the folder `pyunrealsdk.dll` is in (or you can supply absolute paths). ## Using SDK bindings Once you've got code running, you probably want to setup some hooks - the sdk can run callbacks diff --git a/changelog.md b/changelog.md index 1834014..56d5758 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Changelog +## Upcoming +- The `pyunrealsdk.init_script` and `pyunrealsdk.pyexec_root` config options are now relative to the + folder containing the `pyunrealsdk.dll`. Previously, they were relative to the cwd, which could + cause issues if it changed. + ## v1.8.0 - Added `WeakPointer.replace`, to modify a pointer in-place. diff --git a/src/pyunrealsdk/commands.cpp b/src/pyunrealsdk/commands.cpp index 2aa1a06..e623481 100644 --- a/src/pyunrealsdk/commands.cpp +++ b/src/pyunrealsdk/commands.cpp @@ -15,7 +15,8 @@ namespace { void pyexec_cmd_handler(const wchar_t* line, size_t size, size_t cmd_len) { static const std::filesystem::path root = - unrealsdk::config::get_str("pyunrealsdk.pyexec_root").value_or(""); + unrealsdk::utils::get_this_dll().parent_path() + / unrealsdk::config::get_str("pyunrealsdk.pyexec_root").value_or(""); auto file_start = std::find_if_not(line + cmd_len, line + size, &std::iswspace); const size_t file_len = (line + size) - file_start; diff --git a/src/pyunrealsdk/pyunrealsdk.cpp b/src/pyunrealsdk/pyunrealsdk.cpp index df0925e..4810a8e 100644 --- a/src/pyunrealsdk/pyunrealsdk.cpp +++ b/src/pyunrealsdk/pyunrealsdk.cpp @@ -8,6 +8,7 @@ #include "pyunrealsdk/version.h" #include "unrealsdk/config.h" #include "unrealsdk/unrealsdk.h" +#include "unrealsdk/utils.h" #include "unrealsdk/version.h" #ifdef PYUNREALSDK_INTERNAL @@ -73,8 +74,10 @@ void init(void) { try { // Use a custom globals to make sure we don't contaminate `py`/`pyexec` commands // This also ensures `__file__` gets redefined properly - py::eval_file(unrealsdk::config::get_str("pyunrealsdk.init_script").value_or("__main__.py"), - py::dict{}); + auto startup = + unrealsdk::utils::get_this_dll().parent_path() + / unrealsdk::config::get_str("pyunrealsdk.init_script").value_or("__main__.py"); + py::eval_file(startup.generic_string(), py::dict{}); } catch (const std::exception& ex) { LOG(ERROR, "Error running python initialization script:"); logging::log_python_exception(ex); diff --git a/stubs/unrealsdk/logging/__init__.pyi b/stubs/unrealsdk/logging/__init__.pyi index 9cf3dc3..4dade0e 100644 --- a/stubs/unrealsdk/logging/__init__.pyi +++ b/stubs/unrealsdk/logging/__init__.pyi @@ -1,5 +1,3 @@ -# ruff: noqa: D205 - from __future__ import annotations from typing import Any, ClassVar diff --git a/stubs/unrealsdk/unreal/_uobject_children.pyi b/stubs/unrealsdk/unreal/_uobject_children.pyi index 1cbe652..5e5c7f6 100644 --- a/stubs/unrealsdk/unreal/_uobject_children.pyi +++ b/stubs/unrealsdk/unreal/_uobject_children.pyi @@ -7,8 +7,6 @@ from ._uobject import UObject from ._wrapped_array import WrappedArray from ._wrapped_struct import WrappedStruct -# ruff: noqa: N802, N803 - # ======== First Layer Subclasses ======== class UField(UObject): @@ -107,14 +105,13 @@ class UBoolProperty(UProperty): FieldMask: int class UByteProperty(UProperty): - @property - def Enum(self) -> UEnum | None: ... + Enum: UEnum | None class UClass(UStruct): ClassDefaultObject: UObject @property - def Interfaces(self) -> list[UClass]: ... + def Interfaces(self) -> list[UClass]: ... # noqa: N802 def _implements(self, interface: UClass) -> bool: """ Checks if this class implements a given interface.