Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move mods_base.raw_keybinds to keybinds.raw_keybinds, init script improvements #28

Merged
merged 4 commits into from
Jun 10, 2024
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
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ jobs:
- name: Run pyright
uses: jakebailey/pyright-action@v2
with:
pylance-version: latest-release
working-directory: "./src/"

ruff:
Expand Down
53 changes: 51 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,73 @@
# Changelog

## Upcoming
## v1.3 (Upcoming)

### General
- Added a warning for when Proton fails to propagate environment variables, which mods or the mod
manager may have been expecting.

An example consequence of this is that the base mod may end up as version "Unknown Version".

[f420d77b](https://github.com/bl-sdk/oak-mod-manager/commit/f420d77b)

### General - Developer
- When developing third party native modules, you can now include this repo as a submodule to
automatically keep the Python version in sync. There was a bit of build system restructuring to
allow our `CMakeLists.txt` to define this.

[6f9a8717](https://github.com/bl-sdk/oak-mod-manager/commit/6f9a8717)

- Changed the `OAK_MOD_MANAGER_EXTRA_FOLDERS` env var to read from `MOD_MANAGER_EXTRA_FOLDERS`
instead, for consistency.

[f420d77b](https://github.com/bl-sdk/oak-mod-manager/commit/f420d77b)

- Python warnings are now hooked up to the logging system.

[f420d77b](https://github.com/bl-sdk/oak-mod-manager/commit/f420d77b)

### BL3 Mod Menu v1.2

- Updated type hinting to use 3.12 syntax.

[dfb72a92](https://github.com/bl-sdk/oak-mod-manager/commit/dfb72a92)
[dfb72a92](https://github.com/bl-sdk/oak-mod-manager/commit/dfb72a92),
[95cc37eb](https://github.com/bl-sdk/oak-mod-manager/commit/95cc37eb)

### Console Mod Menu v1.2

- Updated type hinting to use 3.12 syntax.

[95cc37eb](https://github.com/bl-sdk/oak-mod-manager/commit/95cc37eb)

- Changed strict keybind and ui utils dependencies to be soft dependencies. This is of no
consequence to this project, but it makes the mod menu more game-agnostic for other ones.

These dependencies were only used for the "Rebind using key press" screen, this functionality will
now gracefully degrade based on what's available.

[9ab26173](https://github.com/bl-sdk/oak-mod-manager/commit/9ab26173),
[216a739d](https://github.com/bl-sdk/oak-mod-manager/commit/216a739d)

### Keybinds v2.2

- Updated type hinting to use 3.12 syntax.

[dfb72a92](https://github.com/bl-sdk/oak-mod-manager/commit/dfb72a92)

- Moved `raw_keybinds` out of mods base, into keybinds.

[216a739d](https://github.com/bl-sdk/oak-mod-manager/commit/216a739d)

### Mods Base v1.3

- Updated type hinting to use 3.12 syntax.

[dfb72a92](https://github.com/bl-sdk/oak-mod-manager/commit/dfb72a92)
[95cc37eb](https://github.com/bl-sdk/oak-mod-manager/commit/95cc37eb)

- Moved `raw_keybinds` out of mods base, into keybinds.

[216a739d](https://github.com/bl-sdk/oak-mod-manager/commit/216a739d)

## v1.2

Expand Down
2 changes: 1 addition & 1 deletion libs/pyunrealsdk
2 changes: 1 addition & 1 deletion manager_pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[project]
name = "oak_mod_manager"
version = "1.2"
version = "1.3"
authors = [{ name = "bl-sdk" }]

[tool.sdkmod]
Expand Down
84 changes: 68 additions & 16 deletions src/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
import os
import sys
import traceback
import warnings
import zipfile
from collections.abc import Collection
from functools import wraps
from pathlib import Path
from typing import TextIO

# Note we try to import as few third party modules as possible before the console is ready, in case
# any of them cause errors we'd like to have logged
# Trusting that we can keep all the above standard library modules without issue
import unrealsdk
from unrealsdk import logging

Expand All @@ -31,7 +37,7 @@
WAIT_FOR_CLIENT: bool = False

# A json list of paths to also to import mods from - you can add your repo to keep it separated
EXTRA_FOLDERS_ENV_VAR: str = "OAK_MOD_MANAGER_EXTRA_FOLDERS"
EXTRA_FOLDERS_ENV_VAR: str = "MOD_MANAGER_EXTRA_FOLDERS"


def init_debugpy() -> None:
Expand Down Expand Up @@ -236,29 +242,54 @@ def import_mods(mods_to_import: Collection[str]) -> None:
logging.error("".join(traceback.format_list(tb)))


def proton_null_exception_check() -> None:
"""
Tries to detect and warn if we're running under a version of Proton which has the exception bug.
def hookup_warnings() -> None:
"""Hooks up the Python warnings system to the dev warning log type."""

original_show_warning = warnings.showwarning
dev_warn_logger = logging.Logger(logging.Level.DEV_WARNING)

@wraps(warnings.showwarning)
def showwarning(
message: Warning | str,
category: type[Warning],
filename: str,
lineno: int,
file: TextIO | None = None,
line: str | None = None,
) -> None:
if file is None:
# Typeshed has this as a TextIO, but the implementation only actually uses `.write`
file = dev_warn_logger # type: ignore
original_show_warning(message, category, filename, lineno, file, line)

warnings.showwarning = showwarning
warnings.resetwarnings() # Reset filters, show all warnings


For context, usually pybind detects exceptions using a catch all, which eventually calls through
to `std::current_exception` to get the exact exception, and then runs a bunch of translators on
it to convert it to a Python exception. When running under a bad Proton version, this call
fails, and returns an empty exception pointer, so pybind is unable to translate it.
def check_proton_bugs() -> None:
"""Tries to detect and warn about various known proton issues."""

"""
The exception bug
-----------------
Usually pybind detects exceptions using a catch all, which eventually calls through to
`std::current_exception` to get the exact exception, and then runs a bunch of translators on it
to convert it to a Python exception. When running under a bad Proton version, this call fails,
and returns an empty exception pointer, so pybind is unable to translate it.

This means Python throws a:
```
SystemError: <built-in method __getattr__ of PyCapsule object at 0x00000000069AC780> returned NULL without setting an exception
```
This is primarily a problem for `StopIteration`.
""" # noqa: E501

cls = unrealsdk.find_class("Object")
try:
# Cause an attribute error
_ = cls._check_for_proton_null_exception_bug
except AttributeError:
# Working properly
return
pass
except SystemError:
# Have the bug
logging.error(
Expand All @@ -268,13 +299,33 @@ def proton_null_exception_check() -> None:
logging.error(
"\n"
"Some particular Proton versions cause this, try switch to another one.\n"
"Alternatively, the nightly release has builds from other compilers, which may also"
" prevent it.\n"
"Alternatively, the nightly release has builds from other compilers, which may\n"
"also prevent it.\n"
"\n"
"Will attempt to import mods, but they'll likely break with a similar error.\n"
"===============================================================================",
)

"""
Env vars not propagating
------------------------
We set various env vars in `unrealsdk.env`, which unrealsdk sets via `SetEnvironmentVariableA`.
On some proton versions this does not get propagated through to Python - despite clearly having
worked for pyunrealsdk, if we're able to run this script. Some of these are used by Python, and
may cause issues if we cannot find them.
"""
if "PYUNREALSDK_INIT_SCRIPT" not in os.environ:
logging.error(
"===============================================================================\n"
"Some environment variables don't seem to have propagated into Python. This may\n"
"cause issues in parts of the mod manager or individual mods which expect them.\n"
"\n"
"Some particular Proton versions cause this, try switch to another one.\n"
"Alternatively, the nightly release has builds from other compilers, which may\n"
"also prevent it.\n"
"===============================================================================",
)


# Don't really want to put a `__name__` check here, since it's currently just `builtins`, and that
# seems a bit unstable, like something that pybind might eventually change
Expand All @@ -288,14 +339,15 @@ def proton_null_exception_check() -> None:
while not logging.is_console_ready():
pass

# Now that the console's ready, show errors for any non-existent mod folders
# Now that the console's ready, hook up the warnings system, and show some other warnings users may
# be interested in
hookup_warnings()

check_proton_bugs()
for folder in mod_folders:
if not folder.exists() or not folder.is_dir():
logging.dev_warning(f"Extra mod folder does not exist: {folder}")

# And check for the proton null exception bug, if present we also want to print
proton_null_exception_check()

mods_to_import = find_mods_to_import(mod_folders)

import_mod_manager()
Expand Down
3 changes: 2 additions & 1 deletion src/bl3_mod_menu/keybinds.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from enum import StrEnum

import unrealsdk
from mods_base import BoolOption, DropdownOption, EInputEvent, KeybindOption, get_pc, raw_keybinds
from keybinds import raw_keybinds
from mods_base import BoolOption, DropdownOption, EInputEvent, KeybindOption, get_pc
from unrealsdk.unreal import UObject

from .dialog_box import DialogBox
Expand Down
2 changes: 1 addition & 1 deletion src/console_mod_menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"__version_info__",
)

__version_info__: tuple[int, int] = (1, 1)
__version_info__: tuple[int, int] = (1, 2)
__version__: str = f"{__version_info__[0]}.{__version_info__[1]}"
__author__: str = "bl-sdk"

Expand Down
Loading
Loading