Skip to content

Commit bcb093f

Browse files
committed
Merge branch 'staging'
2 parents 6a4aad0 + ae36a39 commit bcb093f

32 files changed

Lines changed: 3137 additions & 926 deletions

CathodeLib/CathodeLib.csproj

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
<Authors>Matt Filer</Authors>
1111
<Description>Provides support for parsing and writing common Alien: Isolation formats from the Cathode engine.</Description>
1212
<Copyright>Matt Filer 2026</Copyright>
13-
<Version>0.11.2</Version>
13+
<Version>0.12.0</Version>
1414
<OutputType>Library</OutputType>
15-
<AssemblyVersion>0.11.2.0</AssemblyVersion>
16-
<FileVersion>0.11.2.0</FileVersion>
15+
<AssemblyVersion>0.12.0.0</AssemblyVersion>
16+
<FileVersion>0.12.0.0</FileVersion>
1717
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
1818
<PackageReadmeFile>README.md</PackageReadmeFile>
1919
<PackageTags>alien, modding, alien isolation, mod tool, file utility</PackageTags>
2020
<Title>CathodeLib</Title>
21+
<Configurations>Debug;Release;Ship</Configurations>
2122
</PropertyGroup>
2223

2324
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -28,6 +29,10 @@
2829
<DefineConstants>$(DefineConstants)TRACE</DefineConstants>
2930
</PropertyGroup>
3031

32+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Ship|AnyCPU'">
33+
<DefineConstants>$(DefineConstants)TRACE</DefineConstants>
34+
</PropertyGroup>
35+
3136
<ItemGroup>
3237
<Compile Remove="CathodeBIN\NewFolder\**" />
3338
<EmbeddedResource Remove="CathodeBIN\NewFolder\**" />
@@ -47,10 +52,13 @@
4752
</ItemGroup>
4853

4954
<ItemGroup>
55+
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.8" />
56+
<PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.3.8" />
5057
<PackageReference Include="System.Buffers" Version="4.5.1" />
51-
<PackageReference Include="System.Memory" Version="4.5.4" />
58+
<PackageReference Include="System.Memory" Version="4.5.5" />
5259
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
5360
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
61+
<PackageReference Include="xxHash.NET" Version="1.0.2" />
5462
</ItemGroup>
5563

5664
<ItemGroup>

CathodeLib/Resources/info.dat

177 KB
Binary file not shown.
-2 MB
Binary file not shown.

CathodeLib/Scripts/CATHODE/CollisionMaps.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7+
using System.IO.Compression;
78
using System.Linq;
89
using System.Runtime.InteropServices;
910
using System.Threading.Tasks;
@@ -25,6 +26,9 @@ public class CollisionMaps : CathodeFile
2526
private Materials _materials;
2627
private MaterialMappings _materialMaps;
2728

29+
public bool Compressed { get { return _compressed; } set { _compressed = value; } }
30+
private bool _compressed = false;
31+
2832
private List<COLLISION_MAPPING> _writeList = new List<COLLISION_MAPPING>();
2933

3034
public CollisionMaps(string path, Materials materials, MaterialMappings materialMaps) : base(path)
@@ -51,7 +55,9 @@ public void ClearReferences()
5155
#region FILE_IO
5256
override protected bool LoadInternal(MemoryStream stream)
5357
{
54-
using (BinaryReader reader = new BinaryReader(stream))
58+
_compressed = _filepath != null && _filepath != "" && Path.GetExtension(_filepath).ToLower() == ".gz";
59+
60+
using (BinaryReader reader = new BinaryReader(_compressed ? Utilities.GZIPDecompress(stream) : stream))
5561
{
5662
//The way this works:
5763
// - First 18 entries are empty
@@ -76,12 +82,18 @@ override protected bool LoadInternal(MemoryStream stream)
7682
Entries.Add(entry);
7783
}
7884
}
85+
7986
_writeList.AddRange(Entries);
8087
return true;
8188
}
8289

8390
override protected bool SaveInternal()
8491
{
92+
if (_compressed && Path.GetExtension(_filepath).ToLower() != ".gz")
93+
_filepath += ".gz";
94+
else if (!_compressed && Path.GetExtension(_filepath).ToLower() == ".gz")
95+
_filepath = _filepath.Substring(0, _filepath.Length - 3);
96+
8597
//composite_instance_id defo has something to do with the ordering as all the zeros are first
8698

8799
//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();
@@ -92,14 +104,19 @@ override protected bool SaveInternal()
92104
entryBuffers[i] = SerializeEntry(Entries[i]);
93105
});
94106

95-
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(_filepath)))
107+
using (Stream stream = File.OpenWrite(_filepath))
108+
using (BinaryWriter writer = new BinaryWriter(stream))
96109
{
97110
writer.BaseStream.SetLength(0);
98111
writer.Write((Entries.Count) * 48);
99112
writer.Write(Entries.Count);
100113
for (int i = 0; i < entryBuffers.Length; i++)
101114
writer.Write(entryBuffers[i]);
102115
}
116+
117+
if (_compressed)
118+
Utilities.GZIPCompress(_filepath);
119+
103120
_writeList.Clear();
104121
_writeList.AddRange(Entries);
105122
return true;

