Skip to content

Commit fbe6e3a

Browse files
authored
Merge pull request #44 from apple1417/master
more legacy compat
2 parents 16490bb + ef69b45 commit fbe6e3a

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

changelog.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
## v3.5 (Upcoming)
44

55
### Legacy Compat v1.4
6-
- Added more fixups for previously unreported issues in Gear Randomizer, Loot Randomizer
7-
and Reign of Giants.
6+
- Added more fixups for previously unreported issues in Gear Randomizer, Loot Randomizer, Player
7+
Randomizer and Reign of Giants.
88

99
### Willow2 Mod Menu v3.4
1010
- Fixed that some keybinds would not be displayed properly if there were two separate grouped/nested

src/legacy_compat/meta_path_finder.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def find_spec( # noqa: D102, C901
188188
),
189189
)
190190

191-
# Loot randomizer needs a few fixes
191+
# Loot randomizer needs quite a few fixes
192192
case (
193193
# Here's the downside of using a single folder name, these cases just look weird.
194194
("Mod", "Mods.LootRandomizer.Mod.missions")
@@ -211,6 +211,18 @@ def find_spec( # noqa: D102, C901
211211
rb"pawn.bHidden = True([\r\n]+ +)pawn.CollisionType = 1",
212212
rb"pawn.SetHidden(True)\1pawn.SetCollisionType(1)",
213213
),
214+
# This one seems to be another post edit issue. Work around it with a console
215+
# command instead. Matching any number at the end for testing.
216+
(
217+
rb"raise Exception\(\"Could not locate switch for Michael Mamaril\"\)"
218+
rb"([\r\n]+ +)switch\.LinkCount = (\d+)",
219+
b'raise Exception("Could not locate switch for Michael Mamaril")\\1'
220+
b"import unrealsdk; unrealsdk.DoInjectedCallNext(); "
221+
b"GetEngine().GamePlayers[0].Actor.ConsoleCommand("
222+
b'f"set {switch.PathName(switch)} LinkCount \\2")',
223+
),
224+
# I was just told this one never did anything, idk what the bug is
225+
(rb"sequence\.CustomEnableCondition\.bComplete = True", b""),
214226
)
215227

216228
case ("Mod", "Mods.LootRandomizer.Mod.locations"):

src/legacy_compat/unrealsdk/__init__.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from contextlib import contextmanager
77
from dataclasses import dataclass
88
from functools import cache, wraps
9-
from typing import Any
9+
from typing import Any, overload
1010

1111
from unrealsdk import (
1212
__version_info__,
@@ -346,15 +346,23 @@ def _convert_struct_tuple_if_required(
346346
_RE_NAME_SUFFIX = re.compile(r"^(.+)_\d+$")
347347

348348

349-
def _strip_name_property_suffix(name: str) -> str:
349+
@overload
350+
def _strip_name_property_suffix(name: str) -> str: ...
351+
@overload
352+
def _strip_name_property_suffix(name: tuple[str, ...]) -> tuple[str, ...]: ...
353+
354+
355+
def _strip_name_property_suffix(name: str | tuple[str, ...]) -> str | tuple[str, ...]:
350356
"""
351357
Tries to strip the numeric suffix from a name property.
352358
353359
Args:
354-
name: The input name.
360+
name: The input name(s).
355361
Returns:
356-
The stripped name.
362+
The stripped name(s).
357363
"""
364+
if isinstance(name, tuple):
365+
return tuple(_strip_name_property_suffix(x) for x in name)
358366
return match.group(1) if (match := _RE_NAME_SUFFIX.match(name)) else name
359367

360368

@@ -371,7 +379,7 @@ def _uobject_getattr(self: UObject, name: str) -> Any:
371379
case UInterfaceProperty():
372380
return FScriptInterface(value)
373381
case UNameProperty():
374-
return _strip_name_property_suffix(value)
382+
return _strip_name_property_suffix(value) # type: ignore
375383
case _:
376384
return value
377385

@@ -412,7 +420,7 @@ def _uobject_getattribute(self: UObject, name: str) -> Any:
412420
case "ObjectFlags":
413421
return _ObjectFlagsProxy(self)
414422
case "Name":
415-
return _strip_name_property_suffix(_default_object_getattribute(self, "Name"))
423+
return _strip_name_property_suffix(_default_object_getattribute(self, "Name")) # type: ignore
416424
case _:
417425
return _default_object_getattribute(self, name)
418426

@@ -454,7 +462,7 @@ def _struct_getattr(self: WrappedStruct, name: str) -> Any:
454462
case UInterfaceProperty():
455463
return FScriptInterface(value)
456464
case UNameProperty():
457-
return _strip_name_property_suffix(value)
465+
return _strip_name_property_suffix(value) # type: ignore
458466
case _:
459467
return value
460468

@@ -487,8 +495,6 @@ def _array_getitem[T](self: WrappedArray[T], idx: int | slice) -> T | list[T]:
487495
return [_strip_name_property_suffix(x) for x in val_seq] # type: ignore
488496

489497
return _strip_name_property_suffix(value) # type: ignore
490-
491-
return _strip_name_property_suffix(value)
492498
case _:
493499
return value
494500

@@ -614,6 +620,14 @@ def _uobject_get_name(obj: UObject, /) -> str:
614620
return obj.Name
615621

616622

623+
def _uobject_get_object_name(obj: UObject, /) -> str:
624+
current = obj
625+
output = f"{obj.Name}"
626+
while current := current.Outer:
627+
output = f"{current.Name}.{output}"
628+
return output
629+
630+
617631
@staticmethod
618632
def _uobject_path_name(obj: UObject | None, /) -> str:
619633
if obj is None:
@@ -657,6 +671,7 @@ def _unreal_method_compat_handler() -> Iterator[None]:
657671
UObject.GetAddress = UObject._get_address # type: ignore
658672
UObject.GetFullName = _uobject_repr # type: ignore
659673
UObject.GetName = _uobject_get_name # type: ignore
674+
UObject.GetObjectName = _uobject_get_object_name # type: ignore
660675
UObject.PathName = _uobject_path_name # type: ignore
661676
UStructProperty.GetStruct = _ustructproperty_get_struct # type: ignore
662677
WrappedStruct.structType = _wrapped_struct_structType # type: ignore
@@ -680,6 +695,7 @@ def _unreal_method_compat_handler() -> Iterator[None]:
680695
del UObject.GetAddress # type: ignore
681696
del UObject.GetFullName # type: ignore
682697
del UObject.GetName # type: ignore
698+
del UObject.GetObjectName # type: ignore
683699
del UObject.PathName # type: ignore
684700
del UStructProperty.GetStruct # type: ignore
685701
del WrappedStruct.structType # type: ignore

0 commit comments

Comments
 (0)