Last active
September 6, 2015 23:44
-
-
Save segrax/00ad90a9bc54e2518c38 to your computer and use it in GitHub Desktop.
Convert structures of sprite data and change address to a relative address, instead of an absolute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* | |
const sSpriteSheet* stru_8C358[] = { | |
{ 0x57F60, 0, 2, 0xE, 0x3480, 0 }, | |
{ 0x57F62, 0, 2, 0xE, 0x3480, 0 }, | |
{ 0x57F64, 0, 2, 0xE, 0x3480, 0 }, | |
}; | |
*/ | |
$data = file_get_contents('sprite.txt'); | |
$lines = explode("\r\n", $data); | |
$inside = false; | |
$output = array(); | |
foreach($lines as $number => $line) { | |
if( strpos( $line, "{") !== false && $inside === false ) { | |
$inside = true; | |
$output[] = $line . "\r\n"; | |
continue; | |
} | |
if($inside === true) { | |
if( strpos( $line, "};") !== false ) { | |
$inside = false; | |
$output[] = $line . "\r\n"; | |
continue; | |
} | |
preg_match("/{ (.*), (\d?), (\d?), (.*), (.*), (.*) },/", $line, $struct_data ); | |
foreach($struct_data as $key => $data) { | |
if($key===0) | |
continue; | |
$struct_data[$key] = hexdec($data); | |
} | |
$rr = 0; | |
if($struct_data[1] >= 0x57F60) { | |
$struct_data[1] -= 0x57F60; | |
$rr = 0; | |
} | |
// mDataCopt | |
if($struct_data[1] >= 0x3294A) { | |
$struct_data[1] -= 0x3294A; | |
$rr = 1; | |
} | |
if($struct_data[1] < 0) { | |
var_dump($struct_data, $line ); | |
exit; | |
} | |
$final = " { " . $struct_data[1] . ", $rr, " . $struct_data[2] . ", " . $struct_data[3] . ", " . $struct_data[4] . ", " . $struct_data[5] . ", 0x" . strtoupper(dechex( $struct_data[6] )); | |
$final .= " };\r\n"; | |
$output[] = $final; | |
continue; | |
} | |
} | |
file_put_contents('output.txt', $output); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment