Skip to content

Commit b9a66cf

Browse files
committed
nicely handle entry point issues
1 parent 5118694 commit b9a66cf

4 files changed

Lines changed: 54 additions & 12 deletions

File tree

CathodeLib/Scripts/CATHODE/Commands.cs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,40 @@ public Commands(string path) : base(path) { }
3333
/* Save all changes back out */
3434
override public bool Save()
3535
{
36-
if (_entryPoints == null || _entryPoints[0].val == null)
37-
return false;
36+
//Validate entry points and composite count
37+
if (_composites.Count == 0) return false;
38+
if (_entryPoints == null) _entryPoints = new ShortGuid[3];
39+
if (_entryPoints[0].val == null && _entryPoints[1].val == null && _entryPoints[2].val == null && _composites.Count == 0) return false;
40+
41+
//If we have composites but the entry points are broken, correct them first!
42+
if (GetComposite(_entryPoints[2]) == null)
43+
{
44+
Composite pausemenu = GetComposite("PAUSEMENU");
45+
if (pausemenu == null)
46+
{
47+
Console.WriteLine("WARNING: PAUSEMENU composite does not exist! Creating blank placeholder.");
48+
pausemenu = AddComposite("PAUSEMENU");
49+
pausemenu.shortGUID = new ShortGuid("FE-7B-FE-B3");
50+
}
51+
_entryPoints[2] = pausemenu.shortGUID;
52+
}
53+
if (GetComposite(_entryPoints[1]) == null)
54+
{
55+
Composite global = GetComposite("GLOBAL");
56+
if (global == null)
57+
{
58+
Console.WriteLine("WARNING: GLOBAL composite does not exist! Creating blank placeholder. This may cause issues with GLOBAL references.");
59+
global = AddComposite("GLOBAL");
60+
global.shortGUID = new ShortGuid("1D-2E-CE-E5");
61+
}
62+
_entryPoints[1] = global.shortGUID;
63+
}
64+
if (GetComposite(_entryPoints[0]) == null)
65+
{
66+
Console.WriteLine("WARNING: Entry point was not set! Defaulting to composite at index zero.");
67+
_entryPoints[0] = _composites[0].shortGUID;
68+
}
69+
RefreshEntryPointObjects();
3870

3971
BinaryWriter writer = new BinaryWriter(File.OpenWrite(_filepath));
4072
writer.BaseStream.SetLength(0);
@@ -428,7 +460,7 @@ override public bool Save()
428460
break;
429461
case ResourceType.COLLISION_MAPPING:
430462
writer.Write(resourceReferences[p].startIndex);
431-
writer.Write(resourceReferences[p].entityID.val);
463+
writer.Write(resourceReferences[p].collisionID.val);
432464
break;
433465
case ResourceType.ANIMATED_MODEL:
434466
case ResourceType.DYNAMIC_PHYSICS_SYSTEM:
@@ -867,7 +899,7 @@ override protected bool Load()
867899
break;
868900
case ResourceType.COLLISION_MAPPING:
869901
resource.startIndex = reader.ReadInt32(); //COLLISION.MAP entry index?
870-
resource.entityID = new ShortGuid(reader); //ID which maps to the entity using the resource (?) - check GetFriendlyName
902+
resource.collisionID = new ShortGuid(reader); //ID which maps to *something*
871903
break;
872904
case ResourceType.ANIMATED_MODEL:
873905
case ResourceType.DYNAMIC_PHYSICS_SYSTEM:
@@ -1117,8 +1149,7 @@ public Composite[] EntryPoints
11171149
{
11181150
if (_entryPoints == null) return null;
11191151
if (_entryPointObjects != null) return _entryPointObjects;
1120-
_entryPointObjects = new Composite[_entryPoints.Length];
1121-
for (int i = 0; i < _entryPoints.Length; i++) _entryPointObjects[i] = GetComposite(_entryPoints[i]);
1152+
RefreshEntryPointObjects();
11221153
return _entryPointObjects;
11231154
}
11241155
}
@@ -1169,6 +1200,13 @@ private List<ParameterData> PruneParameterList(List<ParameterData> parameters)
11691200
}
11701201
return prunedList;
11711202
}
1203+
1204+
/* Refresh the composite pointers for our entry points */
1205+
private void RefreshEntryPointObjects()
1206+
{
1207+
_entryPointObjects = new Composite[_entryPoints.Length];
1208+
for (int i = 0; i < _entryPoints.Length; i++) _entryPointObjects[i] = GetComposite(_entryPoints[i]);
1209+
}
11721210
#endregion
11731211

11741212
/* -- */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public Composite(string name)
1818
{
1919
shortGUID = ShortGuidUtils.GenerateRandom();
2020
this.name = name;
21-
unknownPair = new OffsetPair(0, 0);
21+
unknownPair = new OffsetPair(5, 6); //TODO: what on earth this this?
2222
}
2323

2424
public ShortGuid shortGUID; //The id when this composite is used as an entity in another composite

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Diagnostics.SymbolStore;
1010
using System.Linq;
1111
using System.Runtime.InteropServices;
12+
using System.Xml.Linq;
1213

1314
namespace CATHODE.Scripting.Internal
1415
{
@@ -56,9 +57,12 @@ public Parameter GetParameter(ShortGuid id)
5657

5758
/* Add a data-supplying parameter to the entity */
5859
public Parameter AddParameter(string name, ParameterData data, ParameterVariant variant = ParameterVariant.PARAMETER)
60+
{
61+
return AddParameter(ShortGuidUtils.Generate(name), data, variant);
62+
}
63+
public Parameter AddParameter(ShortGuid id, ParameterData data, ParameterVariant variant = ParameterVariant.PARAMETER)
5964
{
6065
//TODO: we are limiting data-supplying params to ONE per entity here - is this correct? I think links are the only place where you can have multiple of the same.
61-
ShortGuid id = ShortGuidUtils.Generate(name);
6266
Parameter param = GetParameter(id);
6367
if (param == null)
6468
{

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public ResourceReference(ResourceType type)
3636
if (x.entryType != y.entryType) return false;
3737
if (x.startIndex != y.startIndex) return false;
3838
if (x.count != y.count) return false;
39-
if (x.entityID != y.entityID) return false;
39+
if (x.collisionID != y.collisionID) return false;
4040

4141
return true;
4242
}
@@ -59,7 +59,7 @@ public override bool Equals(object obj)
5959
entryType == reference.entryType &&
6060
startIndex == reference.startIndex &&
6161
count == reference.count &&
62-
EqualityComparer<ShortGuid>.Default.Equals(entityID, reference.entityID);
62+
EqualityComparer<ShortGuid>.Default.Equals(collisionID, reference.collisionID);
6363
}
6464

6565
public override int GetHashCode()
@@ -71,7 +71,7 @@ public override int GetHashCode()
7171
hashCode = hashCode * -1521134295 + entryType.GetHashCode();
7272
hashCode = hashCode * -1521134295 + startIndex.GetHashCode();
7373
hashCode = hashCode * -1521134295 + count.GetHashCode();
74-
hashCode = hashCode * -1521134295 + entityID.GetHashCode();
74+
hashCode = hashCode * -1521134295 + collisionID.GetHashCode();
7575
return hashCode;
7676
}
7777

@@ -84,6 +84,6 @@ public override int GetHashCode()
8484
public int startIndex = -1;
8585
public int count = 1;
8686

87-
public ShortGuid entityID = new ShortGuid("FF-FF-FF-FF");
87+
public ShortGuid collisionID = new ShortGuid("FF-FF-FF-FF");
8888
}
8989
}

0 commit comments

Comments
 (0)