Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFiler committed Apr 24, 2023
2 parents 0b89d0d + bccf9a2 commit b677520
Show file tree
Hide file tree
Showing 27 changed files with 8,082 additions and 6,334 deletions.
6 changes: 3 additions & 3 deletions CathodeLib/CathodeLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<Authors>Matt Filer</Authors>
<Description>Provides support for parsing and writing common Alien: Isolation formats from the Cathode engine.</Description>
<Copyright>Matt Filer 2023</Copyright>
<Version>0.4.0</Version>
<Version>0.5.0</Version>
<OutputType>Library</OutputType>
<AssemblyVersion>0.4.0.0</AssemblyVersion>
<FileVersion>0.4.0.0</FileVersion>
<AssemblyVersion>0.5.0.0</AssemblyVersion>
<FileVersion>0.5.0.0</FileVersion>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
Binary file modified CathodeLib/Resources/NodeDBs/cathode_enum_lut.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion CathodeLib/Scripts/CATHODE/AnimationStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace CATHODE
/* DATA/GLOBAL/ANIMATION.PAK -> ANIM_STRING_DB.BIN, ANIM_STRING_DB_DEBUG.BIN */
public class AnimationStrings : CathodeFile
{
private Dictionary<uint, string> Entries = new Dictionary<uint, string>();
public Dictionary<uint, string> Entries = new Dictionary<uint, string>();
public static new Implementation Implementation = Implementation.CREATE | Implementation.LOAD | Implementation.SAVE;
public AnimationStrings(string path) : base(path) { }

Expand Down
5 changes: 1 addition & 4 deletions CathodeLib/Scripts/CATHODE/Collisions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CathodeLib;
using CathodeLib;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -93,9 +93,6 @@ override protected bool LoadInternal()
Entry1.Vertices = vertexes.GetRange(verIndex, verIndex + Entry1.VertexCount);
}
}

//string dsfdsfds = "";

}
return true;
}
Expand Down
298 changes: 170 additions & 128 deletions CathodeLib/Scripts/CATHODE/Commands.cs

Large diffs are not rendered by default.

230 changes: 166 additions & 64 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
using CATHODE.Scripting.Internal;
#if DEBUG
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
#endif
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.InteropServices;
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
using UnityEngine;
#else
using System.Numerics;
#endif

namespace CATHODE.Scripting.Internal
{
Expand All @@ -22,6 +32,9 @@ public Entity(ShortGuid shortGUID, EntityVariant variant)
}

public ShortGuid shortGUID; //Translates to string via EntityNameLookup.GetEntityName
#if DEBUG
[JsonConverter(typeof(StringEnumConverter))]
#endif
public EntityVariant variant;

public List<EntityLink> childLinks = new List<EntityLink>();
Expand Down Expand Up @@ -190,6 +203,9 @@ public VariableEntity(ShortGuid shortGUID, string parameter, DataType type, bool
}

public ShortGuid name;
#if DEBUG
[JsonConverter(typeof(StringEnumConverter))]
#endif
public DataType type = DataType.NONE;

public override string ToString()
Expand Down Expand Up @@ -280,31 +296,19 @@ public ProxyEntity(ShortGuid shortGUID) : base(shortGUID, EntityVariant.PROXY) {
public ProxyEntity(List<ShortGuid> hierarchy = null, ShortGuid targetType = new ShortGuid(), bool autoGenerateParameters = false) : base(EntityVariant.PROXY)
{
this.targetType = targetType;
if (hierarchy != null) this.hierarchy = hierarchy;
if (autoGenerateParameters) ApplyDefaults();
if (hierarchy != null) this.connectedEntity.hierarchy = hierarchy;
if (autoGenerateParameters) EntityUtils.ApplyDefaults(this);
}
public ProxyEntity(ShortGuid shortGUID, List<ShortGuid> hierarchy = null, ShortGuid targetType = new ShortGuid(), bool autoGenerateParameters = false) : base(shortGUID, EntityVariant.PROXY)
{
this.shortGUID = shortGUID;
this.targetType = targetType;
if (hierarchy != null) this.hierarchy = hierarchy;
if (autoGenerateParameters) ApplyDefaults();
if (hierarchy != null) this.connectedEntity.hierarchy = hierarchy;
if (autoGenerateParameters) EntityUtils.ApplyDefaults(this);
}

public ShortGuid targetType; //The "function" value on the entity we're pointing to
public List<ShortGuid> hierarchy = new List<ShortGuid>();

private void ApplyDefaults()
{
AddParameter("proxy_filter_targets", new cBool(false));
AddParameter("proxy_enable_on_reset", new cBool(false));
AddParameter("proxy_enable", new cFloat(0.0f));
AddParameter("proxy_enabled", new cFloat(0.0f));
AddParameter("proxy_disable", new cFloat(0.0f));
AddParameter("proxy_disabled", new cFloat(0.0f));
AddParameter("reference", new cString(""));
AddParameter("trigger", new cFloat(0.0f));
}
public EntityHierarchy connectedEntity = new EntityHierarchy();
}
[Serializable]
public class OverrideEntity : Entity
Expand All @@ -315,17 +319,17 @@ public OverrideEntity(ShortGuid shortGUID) : base(shortGUID, EntityVariant.OVERR
public OverrideEntity(List<ShortGuid> hierarchy = null) : base(EntityVariant.OVERRIDE)
{
checksum = ShortGuidUtils.GenerateRandom();
if (hierarchy != null) this.hierarchy = hierarchy;
if (hierarchy != null) this.connectedEntity.hierarchy = hierarchy;
}
public OverrideEntity(ShortGuid shortGUID, List<ShortGuid> hierarchy = null) : base(shortGUID, EntityVariant.OVERRIDE)
{
this.shortGUID = shortGUID;
checksum = ShortGuidUtils.GenerateRandom();
if (hierarchy != null) this.hierarchy = hierarchy;
if (hierarchy != null) this.connectedEntity.hierarchy = hierarchy;
}

public ShortGuid checksum; //TODO: This value is apparently a hash of the hierarchy GUIDs, but need to verify that, and work out the salt.
public List<ShortGuid> hierarchy = new List<ShortGuid>();
public EntityHierarchy connectedEntity = new EntityHierarchy();
}

#region SPECIAL FUNCTION ENTITIES
Expand All @@ -335,63 +339,63 @@ public class CAGEAnimation : FunctionEntity
public CAGEAnimation(bool autoGenerateParameters = false) : base(FunctionType.CAGEAnimation, autoGenerateParameters) { }
public CAGEAnimation(ShortGuid id, bool autoGenerateParameters = false) : base(id, FunctionType.CAGEAnimation, autoGenerateParameters) { }

public List<Header> keyframeHeaders = new List<Header>();
public List<Keyframe> keyframeData = new List<Keyframe>(); //anim keyframes
public List<Keyframe2> keyframeData2 = new List<Keyframe2>(); //TODO: events?
public List<Connection> connections = new List<Connection>();
public List<Animation> animations = new List<Animation>();
public List<Event> events = new List<Event>();

[Serializable]
public class Header
public class Connection
{
public ShortGuid ID;
public DataType unk2;
public ShortGuid keyframeDataID;
//public float unk3;
public ShortGuid shortGUID; //Unique ID - TODO: can we just generate this?
public ShortGuid keyframeID; //The keyframe ID we're pointing to

#if DEBUG
[JsonConverter(typeof(StringEnumConverter))]
#endif
public ObjectType objectType; //The type of object at the connected entity

//Specifics for the parameter we're connected to
public ShortGuid parameterID;
public DataType parameterDataType;
#if DEBUG
[JsonConverter(typeof(StringEnumConverter))]
#endif
public DataType parameterDataType;
public ShortGuid parameterSubID; //if parameterID is position, this might be x for example
public List<ShortGuid> connectedEntity; //path to controlled entity

//The path to the connected entity which has the above parameter
public EntityHierarchy connectedEntity = new EntityHierarchy();
}

[Serializable]
public class Keyframe
public class Animation
{
public float minSeconds;
public float maxSeconds;
public ShortGuid ID;
public List<Data> keyframes = new List<Data>();
public ShortGuid shortGUID;
public List<Keyframe> keyframes = new List<Keyframe>();

[Serializable]
public class Data
public class Keyframe
{
public float unk1;
public float secondsSinceStart;
public float secondsSinceStartValidation;
public float paramValue;
public float unk2;
public float unk3;
public float unk4;
public float unk5;
public float secondsSinceStart = 0.0f;
public float paramValue = 0.0f;

public Vector2 startVelocity = new Vector2(1,0);
public Vector2 endVelocity = new Vector2(1, 0);
}
}

