Skip to content

Commit

Permalink
Merge branch 'without-unkown-fix' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFiler committed Jan 3, 2023
2 parents c9ff73b + 54a9fb5 commit 8924f84
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 48 deletions.
33 changes: 15 additions & 18 deletions CathodeLib/Scripts/CATHODE/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ override public bool Save()
writer.Write(0);

//Fix (& verify) entity-attached resource info
_composites = _composites.OrderBy(o => o.shortGUID.ToUInt32()).ToList<Composite>();
for (int i = 0; i < _composites.Count; i++)
{
List<ResourceReference> animatedModels = new List<ResourceReference>();
Expand Down Expand Up @@ -184,10 +185,10 @@ override public bool Save()
parameters = PruneParameterList(parameters);

//Write out parameters & track offsets
int[] parameterOffsets = new int[parameters.Count];
Dictionary<ParameterData, int> parameterOffsets = new Dictionary<ParameterData, int>();
for (int i = 0; i < parameters.Count; i++)
{
parameterOffsets[i] = (int)writer.BaseStream.Position / 4;
parameterOffsets.Add(parameters[i], (int)writer.BaseStream.Position / 4);
Utilities.Write<ShortGuid>(writer, CommandsUtils.GetDataTypeGUID(parameters[i].dataType));
switch (parameters[i].dataType)
{
Expand Down Expand Up @@ -343,21 +344,16 @@ override public bool Save()
foreach (Entity entityWithParam in entitiesWithParams)
{
offsetPairs.Add(new OffsetPair(writer.BaseStream.Position, entityWithParam.parameters.Count));

Dictionary<ShortGuid, int> paramsWithOffsets = new Dictionary<ShortGuid, int>();
for (int y = 0; y < entityWithParam.parameters.Count; y++)
paramsWithOffsets.Add(entityWithParam.parameters[y].shortGUID, parameterOffsets[entityWithParam.parameters[y].content]);
paramsWithOffsets = paramsWithOffsets.OrderBy(o => o.Value).ToDictionary(o => o.Key, o => o.Value);

foreach (KeyValuePair<ShortGuid, int> entry in paramsWithOffsets)
{
Utilities.Write<ShortGuid>(writer, entityWithParam.parameters[y].shortGUID);
//TODO: this is super slow! Find a better way to lookup parameter content offsets (precalculate a nicer structure)
int paramOffset = -1;
for (int z = 0; z < parameters.Count; z++)
{
if (parameters[z] == entityWithParam.parameters[y].content)
{
paramOffset = parameterOffsets[z];
break;
}
}
if (paramOffset == -1) throw new Exception("Error writing parameter offset. Could not find parameter content!");
writer.Write(paramOffset);
Utilities.Write<ShortGuid>(writer, entry.Key);
writer.Write(entry.Value);
}
}

Expand Down Expand Up @@ -643,14 +639,15 @@ override public bool Save()
if (x == 0) Utilities.Write<ShortGuid>(writer, _composites[i].shortGUID);
}

//Write function entity counts (TODO: these values still aren't correct!)
//Write function count (TODO: sometimes this count excludes some entities in the vanilla paks - why?)
writer.Write(_composites[i].functions.FindAll(o => CommandsUtils.FunctionTypeExists(o.function)).Count);
writer.Write(_composites[i].functions.Count);
writer.Write(_composites[i].functions.Count);
}

//Write out parameter offsets
int parameterOffsetPos = (int)writer.BaseStream.Position;
Utilities.Write<int>(writer, parameterOffsets);
foreach (KeyValuePair<ParameterData, int> offset in parameterOffsets)
writer.Write(offset.Value);

//Write out composite offsets
int compositeOffsetPos = (int)writer.BaseStream.Position;
Expand Down
11 changes: 8 additions & 3 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Composite.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CATHODE.Scripting.Internal;
using CATHODE.Scripting.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -72,9 +72,9 @@ public FunctionEntity AddFunction(string function, bool autopopulateParameters =
functions.Add(func);
return func;
}
public FunctionEntity AddFunction(Composite function, bool autopopulateParameters = false)
public FunctionEntity AddFunction(Composite composite, bool autopopulateParameters = false)
{
FunctionEntity func = new FunctionEntity(function.shortGUID, autopopulateParameters);
FunctionEntity func = new FunctionEntity(composite.shortGUID, autopopulateParameters);
functions.Add(func);
return func;
}
Expand All @@ -86,5 +86,10 @@ public VariableEntity AddVariable(string parameter, DataType type, bool addDefau
variables.Add(vari);
return vari;
}

public override string ToString()
{
return name;
}
}
}
10 changes: 10 additions & 0 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ private void AddDefaultParam()

