forked from bl-sdk/mods_base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
164 lines (140 loc) · 4.39 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from functools import wraps
from pathlib import Path
from typing import Literal, overload
import unrealsdk
from unrealsdk.unreal import UObject
from .dot_sdkmod import open_in_mod_dir
# Need to define a few things first to avoid circular imports
__version_info__: tuple[int, int] = (1, 9)
__version__: str = f"{__version_info__[0]}.{__version_info__[1]}"
__author__: str = "bl-sdk"
# This avoids E402 for all the following imports
if True:
MODS_DIR: Path = (
_mod_dir
if (_mod_dir := Path(__file__).parent.parent).is_dir()
else _mod_dir.parent # If in a .sdkmod, need to go up an extra folder
)
del _mod_dir
from .command import (
AbstractCommand,
ArgParseCommand,
capture_next_console_line,
command,
remove_next_console_line_capture,
)
from .hook import HookType, bind_all_hooks, hook
from .html_to_plain_text import html_to_plain_text
from .keybinds import EInputEvent, KeybindType, keybind
from .mod import CoopSupport, Game, Library, Mod, ModType
from .mod_factory import build_mod
from .mod_list import (
deregister_mod,
get_ordered_mod_list,
register_mod,
)
from .options import (
JSON,
BaseOption,
BoolOption,
ButtonOption,
DropdownOption,
GroupedOption,
HiddenOption,
KeybindOption,
NestedOption,
SliderOption,
SpinnerOption,
ValueOption,
)
from .settings import SETTINGS_DIR
__all__: tuple[str, ...] = (
"ENGINE",
"JSON",
"MODS_DIR",
"SETTINGS_DIR",
"AbstractCommand",
"ArgParseCommand",
"BaseOption",
"BoolOption",
"ButtonOption",
"CoopSupport",
"DropdownOption",
"EInputEvent",
"Game",
"GroupedOption",
"HiddenOption",
"HookType",
"KeybindOption",
"KeybindType",
"Library",
"Mod",
"ModType",
"NestedOption",
"SliderOption",
"SpinnerOption",
"ValueOption",
"__version__",
"__version_info__",
"bind_all_hooks",
"build_mod",
"capture_next_console_line",
"command",
"deregister_mod",
"get_ordered_mod_list",
"get_pc",
"hook",
"html_to_plain_text",
"keybind",
"open_in_mod_dir",
"register_mod",
"remove_next_console_line_capture",
)
ENGINE: UObject
@overload
def get_pc() -> UObject: ...
@overload
def get_pc(*, possibly_loading: Literal[True] = True) -> UObject | None: ...
def get_pc(*, possibly_loading: bool = False) -> UObject | None:
"""
Gets the main (local) player controller object.
Note that this may return None if called during a loading screen. Since hooks and keybinds
should never be able to trigger at this time, for convenience the default type hinting does not
include this possibility. If running on another thread however, this can happen, pass the
`possibly_loading` kwarg to update the type hinting.
Args:
possibly_loading: Changes the type hinting to possibly return None. No runtime impact.
Returns:
The player controller.
"""
raise NotImplementedError
match Game.get_tree():
case Game.Willow2:
ENGINE = unrealsdk.find_object( # pyright: ignore[reportConstantRedefinition]
"WillowGameEngine",
"Transient.WillowGameEngine_0",
)
_GAME_PLAYERS_PROP = ENGINE.Class._find_prop("GamePlayers")
_ACTOR_PROP = _GAME_PLAYERS_PROP.Inner.PropertyClass._find_prop("Actor")
@wraps(get_pc)
def get_pc_willow(*, possibly_loading: bool = False) -> UObject | None: # noqa: ARG001
return ENGINE._get_field(_GAME_PLAYERS_PROP)[0]._get_field(_ACTOR_PROP)
get_pc = get_pc_willow # type: ignore
case Game.Oak:
ENGINE = unrealsdk.find_object( # pyright: ignore[reportConstantRedefinition]
"OakGameEngine",
"/Engine/Transient.OakGameEngine_0",
)
_GAME_INSTANCE_PROP = ENGINE.Class._find_prop("GameInstance")
_LOCAL_PLAYERS_PROP = _GAME_INSTANCE_PROP.PropertyClass._find_prop("LocalPlayers")
_PLAYER_CONTROLLER_PROP = _LOCAL_PLAYERS_PROP.Inner.PropertyClass._find_prop(
"PlayerController",
)
@wraps(get_pc)
def get_pc_oak(*, possibly_loading: bool = False) -> UObject | None: # noqa: ARG001
return (
ENGINE._get_field(_GAME_INSTANCE_PROP)
._get_field(_LOCAL_PLAYERS_PROP)[0]
._get_field(_PLAYER_CONTROLLER_PROP)
)
get_pc = get_pc_oak # type: ignore