Skip to content

Commit

Permalink
Clarify output when recompresed file is bigger than original, and add…
Browse files Browse the repository at this point in the history
… some removable debug strings.
  • Loading branch information
AdmiralCurtiss committed Aug 17, 2014
1 parent 6c48af3 commit 9215189
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static void Main( string[] args ) {
#endif
string newFilename = PatchFile( s );
Console.WriteLine( "Patched to " + newFilename + "!" );
Console.WriteLine();
#if DEBUG
#else
} catch ( Exception ex ) {
Expand Down Expand Up @@ -60,8 +61,6 @@ static string PatchFile( string filename ) {
PatchOverlay( nds, arm9overlayoff, arm9overlaylen );
PatchOverlay( nds, arm7overlayoff, arm7overlaylen );

Console.WriteLine();

nds.Close();

return newFilename;
Expand Down Expand Up @@ -120,6 +119,12 @@ static void PatchArm9( System.IO.FileStream nds, uint pos, uint len ) {
ReplaceInData( decData, 0x00, false );
data = blz.BLZ_Encode( decData, 0 );
newCompressedSize = (uint)data.Length;

int arm9diff = (int)len - (int)newCompressedSize;
if ( arm9diff < 0 ) {
Console.WriteLine( "WARNING: Recompressed ARM9 is " + -arm9diff + " bytes bigger than original!" );
Console.WriteLine( " Patched game may be corrupted!" );
}
}

if ( newCompressedSize != len ) {
Expand Down Expand Up @@ -262,18 +267,16 @@ static void PatchOverlay( System.IO.FileStream nds, uint pos, uint len ) {
diff = (int)overlaySize - newOverlaySize;

if ( diff < 0 ) {
Console.WriteLine( "WARNING: New file bigger than old one!" );
Console.WriteLine( "Attempting to recover by removing known debug strings!" );
Console.WriteLine( "Removing known debug strings and recompressing overlay " + id + "..." );
decData = RemoveDebugStrings( decData );
data = blz.BLZ_Encode( decData, 0 );
newCompressedSize = (uint)data.Length;

newOverlaySize = data.Length;
diff = (int)overlaySize - newOverlaySize;
if ( diff < 0 ) {
Console.WriteLine( "Recovery failed, this will probably not patch right!" );
} else {
Console.WriteLine( "Recovery successful." );
Console.WriteLine( "WARNING: Recompressed overlay is " + -diff + " bytes bigger than original!" );
Console.WriteLine( " Patched game may be corrupted!" );
}
}

Expand Down Expand Up @@ -317,6 +320,10 @@ static byte[] RemoveDebugStrings( byte[] data ) {
"recv buffer size",
"send buffer size",
"unknown connect mode",
"Split packet parse error",
"NULL byte expected!",
"Processing adderror packet",
"Out of memory.",
};

foreach ( string s in debugStrings ) {
Expand Down

0 comments on commit 9215189

Please sign in to comment.