public ShortGuid parameter; //Translates to string via ShortGuidUtils.FindString
public DataType type = DataType.NONE;

public override string ToString()
{
return parameter.ToString();
}
}
[Serializable]
public class FunctionEntity : Entity
Expand Down Expand Up @@ -259,6 +264,11 @@ public ResourceReference GetResource(ResourceType type)
{
return resources.FirstOrDefault(o => o.entryType == type);
}

public override string ToString()
{
return function.ToString();
}
}
[Serializable]
public class ProxyEntity : Entity
Expand Down
38 changes: 11 additions & 27 deletions CathodeLib/Scripts/CATHODE/CommandsPAK/Components/ParameterData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,43 +70,27 @@ public override int GetHashCode()
{
case DataType.TRANSFORM:
cTransform x_t = (cTransform)this;
return Convert.ToInt32(
x_t.rotation.x.ToString() + x_t.rotation.y.ToString() + x_t.rotation.z.ToString() +
x_t.position.x.ToString() + x_t.position.y.ToString() + x_t.position.z.ToString());
return x_t.position.GetHashCode() + x_t.rotation.GetHashCode();
case DataType.INTEGER:
return ((cInteger)this).value;
return ((cInteger)this).value.GetHashCode();
case DataType.STRING:
cString x_s = (cString)this;
string num = "";
for (int i = 0; i < x_s.value.Length; i++) num += ((int)x_s.value[i]).ToString();
return Convert.ToInt32(num);
return ((cString)this).value.GetHashCode();
case DataType.BOOL:
return ((cBool)this).value ? 1 : 0;
return ((cBool)this).value.GetHashCode();
case DataType.FLOAT:
return Convert.ToInt32(((cFloat)this).value.ToString().Replace(".", ""));
return ((cFloat)this).value.GetHashCode();
case DataType.RESOURCE:
string x_g_s = ((cString)this).value.ToString();
string num2 = "";
for (int i = 0; i < x_g_s.Length; i++) num2 += ((int)x_g_s[i]).ToString();
return Convert.ToInt32(num2);
return ((cResource)this).resourceID.GetHashCode();
case DataType.VECTOR:
cVector3 x_v = (cVector3)this;
return Convert.ToInt32(x_v.value.x.ToString() + x_v.value.y.ToString() + x_v.value.z.ToString());
return ((cVector3)this).value.GetHashCode();
case DataType.ENUM:
cEnum x_e = (cEnum)this;
string x_e_s = x_e.enumID.ToByteString();
string num3 = "";
for (int i = 0; i < x_e_s.Length; i++) num3 += ((int)x_e_s[i]).ToString();
return Convert.ToInt32(num3 + x_e.enumIndex.ToString());
return x_e.enumID.ToByteString().GetHashCode() + x_e.enumIndex;
case DataType.SPLINE:
cSpline x_sd = (cSpline)this;
string x_sd_s = "";
for (int i = 0; i < x_sd.splinePoints.Count; i++) x_sd_s += x_sd.splinePoints[i].position.GetHashCode().ToString();
ShortGuid x_sd_g = ShortGuidUtils.Generate(x_sd_s);
string x_sd_g_s = x_sd_g.ToByteString();
string num4 = "";
for (int i = 0; i < x_sd_g_s.Length; i++) num4 += ((int)x_sd_g_s[i]).ToString();
return Convert.ToInt32(num4);
int x_sd_i = 0;
for (int i = 0; i < x_sd.splinePoints.Count; i++) x_sd_i += x_sd.splinePoints[i].GetHashCode();
return x_sd_i;
default:
return -1;
}
Expand Down

0 comments on commit 8924f84

Please sign in to comment.