//TODO: what actually is this?
[Serializable]
public class Keyframe2
public class Event
{
public float minSeconds;
public float maxSeconds;
public ShortGuid ID;
public List<Data> keyframes = new List<Data>();
public ShortGuid shortGUID;
public List<Keyframe> keyframes = new List<Keyframe>();

[Serializable]
public class Data
public class Keyframe
{
public float unk1;
public float secondsSinceStart;
public float unk2;
public float unk3;
public float unk4;
public float unk5;
public float secondsSinceStart = 0.0f;
public ShortGuid start;

public ShortGuid unk3; //this never translates to a string, but is a param on the node -> do we trigger it?
}
}
}
Expand All @@ -407,14 +411,8 @@ public TriggerSequence(ShortGuid id, bool autoGenerateParameters = false) : base
[Serializable]
public class Entity
{
public Entity()
{
hierarchy = new List<ShortGuid>();
hierarchy.Add(new ShortGuid("00-00-00-00"));
}

public float timing = 0.0f;
public List<ShortGuid> hierarchy;
public EntityHierarchy connectedEntity = new EntityHierarchy();
}
[Serializable]
public class Event
Expand Down Expand Up @@ -451,4 +449,108 @@ public EntityLink(ShortGuid childEntityID, ShortGuid parentParam, ShortGuid chil
public ShortGuid childParamID; //The ID of the parameter we're providing into the child
public ShortGuid childID; //The ID of the entity we're linking to to provide the value for
}

[Serializable]
#if DEBUG
[JsonConverter(typeof(EntityHierarchyConverter))]
#endif
public class EntityHierarchy
{
public EntityHierarchy() { }
public EntityHierarchy(List<ShortGuid> _hierarchy)
{
hierarchy = _hierarchy;

if (hierarchy[hierarchy.Count - 1].ToByteString() != "00-00-00-00")
hierarchy.Add(new ShortGuid("00-00-00-00"));
}
public List<ShortGuid> hierarchy = new List<ShortGuid>();

public static bool operator ==(EntityHierarchy x, EntityHierarchy y)
{
if (ReferenceEquals(x, null)) return ReferenceEquals(y, null);
if (ReferenceEquals(y, null)) return ReferenceEquals(x, null);
if (x.hierarchy.Count != y.hierarchy.Count) return false;
for (int i = 0; i < x.hierarchy.Count; i++)
{
if (x.hierarchy[i].ToByteString() != y.hierarchy[i].ToByteString())
return false;
}
return true;
}
public static bool operator !=(EntityHierarchy x, EntityHierarchy y)
{
return !(x == y);
}

public override bool Equals(object obj)
{
return obj is EntityHierarchy hierarchy &&
EqualityComparer<List<ShortGuid>>.Default.Equals(this.hierarchy, hierarchy.hierarchy);
}

public override int GetHashCode()
{
return 218564712 + EqualityComparer<List<ShortGuid>>.Default.GetHashCode(hierarchy);
}

/* Get this hierarchy as a string */
public string GetHierarchyAsString()
{
string val = "";
for (int i = 0; i < hierarchy.Count; i++)
{
val += hierarchy[i].ToByteString();
if (i != hierarchy.Count - 1) val += " -> ";
}
return val;
}
public string GetHierarchyAsString(Commands commands, Composite composite, bool withIDs = true)
{
CommandsUtils.ResolveHierarchy(commands, composite, hierarchy, out Composite comp, out string str, withIDs);
return str;
}

public UInt32 ToUInt32()
{
UInt32 val = 0;
for (int i = 0; i < hierarchy.Count; i++) val += hierarchy[i].ToUInt32();
return val;
}

/* Get the entity this hierarchy points to */
public Entity GetPointedEntity(Commands commands, Composite composite)
{
return CommandsUtils.ResolveHierarchy(commands, composite, hierarchy, out Composite comp, out string str);
}

/* Does this hierarchy point to a valid entity? */
public bool IsHierarchyValid(Commands commands, Composite composite)
{
return GetPointedEntity(commands, composite) != null;
}
}

#if DEBUG
public class EntityHierarchyConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteValue(((EntityHierarchy)value).GetHierarchyAsString());
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
EntityHierarchy e = new EntityHierarchy();
List<string> vals = reader.Value.ToString().Split(new[] { " -> " }, StringSplitOptions.None).ToList();
for (int i = 0; i < vals.Count; i++) e.hierarchy.Add(new ShortGuid(vals[i]));
return e;
}

public override bool CanConvert(Type objectType)
{
return objectType == typeof(EntityHierarchy);
}
}
#endif
}
Loading

0 comments on commit b677520

Please sign in to comment.