Skip to content

Commit cee228a

Browse files
committed
Merge branch 'hotfix'
2 parents 2098538 + b7ffb0f commit cee228a

5 files changed

Lines changed: 31 additions & 22 deletions

File tree

CathodeLib/CathodeLib.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
<PackageId>CathodeLib</PackageId>
1010
<Authors>Matt Filer</Authors>
1111
<Description>Provides support for parsing and writing common Alien: Isolation formats from the Cathode engine.</Description>
12-
<Copyright>Matt Filer 2024</Copyright>
13-
<Version>0.7.1</Version>
12+
<Copyright>Matt Filer 2025</Copyright>
13+
<Version>0.7.2</Version>
1414
<OutputType>Library</OutputType>
15-
<AssemblyVersion>0.7.1.0</AssemblyVersion>
16-
<FileVersion>0.7.1.0</FileVersion>
15+
<AssemblyVersion>0.7.2.0</AssemblyVersion>
16+
<FileVersion>0.7.2.0</FileVersion>
1717
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
1818
</PropertyGroup>
1919

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,13 @@ public object Clone()
106106
switch (dataType)
107107
{
108108
case DataType.RESOURCE:
109-
return Utilities.CloneObject(this);
110-
//HOTFIX FOR VECTOR 3 CLONE ISSUE - TODO: FIND WHY THIS ISN'T WORKING WITH MEMBERWISE CLONE
109+
cResource r = (cResource)this.MemberwiseClone();
110+
r.value = ((cResource)this).value.Select(item => (ResourceReference)item.Clone()).ToList();
111+
return r;
112+
case DataType.SPLINE:
113+
cSpline s = (cSpline)this.MemberwiseClone();
114+
s.splinePoints = ((cSpline)this).splinePoints.Select(item => (cTransform)item.Clone()).ToList();
115+
return s;
111116
case DataType.VECTOR:
112117
cVector3 v3 = (cVector3)this.MemberwiseClone();
113118
Vector3 v3_v = (Vector3)((cVector3)this).value;
@@ -132,7 +137,6 @@ public object Clone()
132137
tr.rotation = new Vector3(tr_r.X, tr_r.Y, tr_r.Z);
133138
#endif
134139
return tr;
135-
//END OF HOTFIX - SHOULD THIS ALSO APPLY TO OTHERS?? SPLINE?
136140
default:
137141
return this.MemberwiseClone();
138142
}

CathodeLib/Scripts/CATHODE/SoundBankData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace CATHODE
1313
/* DATA/ENV/PRODUCTION/x/WORLD/SOUNDBANKDATA.DAT */
1414
public class SoundBankData : CathodeFile
1515
{
16+
//NOTE: you can use Utilities.SoundHashedString to hash these strings and get the Wwise ID used in other places like SoundEventData
17+
1618
public List<string> Entries = new List<string>();
1719
public static new Implementation Implementation = Implementation.CREATE | Implementation.LOAD | Implementation.SAVE;
1820
public SoundBankData(string path) : base(path) { }

CathodeLib/Scripts/CATHODE/SoundEventData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ override protected bool SaveInternal()
7575
#region STRUCTURES
7676
public class Soundbank
7777
{
78-
public uint id;
78+
public uint id; //This is the hashed soundbank string name (hashed via Utilities.SoundHashedString)
7979
public List<Event> events = new List<Event>();
8080

8181
public class Event

CathodeLib/Scripts/Utilities.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
using System.Linq;
77
using System.Numerics;
88
using System.Runtime.InteropServices;
9-
using System.Runtime.Serialization.Formatters.Binary;
9+
using System.Runtime.Serialization.Formatters.Binary;
10+
using System.Text;
1011

1112
namespace CathodeLib
1213
{
@@ -183,19 +184,6 @@ public static void Write<T>(BinaryWriter stream, List<T> aux)
183184
Write<T>(stream, aux.ToArray<T>());
184185
}
185186

186-
//Clones an object (slow!)
187-
public static T CloneObject<T>(T obj)
188-
{
189-
//A somewhat hacky an inefficient way of deep cloning an object (TODO: optimise this as we use it a lot!)
190-
MemoryStream ms = new MemoryStream();
191-
new BinaryFormatter().Serialize(ms, obj);
192-
ms.Position = 0;
193-
T obj2 = (T)new BinaryFormatter().Deserialize(ms);
194-
ms.Close();
195-
return obj2;
196-
//obj.MemberwiseClone();
197-
}
198-
199187
//Generate a hashed string for use in the animation system (FNV hash)
200188
public static uint AnimationHashedString(string str)
201189
{
@@ -212,6 +200,21 @@ public static uint AnimationHashedString(string str)
212200
return hash;
213201
}
214202

203+
//Generate a hashed string for use in sound system (wwise FNV-1)
204+
public static uint SoundHashedString(string str)
205+
{
206+
byte[] namebytes = Encoding.UTF8.GetBytes(str.ToLower());
207+
uint hash = 2166136261;
208+
for (int i = 0; i < namebytes.Length; i++)
209+
{
210+
byte namebyte = namebytes[i];
211+
hash = hash * 16777619;
212+
hash = hash ^ namebyte;
213+
hash = hash & 0xFFFFFFFF;
214+
}
215+
return hash;
216+
}
217+
215218
//Read a PAK
216219
public static List<PAKContent> ReadPAK(string path, FileIdentifiers type)
217220
{

0 commit comments

Comments
 (0)