Skip to content

Commit

Permalink
Avoid printing BLZ warnings multiple times.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiralCurtiss committed Nov 2, 2014
1 parent b8a8361 commit f90c449
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static bool PatchArm9( System.IO.FileStream nds, uint pos, uint len ) {
// new ARM is actually bigger, redo without the additional nullterm replacement
decData = decDataUnmodified;
ReplaceInData( decData, 0x00, false );
data = blz.BLZ_Encode( decData, 0 );
data = blz.BLZ_Encode( decData, 0, supressWarnings: true );
newCompressedSize = (uint)data.Length;

int arm9diff = (int)len - (int)newCompressedSize;
Expand All @@ -147,7 +147,7 @@ static bool PatchArm9( System.IO.FileStream nds, uint pos, uint len ) {
#if DEBUG
System.IO.File.WriteAllBytes( "arm9-dec-without-debug.bin", decData );
#endif
data = blz.BLZ_Encode( decData, 0 );
data = blz.BLZ_Encode( decData, 0, supressWarnings: true );
newCompressedSize = (uint)data.Length;

arm9diff = (int)len - (int)newCompressedSize;
Expand Down Expand Up @@ -327,7 +327,7 @@ static bool PatchOverlay( System.IO.FileStream nds, uint pos, uint len ) {
if ( diff < 0 ) {
Console.WriteLine( "Removing known debug strings and recompressing overlay " + id + "..." );
RemoveDebugStrings( decData );
data = blz.BLZ_Encode( decData, 0 );
data = blz.BLZ_Encode( decData, 0, supressWarnings: true );
newCompressedSize = (uint)data.Length;

newOverlaySize = data.Length;
Expand Down
20 changes: 12 additions & 8 deletions blz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public byte[] BLZ_Decode( byte[] pak_buffer ) {
}

//*----------------------------------------------------------------------------
public byte[] BLZ_Encode( byte[] raw_buffer, uint mode ) {
public byte[] BLZ_Encode( byte[] raw_buffer, uint mode, bool supressWarnings = false ) {
byte[] pak_buffer, new_buffer;
uint raw_len, pak_len, new_len;

Expand All @@ -267,7 +267,7 @@ public byte[] BLZ_Encode( byte[] raw_buffer, uint mode ) {
pak_buffer = null;
pak_len = BLZ_MAXIM + 1;

new_buffer = BLZ_Code(raw_buffer, raw_len, out new_len, mode);
new_buffer = BLZ_Code( raw_buffer, raw_len, out new_len, mode, supressWarnings );
if (new_len < pak_len) {
pak_buffer = new_buffer;
pak_len = new_len;
Expand Down Expand Up @@ -306,7 +306,7 @@ private void SEARCH(ref uint l, ref uint p, ref byte[] raw_buffer, ref uint raw,
}
}
//*----------------------------------------------------------------------------
byte[] BLZ_Code( byte[] raw_buffer, uint raw_len, out uint new_len, uint best ) {
byte[] BLZ_Code( byte[] raw_buffer, uint raw_len, out uint new_len, uint best, bool supressWarnings = false ) {
byte[] pak_buffer;
uint pak, raw, raw_end, flg = 0;
byte[] tmp;
Expand All @@ -325,7 +325,9 @@ byte[] BLZ_Code( byte[] raw_buffer, uint raw_len, out uint new_len, uint best )
raw_new = raw_len;
if (arm9 != 0) {
if (raw_len < 0x4000) {
Console.Write(", WARNING: ARM9 must be greater as 16KB, switch [9] disabled");
if ( !supressWarnings ) {
Console.WriteLine( "WARNING: ARM9 must be greater than 16KB, switch [9] disabled" );
}
//} else if (
// BitConverter.ToUInt32(raw_buffer, 0x0) != 0xE7FFDEFFu ||
// BitConverter.ToUInt32(raw_buffer, 0x4) != 0xE7FFDEFFu ||
Expand All @@ -339,10 +341,12 @@ byte[] BLZ_Code( byte[] raw_buffer, uint raw_len, out uint new_len, uint best )
crc = BLZ_CRC16(raw_buffer, 0x10, 0x07F0);
byte[] crcbytes = BitConverter.GetBytes( crc );
if (!(raw_buffer[0x0E] == crcbytes[0] && raw_buffer[0x0F] == crcbytes[1])) {
Console.WriteLine( "NOTICE: CRC16 Secure Area 2KB do not match" );
Console.WriteLine( " This may be indicative of a bad dump." );
Console.WriteLine( " If you're patching a modified ROM, such as a hack or" );
Console.WriteLine( " fan-translation, you can safely ignore this." );
if ( !supressWarnings ) {
Console.WriteLine( "NOTICE: CRC16 Secure Area 2KB do not match" );
Console.WriteLine( " This may be indicative of a bad dump." );
Console.WriteLine( " If you're patching a modified ROM, such as a hack or" );
Console.WriteLine( " fan-translation, you can safely ignore this." );
}
raw_buffer[0x0E] = crcbytes[0];
raw_buffer[0x0F] = crcbytes[1];
}
Expand Down

0 comments on commit f90c449

Please sign in to comment.