Skip to content

Commit a776596

Browse files
committed
Implement room obj. inst. [pre-]creation code reference searching, rename "Room object instances".
1 parent 30301f5 commit a776596

2 files changed

Lines changed: 94 additions & 2 deletions

File tree

UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMap.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,19 @@ public static class UndertaleResourceReferenceMap
307307
{
308308
(typeof(UndertaleGameObject), "Game objects"),
309309
(typeof(UndertaleRoom), "Rooms"),
310+
(typeof(UndertaleRoom.GameObject), "Room object instances (creation code)"),
310311
(typeof(UndertaleGlobalInit), "Global initialization and game end scripts"),
311312
(typeof(UndertaleScript), "Scripts")
312313
}
314+
},
315+
new TypesForVersion()
316+
{
317+
// Bytecode version 16
318+
Version = (16, uint.MaxValue, uint.MaxValue),
319+
Types = new[]
320+
{
321+
(typeof(UndertaleRoom.GameObject), "Room object instances (pre create code)")
322+
}
313323
}
314324
}
315325
},

UndertaleModTool/Windows/FindReferencesTypesDialog/UndertaleResourceReferenceMethodsMap.cs

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Concurrent;
44
using System.Collections.Generic;
@@ -1107,7 +1107,7 @@ IEnumerable<object[]> GetObjInstances()
11071107

11081108
var objInstances = GetObjInstances();
11091109
if (objInstances.Any())
1110-
outDict["Room object instance"] = checkOne ? objInstances.ToEmptyArray() : objInstances.ToArray();
1110+
outDict["Room object instances"] = checkOne ? objInstances.ToEmptyArray() : objInstances.ToArray();
11111111
}
11121112

11131113
if (outDict.Count == 0)
@@ -1193,6 +1193,41 @@ void ProcessTrack(UndertaleSequence seq, Track track, List<object> trackChain)
11931193
outDict["Rooms"] = checkOne ? rooms.ToEmptyArray() : rooms.ToArray();
11941194
}
11951195

1196+
if (types.Contains(typeof(UndertaleRoom.GameObject)))
1197+
{
1198+
IEnumerable<object[]> GetObjInstances()
1199+
{
1200+
if (data.IsGameMaker2())
1201+
{
1202+
foreach (var room in data.Rooms)
1203+
{
1204+
foreach (var layer in room.Layers)
1205+
{
1206+
if (layer.InstancesData is not null)
1207+
{
1208+
foreach (var inst in layer.InstancesData.Instances)
1209+
if (inst.CreationCode == obj)
1210+
yield return new object[] { inst, layer, room };
1211+
}
1212+
}
1213+
}
1214+
}
1215+
else
1216+
{
1217+
foreach (var room in data.Rooms)
1218+
{
1219+
foreach (var inst in room.GameObjects)
1220+
if (inst.CreationCode == obj)
1221+
yield return new object[] { inst, room };
1222+
}
1223+
}
1224+
}
1225+
1226+
var objInstances = GetObjInstances();
1227+
if (objInstances.Any())
1228+
outDict["Room object instances (creation code)"] = checkOne ? objInstances.ToEmptyArray() : objInstances.ToArray();
1229+
}
1230+
11961231
if (types.Contains(typeof(UndertaleGlobalInit)))
11971232
{
11981233
bool matches = data.GlobalInitScripts?.Any(x => x.Code == obj) == true;
@@ -1215,6 +1250,53 @@ void ProcessTrack(UndertaleSequence seq, Track track, List<object> trackChain)
12151250
return null;
12161251
return outDict;
12171252
}
1253+
},
1254+
new PredicateForVersion()
1255+
{
1256+
// Bytecode version 16
1257+
Version = (16, uint.MaxValue, uint.MaxValue),
1258+
Predicate = (objSrc, types, checkOne) =>
1259+
{
1260+
if (!types.Contains(typeof(UndertaleRoom.GameObject)))
1261+
return null;
1262+
1263+
if (objSrc is not UndertaleCode obj)
1264+
return null;
1265+
1266+
IEnumerable<object[]> GetObjInstances()
1267+
{
1268+
if (data.IsGameMaker2())
1269+
{
1270+
foreach (var room in data.Rooms)
1271+
{
1272+
foreach (var layer in room.Layers)
1273+
{
1274+
if (layer.InstancesData is not null)
1275+
{
1276+
foreach (var inst in layer.InstancesData.Instances)
1277+
if (inst.PreCreateCode == obj)
1278+
yield return new object[] { inst, layer, room };
1279+
}
1280+
}
1281+
}
1282+
}
1283+
else
1284+
{
1285+
foreach (var room in data.Rooms)
1286+
{
1287+
foreach (var inst in room.GameObjects)
1288+
if (inst.PreCreateCode == obj)
1289+
yield return new object[] { inst, room };
1290+
}
1291+
}
1292+
}
1293+
1294+
var objInstances = GetObjInstances();
1295+
if (objInstances.Any())
1296+
return new() { { "Room object instances (pre create code)", checkOne ? objInstances.ToEmptyArray() : objInstances.ToArray() } };
1297+
else
1298+
return null;
1299+
}
12181300
}
12191301
}
12201302
},

0 commit comments

Comments
 (0)