Skip to content

Commit de2174e

Browse files
committed
Merge branch 'staging'
2 parents c1bd41d + f9597a5 commit de2174e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1347
-831
lines changed

AlienBML

CathodeLib/CathodeLib.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
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 2025</Copyright>
13-
<Version>0.9.1</Version>
13+
<Version>0.10.0</Version>
1414
<OutputType>Library</OutputType>
15-
<AssemblyVersion>0.9.1.0</AssemblyVersion>
16-
<FileVersion>0.9.1.0</FileVersion>
15+
<AssemblyVersion>0.10.0.0</AssemblyVersion>
16+
<FileVersion>0.10.0.0</FileVersion>
1717
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
1818
<PackageReadmeFile>README.md</PackageReadmeFile>
1919
<PackageTags>alien, modding, alien isolation, mod tool, file utility</PackageTags>

CathodeLib/Resources/info.dat

-254 KB
Binary file not shown.

CathodeLib/Scripts/Base Classes/CathodeFile.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,39 @@ public CathodeFile(string filepath)
2727
_loaded = Load();
2828
}
2929

30+
public CathodeFile(MemoryStream stream, string virtualPath = "")
31+
{
32+
_filepath = virtualPath;
33+
_loaded = Load(stream);
34+
}
35+
36+
public CathodeFile(byte[] data, string virtualPath = "")
37+
{
38+
_filepath = virtualPath;
39+
using (var stream = new MemoryStream(data))
40+
{
41+
_loaded = Load(stream);
42+
}
43+
}
44+
3045
#region EXTERNAL_FUNCS
3146
/* Try and load the file, if it exists */
32-
private bool Load()
47+
protected bool Load()
48+
{
49+
return Load(File.Exists(_filepath) ? new MemoryStream(File.ReadAllBytes(_filepath)) : null);
50+
}
51+
52+
/* Load from MemoryStream */
53+
protected bool Load(MemoryStream stream)
3354
{
3455
OnLoadBegin?.Invoke(_filepath);
35-
if (!File.Exists(_filepath)) return false;
56+
if (stream == null || stream.Length == 0) return false;
3657

3758
#if !CATHODE_FAIL_HARD
3859
try
3960
{
4061
#endif
41-
if (LoadInternal())
62+
if (LoadInternal(stream))
4263
{
4364
OnLoadSuccess?.Invoke(_filepath);
4465
return true;
@@ -57,6 +78,7 @@ private bool Load()
5778
public bool Save()
5879
{
5980
OnSaveBegin?.Invoke(_filepath);
81+
if (_filepath == "") return false;
6082

6183
#if !CATHODE_FAIL_HARD
6284
try
@@ -90,7 +112,7 @@ public bool Save(string path = "", bool updatePath = true)
90112

91113
#region TO_OVERRIDE
92114
/* Virtual function to override in inherited classes for loading the file */
93-
protected virtual bool LoadInternal()
115+
protected virtual bool LoadInternal(MemoryStream stream)
94116
{
95117
Console.WriteLine("WARNING: This class does not implement loading functionality!");
96118
return false;

CathodeLib/Scripts/CATHODE/AlphaLightLevel.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ namespace CATHODE
1515
public class AlphaLightLevel : CathodeFile
1616
{
1717
public static new Implementation Implementation = Implementation.CREATE | Implementation.LOAD | Implementation.SAVE;
18+
1819
public AlphaLightLevel(string path) : base(path) { }
20+
public AlphaLightLevel(MemoryStream stream, string path = "") : base(stream, path) { }
21+
public AlphaLightLevel(byte[] data, string path = "") : base(data, path) { }
1922

2023
public Vector2 Resolution;
2124
public byte[] ImageData; // this is in A16B16G16R16F format
2225

2326
#region FILE_IO
24-
override protected bool LoadInternal()
27+
override protected bool LoadInternal(MemoryStream stream)
2528
{
26-
using (BinaryReader reader = new BinaryReader(File.OpenRead(_filepath)))
29+
using (BinaryReader reader = new BinaryReader(stream))
2730
{
2831
reader.BaseStream.Position += 8;
2932
Resolution = new Vector2(reader.ReadInt32(), reader.ReadInt32());

CathodeLib/Scripts/CATHODE/AnimClipDB.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ public class AnimClipDB : CathodeFile
1616
{
1717
public Dictionary<uint, string> Entries = new Dictionary<uint, string>();
1818
public static new Implementation Implementation = Implementation.LOAD;
19+
1920
public AnimClipDB(string path) : base(path) { }
21+
public AnimClipDB(MemoryStream stream, string path = "") : base(stream, path) { }
22+
public AnimClipDB(byte[] data, string path = "") : base(data, path) { }
2023

2124
#region FILE_IO
22-
override protected bool LoadInternal()
25+
override protected bool LoadInternal(MemoryStream stream)
2326
{
24-
using (BinaryReader reader = new BinaryReader(File.OpenRead(_filepath)))
27+
using (BinaryReader reader = new BinaryReader(stream))
2528
{
2629
int EntryCount1 = reader.ReadInt32();
2730
int EntryCount2 = reader.ReadInt32();

CathodeLib/Scripts/CATHODE/AnimationStrings.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,28 @@ public class AnimationStrings : CathodeFile
1414
{
1515
public Dictionary<uint, string> Entries = new Dictionary<uint, string>();
1616
public static new Implementation Implementation = Implementation.CREATE | Implementation.LOAD | Implementation.SAVE;
17+
1718
public AnimationStrings(string path) : base(path) { }
19+
public AnimationStrings(MemoryStream stream, string path = "") : base(stream, path) { }
20+
public AnimationStrings(byte[] data, string path = "") : base(data, path) { }
1821

1922
#region FILE_IO
20-
override protected bool LoadInternal()
23+
override protected bool LoadInternal(MemoryStream stream)
2124
{
22-
using (BinaryReader reader = new BinaryReader(File.OpenRead(_filepath)))
25+
using (BinaryReader reader = new BinaryReader(stream))
2326
{
24-
//Read all data in
25-
int EntryCount = reader.ReadInt32();
26-
int StringCount = reader.ReadInt32();
27-
Entry[] entries = Utilities.ConsumeArray<Entry>(reader, EntryCount);
28-
int[] stringOffsets = Utilities.ConsumeArray<int>(reader, StringCount);
29-
List<string> strings = new List<string>();
30-
for (int i = 0; i < StringCount; i++) strings.Add(Utilities.ReadString(reader));
27+
int entryCount = reader.ReadInt32();
28+
int stringCount = reader.ReadInt32();
29+
Entry[] entries = Utilities.ConsumeArray<Entry>(reader, entryCount);
30+
int[] stringOffsets = Utilities.ConsumeArray<int>(reader, stringCount);
3131

32-
//Parse
33-
for (int i = 0; i < entries.Length; i++) Entries.Add(entries[i].StringID, strings[entries[i].StringIndex]);
34-
//TODO: encoding on a couple strings here is wrong
32+
int baseline = (entryCount * 4 * 2) + 8 + (stringCount * 4);
33+
34+
List<string> strings = new List<string>();
35+
for (int i = 0; i < stringCount; i++)
36+
strings.Add(Utilities.ReadString(reader, stringOffsets[i] + baseline, false));
37+
for (int i = 0; i < entries.Length; i++)
38+
Entries.Add(entries[i].StringID, strings[entries[i].StringIndex]);
3539
}
3640
return true;
3741
}

CathodeLib/Scripts/CATHODE/CharacterAccessorySets.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ public class CharacterAccessorySets : CathodeFile
1313
{
1414
public List<CharacterAttributes> Entries = new List<CharacterAttributes>();
1515
public static new Implementation Implementation = Implementation.CREATE | Implementation.LOAD | Implementation.SAVE;
16+
1617
public CharacterAccessorySets(string path) : base(path) { }
18+
public CharacterAccessorySets(MemoryStream stream, string path = "") : base(stream, path) { }
19+
public CharacterAccessorySets(byte[] data, string path = "") : base(data, path) { }
1720

1821
#region FILE_IO
19-
override protected bool LoadInternal()
22+
override protected bool LoadInternal(MemoryStream stream)
2023
{
21-
using (BinaryReader reader = new BinaryReader(File.OpenRead(_filepath)))
24+
using (BinaryReader reader = new BinaryReader(stream))
2225
{
2326
reader.BaseStream.Position = 4;
2427
int entryCount = reader.ReadInt32();

CathodeLib/Scripts/CATHODE/CollisionMaps.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ public class CollisionMaps : CathodeFile
1515
{
1616
public List<Entry> Entries = new List<Entry>();
1717
public static new Implementation Implementation = Implementation.CREATE | Implementation.LOAD | Implementation.SAVE;
18+
1819
public CollisionMaps(string path) : base(path) { }
20+
public CollisionMaps(MemoryStream stream, string path = "") : base(stream, path) { }
21+
public CollisionMaps(byte[] data, string path = "") : base(data, path) { }
1922

2023
#region FILE_IO
21-
override protected bool LoadInternal()
24+
override protected bool LoadInternal(MemoryStream stream)
2225
{
2326
int minUnk1 = 0;
2427
int minUnk2 = 0;
@@ -27,7 +30,7 @@ override protected bool LoadInternal()
2730
List<int> flags = new List<int>();
2831
Dictionary<string, List<string>> dictest = new Dictionary<string, List<string>>();
2932

30-
using (BinaryReader reader = new BinaryReader(File.OpenRead(_filepath)))
33+
using (BinaryReader reader = new BinaryReader(stream))
3134
{
3235
//The way this works:
3336
// - First 18 entries are empty

CathodeLib/Scripts/CATHODE/Collisions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ public class Collisions : CathodeFile
2121
{
2222
public List<WeightedCollision> Entries = new List<WeightedCollision>();
2323
public static new Implementation Implementation = Implementation.CREATE | Implementation.LOAD | Implementation.SAVE;
24+
2425
public Collisions(string path) : base(path) { }
26+
public Collisions(MemoryStream stream, string path = "") : base(stream, path) { }
27+
public Collisions(byte[] data, string path = "") : base(data, path) { }
2528

2629
#region FILE_IO
27-
override protected bool LoadInternal()
30+
override protected bool LoadInternal(MemoryStream stream)
2831
{
29-
using (var reader = new BinaryReader(File.OpenRead(_filepath)))
32+
using (var reader = new BinaryReader(stream))
3033
{
3134
//remove these if exceptions dont throw
3235
byte[] magic = reader.ReadBytes(4);

0 commit comments

Comments
 (0)