mirror of https://github.com/zeldaret/oot.git
				
				
				
			Remove 0xFF padding from uncompressed ROMs (#1910)
* Remove 0xFF padding from uncompressed ROMs * Add comment about overdump contents * Update checksum in README * Reword comment
This commit is contained in:
		
							parent
							
								
									e7b1868d84
								
							
						
					
					
						commit
						01a5fa9a45
					
				| 
						 | 
				
			
			@ -29,7 +29,7 @@ The only build currently supported is Master Quest (Debug), but other versions a
 | 
			
		|||
 | 
			
		||||
It builds the following ROM:
 | 
			
		||||
 | 
			
		||||
* oot-gc-eu-mq-dbg.z64 `md5: f0b7f35375f9cc8ca1b2d59d78e35405`
 | 
			
		||||
* oot-gc-eu-mq-dbg.z64 `md5: 75e344f41c26ec2ec5ad92caa9e25629`
 | 
			
		||||
 | 
			
		||||
**Note: This repository does not include any of the assets necessary to build the ROM. A prior copy of the game is required to extract the needed assets.**
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
f0b7f35375f9cc8ca1b2d59d78e35405  build/gc-eu-mq-dbg/oot-gc-eu-mq-dbg.z64
 | 
			
		||||
75e344f41c26ec2ec5ad92caa9e25629  build/gc-eu-mq-dbg/oot-gc-eu-mq-dbg.z64
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1 +1 @@
 | 
			
		|||
1a438f4235f8038856971c14a798122a  build/gc-eu-mq/oot-gc-eu-mq.z64
 | 
			
		||||
4920520254b9aab86de57b42ab477dbb  build/gc-eu-mq/oot-gc-eu-mq.z64
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -88,9 +88,10 @@ def decompress_rom(
 | 
			
		|||
        dma_entry.to_bin(entry_data)
 | 
			
		||||
        decompressed.write(entry_data)
 | 
			
		||||
    # pad to size
 | 
			
		||||
    padding_end = round_up(dma_entries[-1].vrom_end, 14)
 | 
			
		||||
    decompressed.seek(padding_end - 1)
 | 
			
		||||
    decompressed.write(bytearray([0]))
 | 
			
		||||
    padding_start = dma_entries[-1].vrom_end
 | 
			
		||||
    padding_end = round_up(padding_start, 12)
 | 
			
		||||
    decompressed.seek(padding_start)
 | 
			
		||||
    decompressed.write(b"\x00" * (padding_end - padding_start))
 | 
			
		||||
    # re-calculate crc
 | 
			
		||||
    return bytearray(update_crc(decompressed).getbuffer())
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -127,9 +128,10 @@ def byte_swap(file_content: bytearray) -> bytearray:
 | 
			
		|||
 | 
			
		||||
def per_version_fixes(file_content: bytearray, version: str) -> bytearray:
 | 
			
		||||
    if version == "gc-eu-mq-dbg":
 | 
			
		||||
        # Strip the overdump
 | 
			
		||||
        # Strip the overdump, which consists of an area of 0xFF bytes (which may
 | 
			
		||||
        # be erased flash memory) and ROM data from an unrelated game
 | 
			
		||||
        print("Stripping overdump...")
 | 
			
		||||
        file_content = file_content[0:0x3600000]
 | 
			
		||||
        file_content = file_content[0:0x035CF000]
 | 
			
		||||
 | 
			
		||||
        # Patch the header
 | 
			
		||||
        print("Patching header...")
 | 
			
		||||
| 
						 | 
				
			
			@ -137,15 +139,6 @@ def per_version_fixes(file_content: bytearray, version: str) -> bytearray:
 | 
			
		|||
    return file_content
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def pad_rom(file_content: bytearray, dma_entries: list[dmadata.DmaEntry]) -> bytearray:
 | 
			
		||||
    padding_start = round_up(dma_entries[-1].vrom_end, 12)
 | 
			
		||||
    padding_end = round_up(dma_entries[-1].vrom_end, 14)
 | 
			
		||||
    print(f"Padding from {padding_start:X} to {padding_end:X}...")
 | 
			
		||||
    for i in range(padding_start, padding_end):
 | 
			
		||||
        file_content[i] = 0xFF
 | 
			
		||||
    return file_content
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Determine if we have a ROM file
 | 
			
		||||
ROM_FILE_EXTENSIONS = ["z64", "n64", "v64"]
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -227,8 +220,6 @@ def main():
 | 
			
		|||
            file_content, dmadata_start, dma_entries, is_zlib_compressed
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    file_content = pad_rom(file_content, dma_entries)
 | 
			
		||||
 | 
			
		||||
    # Check to see if the ROM is a "vanilla" ROM
 | 
			
		||||
    str_hash = get_str_hash(file_content)
 | 
			
		||||
    if str_hash != correct_str_hash:
 | 
			
		||||
| 
						 | 
				
			
			@ -237,7 +228,7 @@ def main():
 | 
			
		|||
        )
 | 
			
		||||
 | 
			
		||||
        if version == "gc-eu-mq-dbg":
 | 
			
		||||
            if str_hash == "32fe2770c0f9b1a9cd2a4d449348c1cb":
 | 
			
		||||
            if str_hash == "9fede30e3239558cf3993f12b7ed7458":
 | 
			
		||||
                print(
 | 
			
		||||
                    "The provided baserom is a rom which has been edited with ZeldaEdit and is not suitable for use with decomp. Find a new one."
 | 
			
		||||
                )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,12 +33,6 @@ static bool parse_number(const char *str, int *num)
 | 
			
		|||
    return endptr > str;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static unsigned int round_up(unsigned int num, unsigned int multiple)
 | 
			
		||||
{
 | 
			
		||||
    num += multiple - 1;
 | 
			
		||||
    return num / multiple * multiple;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static char *sprintf_alloc(const char *fmt, ...)
 | 
			
		||||
{
 | 
			
		||||
    va_list args;
 | 
			
		||||
| 
						 | 
				
			
			@ -163,11 +157,10 @@ static void parse_input_file(const char *filename)
 | 
			
		|||
    free(syms);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Writes the N64 ROM, padding the file size to a multiple of 1 MiB
 | 
			
		||||
// Writes the N64 ROM
 | 
			
		||||
static void write_rom_file(const char *filename, int cicType)
 | 
			
		||||
{
 | 
			
		||||
    size_t fileSize = round_up(g_romSize, 0x100000);
 | 
			
		||||
    uint8_t *buffer = calloc(fileSize, 1);
 | 
			
		||||
    uint8_t *buffer = calloc(g_romSize, 1);
 | 
			
		||||
    int i;
 | 
			
		||||
    uint32_t chksum[2];
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -179,16 +172,13 @@ static void write_rom_file(const char *filename, int cicType)
 | 
			
		|||
        memcpy(buffer + g_romSegments[i].romStart, g_romSegments[i].data, size);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // pad the remaining space with 0xFF
 | 
			
		||||
    memset(buffer + g_romSize, 0xFF, fileSize - g_romSize);
 | 
			
		||||
 | 
			
		||||
    // write checksum
 | 
			
		||||
    if (!n64chksum_calculate(buffer, cicType, chksum))
 | 
			
		||||
        util_fatal_error("invalid cic type %i", cicType);
 | 
			
		||||
    util_write_uint32_be(buffer + 0x10, chksum[0]);
 | 
			
		||||
    util_write_uint32_be(buffer + 0x14, chksum[1]);
 | 
			
		||||
 | 
			
		||||
    util_write_whole_file(filename, buffer, fileSize);
 | 
			
		||||
    util_write_whole_file(filename, buffer, g_romSize);
 | 
			
		||||
    free(buffer);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue