@@ -39,6 +39,8 @@ public class Package
3939 public uint reserved1 = 0x00 ;
4040 public uint reserved2 = 0x00 ;
4141
42+ uint MSKindexversion = 0x00 ;
43+
4244 public List < IndexEntry > IndexEntries = new List < IndexEntry > ( ) ;
4345 public ulong indexnumberofentries = 0x00 ;
4446
@@ -203,9 +205,9 @@ public void LoadPackage()
203205 }
204206 else //MySims and MySims Kingdom use these
205207 {
206- uint indexversion = reader . ReadUInt32 ( ) ;
208+ MSKindexversion = reader . ReadUInt32 ( ) ;
207209
208- if ( indexversion == 0 )
210+ if ( MSKindexversion == 0 )
209211 {
210212 Console . WriteLine ( "index version 0" ) ;
211213 for ( uint i = 0 ; i < filecount ; i ++ )
@@ -228,12 +230,12 @@ public void LoadPackage()
228230 subfiles . Add ( newSubfile ) ;
229231 }
230232 }
231- else if ( indexversion == 1 )
233+ else if ( MSKindexversion == 1 )
232234 {
233235 MessageBox . Show ( "Index version 1 not implemented!" ) ;
234236
235237 }
236- else if ( indexversion == 2 )
238+ else if ( MSKindexversion == 2 )
237239 {
238240 Console . WriteLine ( "index version 2" ) ;
239241
@@ -259,7 +261,7 @@ public void LoadPackage()
259261 subfiles . Add ( newSubfile ) ;
260262 }
261263 }
262- else if ( indexversion == 3 )
264+ else if ( MSKindexversion == 3 )
263265 {
264266 Console . WriteLine ( "index version 3" ) ;
265267 uint allFilesTypeID = reader . ReadUInt32 ( ) ;
@@ -284,7 +286,7 @@ public void LoadPackage()
284286 subfiles . Add ( newSubfile ) ;
285287 }
286288 }
287- if ( indexversion == 4 )
289+ if ( MSKindexversion == 4 )
288290 {
289291 Console . WriteLine ( "index version 4" ) ;
290292 reader . BaseStream . Position += 4 ;
@@ -309,7 +311,7 @@ public void LoadPackage()
309311 }
310312 else
311313 {
312- MessageBox . Show ( "Unknown index version: " + indexversion ) ;
314+ MessageBox . Show ( "Unknown index version: " + MSKindexversion ) ;
313315 return ;
314316 }
315317 }
@@ -787,6 +789,141 @@ public void LoadSkyHeroesPackage()
787789 }
788790
789791 MessageBox . Show ( "Files extracted. They are in the same folder as the original archive." , "Extraction complete" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
792+ }
793+
794+
795+ public uint ReverseEndianIfNeeded ( uint input ) {
796+ if ( packageType == PackageType . Agents )
797+ {
798+ input = utility . ReverseEndian ( input ) ;
799+ }
800+ return input ;
801+ }
802+
803+
804+ public void RebuildPackage ( )
805+ {
806+
807+ List < byte > output = new List < byte > ( ) ;
808+
809+ uint packageVersion = 0 ;
810+
811+ if ( packageType == PackageType . Kingdom )
812+ {
813+ output . Add ( ( byte ) 'D' ) ;
814+ output . Add ( ( byte ) 'B' ) ;
815+ output . Add ( ( byte ) 'P' ) ;
816+ output . Add ( ( byte ) 'F' ) ;
817+ packageVersion = 2 ;
818+ }
819+ else if ( packageType == PackageType . Agents )
820+ {
821+ output . Add ( ( byte ) 'F' ) ;
822+ output . Add ( ( byte ) 'P' ) ;
823+ output . Add ( ( byte ) 'B' ) ;
824+ output . Add ( ( byte ) 'D' ) ;
825+ packageVersion = 3 ;
826+ }
827+
828+ //offset 0x04
829+
830+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( packageVersion ) ) ;
831+
832+ //offset 0x08
833+
834+ for ( int i = 0 ; i < 0x10 ; i ++ )
835+ {
836+ output . Add ( 0x00 ) ;
837+ }
838+
839+ //offset 0x18
840+
841+ if ( packageType == PackageType . Kingdom )
842+ {
843+ for ( int i = 0 ; i < 8 ; i ++ )
844+ {
845+ output . Add ( 0x00 ) ; //pad
846+ }
847+ }
848+ else if ( packageType == PackageType . Agents )
849+ {
850+ utility . AddLongToList ( output , utility . ReverseEndianLong ( DateTime . Now . ToBinary ( ) ) ) ;
851+ }
852+
853+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( indexmajorversion ) ) ;
854+
855+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( filecount ) ) ;
856+
857+ //offset 0x28
858+
859+ if ( packageType == PackageType . Kingdom )
860+ {
861+ for ( int i = 0 ; i < 4 ; i ++ )
862+ {
863+ output . Add ( 0x00 ) ; //pad
864+ }
865+ }
866+ else if ( packageType == PackageType . Agents )
867+ {
868+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( indexoffset ) ) ; //this will be returned to later once we know what it is
869+ }
870+
871+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( indexsize ) ) ; //this will be returned to later once we know what it is
872+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( holeentrycount ) ) ;
873+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( holeoffset ) ) ;
874+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( holesize ) ) ;
875+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( indexminorversion ) ) ;
876+
877+ if ( packageType == PackageType . Agents )
878+ {
879+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( unknown4 ) ) ;
880+ }
881+
882+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( indexoffset ) ) ; //this will be returned to later once we know what it is
883+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( unknown5 ) ) ;
884+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( unknown6 ) ) ;
885+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( reserved1 ) ) ;
886+ utility . AddUIntToList ( output , ReverseEndianIfNeeded ( reserved2 ) ) ;
887+
888+ while ( output . Count < 0x60 )
889+ {
890+ output . Add ( 0x00 ) ;
891+ }
892+
893+ //=====================================================================================
894+ //ACTUALLY, ISN'T IT ORGANISED BY TYPE ID? (IN MSA, AT LEAST?) THAT MIGHT BE IMPORTANT
895+ //and then, within a type id, it's alphabetical
896+ //=====================================================================================
897+
898+ foreach ( Subfile f in subfiles )
899+ {
900+ if ( f . filebytes == null || f . filebytes . Length == 0 ) //then the file was not modified or read, so transfer it directly from the old package
901+ {
902+ for ( int i = 0 ; i < f . filesize ; i ++ )
903+ {
904+ output . Add ( filebytes [ f . fileoffset + i ] ) ;
905+ }
906+ }
907+ else //if it was modified or read, use the bytes from its filebytes array
908+ {
909+ for ( int i = 0 ; i < f . filebytes . Length ; i ++ )
910+ {
911+ output . Add ( f . filebytes [ i ] ) ;
912+ }
913+ }
914+ }
915+
916+ //that should bring us up to the start of the index table
917+
918+ //=====================================================================================
919+ //ACTUALLY, ISN'T IT ORGANISED BY TYPE ID? (IN MSA, AT LEAST?) THAT MIGHT BE IMPORTANT.
920+ //and then, within a type id, it's alphabetical
921+ //=====================================================================================
922+
923+
924+
925+
926+
790927 }
791928 }
792929
0 commit comments