Skip to content

Instantly share code, notes, and snippets.

@segrax
Last active September 6, 2015 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save segrax/00ad90a9bc54e2518c38 to your computer and use it in GitHub Desktop.
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
<?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