forked from juso40/bl2sdk_Mods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
353 lines (303 loc) · 13.7 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
from typing import Any
from enum import IntEnum
import os
import re
import json
import unrealsdk
from ..ModMenu import EnabledSaveType, SDKMod, Hook, Game, OptionManager
class ERadarIconType(IntEnum):
RadarIconType_None = 0
RadarIconType_Gunfire = 1
RadarIconType_Threat = 2
RadarIconType_BountyBoard = 3
RadarIconType_Shop = 4
RadarIconType_Health = 5
RadarIconType_NewU = 6
RadarIconType_CatchARide = 7
RadarIconType_Settlement = 8
RadarIconType_MissionNPC = 9
RadarIconType_NamedNPC = 10
RadarIconType_Loot = 11
RadarIconType_Objective = 12
RadarIconType_Checkpoint = 13
RadarIconType_TravelStation = 14
RadarIconType_CustomizationStation = 15
RadarIconType_LevelTransition = 16
working_icons = {
"Shop": ERadarIconType.RadarIconType_Shop,
"Health": ERadarIconType.RadarIconType_Health,
"Catch a Ride": ERadarIconType.RadarIconType_CatchARide,
"Travel Station": ERadarIconType.RadarIconType_TravelStation,
"Customization Station": ERadarIconType.RadarIconType_CustomizationStation,
"Level Transition": ERadarIconType.RadarIconType_LevelTransition,
}
name_to_event = {
Game.TPS: {
"Coop-Ding": "Ake_UI.UI_HUD_Audio.Ak_Play_UI_Alert_CoOp_Ding",
"Coop-Buddy Down": "Ake_UI.UI_HUD_Audio.Ak_Play_UI_Alert_CoOp_Buddy_Down",
"Challenge Completed": "Ake_UI.UI_HUD_Audio.Ak_Play_UI_HUD_Challenge_Completed",
"New Skin Unlocked": "Ake_UI.UI_HUD_Audio.Ak_Play_UI_HUD_New_Skin_Unlocked",
"Token Unlocked": "Ake_UI.UI_HUD_Audio.Ak_Play_UI_HUD_Token_Unlocked",
"PVP Duel End": "Ake_UI.UI_HUD_Audio.Ak_Play_UI_PVP_Duel_End",
"PVP Duel Start": "Ake_UI.UI_HUD_Audio.Ak_Play_UI_PVP_Duel_Start",
"Mission Reward": "Ake_UI.UI_Mission.Ak_Play_UI_Mission_Reward",
},
Game.BL2: {
"Coop-Ding": "Ake_UI.UI_HUD.Ak_Play_UI_Alert_CoOp_Ding",
"Coop-Buddy Down": "Ake_UI.UI_HUD.Ak_Play_UI_Alert_CoOp_Buddy_Down",
"Challenge Completed": "Ake_UI.UI_HUD.Ak_Play_UI_HUD_Challenge_Completed",
"New Skin Unlocked": "Ake_UI.UI_HUD.Ak_Play_UI_HUD_New_Skin_Unlocked",
"Token Unlocked": "Ake_UI.UI_HUD.Ak_Play_UI_HUD_Token_Unlocked",
"PVP Duel End": "Ake_UI.UI_HUD.Ak_Play_UI_PVP_Duel_End",
"PVP Duel Start": "Ake_UI.UI_HUD.Ak_Play_UI_PVP_Duel_Start",
"Mission Reward": "Ake_UI.UI_Mission.Ak_Play_UI_Mission_Reward",
}
}
def get_pc():
return unrealsdk.GetEngine().GamePlayers[0].Actor
def spawn_dummy_object(io_def: unrealsdk.UObject, loc: tuple) -> unrealsdk.UObject:
pop_master: unrealsdk.UObject = unrealsdk.FindAll("WillowPopulationMaster")[-1]
iobject: unrealsdk.UObject = pop_master.SpawnPopulationControlledActor(
io_def.InteractiveObjectClass, None, "", loc, (0, 0, 0)
)
iobject.SetGameStage(1)
iobject.SetExpLevel(1)
iobject.InitializeFromDefinition(io_def, False)
return iobject
game_to_str = {
Game.BL2: "BL2",
Game.TPS: "TPS",
Game.AoDK: "AoDK"
}
class LootMarker(SDKMod):
Name = "Loot Marker"
Description = "Places markers on the map for specific loot."
Author = "Juso"
Version = "1.4"
SaveEnabledState = EnabledSaveType.LoadWithSettings
SupportedGames = Game.TPS | Game.BL2
def __init__(self):
super(LootMarker, self).__init__()
self.name_to_io_def = {}
self.path_name_to_willow_io = {}
self.enable_spawn_sound = True
self.player_drop_sound = False
self.ak_event = None
self.marker_type: int = int(ERadarIconType.RadarIconType_CustomizationStation)
self.dynamic_marker_objs = []
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "rarities.json"), "r") as f:
self.rarity_configs = json.load(f)
self.Options = [
OptionManager.Options.Spinner(
"Compatibility Mode",
f"Enable compatibility with a given mod.",
StartingValue="Exodus",
Choices=list(self.rarity_configs[game_to_str[Game.GetCurrent()]].keys())
),
OptionManager.Options.Boolean(
"Enable Spawn Sound",
"Play a sound when a unique item is spawned.",
StartingValue=True
),
OptionManager.Options.Boolean(
"Enable Player Dropped Sound",
"Play a sound when a legendary was dropped by the player.",
StartingValue=False
),
OptionManager.Options.Spinner(
"Sound Event",
"Change the sound that should play when a legendary spawns.",
StartingValue="Coop-Ding",
Choices=list(name_to_event[Game.GetCurrent()].keys()),
),
OptionManager.Options.Boolean(
"Enable Dynamic Markers",
"This option will live update the location of the markers. This might decrease your performance.",
StartingValue=False,
),
OptionManager.Options.Spinner(
"Marker Type",
"Change the marker on the map for the Loot.",
StartingValue="Customization Station",
Choices=list(working_icons.keys()),
)
]
self.selected_config = self.rarity_configs[game_to_str[Game.GetCurrent()]]["Exodus"]
def Enable(self):
self.ak_event = unrealsdk.FindObject("AkEvent", name_to_event[Game.GetCurrent()]["Coop-Ding"])
super().Enable()
def Disable(self):
super().Disable()
def ModOptionChanged(self, option: OptionManager.Options.Base, new_value: Any) -> None:
if option.Caption == "Compatibility Mode":
self.selected_config = self.rarity_configs[game_to_str[Game.GetCurrent()]][new_value]
# Config has changed, clear up wrong waypoints
for willow_io in self.path_name_to_willow_io.values():
willow_io.Destroyed()
self.path_name_to_willow_io.clear()
elif option.Caption == "Enable Spawn Sound":
self.enable_spawn_sound = new_value
elif option.Caption == "Enable Player Dropped Sound":
self.player_drop_sound = new_value
elif option.Caption == "Sound Event":
self.ak_event = unrealsdk.FindObject("AkEvent", name_to_event[Game.GetCurrent()][new_value])
if unrealsdk.GetEngine().GetCurrentWorldInfo().GetStreamingPersistentMapName().lower() != "menumap":
unrealsdk.GetEngine().GamePlayers[0].Actor.PlayAkEvent(self.ak_event)
elif option.Caption == "Marker Type":
self.marker_type = int(working_icons[new_value])
for m in self.path_name_to_willow_io.values():
m.SetCompassIcon(self.marker_type)
elif option.Caption == "Enable Dynamic Markers":
self.set_dynamic_markers(new_value)
def place_marker_for_pickup(self, pickup: unrealsdk.UObject) -> None:
name = pickup.Inventory.GenerateHumanReadableName() if pickup.Inventory else "Loot"
if name not in self.name_to_io_def:
item_level = re.search(r"\d+", name)
if item_level:
item_level = int(item_level.group(0))
description = f"Level {item_level}"
else:
description = "Loot baby baby!"
header = re.sub(r" INVALID \d+", "", name)
description = fr"{description}\n{header}"
new_io = unrealsdk.ConstructObject(Class="InteractiveObjectDefinition", Name=name.replace(" ", "_"))
unrealsdk.KeepAlive(new_io)
new_io.ObjectFlags.B |= 4
pc = get_pc()
rarity_name = ""
for c in self.selected_config:
if pickup.InventoryRarityLevel in range(c["min_level"], c["max_level"] + 1):
rarity_name = c["name"]
break
pc.ConsoleCommand(fr"set {pc.PathName(new_io)} StatusMenuMapInfoBoxHeader {rarity_name}")
pc.ConsoleCommand(fr"set {pc.PathName(new_io)} StatusMenuMapInfoBoxDescription {description}")
self.name_to_io_def[name] = new_io
path_name = pickup.PathName(pickup)
if path_name not in self.path_name_to_willow_io:
dummy = spawn_dummy_object(self.name_to_io_def[name],
(pickup.Location.X, pickup.Location.Y, pickup.Location.Z))
dummy.SetCompassIcon(self.marker_type)
self.path_name_to_willow_io[path_name] = dummy
def play_sound(self, uobj: unrealsdk.UObject) -> None:
"""Play the legendary spawn sound."""
uobj.PlayAkEvent(self.ak_event)
def is_valid_pickup(self, item: unrealsdk.UObject) -> bool:
"""Check if the item is a valid item to be marked."""
if not item:
return False
if item.Class == unrealsdk.FindClass("WillowMissionItem"):
return False
if any(
item.RarityLevel in range(c["min_level"], c["max_level"] + 1)
for c in self.selected_config
):
return True
return False
@Hook("Engine.WillowInventory.DropFrom")
def willow_pickup_spawned(
self,
caller: unrealsdk.UObject,
function: unrealsdk.UFunction,
params: unrealsdk.FStruct
) -> bool:
if not self.enable_spawn_sound or (caller.Owner is get_pc().Pawn and not self.player_drop_sound):
return True
if self.is_valid_pickup(caller):
self.play_sound(caller)
return True
@Hook("WillowGame.WillowPickup.AdjustPickupPhysicsAndCollisionForBeingAttached")
def willow_pickup_attached(
self,
caller: unrealsdk.UObject,
function: unrealsdk.UFunction,
params: unrealsdk.FStruct
) -> bool:
"""Creates a marker for the pickup when it is attached to a chest."""
if self.is_valid_pickup(caller.Inventory):
self.place_marker_for_pickup(caller)
self.play_sound(caller)
return True
@Hook("WillowGame.WillowPickup.ConvertRigidBodyToFixed")
def willow_pickup_ground(
self,
caller: unrealsdk.UObject,
function: unrealsdk.UFunction,
params: unrealsdk.FStruct
) -> bool:
"""Creates a marker for the pickup when it is on the ground."""
if self.is_valid_pickup(caller.Inventory):
path_name = caller.PathName(caller)
willow_io = self.path_name_to_willow_io.get(path_name)
if not willow_io:
self.place_marker_for_pickup(caller)
willow_io = self.path_name_to_willow_io.get(path_name)
willow_io.Location = (caller.Location.X, caller.Location.Y, caller.Location.Z)
try:
self.dynamic_marker_objs.remove(caller)
except ValueError:
pass
return True
def set_dynamic_markers(self, enabled: bool) -> bool:
"""Creates a marker and updates its position while it's not on the ground."""
def update_marker(
caller: unrealsdk.UObject,
function: unrealsdk.UFunction,
params: unrealsdk.FStruct
) -> bool:
for dyn_marker in self.dynamic_marker_objs:
path_name = dyn_marker.PathName(dyn_marker)
willow_io = self.path_name_to_willow_io.get(path_name)
if not willow_io:
self.place_marker_for_pickup(dyn_marker)
willow_io = self.path_name_to_willow_io.get(path_name)
willow_io.Location.X = dyn_marker.Location.X
willow_io.Location.Y = dyn_marker.Location.Y
willow_io.Location.Z = dyn_marker.Location.Z
return True
def needs_dynamic_marker(
caller: unrealsdk.UObject,
function: unrealsdk.UFunction,
params: unrealsdk.FStruct
) -> bool:
if self.is_valid_pickup(caller.Inventory):
self.dynamic_marker_objs.append(caller)
return True
if enabled:
unrealsdk.RegisterHook("WillowGame.WillowPickup.EnableRagdollCollision", "NewDrop", needs_dynamic_marker)
unrealsdk.RegisterHook("WillowGame.WillowGameViewportClient.Tick", "UpdateMarker", update_marker)
else:
self.dynamic_marker_objs = []
unrealsdk.RemoveHook("WillowGame.WillowPickup.EnableRagdollCollision", "NewDrop")
unrealsdk.RemoveHook("WillowGame.WillowGameViewportClient.Tick", "UpdateMarker")
return True
@Hook("WillowGame.WillowPickup.PickedUpBy")
def willow_pickup_picked_up(
self,
caller: unrealsdk.UObject,
function: unrealsdk.UFunction,
params: unrealsdk.FStruct
) -> bool:
"""Remove the marker for the pickup when it is picked up."""
path_name = caller.PathName(caller)
if path_name in self.path_name_to_willow_io:
self.path_name_to_willow_io[path_name].Destroyed()
del self.path_name_to_willow_io[path_name]
try:
self.dynamic_marker_objs.remove(caller)
except ValueError:
pass
return True
@Hook("WillowGame.WillowPlayerController.WillowClientShowLoadingMovie")
def level_cleanup(
self,
caller: unrealsdk.UObject,
function: unrealsdk.UFunction,
params: unrealsdk.FStruct
) -> bool:
"""Cleanup the markers when the level is unloaded."""
for w_io in self.path_name_to_willow_io.values():
w_io.Destroyed()
self.path_name_to_willow_io.clear()
self.dynamic_marker_objs.clear()
return True
unrealsdk.RegisterMod(LootMarker())