CathodeLib/Scripts/CATHODE/Collisions.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using static CATHODE.Movers;
1111
using static CATHODE.Models;
1212
using CathodeLib.ObjectExtensions;
13+
using System.IO.Compression;
14+
1315

1416

1517
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
@@ -28,12 +30,15 @@ public class Collisions : CathodeFile
2830
public List<WeightedCollision> Entries = new List<WeightedCollision>();
2931
public static new Implementation Implementation = Implementation.CREATE | Implementation.LOAD | Implementation.SAVE;
3032

33+
public bool Compressed { get { return _compressed; } set { _compressed = value; } }
34+
private bool _compressed = false;
35+
36+
private List<WeightedCollision> _writeList = new List<WeightedCollision>();
37+
3138
public Collisions(string path) : base(path) { }
3239
public Collisions(MemoryStream stream, string path = "") : base(stream, path) { }
3340
public Collisions(byte[] data, string path = "") : base(data, path) { }
3441

35-
private List<WeightedCollision> _writeList = new List<WeightedCollision>();
36-
3742
~Collisions()
3843
{
3944
Entries.Clear();
@@ -43,7 +48,9 @@ public Collisions(byte[] data, string path = "") : base(data, path) { }
4348
#region FILE_IO
4449
override protected bool LoadInternal(MemoryStream stream)
4550
{
46-
using (var reader = new BinaryReader(stream))
51+
_compressed = _filepath != null && _filepath != "" && Path.GetExtension(_filepath).ToLower() == ".gz";
52+
53+
using (var reader = new BinaryReader(_compressed ? Utilities.GZIPDecompress(stream) : stream))
4754
{
4855
//remove these if exceptions dont throw
4956
byte[] magic = reader.ReadBytes(4);
@@ -109,12 +116,18 @@ override protected bool LoadInternal(MemoryStream stream)
109116
}
110117
}
111118
}
119+
112120
_writeList.AddRange(Entries);
113121
return true;
114122
}
115123

116124
override protected bool SaveInternal()
117125
{
126+
if (_compressed && Path.GetExtension(_filepath).ToLower() != ".gz")
127+
_filepath += ".gz";
128+
else if (!_compressed && Path.GetExtension(_filepath).ToLower() == ".gz")
129+
_filepath = _filepath.Substring(0, _filepath.Length - 3);
130+
118131
var collisionData = new List<WeightedCollisionData>();
119132
var boneData = new List<BoneData>();
120133
var vertexData = new List<VertexData>();
@@ -177,7 +190,8 @@ override protected bool SaveInternal()
177190
}
178191
}
179192

180-
using (var writer = new BinaryWriter(File.OpenWrite(_filepath)))
193+
using (Stream stream = File.OpenWrite(_filepath))
194+
using (BinaryWriter writer = new BinaryWriter(stream))
181195
{
182196
writer.BaseStream.SetLength(0);
183197
writer.Write(new byte[4] { 0x0C, 0xA0, 0xFE, 0xEF });
@@ -200,6 +214,10 @@ override protected bool SaveInternal()
200214
vertexData.ForEach(v => Utilities.Write(writer, v));
201215
indexData.ForEach(i => writer.Write(i));
202216
}
217+
218+
if (_compressed)
219+
Utilities.GZIPCompress(_filepath);
220+
203221
_writeList.Clear();
204222
_writeList.AddRange(Entries);
205223
return true;

CathodeLib/Scripts/CATHODE/Commands.cs

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
using System.Runtime.InteropServices.ComTypes;
1010
using System.Threading.Tasks;
1111
using CATHODE.Scripting.Internal.Parsers;
12+
using System.Runtime.CompilerServices;
13+
14+
1215

1316

1417
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
@@ -32,6 +35,9 @@ public class Commands : CathodeFile
3235
private CollisionMaps _colMaps;
3336
private RenderableElements _reds;
3437

