Skip to content

Commit f64e503

Browse files
authored
ModMenu 2.3 fixes (#87)
* fix missing self * fix a few places which forgot legacy keybinds exist * fix backpack manager always being active
1 parent 64c857b commit f64e503

File tree

6 files changed

+51
-46
lines changed

6 files changed

+51
-46
lines changed

Mods/BackpackManager/__init__.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unrealsdk
2-
from Mods.ModMenu import EnabledSaveType, Mods, ModTypes, Options, RegisterMod, SDKMod, Hook
3-
from Mods import ModMenu
2+
3+
from Mods.ModMenu import EnabledSaveType, Hook, ModTypes, Options, RegisterMod, SDKMod
44

55

66
class BackpackManager(SDKMod):
@@ -12,30 +12,23 @@ class BackpackManager(SDKMod):
1212
Types: ModTypes = ModTypes.Gameplay
1313
SaveEnabledState: EnabledSaveType = EnabledSaveType.LoadWithSettings
1414

15-
BackpackSize: ModMenu.Options.Slider = Options.Slider(
15+
BackpackSize: Options.Slider = Options.Slider(
1616
"Backpack", "Change the size of your character's backpack<br>Default is 39", 39, 0, 200, 1
1717
)
1818
Options = [BackpackSize]
1919

2020
@Hook("WillowGame.WillowHUD.CreateWeaponScopeMovie")
21-
def _GameLoad(caller: unrealsdk.UObject, function: unrealsdk.UFunction, params: unrealsdk.FStruct) -> bool:
21+
def _GameLoad(self, caller: unrealsdk.UObject, function: unrealsdk.UFunction, params: unrealsdk.FStruct) -> bool:
2222
PC = unrealsdk.GetEngine().GamePlayers[0].Actor
2323
if PC and PC.Pawn:
24-
PC.Pawn.InvManager.InventorySlotMax_Misc = _ModInstance.BackpackSize.CurrentValue
24+
PC.Pawn.InvManager.InventorySlotMax_Misc = self.BackpackSize.CurrentValue
2525
return True
2626

27-
def Enable(self) -> None:
28-
super().Enable()
29-
30-
def Disable(self) -> None:
31-
ModMenu.RemoveHooks(self)
32-
3327
def ModOptionChanged(self, option, newValue) -> None:
34-
if option.Caption == "Backpack":
28+
if option == self.BackpackSize:
3529
PC = unrealsdk.GetEngine().GamePlayers[0].Actor
3630
if PC and PC.Pawn:
3731
PC.Pawn.InvManager.InventorySlotMax_Misc = newValue
3832

3933

40-
_ModInstance = BackpackManager()
41-
RegisterMod(_ModInstance)
34+
RegisterMod(BackpackManager())

Mods/ModMenu/HookManager.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import functools
55
import weakref
66
from inspect import Parameter, signature
7-
from typing import Any, Callable, Tuple, Union
7+
from typing import Any, Callable, Optional, Tuple, Union
88

99
__all__: Tuple[str, ...] = (
1010
"AnyHook",
@@ -16,8 +16,14 @@
1616
)
1717

1818

19-
HookFunction = Callable[[unrealsdk.UObject, unrealsdk.UFunction, unrealsdk.FStruct], Any]
20-
HookMethod = Callable[[object, unrealsdk.UObject, unrealsdk.UFunction, unrealsdk.FStruct], Any]
19+
HookFunction = Callable[
20+
[unrealsdk.UObject, unrealsdk.UFunction, unrealsdk.FStruct],
21+
Optional[bool]
22+
]
23+
HookMethod = Callable[
24+
[Any, unrealsdk.UObject, unrealsdk.UFunction, unrealsdk.FStruct],
25+
Optional[bool]
26+
]
2127
AnyHook = Union[HookFunction, HookMethod]
2228

2329

Mods/ModMenu/KeybindManager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,13 @@ def _KeyboardMouseOptionsPopulate(caller: unrealsdk.UObject, function: unrealsdk
163163
for mod in ModObjects.Mods:
164164
if not mod.IsEnabled:
165165
continue
166-
if len(mod.Keybinds) > 0:
166+
for input in mod.Keybinds:
167+
if isinstance(input, Keybind) and input.IsHidden:
168+
continue
167169
disabled = False
168170
break
171+
if not disabled:
172+
break
169173

170174
def AddListItem(caller: unrealsdk.UObject, function: unrealsdk.UFunction, params: unrealsdk.FStruct) -> bool:
171175
"""
@@ -209,7 +213,7 @@ def _extOnPopulateKeys(caller: unrealsdk.UObject, function: unrealsdk.UFunction,
209213
if not mod.IsEnabled:
210214
continue
211215

212-
if all(k.IsHidden for k in mod.Keybinds):
216+
if all(isinstance(k, Keybind) and k.IsHidden for k in mod.Keybinds):
213217
continue
214218

215219
tag = f"{_TAG_SEPERATOR}.{mod.Name}"

Mods/ModMenu/SettingsManager.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,32 @@ def SaveModSettings(mod: ModObjects.SDKMod) -> None:
4747
"""
4848
mod_settings: Dict[str, Any] = {}
4949

50-
if len(mod.Options) > 0:
51-
mod_settings[_OPTIONS_CATEGORY_NAME] = {}
52-
53-
def create_options_dict(options: Sequence[Options.Base]) -> Dict[str, Any]:
54-
settings = {}
55-
for option in options:
56-
if isinstance(option, Options.Value):
57-
settings[option.Caption] = option.CurrentValue
58-
elif isinstance(option, Options.Nested):
59-
settings[option.Caption] = create_options_dict(option.Children)
60-
return settings
61-
62-
mod_settings[_OPTIONS_CATEGORY_NAME] = create_options_dict(mod.Options)
63-
64-
if any(k.IsRebindable for k in mod.Keybinds):
65-
mod_settings[_KEYBINDS_CATEGORY_NAME] = {}
66-
for input in mod.Keybinds:
67-
if isinstance(input, KeybindManager.Keybind):
68-
if not input.IsRebindable:
69-
continue
70-
mod_settings[_KEYBINDS_CATEGORY_NAME][input.Name] = input.Key
71-
else:
72-
dh.PrintWarning(KeybindManager.Keybind._list_deprecation_warning)
73-
mod_settings[_KEYBINDS_CATEGORY_NAME][input[0]] = input[1]
50+
def create_options_dict(options: Sequence[Options.Base]) -> Dict[str, Any]:
51+
settings = {}
52+
for option in options:
53+
if isinstance(option, Options.Value):
54+
settings[option.Caption] = option.CurrentValue
55+
elif isinstance(option, Options.Nested):
56+
settings[option.Caption] = create_options_dict(option.Children)
57+
return settings
58+
59+
options_dict = create_options_dict(mod.Options)
60+
61+
if len(options_dict) > 0:
62+
mod_settings[_OPTIONS_CATEGORY_NAME] = options_dict
63+
64+
keybinds_dict = {}
65+
for input in mod.Keybinds:
66+
if isinstance(input, KeybindManager.Keybind):
67+
if not input.IsRebindable:
68+
continue
69+
keybinds_dict[input.Name] = input.Key
70+
else:
71+
dh.PrintWarning(KeybindManager.Keybind._list_deprecation_warning)
72+
keybinds_dict[input[0]] = input[1]
73+
74+
if len(keybinds_dict) > 0:
75+
mod_settings[_KEYBINDS_CATEGORY_NAME] = keybinds_dict
7476

7577
if mod.SaveEnabledState != ModObjects.EnabledSaveType.NotSaved:
7678
mod_settings[_ENABLED_CATEGORY_NAME] = mod.IsEnabled

Mods/ModMenu/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# Need to define these up here so that they're accessable when importing the other files
3939
VERSION_MAJOR = 2
40-
VERSION_MINOR = 3
40+
VERSION_MINOR = 4
4141

4242
unrealsdk.Log(f"[ModMenu] Version: {VERSION_MAJOR}.{VERSION_MINOR}")
4343

Mods/SkillRandomizer/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class CrossSkillRandomizer(BL2MOD):
1313
Name: str = "Cross Class Skill Randomizer ({})"
1414
Description: str = "Randomize all the skills!"
15-
Version: str = "1.1"
15+
Version: str = "1.2"
1616
Author: str = "Abahbob"
1717
SupportedGames = Game.BL2
1818
LocalModDir: str = os.path.dirname(os.path.realpath(__file__))
@@ -38,7 +38,7 @@ def RecordSeed(self) -> None:
3838
unrealsdk.Mods.insert(0, NewRando)
3939

4040
@Hook("WillowGame.PlayerSkillTree.Initialize")
41-
def InjectSkills(caller: UObject, function: UFunction, params: FStruct) -> bool:
41+
def InjectSkills(self, caller: UObject, function: UFunction, params: FStruct) -> bool:
4242
if not self.Seed:
4343
self.Seed = random.randrange(sys.maxsize)
4444
unrealsdk.Log("Randomizing with seed '{}'".format(self.Seed))

0 commit comments

Comments
 (0)