Skip to content

Commit 1d40340

Browse files
authored
Merge pull request #80 from apple1417/master
swap path config to be relative to dll instead of cwd
2 parents de9d2a5 + ede194d commit 1d40340

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

Readme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ accept arguments into `sys.argv`.
3535

3636
## Initialization Script
3737
If you want to make more permanent mods, you'll want to use the initialization script. By default
38-
this is `__main__.py` in the game's cwd. The initialization script is automatically run after sdk
39-
initialization, so you can use it to import other files and generally perform all your setup.
38+
this is `__main__.py` in the same folder as the `pyunrealsdk.dll`. The initialization script is
39+
automatically run after sdk initialization, so you can use it to import other files and generally
40+
perform all your setup.
4041

4142
You can swap to a different initialization script by using setting `pyunrealsdk.init_script` in the
4243
[unrealsdk configuration file](https://github.com/bl-sdk/unrealsdk/#configuration). If you do this
4344
you may also want to set `pyunrealsdk.pyexec_root`, so that `pyexec` commands work from the same
44-
folder.
45+
folder. These are relative to the folder `pyunrealsdk.dll` is in (or you can supply absolute paths).
4546

4647
## Using SDK bindings
4748
Once you've got code running, you probably want to setup some hooks - the sdk can run callbacks

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Upcoming
4+
- The `pyunrealsdk.init_script` and `pyunrealsdk.pyexec_root` config options are now relative to the
5+
folder containing the `pyunrealsdk.dll`. Previously, they were relative to the cwd, which could
6+
cause issues if it changed.
7+
38
## v1.8.0
49
- Added `WeakPointer.replace`, to modify a pointer in-place.
510

src/pyunrealsdk/commands.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ namespace {
1515

1616
void pyexec_cmd_handler(const wchar_t* line, size_t size, size_t cmd_len) {
1717
static const std::filesystem::path root =
18-
unrealsdk::config::get_str("pyunrealsdk.pyexec_root").value_or("");
18+
unrealsdk::utils::get_this_dll().parent_path()
19+
/ unrealsdk::config::get_str("pyunrealsdk.pyexec_root").value_or("");
1920

2021
auto file_start = std::find_if_not(line + cmd_len, line + size, &std::iswspace);
2122
const size_t file_len = (line + size) - file_start;

src/pyunrealsdk/pyunrealsdk.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "pyunrealsdk/version.h"
99
#include "unrealsdk/config.h"
1010
#include "unrealsdk/unrealsdk.h"
11+
#include "unrealsdk/utils.h"
1112
#include "unrealsdk/version.h"
1213

1314
#ifdef PYUNREALSDK_INTERNAL
@@ -73,8 +74,10 @@ void init(void) {
7374
try {
7475
// Use a custom globals to make sure we don't contaminate `py`/`pyexec` commands
7576
// This also ensures `__file__` gets redefined properly
76-
py::eval_file(unrealsdk::config::get_str("pyunrealsdk.init_script").value_or("__main__.py"),
77-
py::dict{});
77+
auto startup =
78+
unrealsdk::utils::get_this_dll().parent_path()
79+
/ unrealsdk::config::get_str("pyunrealsdk.init_script").value_or("__main__.py");
80+
py::eval_file(startup.generic_string(), py::dict{});
7881
} catch (const std::exception& ex) {
7982
LOG(ERROR, "Error running python initialization script:");
8083
logging::log_python_exception(ex);

stubs/unrealsdk/logging/__init__.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# ruff: noqa: D205
2-
31
from __future__ import annotations
42

53
from typing import Any, ClassVar

stubs/unrealsdk/unreal/_uobject_children.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ from ._uobject import UObject
77
from ._wrapped_array import WrappedArray
88
from ._wrapped_struct import WrappedStruct
99

10-
# ruff: noqa: N802, N803
11-
1210
# ======== First Layer Subclasses ========
1311

1412
class UField(UObject):
@@ -107,14 +105,13 @@ class UBoolProperty(UProperty):
107105
FieldMask: int
108106

109107
class UByteProperty(UProperty):
110-
@property
111-
def Enum(self) -> UEnum | None: ...
108+
Enum: UEnum | None
112109

113110
class UClass(UStruct):
114111
ClassDefaultObject: UObject
115112

116113
@property
117-
def Interfaces(self) -> list[UClass]: ...
114+
def Interfaces(self) -> list[UClass]: ... # noqa: N802
118115
def _implements(self, interface: UClass) -> bool:
119116
"""
120117
Checks if this class implements a given interface.

0 commit comments

Comments
 (0)