Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFiler committed Oct 24, 2024
2 parents 4d53561 + 02b7bf2 commit 9af6e0e
Show file tree
Hide file tree
Showing 25 changed files with 1,612 additions and 371 deletions.
25 changes: 21 additions & 4 deletions CathodeLib/Scripts/CATHODE/AlphaLightLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ override protected bool LoadInternal()
{
using (BinaryReader reader = new BinaryReader(File.OpenRead(_filepath)))
{
//todo
reader.BaseStream.Position += 8;

//NOTE: these values are always 64/128/256 i think
int count = reader.ReadInt32();
int length = reader.ReadInt32() * 8;

for (int i = 0; i < count; i++)
{
Entries.Add(new Entry()
{
content = reader.ReadBytes(length)
});
}
}
return true;
}
Expand All @@ -31,8 +43,13 @@ override protected bool SaveInternal()
{
writer.BaseStream.SetLength(0);
Utilities.WriteString("alph", writer);

//todo
writer.Write(0);
writer.Write(Entries.Count);
writer.Write(Entries.Count);
for (int i = 0; i < Entries.Count; i++)
{
writer.Write(Entries[i].content);
}
}
return true;
}
Expand All @@ -41,7 +58,7 @@ override protected bool SaveInternal()
#region STRUCTURES
public class Entry
{
//todo
public byte[] content;
};
#endregion
}
Expand Down
4 changes: 2 additions & 2 deletions CathodeLib/Scripts/CATHODE/CharacterAccessorySets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ override protected bool LoadInternal()
for (int i = 0; i < entryCount; i++)
{
Entry entry = new Entry();
entry.character = Utilities.Consume<CommandsEntityReference>(reader);
entry.character = Utilities.Consume<EntityHandle>(reader);

entry.shirt_composite = Utilities.Consume<ShortGuid>(reader);
entry.trousers_composite = Utilities.Consume<ShortGuid>(reader);
Expand Down Expand Up @@ -112,7 +112,7 @@ override protected bool SaveInternal()
#region STRUCTURES
public class Entry
{
public CommandsEntityReference character = new CommandsEntityReference();
public EntityHandle character = new EntityHandle();

public ShortGuid shirt_composite = ShortGuid.Invalid;
public ShortGuid trousers_composite = ShortGuid.Invalid;
Expand Down
149 changes: 125 additions & 24 deletions CathodeLib/Scripts/CATHODE/CollisionMaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

namespace CATHODE
Expand All @@ -19,45 +20,117 @@ public CollisionMaps(string path) : base(path) { }
#region FILE_IO
override protected bool LoadInternal()
{
int minUnk1 = 0;
int minUnk2 = 0;
int minColIn = 0;

List<int> flags = new List<int>();
Dictionary<string, List<string>> dictest = new Dictionary<string, List<string>>();

using (BinaryReader reader = new BinaryReader(File.OpenRead(_filepath)))
{
//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.
//The way this works:
// - First 18 entries are empty
// - 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)
// - There are then a few entries that have composite_instance_ids set but I can't resolve them - perhaps these are things from GLOBAL?
// - Then there's all the instanced entities with resolvable composite_instance_ids

reader.BaseStream.Position = 4;
int entryCount = reader.ReadInt32();
for (int i = 0; i < entryCount; i++)
{
Entry entry = new Entry();
entry.unk0 = reader.ReadInt32(); //flag?
entry.Unknown1_ = reader.ReadInt32(); //some sort of index ?
entry.ID = Utilities.Consume<ShortGuid>(reader);
entry.entity = Utilities.Consume<CommandsEntityReference>(reader);
entry.Unknown2_ = reader.ReadInt32(); //Is sometimes -1 and other times a small positive integer. Is this tree node parent?
entry.CollisionHKXEntryIndex = reader.ReadInt16();
entry.Unknown3_ = reader.ReadInt16(); //Most of the time it is -1.
entry.MVRZoneIDThing = reader.ReadInt32();

entry.UnknownFlag = reader.ReadInt32(); //NOTE: if you filter by this value, all the UnknownIndex1s increment, UnknownIndex2s/collision_index don't increment but are grouped by -1s and non -1s,

//todo: compare flag value across levels

entry.UnknownIndex1= reader.ReadInt32();
entry.id = Utilities.Consume<ShortGuid>(reader);
entry.entity = Utilities.Consume<EntityHandle>(reader);
entry.UnknownIndex2 = reader.ReadInt32();
entry.collision_index = reader.ReadInt16();
entry.UnknownValue = reader.ReadInt16();
entry.zone_id = Utilities.Consume<ShortGuid>(reader);
reader.BaseStream.Position += 16;
Entries.Add(entry);

if (minUnk1 < entry.UnknownIndex1)
minUnk1 = entry.UnknownIndex1;
if (minUnk2 < entry.UnknownIndex2)
minUnk2 = entry.UnknownIndex2;
if (minColIn < entry.collision_index)
minColIn = entry.collision_index;

if (!flags.Contains(entry.UnknownFlag))
flags.Add(entry.UnknownFlag);

if (entry.collision_index != -1 && entry.UnknownIndex1 == -1 && entry.UnknownIndex2 == -1 && entry.UnknownValue == -1)
{
string sdfsdf = "";
}

if (entry.UnknownIndex1 == -1 && entry.UnknownIndex2 == -1 && entry.UnknownValue == -1)
{
string sdfsdf = "";
}

string flagBin = BitConverter.ToString(BitConverter.GetBytes(entry.UnknownFlag));
if (!dictest.ContainsKey(flagBin))
dictest.Add(flagBin, new List<string>());

dictest[flagBin].Add(entry.UnknownIndex1 + " -> " + entry.UnknownIndex2 + " -> " + entry.collision_index);

//if (entry.UnknownFlag == -1073737335)
// Console.WriteLine(entry.UnknownIndex1);

//if (entry.UnknownFlag == 4429)
// Console.WriteLine(entry.UnknownIndex1);

//if (entry.UnknownFlag == -1073737405)
// Console.WriteLine(entry.UnknownIndex1);

//Console.WriteLine(entry.UnknownFlag + " -> " + entry.UnknownIndex1 + " -> " + entry.UnknownIndex2 + " -> " + entry.collision_index + " -> " + entry.UnknownValue);
}
}


return true;
}

override protected bool SaveInternal()
{
//composite_instance_id defo has something to do with the ordering as all the zeros are first


//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();

using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(_filepath)))
{
writer.BaseStream.SetLength(0);
writer.Write(Entries.Count * 80);
writer.Write((Entries.Count) * 48);
writer.Write(Entries.Count);

for (int i = 0; i < Entries.Count; i++)
{
writer.Write(Entries[i].Unknown1_);
Utilities.Write<ShortGuid>(writer, Entries[i].ID);
Utilities.Write<CommandsEntityReference>(writer, Entries[i].entity);
writer.Write(Entries[i].CollisionHKXEntryIndex);
writer.Write(Entries[i].Unknown3_);
writer.Write(Entries[i].MVRZoneIDThing);
//writer.Write(-268427008);
//writer.Write(-1);

writer.Write(Entries[i].UnknownFlag);
writer.Write(Entries[i].UnknownIndex1);

Utilities.Write<ShortGuid>(writer, Entries[i].id);
Utilities.Write<EntityHandle>(writer, Entries[i].entity);

writer.Write(-1);
//writer.Write(Entries[i].UnknownIndex2);

writer.Write((Int16)Entries[i].collision_index);

writer.Write((short)-1);
//writer.Write((Int16)Entries[i].UnknownValue);

Utilities.Write<ShortGuid>(writer, Entries[i].zone_id);
writer.Write(new byte[16]);
}
}
Expand All @@ -68,19 +141,47 @@ override protected bool SaveInternal()
#region STRUCTURES
public class Entry
{
public int unk0 = 0; //flags?
public int Unknown1_ = -1; // Is this tree node id?
public ShortGuid id = ShortGuid.Invalid; //This is the name of the entity hashed via ShortGuid
public EntityHandle entity = new EntityHandle();
public ShortGuid zone_id = ShortGuid.Invalid; //this maps the entity to a zone ID. interestingly, this seems to be the point of truth for the zone rendering

public ShortGuid ID = ShortGuid.Invalid; //This is the name of the entity hashed via ShortGuid, as a result, we can't resolve a lot of them. Does the game care about the value? I doubt it. We definitely don't.
public int collision_index = -1; //maps to havok hkx entry

public CommandsEntityReference entity = new CommandsEntityReference();
public int UnknownFlag = 0;
public int UnknownIndex1 = -1;
public int UnknownIndex2 = -1;
public int UnknownValue = -1;

public int Unknown2_= -1; // NOTE: Is sometimes -1 and other times a small positive integer. Is this tree node parent?
public static bool operator ==(Entry x, Entry y)
{
if (ReferenceEquals(x, null)) return ReferenceEquals(y, null);
if (ReferenceEquals(y, null)) return ReferenceEquals(x, null);
if (x.id != y.id) return false;
if (x.zone_id != y.zone_id) return false;
if (x.entity != y.entity) return false;
return true;
}
public static bool operator !=(Entry x, Entry y)
{
return !(x == y);
}

public Int16 CollisionHKXEntryIndex = -1; // NOTE: Most of the time is a positive integer, sometimes -1.
public override bool Equals(object obj)
{
return obj is Entry entry &&
EqualityComparer<ShortGuid>.Default.Equals(id, entry.id) &&
EqualityComparer<EntityHandle>.Default.Equals(entity, entry.entity) &&
EqualityComparer<ShortGuid>.Default.Equals(zone_id, entry.zone_id);
}

public Int16 Unknown3_ = -1; // NOTE: Most of the time it is -1.
public int MVRZoneIDThing = 0; // NOTE: This is CollisionMapThingIDs[0] from alien_mvr_entry
public override int GetHashCode()
{
int hashCode = 1001543423;
hashCode = hashCode * -1521134295 + id.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<EntityHandle>.Default.GetHashCode(entity);
hashCode = hashCode * -1521134295 + zone_id.GetHashCode();
return hashCode;
}
};
#endregion
}
Expand Down
Loading

0 comments on commit 9af6e0e

Please sign in to comment.