38+
public bool Compressed { get { return _compressed; } set { _compressed = value; } }
39+
private bool _compressed = false;
40+
3541
public Commands(string path, EnvironmentAnimations envAnims, CollisionMaps colMaps, RenderableElements reds) : base(path)
3642
{
3743
_envAnims = envAnims;
@@ -41,6 +47,19 @@ public Commands(string path, EnvironmentAnimations envAnims, CollisionMaps colMa
4147
Utils = new CommandsUtils(this);
4248

4349
_loaded = Load();
50+
51+
//Overwrite loaded data with the data from BIN
52+
switch (Path.GetExtension(_filepath).ToUpper())
53+
{
54+
case ".BIN":
55+
case ".GZ":
56+
foreach (var composites in CommandsBIN.EntityNames)
57+
foreach (var entities in composites.Value)
58+
Utils.SetEntityName(composites.Key, entities.Key, entities.Value);
59+
foreach (var others in CommandsBIN.ParameterNames)
60+
ShortGuidUtils.Generate(others.Value); // do we even need to do this?
61+
break;
62+
}
4463
}
4564

4665
public void ClearReferences()
@@ -63,12 +82,6 @@ public void ClearReferences()
6382
private ShortGuid[] _entryPoints = null;
6483
private Composite[] _entryPointObjects = null;
6584

66-
/// <summary>
67-
/// Set this value to true before initialising your Commands object to load with non-capitalised composite names.
68-
/// Changing this value AFTER loading will not make any difference to the loaded Commands object, only future ones.
69-
/// </summary>
70-
public static bool UsePrettyPaths = false;
71-
7285
/// <summary>
7386
/// Use this to access various utilities for dealing with Commands data.
7487
/// Additional metadata generated by these utils will write to your Commands file when saved.
@@ -78,29 +91,21 @@ public void ClearReferences()
7891
#region FILE_IO
7992
override protected bool LoadInternal(MemoryStream stream)
8093
{
81-
byte[] content = stream.ToArray();
94+
_compressed = _filepath != null && _filepath != "" && Path.GetExtension(_filepath).ToLower() == ".gz";
95+
8296
switch (Path.GetExtension(_filepath).ToUpper())
8397
{
8498
case ".PAK":
8599
CommandsPAK.Read(stream, out _entryPoints, out Entries, _envAnims, _colMaps, _reds);
86100
break;
101+
case ".GZ":
87102
case ".BIN":
88-
CommandsBIN.Read(stream, out _entryPoints, out Entries, _envAnims, _colMaps, _reds);
103+
CommandsBIN.Read(_compressed ? Utilities.GZIPDecompress(stream) : stream, out _entryPoints, out Entries, _envAnims, _colMaps, _reds);
89104
break;
90105
default:
91106
return false;
92107
}
93108

94-
if (UsePrettyPaths)
95-
{
96-
foreach (Composite composite in Entries)
97-
{
98-
string prettyPath = CustomTable.Vanilla.CompositePaths.GetPrettyPath(composite.shortGUID);
99-
if (prettyPath != "") composite.name = prettyPath;
100-
composite.name = composite.name.Replace("/", "\\");
101-
}
102-
}
103-
104109
return true;
105110
}
106111

@@ -110,6 +115,11 @@ override protected bool SaveInternal()
110115
if (Entries.Count == 0) return false;
111116
if (_entryPoints == null) _entryPoints = new ShortGuid[3];
112117

118+
if (_compressed && Path.GetExtension(_filepath).ToLower() != ".gz")
119+
_filepath += ".gz";
120+
else if (!_compressed && Path.GetExtension(_filepath).ToLower() == ".gz")
121+
_filepath = _filepath.Substring(0, _filepath.Length - 3);
122+
113123
#region FIX_POTENTIAL_ERRORS
114124
//If we have composites but the entry points are broken, correct them first!
115125
if (GetComposite(_entryPoints[2]) == null)
@@ -228,17 +238,24 @@ override protected bool SaveInternal()
228238
case ".PAK":
229239
CommandsPAK.Write(_entryPoints, Entries, out content, _envAnims, _colMaps, _reds);
230240
break;
241+
case ".GZ":
231242
case ".BIN":
232243
CommandsBIN.Write(_entryPoints, Entries, out content, _envAnims, _colMaps, _reds);
233244
break;
234245
default:
235246
return false;
236247
}
237-
using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(_filepath)))
248+
249+
using (Stream stream = File.OpenWrite(_filepath))
250+
using (BinaryWriter writer = new BinaryWriter(stream))
238251
{
239252
writer.BaseStream.SetLength(0);
240253
writer.Write(content);
241254
}
255+
256+
if (_compressed)
257+
Utilities.GZIPCompress(_filepath);
258+
242259
return true;
243260
}
244261
#endregion

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CATHODE.Scripting.Internal;
2+
using CathodeLib;
23
using System;
34
using System.Collections.Generic;
45
using System.Data;

CathodeLib/Scripts/CATHODE/Commands/Components/TypeEnums.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Text;
44

@@ -1197,6 +1197,8 @@ public enum CustomTableType
11971197
CATHODE_ENUM_INFO, // Database of available Cathode enums
11981198
COMPOSITE_PATHS, // Full properly-cased paths for vanilla composites
11991199
COMPOSITE_PAGE_HISTORY, // Stores the previously opened flowgraph page for a composite
1200+
FLAGS, // A table of generic flags that can store level modification metadata
1201+
MATERIAL_MAPPINGS, // Stores material mappings to populate as parameters or aliases
12001202

12011203
//Add new entries here
12021204

@@ -1211,5 +1213,6 @@ public enum CustomTableFileType
12111213
COMMANDS_PAK,
12121214
COMMANDS_BIN,
12131215
STANDALONE,
1216+
COMMANDS_COMPRESSED,
12141217
}
12151218
}

0 commit comments

Comments
 (0)