Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFiler committed Feb 6, 2024
2 parents e0794f1 + b3e1c9c commit fc610d1
Show file tree
Hide file tree
Showing 26 changed files with 1,879 additions and 580 deletions.
2 changes: 1 addition & 1 deletion AlienBML
48 changes: 48 additions & 0 deletions CathodeLib/Scripts/CATHODE/AlphaLightLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using CathodeLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;

namespace CATHODE.EXPERIMENTAL
{
/* DATA/ENV/PRODUCTION/x/WORLD/ALPHALIGHT_LEVEL.BIN */
public class AlphaLightLevel : CathodeFile
{
public List<Entry> Entries = new List<Entry>();
public static new Implementation Implementation = Implementation.NONE;
public AlphaLightLevel(string path) : base(path) { }

// Lighting information for objects with alpha (e.g. glass). Levels can load without this file, but look worse.

#region FILE_IO
override protected bool LoadInternal()
{
using (BinaryReader reader = new BinaryReader(File.OpenRead(_filepath)))
{
//todo
}
return true;
}

override protected bool SaveInternal()
{
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(_filepath)))
{
writer.BaseStream.SetLength(0);
Utilities.WriteString("alph", writer);

//todo
}
return true;
}
#endregion

#region STRUCTURES
public class Entry
{
//todo
};
#endregion
}
}
90 changes: 90 additions & 0 deletions CathodeLib/Scripts/CATHODE/AnimClipDB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using CATHODE.Scripting;
using CathodeLib;

namespace CATHODE
{
/* DATA/GLOBAL/ANIMATION.PAK -> ANIM_CLIP_DB.BIN */
public class AnimClipDB : CathodeFile
{
public Dictionary<uint, string> Entries = new Dictionary<uint, string>();
public static new Implementation Implementation = Implementation.LOAD;
public AnimClipDB(string path) : base(path) { }

#region FILE_IO
override protected bool LoadInternal()
{
using (BinaryReader reader = new BinaryReader(File.OpenRead(_filepath)))
{
int EntryCount1 = reader.ReadInt32();
int EntryCount2 = reader.ReadInt32();
IndexPair[] Entries1 = Utilities.ConsumeArray<IndexPair>(reader, EntryCount1);
IndexPair[] Entries2 = Utilities.ConsumeArray<IndexPair>(reader, EntryCount2);

int Count0 = reader.ReadInt32();
int Count1 = reader.ReadInt32();
IndexPair[] Stuff0 = Utilities.ConsumeArray<IndexPair>(reader, Count0);
OffsetPair[] Stuff1 = Utilities.ConsumeArray<OffsetPair>(reader, Count1);

int Count2 = reader.ReadInt32();
int[] Stuff2 = Utilities.ConsumeArray<int>(reader, Count2);

int Count4 = reader.ReadInt32();
int Count5 = reader.ReadInt32();
int Count6 = reader.ReadInt32();
IndexPair[] Stuff5 = Utilities.ConsumeArray<IndexPair>(reader, Count5);
int[] Stuff6 = Utilities.ConsumeArray<int>(reader, Count6);

int Count7 = reader.ReadInt32();
int[] Stuff7 = Utilities.ConsumeArray<int>(reader, Count7);

byte[] HeaderCounts0 = Utilities.ConsumeArray<byte>(reader, 5);
float[] HeaderFloats0 = Utilities.ConsumeArray<float>(reader, 6); // TODO: Is this HKX min/max floats for compression?
int[] HeaderStuff0 = Utilities.ConsumeArray<int>(reader, 4);

int[] ContentStuff0 = Utilities.ConsumeArray<int>(reader, HeaderCounts0[1] * 4);
Vector2[] ContentStuff1 = Utilities.ConsumeArray<Vector2>(reader, HeaderCounts0[2]);

bone_entry[] BoneEntries = Utilities.ConsumeArray<bone_entry>(reader, HeaderCounts0[3]);

// NOTE: Following content seems to be 4 unknown u8s followed by 4 u8s of which the 0th is ff and 1, 2 and 3 seem to
// sum to 255. I would guess those are bone weights? Bone weights tend to sum to 1.
}
return true;
}

override protected bool SaveInternal()
{
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(_filepath)))
{
writer.BaseStream.SetLength(0);
}
return true;
}
#endregion

