From f90c4491c287d2fc2cf2b3e114dd109469a3bf03 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 2 Nov 2014 16:56:41 +0100 Subject: [PATCH] Avoid printing BLZ warnings multiple times. --- Program.cs | 6 +++--- blz.cs | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Program.cs b/Program.cs index d4099b4..7186cec 100644 --- a/Program.cs +++ b/Program.cs @@ -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; @@ -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; @@ -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; diff --git a/blz.cs b/blz.cs index 2a55646..c8a41e2 100644 --- a/blz.cs +++ b/blz.cs @@ -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; @@ -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; @@ -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; @@ -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 || @@ -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]; }