@@ -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 /* -- */
0 commit comments