#region STRUCTURES
[StructLayout(LayoutKind.Sequential, Pack = 1)]
private struct IndexPair
{
public uint id;
public int index;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
private struct bone_entry
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
byte[] Joints;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
byte[] Weights;
};
#endregion
}
}
13 changes: 7 additions & 6 deletions CathodeLib/Scripts/CATHODE/AnimationStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public AnimationStrings(string path) : base(path) { }
#region FILE_IO
override protected bool LoadInternal()
{
using (BinaryReader stream = new BinaryReader(File.OpenRead(_filepath)))
using (BinaryReader reader = new BinaryReader(File.OpenRead(_filepath)))
{
//Read all data in
int EntryCount = stream.ReadInt32();
int StringCount = stream.ReadInt32();
Entry[] entries = Utilities.ConsumeArray<Entry>(stream, EntryCount);
int[] stringOffsets = Utilities.ConsumeArray<int>(stream, StringCount);
int EntryCount = reader.ReadInt32();
int StringCount = reader.ReadInt32();
Entry[] entries = Utilities.ConsumeArray<Entry>(reader, EntryCount);
int[] stringOffsets = Utilities.ConsumeArray<int>(reader, StringCount);
List<string> strings = new List<string>();
for (int i = 0; i < StringCount; i++) strings.Add(Utilities.ReadString(stream));
for (int i = 0; i < StringCount; i++) strings.Add(Utilities.ReadString(reader));

//Parse
for (int i = 0; i < entries.Length; i++) Entries.Add(entries[i].StringID, strings[entries[i].StringIndex]);
Expand All @@ -40,6 +40,7 @@ override protected bool SaveInternal()
{
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(_filepath)))
{
writer.BaseStream.SetLength(0);
writer.Write(Entries.Count);
writer.Write(Entries.Count);
int count = 0;
Expand Down
42 changes: 18 additions & 24 deletions CathodeLib/Scripts/CATHODE/CollisionMaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ override protected bool LoadInternal()
{
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.

reader.BaseStream.Position = 4;
int entryCount = reader.ReadInt32();
for (int i = 0; i < entryCount; i++)
{
Entry entry = new Entry();
entry.Unknown1_ = reader.ReadInt32();
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.ResourcesBINID = reader.ReadInt32();
entry.Unknown2_ = reader.ReadInt32();
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();
entry.Unknown3_ = reader.ReadInt16(); //Most of the time it is -1.
entry.MVRZoneIDThing = reader.ReadInt32();
entry.Unknown4_ = reader.ReadInt32();
entry.Unknown5_ = reader.ReadInt32();
entry.Unknown6_ = reader.ReadInt32();
entry.Unknown7_ = reader.ReadInt32();
reader.BaseStream.Position += 16;
Entries.Add(entry);
}
}
Expand All @@ -53,15 +53,12 @@ override protected bool SaveInternal()
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].ResourcesBINID);
writer.Write(Entries[i].CollisionHKXEntryIndex);
writer.Write(Entries[i].Unknown3_);
writer.Write(Entries[i].MVRZoneIDThing);
writer.Write(Entries[i].Unknown4_);
writer.Write(Entries[i].Unknown5_);
writer.Write(Entries[i].Unknown6_);
writer.Write(Entries[i].Unknown7_);
writer.Write(new byte[16]);
}
}
return true;
Expand All @@ -71,22 +68,19 @@ override protected bool SaveInternal()
#region STRUCTURES
public class Entry
{
public int Unknown1_; // Is this tree node id?
public int unk0 = 0; //flags?
public int Unknown1_ = -1; // Is this tree node id?

public CommandsEntityReference entity;
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 ResourcesBINID; // NOTE: This might not be the correct name. It seems to correspond to the similarly named variable at alien_resources_bin_entry.
public int Unknown2_; // NOTE: Is sometimes -1 and other times a small positive integer. Is this tree node parent?
public CommandsEntityReference entity = new CommandsEntityReference();

public Int16 CollisionHKXEntryIndex; // NOTE: Most of the time is a positive integer, sometimes -1.
public int Unknown2_= -1; // NOTE: Is sometimes -1 and other times a small positive integer. Is this tree node parent?

public Int16 Unknown3_; // NOTE: Most of the time it is -1.
public int MVRZoneIDThing; // NOTE: This is CollisionMapThingIDs[0] from alien_mvr_entry
public Int16 CollisionHKXEntryIndex = -1; // NOTE: Most of the time is a positive integer, sometimes -1.

public int Unknown4_;
public int Unknown5_;
public int Unknown6_;
public int Unknown7_;
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
};
#endregion
}
Expand Down
Loading

0 comments on commit fc610d1

Please sign in to comment.