Skip to content

Commit 49c873d

Browse files
committed
correctly check custom cache when generating
1 parent f93d98a commit 49c873d

4 files changed

Lines changed: 24 additions & 23 deletions

File tree

CathodeLib/Scripts/CATHODE/CollisionMaps.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,15 @@ override protected bool LoadInternal()
2929

3030
using (BinaryReader reader = new BinaryReader(File.OpenRead(_filepath)))
3131
{
32-
//It seems typically in this file at the start there are a bunch of empty entries, and then there are a bunch of unresolvable ones, and then a bunch that can be resolved.
32+
//The way this works:
33+
// - First 18 entries are empty
34+
// - Next set of entries are all the COLLISION_MAPPING resources referenced by COMMANDS.PAK (hence they have no composite_instance_id, as the composites aren't instanced - but they do have entity_ids)
35+
// - There are then a few entries that have composite_instance_ids set but I can't resolve them - perhaps these are things from GLOBAL?
36+
// - Then there's all the instanced entities with resolvable composite_instance_ids
3337

34-
//first 18 are always null
35-
36-
//always first 247 are the same? 18 null and the rest in required assets?
37-
38-
//note: some of the things we skip here actually contain useful info, but the game doesn't read it so there's no point us bothering with it
39-
40-
41-
42-
//NOTE: skipping first 18 as they're always empty, at least, for what we parse
4338
reader.BaseStream.Position = 4;
4439
int entryCount = reader.ReadInt32();
45-
reader.BaseStream.Position += (48 * 18);
46-
for (int i = 0; i < entryCount - 18; i++)
40+
for (int i = 0; i < entryCount; i++)
4741
{
4842
Entry entry = new Entry();
4943

@@ -106,15 +100,16 @@ override protected bool LoadInternal()
106100

107101
override protected bool SaveInternal()
108102
{
103+
//composite_instance_id defo has something to do with the ordering as all the zeros are first
104+
105+
109106
//Entries = Entries.OrderBy(o => o.entity.entity_id.ToUInt32() + o.id.ToUInt32()).ThenBy(o => o.entity.composite_instance_id.ToUInt32()).ThenBy(o => o.zone_id.ToUInt32()).ToList();
110107

111108
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(_filepath)))
112109
{
113110
writer.BaseStream.SetLength(0);
114-
writer.Write((Entries.Count + 18) * 48);
115-
writer.Write(Entries.Count + 18);
116-
117-
writer.Write(new byte[18 * 48]);
111+
writer.Write((Entries.Count) * 48);
112+
writer.Write(Entries.Count);
118113

119114
for (int i = 0; i < Entries.Count; i++)
120115
{

CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,6 @@ public EntityPath(List<ShortGuid> _path)
682682
{
683683
path = _path;
684684

685-
//TODO: this whole system of modifying the path is dumb, should really come up with a better solution
686685
if (path.Count == 0 || path[path.Count - 1] != ShortGuid.Invalid)
687686
path.Add(ShortGuid.Invalid);
688687
}

CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/CommandsUtils.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ public static Entity ResolveHierarchy(Commands commands, Composite composite, Li
271271
asString = "";
272272
return null;
273273
}
274-
274+
275275
List<ShortGuid> hierarchyCopy = new List<ShortGuid>();
276276
for (int x = 0; x < hierarchy.Count; x++)
277277
hierarchyCopy.Add(new ShortGuid(hierarchy[x].ToUInt32()));
278-
278+
279279
Composite currentFlowgraphToSearch = composite;
280280
if (currentFlowgraphToSearch == null || currentFlowgraphToSearch.GetEntityByID(hierarchyCopy[0]) == null)
281281
{
@@ -292,19 +292,19 @@ public static Entity ResolveHierarchy(Commands commands, Composite composite, Li
292292
hierarchyCopy.RemoveAt(0);
293293
}
294294
}
295-
295+
296296
Entity entity = null;
297297
string hierarchyString = "";
298298
for (int i = 0; i < hierarchyCopy.Count; i++)
299299
{
300300
entity = currentFlowgraphToSearch.GetEntityByID(hierarchyCopy[i]);
301-
301+
302302
if (entity == null) break;
303303
if (includeShortGuids) hierarchyString += "[" + entity.shortGUID.ToByteString() + "] ";
304304
hierarchyString += EntityUtils.GetName(currentFlowgraphToSearch.shortGUID, entity.shortGUID);
305305
if (i >= hierarchyCopy.Count - 2) break; //Last is always 00-00-00-00
306306
hierarchyString += " -> ";
307-
307+
308308
if (entity.variant == EntityVariant.FUNCTION)
309309
{
310310
Composite flowRef = commands.GetComposite(((FunctionEntity)entity).function);

CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/ShortGuidUtils.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public static ShortGuid Generate(string value, bool cache = true)
5353
{
5454
if (_vanilla.cache.ContainsKey(value))
5555
return _vanilla.cache[value];
56+
if (_custom.cache.ContainsKey(value))
57+
return _custom.cache[value];
5658

5759
SHA1Managed sha1 = new SHA1Managed();
5860
byte[] hash1 = sha1.ComputeHash(Encoding.UTF8.GetBytes(value));
@@ -133,9 +135,14 @@ private static void Cache(ShortGuid guid, string value, bool isVanilla = false)
133135
}
134136
else
135137
{
138+
//TODO: need to fix this for BSPNOSTROMO_RIPLEY_PATCH
136139
if (_custom.cache.ContainsKey(value)) return;
137140
_custom.cache.Add(value, guid);
138-
_custom.cacheReversed.Add(guid, value);
141+
try
142+
{
143+
_custom.cacheReversed.Add(guid, value);
144+
}
145+
catch { }
139146
}
140147
}
141148

0 commit comments

Comments
 (0)