This repository has been archived by the owner on Jul 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
261 lines (223 loc) · 8.17 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import unrealsdk
import webbrowser
from typing import Dict, Optional
from Mods.ModMenu import (
EnabledSaveType,
Game,
Hook,
Keybind,
KeybindManager,
Mods,
ModTypes,
Options,
RegisterMod,
SDKMod,
ServerMethod,
)
try:
from Mods.EridiumLib import (
checkLibraryVersion,
checkModVersion,
getActionSkill,
getCurrentPlayerController,
getSkillManager,
getVaultHunterClassName,
isClient,
log,
)
from Mods.EridiumLib.keys import KeyBinds
except ImportError:
webbrowser.open(
"https://github.com/DAmNRelentless/bl2-eridiumlib/blob/main/docs/TROUBLESHOOTING.md"
)
raise
if __name__ == "__main__":
import importlib
import sys
importlib.reload(sys.modules["Mods.EridiumLib"])
importlib.reload(sys.modules["Mods.EridiumLib.keys"])
# See https://github.com/bl-sdk/PythonSDK/issues/68
try:
raise NotImplementedError
except NotImplementedError:
__file__ = sys.exc_info()[-1].tb_frame.f_code.co_filename # type: ignore
class SkillToggles(SDKMod):
# region Mod Info
Name: str = "Skill Toggles"
Author: str = "Relentless, Chronophylos"
Description: str = "Deactivate Action Skills by holding a configurable hotkey."
Version: str = "1.3.2"
_EridiumVersion: str = "0.4.2"
SupportedGames: Game = Game.BL2 | Game.TPS
Types: ModTypes = ModTypes.Utility
SaveEnabledState: EnabledSaveType = EnabledSaveType.LoadWithSettings
SettingsInputs: Dict[str, str] = {
KeyBinds.Enter.value: "Enable",
KeyBinds.G.value: "GitHub",
}
# endregion Mod Info
# region Mod Setup
def __init__(self) -> None:
super().__init__()
if Game.GetCurrent() == Game.BL2:
optionSirenToggle = Options.Boolean(
"Siren Skill Toggle", "Allows Maya to stop her Phaselock.", True
)
optionGunzerkerToggle = Options.Boolean(
"Gunzerker Skill Toggle", "Allows Salvador to stop his Dual Wield.", True
)
optionCommandoToggle = Options.Boolean(
"Commando Skill Toggle", "Allows Axton to recall his turrets.", True
)
optionAssassinToggle = Options.Boolean(
"Assassin Skill Toggle", "Allows Zer0 to stop Decepti0n.", True
)
optionMechromancerToggle = Options.Boolean(
"Mechromancer Skill Toggle", "Allows Gaige to recall her Deathtrap.", True
)
optionPsychoToggle = Options.Boolean(
"Psycho Skill Toggle",
"Allows Krieg to return from his Buzzaxe Rampage.",
True,
)
self._classOptions = {
"Siren": optionSirenToggle,
"Gunzerker": optionGunzerkerToggle,
"Commando": optionCommandoToggle,
"Assassin": optionAssassinToggle,
"Mechromancer": optionMechromancerToggle,
"Psycho": optionPsychoToggle,
}
elif Game.GetCurrent() == Game.TPS:
optionGladiatorToggle = Options.Boolean(
"Gladiator Skill Toggle", "Allows Athena to stop her Kinetic Aspis.", True
)
optionEnforcerToggle = Options.Boolean(
"Enforcer Skill Toggle", "Allows Wilhelm to recall Wolf and Saint.", True
)
optionLawbringerToggle = Options.Boolean(
"Lawbringer Skill Toggle", "Allows Nisha to stop her showdown.", True
)
optionFragtrapToggle = Options.Boolean(
"Fragtrap Skill Toggle", "Allows Claptrap to stop VaultHunter.EXE.", True
)
optionDoppelgangerToggle = Options.Boolean(
"Doppelganger Skill Toggle", "Allows Jack to stop his Expendable Assets.", True
)
optionBaronessToggle = Options.Boolean(
"Baroness Skill Toggle", "Allows Aurelia to stop Cold As Ice.", True
)
self._classOptions = {
"Gladiator": optionGladiatorToggle,
"Enforcer": optionEnforcerToggle,
"Lawbringer": optionLawbringerToggle,
"Fragtrap": optionFragtrapToggle,
"Doppelganger": optionDoppelgangerToggle,
"Baroness": optionBaronessToggle,
}
self.Options = [*self._classOptions.values()]
self.Keybinds = [
Keybind(
"Deactivate Action Skill",
"F",
True,
OnPress=self._skillDeactivationHotkey,
)
]
def Enable(self) -> None:
super().Enable()
if not checkLibraryVersion(self._EridiumVersion):
raise RuntimeWarning("Incompatible EridiumLib version!")
checkModVersion(self, "DAmNRelentless/bl2-skilltoggles")
def SettingsInputPressed(self, action: str) -> None:
if action == "GitHub":
webbrowser.open("https://github.com/DAmNRelentless/bl2-skilltoggles")
else:
super().SettingsInputPressed(action)
# endregion Mod Setup
# region Hotkey Handling
def _skillDeactivationHotkey(self, event: KeybindManager.InputEvent) -> None:
"""
handles the modded hotkey input
"""
if event == KeybindManager.InputEvent.Repeat:
self._skillDeactivation()
# endregion Hotkey Handling
# region Skill Deactivation
def _skillDeactivation(self) -> None:
"""
handles the skill deactivation
"""
if isClient():
self._requestSkillDeactivation()
else:
self._executeSkillDeactivation()
@ServerMethod
def _requestSkillDeactivation(
self,
PC: Optional[unrealsdk.UObject] = None,
) -> None:
self._executeSkillDeactivation(PC)
def _executeSkillDeactivation(
self,
PC: Optional[unrealsdk.UObject] = None,
) -> None:
# if PC is None, get current local player
if PC is None:
PC = getCurrentPlayerController()
# check if the skill for the current local player is toggleable (config option)
className: str = getVaultHunterClassName(PC)
if (
className not in self._classOptions
or self._classOptions[className].CurrentValue is False
):
return
# deactivate the action skill if it's active
skillManager = getSkillManager()
actionSkill = getActionSkill(PC)
if skillManager.IsSkillActive(PC, actionSkill):
actionSkill.bCanBeToggledOff = True
PC.ServerStartActionSkill()
# endregion Skill Deactivation
# region Info Reset
@Hook("WillowGame.ActionSkill.OnActionSkillEnded")
def _onActionSkillEnded(
self,
caller: unrealsdk.UObject,
function: unrealsdk.UFunction,
params: unrealsdk.FStruct,
) -> bool:
"""
handles reset of the changed player information
runs on player and host so it needs info checks
"""
if isClient():
self._requestInfoReset()
else:
self._executeInfoReset()
return True
@ServerMethod
def _requestInfoReset(self, PC: Optional[unrealsdk.UObject] = None) -> None:
self._executeInfoReset(PC)
def _executeInfoReset(self, PC: Optional[unrealsdk.UObject] = None) -> None:
# if PC is None, get current local player
if PC is None:
PC = getCurrentPlayerController()
# only reset if it was changed because the hook is called for player and host
actionSkill = getActionSkill(PC)
if actionSkill.bCanBeToggledOff is True:
actionSkill.bCanBeToggledOff = False
# endregion Info Reset
instance = SkillToggles()
if __name__ == "__main__":
log(instance, "Manually loaded")
for mod in Mods:
if mod.Name == instance.Name:
if mod.IsEnabled:
mod.Disable()
Mods.remove(mod)
log(instance, "Removed last instance")
# Fixes inspect.getfile()
instance.__class__.__module__ = mod.__class__.__module__
break
RegisterMod(instance)