@@ -14,24 +14,28 @@ public class AnimationStrings : CathodeFile
1414 {
1515 public Dictionary < uint , string > Entries = new Dictionary < uint , string > ( ) ;
1616 public static new Implementation Implementation = Implementation . CREATE | Implementation . LOAD | Implementation . SAVE ;
17+
1718 public AnimationStrings ( string path ) : base ( path ) { }
19+ public AnimationStrings ( MemoryStream stream , string path = "" ) : base ( stream , path ) { }
20+ public AnimationStrings ( byte [ ] data , string path = "" ) : base ( data , path ) { }
1821
1922 #region FILE_IO
20- override protected bool LoadInternal ( )
23+ override protected bool LoadInternal ( MemoryStream stream )
2124 {
22- using ( BinaryReader reader = new BinaryReader ( File . OpenRead ( _filepath ) ) )
25+ using ( BinaryReader reader = new BinaryReader ( stream ) )
2326 {
24- //Read all data in
25- int EntryCount = reader . ReadInt32 ( ) ;
26- int StringCount = reader . ReadInt32 ( ) ;
27- Entry [ ] entries = Utilities . ConsumeArray < Entry > ( reader , EntryCount ) ;
28- int [ ] stringOffsets = Utilities . ConsumeArray < int > ( reader , StringCount ) ;
29- List < string > strings = new List < string > ( ) ;
30- for ( int i = 0 ; i < StringCount ; i ++ ) strings . Add ( Utilities . ReadString ( reader ) ) ;
27+ int entryCount = reader . ReadInt32 ( ) ;
28+ int stringCount = reader . ReadInt32 ( ) ;
29+ Entry [ ] entries = Utilities . ConsumeArray < Entry > ( reader , entryCount ) ;
30+ int [ ] stringOffsets = Utilities . ConsumeArray < int > ( reader , stringCount ) ;
3131
32- //Parse
33- for ( int i = 0 ; i < entries . Length ; i ++ ) Entries . Add ( entries [ i ] . StringID , strings [ entries [ i ] . StringIndex ] ) ;
34- //TODO: encoding on a couple strings here is wrong
32+ int baseline = ( entryCount * 4 * 2 ) + 8 + ( stringCount * 4 ) ;
33+
34+ List < string > strings = new List < string > ( ) ;
35+ for ( int i = 0 ; i < stringCount ; i ++ )
36+ strings . Add ( Utilities . ReadString ( reader , stringOffsets [ i ] + baseline , false ) ) ;
37+ for ( int i = 0 ; i < entries . Length ; i ++ )
38+ Entries . Add ( entries [ i ] . StringID , strings [ entries [ i ] . StringIndex ] ) ;
3539 }
3640 return true ;
3741 }
0 commit comments