Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
3 changes: 2 additions & 1 deletion src/pyunrealsdk/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/pyunrealsdk/pyunrealsdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions stubs/unrealsdk/logging/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# ruff: noqa: D205

from __future__ import annotations

from typing import Any, ClassVar
Expand Down
7 changes: 2 additions & 5 deletions stubs/unrealsdk/unreal/_uobject_children.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
Loading