-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInspect.lua
369 lines (285 loc) · 14.9 KB
/
Inspect.lua
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
-- This script doesn't work at all on RE8 (Village). This will be helpful for someone later, though:
-- - https://cdn.discordapp.com/attachments/925838720534446100/1091125439537348628/image.png?ex=65a9a4c0&is=65972fc0&hm=fc9697872bbd65587bd4bb5d148509a497132201128a8176c16cb008511db2dc&
-- - https://cdn.discordapp.com/attachments/925838720534446100/1092203626568613898/image.png?ex=65ad90e4&is=659b1be4&hm=69b6ab91e182c81d6ab45b60afe89672e1423c479c87e780d93dceddbaa8491a&
--
-- Also doesn't work with RE4R. Things feel more obscured in this one than the others. Did find:
-- - GameObjects that start with "DropItem_" with a number of question marks after -> chainsaw.DropItem (component)
-- -> _ItemData -> ItemID, Count, AmmoItemID, AmmoCount, Durability
-- OR
-- -> _Item -> _ItemId, _CurrentDurability, _CurrentItemCount, _ItemType (lists things like "Powder(4)"), _ItemSize (size in inv, e.g., "_1x1_")
-- - _Item -> _ItemType in the above has Key(0), Ammo(1), Parts(3), Powder(4), Gun(5), Melee(6), Throwing(7), etc.
-- - Could mean that the chainsaw.InteractHolder (component) is the source of interactions that we'd want to hook somewhere
-- - This mod has the item interaction stuff in it, I think:
-- - https://www.nexusmods.com/residentevil42023/mods/1063
-- - These mods also have a lot of relevant Lua code for inventory items, but not ground items:
-- - https://www.nexusmods.com/residentevil42023/mods/896
-- - https://www.nexusmods.com/residentevil42023/mods/126
-- - https://www.nexusmods.com/residentevil42023/mods/1057
--
local Inspect = {}
Inspect.currentMapID = nil -- only used by RE2R and RE3R currently
local InspectItem = {}
local InspectPlayer = {}
local InspectTypewriter = {}
function InspectItem.GetName(gameObject)
return gameObject:call("get_Name()") or ""
end
function InspectItem.GetParentName(gameObject)
local transform = sdk.to_managed_object(gameObject:call('get_Transform()'))
local transform_parent = sdk.to_managed_object(transform:call('get_Parent()'))
if transform_parent then
local gameobject_parent = sdk.to_managed_object(transform_parent:call('get_GameObject()'))
local comp_item_positions = nil
if game == "RE2R" or game == "RE3R" then
comp_item_positions = gameobject_parent:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("item.ItemPositions")))
end
if game == "RE7" then
comp_item_positions = gameobject_parent:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("Item")))
end
-- only return the parent name if it's an item; otherwise, we don't care
if comp_item_positions then
return gameobject_parent:call("get_Name()") or ""
else
return ""
end
end
return ""
end
function InspectItem.GetFolderPath(gameObject)
local gameobject_folder = gameObject:call("get_Folder()")
if gameobject_folder then
return gameobject_folder:call("get_Path()")
end
return ""
end
function InspectPlayer.GetPosition()
local player_position = nil
if game == "RE2R" or game == "RE3R" then
local player_manager = sdk.get_managed_singleton(sdk.game_namespace("PlayerManager"))
player_position = player_manager:call("get_CurrentPosition()")
end
if game == "RE7" or game == "RE8" then
local player_object = player.gameobj -- apparently REF defines this?
local player_transform = player_object:call("get_Transform")
player_position = player_transform:call("get_Position")
end
local x = Inspect._Round(player_position.x)
local y = Inspect._Round(player_position.y)
local z = Inspect._Round(player_position.z)
return { x = x, y = y, z = z }
end
function InspectPlayer.GetPositionString()
local pos = InspectPlayer.GetPosition()
if not pos then return "" end
return "[" .. pos["x"] .. ", " .. pos["y"] .. ", " .. pos["z"] .. "]"
end
function InspectTypewriter.IsTypewriter(gameObject)
local gameobject_name = InspectItem.GetName(gameObject)
local gameobject_parent = InspectItem.GetParentName(gameObject)
if game == "RE2R" or game == "RE3R" then
if string.match(gameobject_name, "Typewriter") then
return true
end
end
if game == "RE7" then
if string.match(gameobject_name, "SaveMenuInteract") then
return true
end
end
if game == "RE8" then
if string.match(gameobject_name, "InteractManualSave") then
return true
end
end
return false
end
function InspectTypewriter.GetLocationId(gameObject)
if game == "RE2R" or game == "RE3R" then
local comp_gimmick_control = gameObject:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("gimmick.action.GimmickControl")))
return comp_gimmick_control:call("get_MyLocation()")
end
if game == "RE7" then
local comp_interact_base = gameObject:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("InteractObjectBase")))
local search_object = comp_interact_base:get_field("_SearchObject")
local comp_map_object = search_object:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("MapObject")))
local map_data = comp_map_object:get_field("Data")
return map_data:get_field("Chapter")
end
if game == "RE8" then
local systemObject = scene:call("findGameObject(System.String)", "SystemObject")
local mapManagerComp = systemObject:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("MapManager")))
local mapInfo = mapManagerComp:get_field("<currentRoomUnit>k__BackingField")
return mapInfo:get_field("ZoneID")
end
return nil
end
function InspectTypewriter.GetMapId(gameObject)
if game == "RE2R" then
local comp_gimmick_control = gameObject:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("gimmick.action.GimmickControl")))
local comp_gimmick_body = comp_gimmick_control:call("get_MyGimmickBody()")
return comp_gimmick_body:get_field("AssignMapID")
end
if game == "RE3R" then
local comp_gimmick_control = gameObject:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("gimmick.action.GimmickControl")))
return comp_gimmick_control:call("getMapIdForMapClearing()")
end
if game == "RE7" then
local comp_interact_base = gameObject:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("InteractObjectBase")))
local search_object = comp_interact_base:get_field("_SearchObject")
local comp_map_object = search_object:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("MapObject")))
local map_data = comp_map_object:get_field("Data")
return map_data:get_field("RoomID")
end
if game == "RE8" then
local systemObject = scene:call("findGameObject(System.String)", "SystemObject")
local mapManagerComp = systemObject:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("MapManager")))
local mapInfo = mapManagerComp:get_field("<currentRoomUnit>k__BackingField")
return mapInfo:get_field("MapID")
end
return nil
end
function Inspect.GetGameByGameName()
local gameName = reframework:get_game_name()
if not gameName then
return nil
end
if gameName == "re2" or gameName == "re3" or gameName == "re4" then
gameName = gameName .. "r" -- add the "remake" on the end
end
return string.upper(gameName)
end
function Inspect.GetGameByNamespace()
local namespace_name = sdk.game_namespace("")
if namespace_name == "app.ropeway." then return "RE2R" end
if namespace_name == "offline." then return "RE3R" end -- what a stupid namespace name
if namespace_name == "app." then
-- this is a silly way to tell the difference between RE7 and RE8
if player.gameobj:get_Name() == "Pl1000" then
return "RE7"
else -- player.gameobj:get_Name() == "pl1000"
return "RE8"
end
end
if namespace_name == "chainsaw." then return "RE4R" end -- awesome namespace name
return nil
end
function Inspect.Log(message, value)
if not message and not value then
log.debug("")
return
end
if not value then
log.debug("| REF_Inspect | " .. tostring(message))
return
end
log.debug("| REF_Inspect | " .. tostring(message) .. ": " .. tostring(value))
end
function Inspect._Setup()
Inspect._SetupHook()
end
function Inspect._SetupHook()
if game == "RE2R" or game == "RE3R" then
-- main interactions hook
local interactType = sdk.find_type_definition(sdk.game_namespace("gimmick.action.FeedbackFSM"))
if interactType then
local interact_method = interactType:get_method("execute")
sdk.hook(interact_method, function(args)
local compFeedbackFSM = sdk.to_managed_object(args[2])
local parentOfComponent = sdk.to_managed_object(compFeedbackFSM:get_field('_Owner'))
Inspect.Log() -- intentional line break
Inspect.Log("Item Object", InspectItem.GetName(parentOfComponent))
Inspect.Log("Parent Object", InspectItem.GetParentName(parentOfComponent))
Inspect.Log("Folder Path", InspectItem.GetFolderPath(parentOfComponent))
Inspect.Log("Player Position", InspectPlayer.GetPositionString())
if InspectTypewriter.IsTypewriter(parentOfComponent) then
Inspect.Log("Typewriter Location ID", InspectTypewriter.GetLocationId(parentOfComponent))
Inspect.Log("Typewriter Map ID", InspectTypewriter.GetMapId(parentOfComponent))
end
end)
end
-- map switching (i.e., room switching) hook
local interactType = sdk.find_type_definition(sdk.game_namespace("EnvironmentStandbyManager"))
if interactType then
local interact_method = interactType:get_method("getStandbyController")
sdk.hook(interact_method, function(args)
local compEnvStandby = sdk.to_managed_object(args[2])
local currentMapID = compEnvStandby:call("get_CurrentMap")
if currentMapID ~= Inspect.currentMapID then
Inspect.currentMapID = currentMapID
Inspect.Log("Current Map ID", currentMapID)
end
end)
end
end
if game == "RE7" then
local interactType = sdk.find_type_definition(sdk.game_namespace("InteractObjectBase"))
if interactType then
local interact_method = interactType:get_method("FsmExecute")
sdk.hook(interact_method, function(args)
local compFeedbackFSM = sdk.to_managed_object(args[2])
local parentOfComponent = sdk.to_managed_object(compFeedbackFSM:call("get_GameObject"))
Inspect.Log() -- intentional line break
Inspect.Log("Item Object", InspectItem.GetName(parentOfComponent))
Inspect.Log("Parent Object", InspectItem.GetParentName(parentOfComponent))
Inspect.Log("Folder Path", InspectItem.GetFolderPath(parentOfComponent))
Inspect.Log("Player Position", InspectPlayer.GetPositionString())
if InspectTypewriter.IsTypewriter(parentOfComponent) then
Inspect.Log("Recorder Location ID", InspectTypewriter.GetLocationId(parentOfComponent))
Inspect.Log("Recorder Map ID", InspectTypewriter.GetMapId(parentOfComponent))
end
end)
end
end
if game == "RE8" then
local interactType = sdk.find_type_definition(sdk.game_namespace("InteractBase"))
if interactType then
local interact_method = interactType:get_method("SuccessInteract")
sdk.hook(interact_method, function(args)
local interactBasic = sdk.to_managed_object(args[2])
local interactItemGet = interactBasic:get_field("ParentObject")
local interactItemGetComp = interactItemGet:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("InteractItemGet")))
-- if it's not an item to get, just have it display information for the first object instead
local itemObject = interactItemGet
-- if it is an item to get, have it find the actual item object and use that
if interactItemGetComp ~= nil then
itemObject = interactItemGetComp:get_field("ItemSetGameObject")
end
local itemObjectTransform = itemObject:call("get_Transform")
-- TODO: move getting transform position (and itemObjectTransform above) into a method for getting position like GetName gets name
local universalPosition = itemObjectTransform:call("get_Position")
local positionValues = { universalPosition.x, universalPosition.y, universalPosition.z }
Inspect.Log() -- intentional line break
Inspect.Log("Item Object", InspectItem.GetName(itemObject))
Inspect.Log("Item Position", "[" .. tostring(table.concat(positionValues, ",")) .. "]")
Inspect.Log("Folder Path", InspectItem.GetFolderPath(itemObject))
Inspect.Log("Player Position", InspectPlayer.GetPositionString())
if InspectTypewriter.IsTypewriter(itemObject) then
Inspect.Log("Typewriter Location ID", InspectTypewriter.GetLocationId(itemObject))
Inspect.Log("Typewriter Map ID", InspectTypewriter.GetMapId(itemObject))
end
--local itemObjectConfigureComp = itemObject:call("getComponent(System.Type)", sdk.typeof(sdk.game_namespace("ItemGetConfigure")))
--> itemObjectConfigureComp -> <references>k__BackingField -> <itemCore>k__BackingField -> <work>k__BackingField --> ItemID, etc.
end)
end
end
end
function Inspect._Round(number)
return math.ceil(number * 100) / 100 -- two decimal places
end
-- this gets used a lot, so just define it outside the function scopes
game = Inspect.GetGameByGameName()
-- had this logic for game by namespace coded, so leaving it in case it's somehow needed
if game == nil then
game = Inspect.GetGameByNamespace()
end
-- run all the setup once
re.on_pre_application_entry("UpdateBehavior", function()
if not Inspect.didInit then
Inspect.didInit = true
Inspect._Setup()
end
end)
Inspect.Log("Script loaded!")
if game ~= nil then
Inspect.Log("Game identified as " .. tostring(game) .. ".")
end