From 541530820a774509b69f8dbf9fdc80b6ab1df2fd Mon Sep 17 00:00:00 2001 From: Techokami Date: Wed, 31 Aug 2016 20:17:26 -0400 Subject: [PATCH] Adding all the old stuff! All my old PHP-based shenanigans. --- PHP/bm2_levelrip.php | 366 +++++++++++++++++++++++++++++++++++++ PHP/busterrip.php | 216 ++++++++++++++++++++++ PHP/cripper.php | 254 ++++++++++++++++++++++++++ PHP/dd_ripper.php | 245 +++++++++++++++++++++++++ PHP/dd_ripperv2.php | 236 ++++++++++++++++++++++++ PHP/hsh_levelrip.php | 242 +++++++++++++++++++++++++ PHP/libripper.php | 218 ++++++++++++++++++++++ PHP/mcripper.php | 107 +++++++++++ PHP/rush_levelrip.php | 110 ++++++++++++ PHP/s1smsgg_levelrip.php | 182 +++++++++++++++++++ PHP/s2_levelrip.php | 307 +++++++++++++++++++++++++++++++ PHP/sadv2_levelrip.php | 377 +++++++++++++++++++++++++++++++++++++++ PHP/sadv3_levelrip.php | 301 +++++++++++++++++++++++++++++++ PHP/sadv_levelrip.php | 331 ++++++++++++++++++++++++++++++++++ PHP/socketrip.php | 234 ++++++++++++++++++++++++ PHP/sonic_levelrip.php | 301 +++++++++++++++++++++++++++++++ PHP/sparkrip.php | 205 +++++++++++++++++++++ PHP/srlp.php | 112 ++++++++++++ PHP/sumlp.php | 120 +++++++++++++ PHP/sumssa.php | 127 +++++++++++++ sadv2_addr.txt | 117 ++++++++++++ sadv3_addr.txt | 64 +++++++ 22 files changed, 4772 insertions(+) create mode 100644 PHP/bm2_levelrip.php create mode 100644 PHP/busterrip.php create mode 100644 PHP/cripper.php create mode 100644 PHP/dd_ripper.php create mode 100644 PHP/dd_ripperv2.php create mode 100644 PHP/hsh_levelrip.php create mode 100644 PHP/libripper.php create mode 100644 PHP/mcripper.php create mode 100644 PHP/rush_levelrip.php create mode 100644 PHP/s1smsgg_levelrip.php create mode 100644 PHP/s2_levelrip.php create mode 100644 PHP/sadv2_levelrip.php create mode 100644 PHP/sadv3_levelrip.php create mode 100644 PHP/sadv_levelrip.php create mode 100644 PHP/socketrip.php create mode 100644 PHP/sonic_levelrip.php create mode 100644 PHP/sparkrip.php create mode 100644 PHP/srlp.php create mode 100644 PHP/sumlp.php create mode 100644 PHP/sumssa.php create mode 100644 sadv2_addr.txt create mode 100644 sadv3_addr.txt diff --git a/PHP/bm2_levelrip.php b/PHP/bm2_levelrip.php new file mode 100644 index 0000000..cbe28cc --- /dev/null +++ b/PHP/bm2_levelrip.php @@ -0,0 +1,366 @@ +Oh crunch.FATALITY: You have to specify a filename with 'file' in the URL!"); +if(!file_exists($file)) die("Oh crunch.FATALITY: The file you specified doesn't exist. Man, I can't work with imaginary data, I need REAL data!"); + +//Next, do we want to save it somewhere specific, or do you want to put it +//in a new directory named from the input file? +$savepath = ""; +$filename = explode(".",$file); +$savepath = $filename[0]; +if(isset($_GET['savepath'])) $savepath = $_GET['savepath']; +if(!file_exists($savepath)) mkdir($savepath); + +//Okay, is this Sonic 2, or Sonic 3??? +//Default is Sonic 2. +$game = 2; +$paloffset = 0x278A; +$bgcoffset = 0x11FB8; +$map16offset = 0xD0E2; //0x6822 is BG +$layout = 0xA478; +/*if(isset($_GET['game'])) $game = $_GET['game']; +switch ($game) +{ + case 1: $paloffset = 0x11F78; $bgcoffset = 0x11FB8; $map16offset = 0xD478; $layout = 0xC878; break; + case 2: $paloffset = 0x11F78; $bgcoffset = 0x11FB8; $map16offset = 0xB478; $layout = 0xA478; break; + case 3: $paloffset = 0x12078; $bgcoffset = 0x120B8; $map16offset = 0xB478; $layout = 0xA478; break; + default: $paloffset = 0x11F78; $bgcoffset = 0x11FB8; $map16offset = 0xB478; $layout = 0xA478; break; +} */ + +//Make the images to hold the tile data +$tilesone = imagecreatetruecolor(256, 384); +$tilestwo = imagecreatetruecolor(256, 384); +$tilesthree = imagecreatetruecolor(256, 384); +$tilesfour = imagecreatetruecolor(256, 384); + +//Open the savestate, seek to the location of the pallete +$ram = fopen($file, "r"); +fseek($ram, $paloffset); + +//Make the palletes +$palone = makePallete($ram, $tilesone); +$paltwo = makePallete($ram, $tilestwo); +$palthree = makePallete($ram, $tilesthree); +$palfour = makePallete($ram, $tilesfour); + +//Build the 8x8 tile images +$tilesaddr = 0x12478; +$tilesone = make8x8Tiles($ram, $tilesone, $palone, $tilesaddr); +$tilestwo = make8x8Tiles($ram, $tilestwo, $paltwo, $tilesaddr); +$tilesthree = make8x8Tiles($ram, $tilesthree, $palthree, $tilesaddr); +$tilesfour = make8x8Tiles($ram, $tilesfour, $palfour, $tilesaddr); + +//Okay we got the tiles! Let's start building the Map16. +$map16 = imagecreatetruecolor(512, 512); +fseek($ram, $map16offset); +$i = 0; +for($i= 0; $i < 32; $i++) +{ + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 2; $y++) + { + $x = 0; + for($x= 0; $x < 2; $x++) + { + $tile = getWord($ram); + // PCCY XAAA AAAA AAAA + //0110 0000 0000 0000 - 0x6000 - determine pallete + //0 = Pallete 0, 8192 = Pallete 1, 16384 = Pallete 2, 24576 = Pallete 3 + $tilepallete = $tile & 0x6000; + switch($tilepallete) { + case 0: $tilepallete = 0; break; + case 8192: $tilepallete = 1; break; + case 16384: $tilepallete = 2; break; + case 24576: $tilepallete = 3; break; + default: $tilepallete = 0; break; + } + //0001 0000 0000 0000 - 0x1000 - determine Y flip + //0 = No, 4096 = Yes + $tileyflip = $tile & 0x1000; + //0000 1000 0000 0000 - 0x0800 - determine X flip + //0 = No, 2048 = Yes + $tilexflip = $tile & 0x800; + //0000 0111 1111 1111 - 0x07FF - get tile ID + $tileID = $tile & 0x07FF; + //imagecopyresampled($map32, $tilesone, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + $tempimg = imagecreatetruecolor(8,8); + switch($tilepallete) { + case 0: imagecopyresampled($tempimg, $tilesone, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 1: imagecopyresampled($tempimg, $tilestwo, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 2: imagecopyresampled($tempimg, $tilesthree, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 3: imagecopyresampled($tempimg, $tilesfour, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + default: imagecopyresampled($tempimg, $tilesone, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + } + $flipflag = $tileyflip + $tilexflip; + $tempimg = image_flip($tempimg, $flipflag); + imagecopyresampled($map16, $tempimg, ($x * 8) + ($j * 16), ($y * 8) + ($i * 16), 0, 0, 8, 8, 8, 8); + imagedestroy($tempimg); + } + } + } +} +/* +//And now, the Map128 OR Map256, depending on the game. +if($game != 1) +{ + $map128 = imagecreatetruecolor(128, 128); + $map128addr = 0x2478; + fseek($ram, $map128addr); + $i = 0; + for($i= 0; $i < 16; $i++) + { + $j = 0; + for($j= 0; $j < 16; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x++) + { + $tile16 = getWord($ram); + //So the format is a bitmask SSTT YXII IIII IIII + //SS and TT are solidity info, Y is Y flip, X is X flip, and II IIII IIII is the Map16 ID + //We only care about the last 3 parts of this + + //determine Y flip + $tileyflip = $tile16 & 0x0800; + //determine X flip + $tilexflip = $tile16 & 0x0400; + //get tile ID + $tileID = $tile16 & 0x03FF; + + //Get the tile, determine its flip + $tempimg = imagecreatetruecolor(16,16); + imagecopyresampled($tempimg, $map16, 0, 0, ($tileID % 32) * 16, (floor($tileID / 32)) * 16, 16, 16, 16, 16); + + $flipflag = ($tileyflip * 2) + ($tilexflip * 2); + $tempimg = image_flip($tempimg, $flipflag); + imagecopyresampled($map128, $tempimg, ($x * 16), ($y * 16), 0, 0, 16, 16, 16, 16); + imagedestroy($tempimg); + //imagecopy($map128, $map16, ($x * 16), ($y * 16), ($tile16 % 32) * 16, (floor($tile16 / 32)) * 16, 16, 16); + } + } + //Save the Map128 tile! + imagecolortransparent($map128, $palone[0]); + imagepng($map128, $savepath."\\".(($i * 16) + $j).".png"); + } + } +} +else +{ + $map256 = imagecreatetruecolor(256, 256); + imagefill($map256, 0, 0, $palone[0]); + imagecolortransparent($map256, $palone[0]); + imagepng($map256, $savepath."\\0.png"); + $map256addr = 0x2478; + fseek($ram, $map256addr); + $i = 0; + for($i= 0; $i < 9; $i++) + { + $j = 0; + for($j= 0; $j < 8; $j++) + { + $y = 0; + for($y= 0; $y < 16; $y++) + { + $x = 0; + for($x= 0; $x < 16; $x++) + { + $tile16 = getWord($ram); + //So the format is a bitmask SSTT YXII IIII IIII + //SS and TT are solidity info, Y is Y flip, X is X flip, and II IIII IIII is the Map16 ID + //We only care about the last 3 parts of this + + //determine Y flip + $tileyflip = floor(($tile16 & 0x2000) / 8192); + //determine X flip + $tilexflip = floor(($tile16 & 0x1000) / 2048); + //get tile ID + $tileID = $tile16 & 0x03FF; + + //Get the tile, determine its flip + $tempimg = imagecreatetruecolor(16,16); + imagecopyresampled($tempimg, $map16, 0, 0, ($tileID % 32) * 16, (floor($tileID / 32)) * 16, 16, 16, 16, 16); + + //$flipflag = ($tileyflip * 4096); + //$tempimg = image_flip($tempimg, $flipflag); + $flipflag = ($tilexflip * 2); + $tempimg = image_flip($tempimg, $flipflag); + imagecopyresampled($map256, $tempimg, ($x * 16), ($y * 16), 0, 0, 16, 16, 16, 16); + imagedestroy($tempimg); + } + } + //Save the Map256 tile! + imagecolortransparent($map256, $palone[0]); + imagepng($map256, $savepath."\\".(($i * 8) + $j + 1).".png"); + } + } +} */ + +header('Content-Type: image/png'); +imagepng($map16); + +/* +//It is time to start making the level layout! +//First, what is the background color? +fseek($ram, $bgcoffset); +$color = getByte($ram); +$color2 = getByte($ram); +// Genesis pallete entries are words - 0B GR +$red = 16 * ($color2 % 16); +$green = 16 * floor($color2 / 16); +$blue = 16 * ($color % 16); +$bgcolor = "rgb(".$red.",".$green.",".$blue.")"; +//Make a pair of arrays: one for the BG, one for the FG +$bgtiles = array(); +$fgtiles = array(); +//Let's jump to the layout data! +fseek($ram, $layout); +$i = 0; +for($i= 0; $i < 16; $i++) +{ + $j = 0; + for($j= 0; $j < 128; $j++) + { + $fgtiles[$i][$j] = getByte($ram); + if($_GET['hidefg'] == 1) $fgtiles[$i][$j] = 0; + } + $j = 0; + for($j= 0; $j < 128; $j++) + { + $bgtiles[$i][$j] = getByte($ram); + if($_GET['hidebg'] == 1) $bgtiles[$i][$j] = 0; + } +} +//Now let's begin outputting HTML. +?> +Ripped Level +"; + $j = 0; + for($j= 0; $j < 128; $j++) + { + echo ""; + } + echo ""; +} +echo "
BG: ".$bgtiles[$i][$j].", FG: ".$fgtiles[$i][$j]."
"; +*/ + +//FUNCTIONS +//Read a single byte from the file +function getByte( &$source ) +{ + return ord( fread( $source,1 ) ); +} + +//Read a 16-bit WORD from the file +function getWord( &$source ) +{ + return (getByte( $source ) * 0x100) + getByte( $source ); +} + +//Generate a 16-color pallete +function makePallete( $source, $gd ) +{ + $result = array(); + $i = 0; + for($i= 0; $i < 16; $i++) + { + $color = getByte($source); + $color2 = getByte($source); + // Genesis pallete entries are words - 0B GR + $red = 16 * ($color2 % 16); + $green = 16 * floor($color2 / 16); + $blue = 16 * ($color % 16); + if ($i == 0) $result[$i] = imagecolorallocate( $gd, 255, 0, 255 ); + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + return $result; +} + +//Build a set of 8x8 tiles +function make8x8Tiles( $source, $gd, $pal, $tileAddr ) { + fseek($source, $tileAddr); + $i = 0; + for($i= 0; $i < 48; $i++) + { + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($source); + // Split a byte into nybbles + $leftpixel = floor($byte / 16); + $rightpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($gd, $x + ($j * 8), $y + ($i * 8), $pal[$leftpixel]); + imagesetpixel($gd, $x + 1 + ($j * 8), $y + ($i * 8), $pal[$rightpixel]); + } + } + } + } + return $gd; +} + +//Borrowed from something open source Lightning linked me to. +function image_flip($img, $type){ + $width = imagesx($img); + $height = imagesy($img); + $dest = imagecreatetruecolor($width, $height); + switch($type){ + case 0: + return $img; + break; + case 4096: + for($i=0;$i<$height;$i++){ + imagecopy($dest, $img, 0, ($height - $i - 1), 0, $i, $width, 1); + } + break; + case 2048: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + } + break; + case 6144: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + + } + $buffer = imagecreatetruecolor($width, 1); + for($i=0;$i<($height/2);$i++){ + imagecopy($buffer, $dest, 0, 0, 0, ($height - $i -1), $width, 1); + imagecopy($dest, $dest, 0, ($height - $i - 1), 0, $i, $width, 1); + imagecopy($dest, $buffer, 0, $i, 0, 0, $width, 1); + } + imagedestroy($buffer); + break; + default: + return $img; + break; + } + return $dest; +} + +?> diff --git a/PHP/busterrip.php b/PHP/busterrip.php new file mode 100644 index 0000000..c625ec8 --- /dev/null +++ b/PHP/busterrip.php @@ -0,0 +1,216 @@ +Oh crunch.FATALITY: You have to specify a filename with 'file' in the URL!"); +if(!file_exists($file)) die("Oh crunch.FATALITY: The file you specified doesn't exist. Man, I can't work with imaginary data, I need REAL data!"); + +//Next, do we want to save it somewhere specific, or do you want to put it +//in a new directory named from the input file? +$savepath = ""; +$filename = explode(".",$file); +$savepath = $filename[0]; +if(isset($_GET['savepath'])) $savepath = $_GET['savepath']; +if(!file_exists($savepath)) mkdir($savepath); + +//Address Constants +$paloffset = 0x11378; +$map16offset = 0x8478; + +//Make the images to hold the tile data +$tilesone = imagecreatetruecolor(256, 384); +$tilestwo = imagecreatetruecolor(256, 384); +$tilesthree = imagecreatetruecolor(256, 384); +$tilesfour = imagecreatetruecolor(256, 384); + +//Open the savestate, seek to the location of the pallete +$ram = fopen($file, "r"); +fseek($ram, $paloffset); + +//Make the palletes +$palone = makePallete($ram, $tilesone, TRUE); +$paltwo = makePallete($ram, $tilestwo, TRUE); +$palthree = makePallete($ram, $tilesthree, TRUE); +$palfour = makePallete($ram, $tilesfour, TRUE); + +//Build the 8x8 tile images +$tilesaddr = 0x12478; +$tilesone = make8x8Tiles($ram, $tilesone, $palone, $tilesaddr); +$tilestwo = make8x8Tiles($ram, $tilestwo, $paltwo, $tilesaddr); +$tilesthree = make8x8Tiles($ram, $tilesthree, $palthree, $tilesaddr); +$tilesfour = make8x8Tiles($ram, $tilesfour, $palfour, $tilesaddr); + +//Okay we got the tiles! Let's start building the Map32. +$map32 = imagecreatetruecolor(32, 32); +fseek($ram, $map16offset); +$i = 0; +for($i= 0; $i < 256; $i++) +{ + $y = 0; + for($y= 0; $y < 4; $y++) + { + $x = 0; + for($x= 0; $x < 4; $x++) + { + $tile = getWord($ram); + // PCCY XAAA AAAA AAAA + //0110 0000 0000 0000 - 0x6000 - determine pallete + //0 = Pallete 0, 8192 = Pallete 1, 16384 = Pallete 2, 24576 = Pallete 3 + $tilepallete = $tile & 0x6000; + switch($tilepallete) { + case 0: $tilepallete = 0; break; + case 8192: $tilepallete = 1; break; + case 16384: $tilepallete = 2; break; + case 24576: $tilepallete = 3; break; + default: $tilepallete = 0; break; + } + //0001 0000 0000 0000 - 0x1000 - determine Y flip + //0 = No, 4096 = Yes + $tileyflip = $tile & 0x1000; + //0000 1000 0000 0000 - 0x0800 - determine X flip + //0 = No, 2048 = Yes + $tilexflip = $tile & 0x800; + //0000 0111 1111 1111 - 0x07FF - get tile ID + $tileID = $tile & 0x07FF; + //imagecopyresampled($map32, $tilesone, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + $tempimg = imagecreatetruecolor(8,8); + switch($tilepallete) { + case 0: imagecopyresampled($tempimg, $tilesone, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 1: imagecopyresampled($tempimg, $tilestwo, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 2: imagecopyresampled($tempimg, $tilesthree, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 3: imagecopyresampled($tempimg, $tilesfour, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + default: imagecopyresampled($tempimg, $tilesone, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + } + $flipflag = $tileyflip + $tilexflip; + $tempimg = image_flip($tempimg, $flipflag); + imagecopyresampled($map32, $tempimg, ($x * 8), ($y * 8), 0, 0, 8, 8, 8, 8); + imagedestroy($tempimg); + } + } + //Save the Map32 + imagecolortransparent($map32, $palone[0]); + imagepng($map32, $savepath."\\".$i.".png"); +} + +//And we're done! ...well, almost. How long did it take? LET'S FIND OUT :D +$time_end = microtime(true); +$time = $time_end - $time_start; + +echo "Ripping complete!Completed in $time seconds!"; + +//FUNCTIONS +//Read a single byte from the file +function getByte( &$source ) +{ + return ord( fread( $source,1 ) ); +} + +//Read a 16-bit WORD from the file +function getWord( &$source ) +{ + return (getByte( $source ) * 0x100) + getByte( $source ); +} + +//Generate a 16-color pallete +function makePallete( $source, $gd, $bgcolor = FALSE ) +{ + $result = array(); + $i = 0; + for($i= 0; $i < 16; $i++) + { + $color = getByte($source); + $color2 = getByte($source); + // Genesis pallete entries are words - 0B GR + $red = 16 * ($color2 % 16); + $green = 16 * floor($color2 / 16); + $blue = 16 * ($color % 16); + //Should we define a different BG color? Or use what exists? + if ($bgcolor) + { + //We define our own. + if ($i == 0) $result[$i] = imagecolorallocate( $gd, 255, 0, 255 ); + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + //We'll use what exists. + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + return $result; +} + +//Build a set of 8x8 tiles +function make8x8Tiles( $source, $gd, $pal, $tileAddr ) { + fseek($source, $tileAddr); + $i = 0; + for($i= 0; $i < 48; $i++) + { + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($source); + // Split a byte into nybbles + $leftpixel = floor($byte / 16); + $rightpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($gd, $x + ($j * 8), $y + ($i * 8), $pal[$leftpixel]); + imagesetpixel($gd, $x + 1 + ($j * 8), $y + ($i * 8), $pal[$rightpixel]); + } + } + } + } + return $gd; +} + +//Borrowed from something open source Lightning linked me to. +function image_flip($img, $type){ + $width = imagesx($img); + $height = imagesy($img); + $dest = imagecreatetruecolor($width, $height); + switch($type){ + case 0: + return $img; + break; + case 4096: + for($i=0;$i<$height;$i++){ + imagecopy($dest, $img, 0, ($height - $i - 1), 0, $i, $width, 1); + } + break; + case 2048: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + } + break; + case 6144: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + + } + $buffer = imagecreatetruecolor($width, 1); + for($i=0;$i<($height/2);$i++){ + imagecopy($buffer, $dest, 0, 0, 0, ($height - $i -1), $width, 1); + imagecopy($dest, $dest, 0, ($height - $i - 1), 0, $i, $width, 1); + imagecopy($dest, $buffer, 0, $i, 0, 0, $width, 1); + } + imagedestroy($buffer); + break; + default: + return $img; + break; + } + return $dest; +} + +?> \ No newline at end of file diff --git a/PHP/cripper.php b/PHP/cripper.php new file mode 100644 index 0000000..3b1e5a4 --- /dev/null +++ b/PHP/cripper.php @@ -0,0 +1,254 @@ +Completed in $time seconds!"; + +?> diff --git a/PHP/dd_ripper.php b/PHP/dd_ripper.php new file mode 100644 index 0000000..0576878 --- /dev/null +++ b/PHP/dd_ripper.php @@ -0,0 +1,245 @@ +"; +$i = 0; +for($i= 0; $i < 16; $i++) +{ + echo " "; +} +echo ""; +$i = 0; +for($i= 0; $i < 16; $i++) +{ + echo " "; +} +echo ""; +$i = 0; +for($i= 0; $i < 16; $i++) +{ + echo " "; +} +echo ""; +$i = 0; +for($i= 0; $i < 16; $i++) +{ + echo " "; +} +echo ""; */ + +//Test 2: Make image with the tiles in VRAM +$tilesone = imagecreate(128, 384); +$tilestwo = imagecreate(128, 384); +$tilesthree = imagecreate(128, 384); +$tilesfour = imagecreate(128, 384); +$ram = fopen("dd.gs0", "r"); +fseek($ram, 0xA50C); +$palone = makePallete($ram, $tilesone); +$paltwo = makePallete($ram, $tilestwo); +$palthree = makePallete($ram, $tilesthree); +$palfour = makePallete($ram, $tilesfour); +//Now that we have the images and palletes ready, jump to the tiles! +fseek($ram, 0x17D98); +$i = 0; +for($i= 0; $i < 48; $i++) +{ + $j = 0; + for($j= 0; $j < 16; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($ram); + // Split a byte into nybbles + $leftpixel = floor($byte / 16); + $rightpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($tilesone, $x + ($j * 8), $y + ($i * 8), $palone[$leftpixel]); + imagesetpixel($tilesone, $x + 1 + ($j * 8), $y + ($i * 8), $palone[$rightpixel]); + } + } + } +} +fseek($ram, 0x17D98); +$i = 0; +for($i= 0; $i < 48; $i++) +{ + $j = 0; + for($j= 0; $j < 16; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($ram); + // Split a byte into nybbles + $leftpixel = floor($byte / 16); + $rightpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($tilestwo, $x + ($j * 8), $y + ($i * 8), $paltwo[$leftpixel]); + imagesetpixel($tilestwo, $x + 1 + ($j * 8), $y + ($i * 8), $paltwo[$rightpixel]); + } + } + } +} +fseek($ram, 0x17D98); +$i = 0; +for($i= 0; $i < 48; $i++) +{ + $j = 0; + for($j= 0; $j < 16; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($ram); + // Split a byte into nybbles + $leftpixel = floor($byte / 16); + $rightpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($tilesthree, $x + ($j * 8), $y + ($i * 8), $palthree[$leftpixel]); + imagesetpixel($tilesthree, $x + 1 + ($j * 8), $y + ($i * 8), $palthree[$rightpixel]); + } + } + } +} +fseek($ram, 0x17D98); +$i = 0; +for($i= 0; $i < 48; $i++) +{ + $j = 0; + for($j= 0; $j < 16; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($ram); + // Split a byte into nybbles + $leftpixel = floor($byte / 16); + $rightpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($tilesfour, $x + ($j * 8), $y + ($i * 8), $palfour[$leftpixel]); + imagesetpixel($tilesfour, $x + 1 + ($j * 8), $y + ($i * 8), $palfour[$rightpixel]); + } + } + } +} +//header('Content-Type: image/png'); +//imagepng($tilesfour); +//Okay we got the tiles! Let's start building the Map32. +$map32 = imagecreatetruecolor(512, 512); +fseek($ram, 0x26C0); +$i = 0; +for($i= 0; $i < 16; $i++) +{ + $j = 0; + for($j= 0; $j < 16; $j++) + { + $y = 0; + for($y= 0; $y < 4; $y++) + { + $x = 0; + for($x= 0; $x < 4; $x++) + { + $tile = getWord($ram); + // PCCY XAAA AAAA AAAA + //0110 0000 0000 0000 - 0x6000 - determine pallete + //0 = Pallete 0, 8192 = Pallete 1, 16384 = Pallete 2, 24576 = Pallete 3 + $tilepallete = $tile & 0x6000; + switch($tilepallete) { + case 0: $tilepallete = 0; break; + case 8192: $tilepallete = 1; break; + case 16384: $tilepallete = 2; break; + case 24576: $tilepallete = 3; break; + default: $tilepallete = 0; break; + } + //0001 0000 0000 0000 - 0x1000 - determine Y flip + //0 = No, 4096 = Yes + $tileyflip = $tile & 0x1000; + $tilehorsiz = 8; + switch($tileyflip) { + case 0: $tileyflip = 0; break; + case 4096: $tileyflip = 1; $tilehorsiz = -$tilehorsiz; break; + default: $tileyflip = 0; break; + } + //0000 1000 0000 0000 - 0x0800 - determine X flip + //0 = No, 2048 = Yes + $tilexflip = $tile & 0x800; + $tileversiz = 8; + switch($tilexflip) { + case 0: $tilexflip = 0; break; + case 2048: $tilexflip = 1; $tileversiz = -$tileversiz; break; + default: $tilexflip = 0; break; + } + //0000 0111 1111 1111 - 0x07FF - get tile ID + $tileID = $tile & 0x07FF; + imagecopyresampled($map32, $tilesfour, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 16), (floor($tileID / 16)), 8, 8, $tilehorsiz, $tileversiz); + /*switch($tilepallete) { + case 0: imagecopyresampled($map32, $tilesone, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 16), (floor($tileID / 16))-8, 8 - ($tilexflip * 1), 8 - ($tileyflip * 1), $tilehorsiz, $tileversiz); break; + case 1: imagecopyresampled($map32, $tilestwo, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 16), (floor($tileID / 16))-8, 8 - ($tilexflip * 1), 8 - ($tileyflip * 1), $tilehorsiz, $tileversiz); break; + case 2: imagecopyresampled($map32, $tilesthree, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 16), (floor($tileID / 16))-8, 8 - ($tilexflip * 1), 8 - ($tileyflip * 1), $tilehorsiz, $tileversiz); break; + case 3: imagecopyresampled($map32, $tilesfour, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 16), (floor($tileID / 16))-8, 8 - ($tilexflip * 1), 8 - ($tileyflip * 1), $tilehorsiz, $tileversiz); break; + default: imagecopyresampled($map32, $tilesone, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 16), (floor($tileID / 16))-8, 8 - ($tilexflip * 1), 8 - ($tileyflip * 1), $tilehorsiz, $tileversiz); break; + }*/ + } + } + } +} +header('Content-Type: image/png'); +imagepng($map32); +?> diff --git a/PHP/dd_ripperv2.php b/PHP/dd_ripperv2.php new file mode 100644 index 0000000..d9f8c7c --- /dev/null +++ b/PHP/dd_ripperv2.php @@ -0,0 +1,236 @@ +Oh crunch.FATALITY: You have to specify a filename with 'file' in the URL!"); +if(!file_exists($file)) die("Oh crunch.FATALITY: The file you specified doesn't exist. Man, I can't work with imaginary data, I need REAL data!"); + +//Next, do we want to save it somewhere specific, or do you want to put it +//in a new directory named from the input file? +$savepath = ""; +$filename = explode(".",$file); +$savepath = $filename[0]; +if(isset($_GET['savepath'])) $savepath = $_GET['savepath']; +if(!file_exists($savepath)) mkdir($savepath); +if(!file_exists($savepath."\\strips")) mkdir($savepath."\\strips"); + +//Address Constants +$paloffset = 0xA50C; +$map16offset = 0x26C0; + +//Make the images to hold the tile data +$tilesone = imagecreatetruecolor(256, 384); +$tilestwo = imagecreatetruecolor(256, 384); +$tilesthree = imagecreatetruecolor(256, 384); +$tilesfour = imagecreatetruecolor(256, 384); + +//Open the savestate, seek to the location of the pallete +$ram = fopen($file, "r"); +fseek($ram, $paloffset); + +//Make the palletes +$palone = makePallete($ram, $tilesone, TRUE); +$paltwo = makePallete($ram, $tilestwo, TRUE); +$palthree = makePallete($ram, $tilesthree, TRUE); +$palfour = makePallete($ram, $tilesfour, TRUE); + +//Build the 8x8 tile images +$tilesaddr = 0x17D98; +$tilesone = make8x8Tiles($ram, $tilesone, $palone, $tilesaddr); +$tilestwo = make8x8Tiles($ram, $tilestwo, $paltwo, $tilesaddr); +$tilesthree = make8x8Tiles($ram, $tilesthree, $palthree, $tilesaddr); +$tilesfour = make8x8Tiles($ram, $tilesfour, $palfour, $tilesaddr); + +//Okay we got the tiles! Let's start building the Map32. +$map32 = imagecreatetruecolor(32, 32); +fseek($ram, $map16offset); +$i = 0; +for($i= 0; $i < 512; $i++) +{ + $y = 0; + for($y= 0; $y < 4; $y++) + { + $x = 0; + for($x= 0; $x < 4; $x++) + { + $tile = getWord($ram); + // PCCY XAAA AAAA AAAA + //0110 0000 0000 0000 - 0x6000 - determine pallete + //0 = Pallete 0, 8192 = Pallete 1, 16384 = Pallete 2, 24576 = Pallete 3 + $tilepallete = $tile & 0x6000; + switch($tilepallete) { + case 0: $tilepallete = 0; break; + case 8192: $tilepallete = 1; break; + case 16384: $tilepallete = 2; break; + case 24576: $tilepallete = 3; break; + default: $tilepallete = 0; break; + } + //0001 0000 0000 0000 - 0x1000 - determine Y flip + //0 = No, 4096 = Yes + $tileyflip = $tile & 0x1000; + //0000 1000 0000 0000 - 0x0800 - determine X flip + //0 = No, 2048 = Yes + $tilexflip = $tile & 0x800; + //0000 0111 1111 1111 - 0x07FF - get tile ID + $tileID = $tile & 0x07FF; + //imagecopyresampled($map32, $tilesone, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + $tempimg = imagecreatetruecolor(8,8); + switch($tilepallete) { + case 0: imagecopyresampled($tempimg, $tilesone, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 1: imagecopyresampled($tempimg, $tilestwo, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 2: imagecopyresampled($tempimg, $tilesthree, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 3: imagecopyresampled($tempimg, $tilesfour, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + default: imagecopyresampled($tempimg, $tilesone, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + } + $flipflag = $tileyflip + $tilexflip; + $tempimg = image_flip($tempimg, $flipflag); + imagecopyresampled($map32, $tempimg, ($x * 8), ($y * 8), 0, 0, 8, 8, 8, 8); + imagedestroy($tempimg); + } + } + //Save the Map32 + imagecolortransparent($map32, $palone[0]); + imagepng($map32, $savepath."\\".$i.".png"); +} +//Let's get the level strips! +$map256 = imagecreatetruecolor(512, 256); +fseek($ram, 0x6400); +$i = 0; +for($i= 0; $i < 32; $i++) +{ + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 16; $x++) + { + imagecopy($map256, imagecreatefrompng($savepath."\\".getword($ram).".png"), $x * 32, $y * 32, 0, 0, 32, 32); + } + } + //Save the Map256 + imagecolortransparent($map256, $palone[0]); + imagepng($map256, $savepath."\\strips\\".($i).".png"); +} + +//And we're done! ...well, almost. How long did it take? LET'S FIND OUT :D +$time_end = microtime(true); +$time = $time_end - $time_start; + +echo "Ripping complete!Completed in $time seconds!"; + +//FUNCTIONS +//Read a single byte from the file +function getByte( &$source ) +{ + return ord( fread( $source,1 ) ); +} + +//Read a 16-bit WORD from the file +function getWord( &$source ) +{ + return (getByte( $source ) * 0x100) + getByte( $source ); +} + +//Generate a 16-color pallete +function makePallete( $source, $gd, $bgcolor = FALSE ) +{ + $result = array(); + $i = 0; + for($i= 0; $i < 16; $i++) + { + $color = getByte($source); + $color2 = getByte($source); + // Genesis pallete entries are words - 0B GR + $red = 16 * ($color2 % 16); + $green = 16 * floor($color2 / 16); + $blue = 16 * ($color % 16); + //Should we define a different BG color? Or use what exists? + if ($bgcolor) + { + //We define our own. + if ($i == 0) $result[$i] = imagecolorallocate( $gd, 255, 0, 255 ); + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + //We'll use what exists. + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + return $result; +} + +//Build a set of 8x8 tiles +function make8x8Tiles( $source, $gd, $pal, $tileAddr ) { + fseek($source, $tileAddr); + $i = 0; + for($i= 0; $i < 48; $i++) + { + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($source); + // Split a byte into nybbles + $leftpixel = floor($byte / 16); + $rightpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($gd, $x + ($j * 8), $y + ($i * 8), $pal[$leftpixel]); + imagesetpixel($gd, $x + 1 + ($j * 8), $y + ($i * 8), $pal[$rightpixel]); + } + } + } + } + return $gd; +} + +//Borrowed from something open source Lightning linked me to. +function image_flip($img, $type){ + $width = imagesx($img); + $height = imagesy($img); + $dest = imagecreatetruecolor($width, $height); + switch($type){ + case 0: + return $img; + break; + case 4096: + for($i=0;$i<$height;$i++){ + imagecopy($dest, $img, 0, ($height - $i - 1), 0, $i, $width, 1); + } + break; + case 2048: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + } + break; + case 6144: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + + } + $buffer = imagecreatetruecolor($width, 1); + for($i=0;$i<($height/2);$i++){ + imagecopy($buffer, $dest, 0, 0, 0, ($height - $i -1), $width, 1); + imagecopy($dest, $dest, 0, ($height - $i - 1), 0, $i, $width, 1); + imagecopy($dest, $buffer, 0, $i, 0, 0, $width, 1); + } + imagedestroy($buffer); + break; + default: + return $img; + break; + } + return $dest; +} + +?> \ No newline at end of file diff --git a/PHP/hsh_levelrip.php b/PHP/hsh_levelrip.php new file mode 100644 index 0000000..be586dd --- /dev/null +++ b/PHP/hsh_levelrip.php @@ -0,0 +1,242 @@ + diff --git a/PHP/libripper.php b/PHP/libripper.php new file mode 100644 index 0000000..227e750 --- /dev/null +++ b/PHP/libripper.php @@ -0,0 +1,218 @@ +>10)&31) << 3; + $blue += $blue >>5; + $green = (($color>>5)&31) << 3; + $green += $green >>5; + $red = (($color)&31) << 3; + $red += $red >>5; + // The above function was written by Justin Aquadero (Retriever II) + if ($keeptrans == FALSE && $i == 0) $result[$i] = imagecolorallocate( $gd, 255, 0, 255 ); + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + return $result; +} +//Generate a 256-color GBA pallete +function make8BitGBAPallete( $source, $gd ) +{ + $result = array(); + $i = 0; + for($i= 0; $i < 256; $i++) + { + $color = getFWord($source); + // GBA pallete entries are words - 0bbb bbgg gggr rrrr + // This function was written by Justin Aquadero (Retriever II) + $blue = (($color>>10)&31) << 3; + $blue += $blue >>5; + $green = (($color>>5)&31) << 3; + $green += $green >>5; + $red = (($color)&31) << 3; + $red += $red >>5; + // The above function was written by Justin Aquadero (Retriever II) + $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + return $result; +} + +//Build a set of 8x8 tiles (4bpp) +function make8x8Tiles($source, $gd, $pal, $tileAddr, $bigendian = TRUE) +{ + fseek($source, $tileAddr); + $i = 0; + for($i= 0; $i < 256; $i++) + { + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($source); + // Split a byte into nybbles + if ($bigendian) + { + $leftpixel = floor($byte / 16); + $rightpixel = ($byte % 16); + } + else + { + $rightpixel = floor($byte / 16); + $leftpixel = ($byte % 16); + } + //Paint the two pixels + imagesetpixel($gd, $x + ($j * 8), $y + ($i * 8), $pal[$leftpixel]); + imagesetpixel($gd, $x + 1 + ($j * 8), $y + ($i * 8), $pal[$rightpixel]); + } + } + } + } + return $gd; +} + +//Build a set of 8x8 tiles (8bpp) +function make8bppTiles( $source, $gd, $pal, $tileAddr ) { + fseek($source, $tileAddr); + $i = 0; + for($i= 0; $i < 48; $i++) + { + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x++) + { + $byte = getByte($source); + //Paint the pixel + imagesetpixel($gd, $x + ($j * 8), $y + ($i * 8), $pal[$byte]); + } + } + } + } + return $gd; +} + +//Borrowed from something open source Lightning linked me to. +function image_flip($img, $type) +{ + $width = imagesx($img); + $height = imagesy($img); + $dest = imagecreatetruecolor($width, $height); + imagealphablending($dest, false); + imagesavealpha($dest, true); + switch($type){ + case 0: + return $img; + break; + case 4096: + for($i=0;$i<$height;$i++){ + imagecopy($dest, $img, 0, ($height - $i - 1), 0, $i, $width, 1); + } + break; + case 2048: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + } + break; + case 6144: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + + } + $buffer = imagecreatetruecolor($width, 1); + imagealphablending($buffer, false); + imagesavealpha($buffer, true); + for($i=0;$i<($height/2);$i++){ + imagecopy($buffer, $dest, 0, 0, 0, ($height - $i -1), $width, 1); + imagecopy($dest, $dest, 0, ($height - $i - 1), 0, $i, $width, 1); + imagecopy($dest, $buffer, 0, $i, 0, 0, $width, 1); + } + imagedestroy($buffer); + break; + default: + return $img; + break; + } + return $dest; +} + + /** + * PNG ALPHA CHANNEL SUPPORT for imagecopymerge(); + * This is a function like imagecopymerge but it handle alpha channel well!!! + **/ + function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){ + $opacity=$pct; + // getting the watermark width + $w = imagesx($src_im); + // getting the watermark height + $h = imagesy($src_im); + + // creating a cut resource + $cut = imagecreatetruecolor($src_w, $src_h); + // copying that section of the background to the cut + imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h); + // inverting the opacity + $opacity = 100 - $opacity; + + // placing the watermark now + imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h); + imagecopymerge($dst_im, $cut, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $opacity); + } +?> diff --git a/PHP/mcripper.php b/PHP/mcripper.php new file mode 100644 index 0000000..a54a79e --- /dev/null +++ b/PHP/mcripper.php @@ -0,0 +1,107 @@ +Completed in $time seconds!"; +?> diff --git a/PHP/rush_levelrip.php b/PHP/rush_levelrip.php new file mode 100644 index 0000000..727cf8d --- /dev/null +++ b/PHP/rush_levelrip.php @@ -0,0 +1,110 @@ +FATALITYHey, you have file(s) missing! TRY AGAIN"); +// Next, do we want to save it somewhere specific, or do you want to put it +// all in the current working directory? PROTIP: Make a new directory. +$savepath = $game.$level; +if(!file_exists($savepath)) mkdir($savepath); + +// Open the pallete +$pl_data = fopen($pl_file, "r"); + +// Make the image to hold the tile data +$tiles = imagecreate(256, 256); + +// Make the pallete +$pal = make8BitGBAPallete($pl_data, $tiles); +fclose($pl_data); + +// Open the tile image data, build the 8x8 tile images +$ch_data = fopen($ch_file, "r"); +$tiles = make8bppTiles($ch_data, $tiles, $pal, 0); + +// Save the image +imagepng($tiles, $savepath."//_tiles.png"); + +// So, how many metatiles will we be building? +$max64 = filesize($bk_file) / 128; + +// Okay we got the tiles! Let's start building the Map64. +$pl_data = fopen($pl_file, "r"); +$map64 = imagecreate(64, 64); +$pal64 = make8BitGBAPallete($pl_data, $map64); +$bk_data = fopen($bk_file, "r"); +$j = 0; +for($j= 0; $j < $max64; $j++) +{ + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x++) + { + $tile = getFWord($bk_data); + // PPPP XYAA AAAA AAAA + // 1111 0000 0000 0000 - 0x6000 - determine pallete + $tilepallete = floor(($tile & 0xF000)/4096); + // 0000 1000 0000 0000 - 0x0800 - determine X flip + $tileyflip = floor(($tile & 0x800)/2048); + // 0000 0100 0000 0000 - 0x0400 - determine Y flip + $tilexflip = floor(($tile & 0x400)/1024); + // 0000 0111 1111 1111 - 0x03FF - get tile ID + $tileID = $tile & 0x03FF; + // Grab the tile + $tempimg = imagecreatetruecolor(8,8); + imagecopyresampled($tempimg, $tiles, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); + // Flip it! + $tempimg = image_flip($tempimg, (($tilexflip * 2048) + ($tileyflip * 4096))); + // Draw it to the Map64 + imagecopyresampled($map64, $tempimg, ($x * 8), ($y * 8), 0, 0, 8, 8, 8, 8); + imagedestroy($tempimg); + } + } + // Save the image + imagepng($map64, $savepath."//".$j.".png"); +} + +// Cleanup. +fclose($pl_data); +fclose($ch_data); +fclose($bk_data); + +// And we're done! ...well, almost. How long did it take? LET'S FIND OUT :D +$time_end = microtime(true); +$time = $time_end - $time_start; + +echo "Sonic Rush Level Data RipperRipping complete!
Completed in $time seconds!"; + +?> diff --git a/PHP/s1smsgg_levelrip.php b/PHP/s1smsgg_levelrip.php new file mode 100644 index 0000000..47f11ec --- /dev/null +++ b/PHP/s1smsgg_levelrip.php @@ -0,0 +1,182 @@ +Oh crunch.FATALITY: The ROM file you specified doesn't exist. Man, I can't work with imaginary data, I need REAL data!"); + +// Now, what version of the game? Default is Master System +$version = 1; +if(isset($_GET['game'])) +{ + // Make sure the input is legal + if(intval($_GET['game']) == 1) $version = 1; + else if(intval($_GET['game']) == 2) $version = 2; +} + +// Next, what tilesheet to load? Default is s1sms_ghz1.png +$tilesheet = 's1sms_ghz1.png'; +if(isset($_GET['tiles'])) $tilesheet = $_GET['tiles']; +// Check to see if the file exists +if(!file_exists($tilesheet)) die("Oh crunch.FATALITY: The tilesheet you specified doesn't exist. Man, I can't work with imaginary data, I need REAL data!"); + +// Now for the directory to save everything to. Default is a directory with the same name as the tilesheet +$savepath = ""; +$filename = explode(".",$tilesheet); +$savepath = $filename[0]; +if(isset($_GET['savedir'])) $savepath = $_GET['savedir']; +if(!file_exists($savepath)) mkdir($savepath); + +// Finally, before we start ripping, what level is it? Default is Green Hill Zone. +$level = 'GHZ'; +if(isset($_GET['level'])) $level = strtoupper($_GET['level']); + +// Setting the parameters to the proper level... +$offset = 0x10000; +$tilecount = 184; +if($version == 2) +{ + // Game Gear Version + switch($level) + { + case 'GHZ': + $offset = 0x10000; + $tilecount = 187; + break; + case 'BZ': + $offset = 0x10BB0; + $tilecount = 150; + break; + case 'JZ': + $offset = 0x11510; + $tilecount = 128; + break; + case 'LZ': + $offset = 0x11FE0; + $tilecount = 208; + break; + case 'SBZ': + $offset = 0x12A10; + $tilecount = 186; + break; + case 'SKY': + $offset = 0x135B0; + $tilecount = 216; + break; + case 'SKY2': + $offset = 0x14330; + $tilecount = 104; + break; + case 'BONUS': + $offset = 0x149B0; + $tilecount = 53; + break; + default: + $offset = 0x10000; + $tilecount = 187; + break; + } +} +else +{ + // Master System Version + switch($level) + { + case 'GHZ': + $offset = 0x10000; + $tilecount = 184; + break; + case 'BZ': + $offset = 0x10B80; + $tilecount = 144; + break; + case 'JZ': + $offset = 0x11480; + $tilecount = 160; + break; + case 'LZ': + $offset = 0x11E80; + $tilecount = 176; + break; + case 'SBZ': + $offset = 0x12980; + $tilecount = 192; + break; + case 'SKY': + $offset = 0x13580; + $tilecount = 216; + break; + case 'SKY2': + $offset = 0x14300; + $tilecount = 104; + break; + case 'BONUS': + $offset = 0x14980; + $tilecount = 55; + break; + default: + $offset = 0x10000; + $tilecount = 184; + break; + } +} + +// We now have all our ducks in a row! Let's start rippin'. +$tiles = imagecreatefrompng($tilesheet); +$rom = fopen($file, "r"); +fseek($rom, $offset); +$map32 = imagecreatetruecolor(32, 32); +$i = 0; +for($i= 0; $i < $tilecount; $i++) +{ + $y = 0; + for($y= 0; $y < 4; $y++) + { + $x = 0; + for($x= 0; $x < 4; $x++) + { + $tile = getByte($rom); + // DEBUG + // echo "Tile:".$i." X:".$x." Y:".$y." TileX:".(($tile % 16) * 8)." TileY:".(floor($tile / 16) * 8)."
"; + imagecopyresampled($map32, $tiles, ($x * 8), ($y * 8), (($tile % 16) * 8), (floor($tile / 16) * 8), 8, 8, 8, 8); + } + } + imagepng($map32, $savepath."//".$i.".png"); +} + +// And we're done! ...well, almost. How long did it take? LET'S FIND OUT :D +$time_end = microtime(true); +$time = $time_end - $time_start; + +echo "Ripping complete!Completed in $time seconds!"; +// MAIN CODE END + +// FUNCTIONS +// Read a single byte from the file +function getByte( &$source ) +{ + return ord( fread( $source,1 ) ); +} +// FUNCTIONS END +?> diff --git a/PHP/s2_levelrip.php b/PHP/s2_levelrip.php new file mode 100644 index 0000000..e9a1c5e --- /dev/null +++ b/PHP/s2_levelrip.php @@ -0,0 +1,307 @@ +Oh crunch.FATALITY: You have to specify a filename with 'file' in the URL!"); +if(!file_exists($file)) die("Oh crunch.FATALITY: The file you specified doesn't exist. Man, I can't work with imaginary data, I need REAL data!"); + +//Next, do we want to save it somewhere specific, or do you want to put it +//in a new directory named from the input file? +$savepath = ""; +$filename = explode(".",$file); +$savepath = $filename[0]; +if(isset($_GET['savepath'])) $savepath = $_GET['savepath']; +if(!file_exists($savepath)) mkdir($savepath); + +//Okay, is this Sonic 2, or Sonic 3??? +$game = 2; +$paloffset = 0x11F78; +$bgcoffset = 0x11FB8; +if(isset($_GET['game'])) $game = $_GET['game']; +switch ($game) +{ + case 2: $paloffset = 0x11F78; $bgcoffset = 0x11FB8; break; + case 3: $paloffset = 0x12078; $bgcoffset = 0x120B8; break; + default: $paloffset = 0x11F78; $bgcoffset = 0x11FB8; break; +} + +//Make the images to hold the tile data +$tilesone = imagecreatetruecolor(256, 384); +$tilestwo = imagecreatetruecolor(256, 384); +$tilesthree = imagecreatetruecolor(256, 384); +$tilesfour = imagecreatetruecolor(256, 384); + +//Open the savestate, seek to the location of the pallete +$ram = fopen($file, "r"); +fseek($ram, $paloffset); + +//Make the palletes +$palone = makePallete($ram, $tilesone); +$paltwo = makePallete($ram, $tilestwo); +$palthree = makePallete($ram, $tilesthree); +$palfour = makePallete($ram, $tilesfour); + +//Build the 8x8 tile images +$tilesaddr = 0x12478; +$tilesone = make8x8Tiles($ram, $tilesone, $palone, $tilesaddr); +$tilestwo = make8x8Tiles($ram, $tilestwo, $paltwo, $tilesaddr); +$tilesthree = make8x8Tiles($ram, $tilesthree, $palthree, $tilesaddr); +$tilesfour = make8x8Tiles($ram, $tilesfour, $palfour, $tilesaddr); + +//Okay we got the tiles! Let's start building the Map16. +$map16 = imagecreatetruecolor(512, 512); +$mapaddr = 0xB478; +fseek($ram, $mapaddr); +$i = 0; +for($i= 0; $i < 32; $i++) +{ + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 2; $y++) + { + $x = 0; + for($x= 0; $x < 2; $x++) + { + $tile = getWord($ram); + // PCCY XAAA AAAA AAAA + //0110 0000 0000 0000 - 0x6000 - determine pallete + //0 = Pallete 0, 8192 = Pallete 1, 16384 = Pallete 2, 24576 = Pallete 3 + $tilepallete = $tile & 0x6000; + switch($tilepallete) { + case 0: $tilepallete = 0; break; + case 8192: $tilepallete = 1; break; + case 16384: $tilepallete = 2; break; + case 24576: $tilepallete = 3; break; + default: $tilepallete = 0; break; + } + //0001 0000 0000 0000 - 0x1000 - determine Y flip + //0 = No, 4096 = Yes + $tileyflip = $tile & 0x1000; + //0000 1000 0000 0000 - 0x0800 - determine X flip + //0 = No, 2048 = Yes + $tilexflip = $tile & 0x800; + //0000 0111 1111 1111 - 0x07FF - get tile ID + $tileID = $tile & 0x07FF; + //imagecopyresampled($map32, $tilesone, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + $tempimg = imagecreatetruecolor(8,8); + switch($tilepallete) { + case 0: imagecopyresampled($tempimg, $tilesone, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 1: imagecopyresampled($tempimg, $tilestwo, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 2: imagecopyresampled($tempimg, $tilesthree, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 3: imagecopyresampled($tempimg, $tilesfour, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + default: imagecopyresampled($tempimg, $tilesone, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + } + $flipflag = $tileyflip + $tilexflip; + $tempimg = image_flip($tempimg, $flipflag); + imagecopyresampled($map16, $tempimg, ($x * 8) + ($j * 16), ($y * 8) + ($i * 16), 0, 0, 8, 8, 8, 8); + imagedestroy($tempimg); + } + } + } +} + +//And now, the Map128. +$map128 = imagecreatetruecolor(128, 128); +$map128addr = 0x2478; +fseek($ram, $map128addr); +$i = 0; +for($i= 0; $i < 16; $i++) +{ + $j = 0; + for($j= 0; $j < 16; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x++) + { + $tile16 = getWord($ram); + //So the format is a bitmask SSTT YXII IIII IIII + //SS and TT are solidity info, Y is Y flip, X is X flip, and II IIII IIII is the Map16 ID + //We only care about the last 3 parts of this + + //determine Y flip + $tileyflip = $tile16 & 0x0800; + //determine X flip + $tilexflip = $tile16 & 0x0400; + //get tile ID + $tileID = $tile16 & 0x03FF; + + //Get the tile, determine its flip + $tempimg = imagecreatetruecolor(16,16); + imagecopyresampled($tempimg, $map16, 0, 0, ($tileID % 32) * 16, (floor($tileID / 32)) * 16, 16, 16, 16, 16); + + $flipflag = ($tileyflip * 2) + ($tilexflip * 2); + $tempimg = image_flip($tempimg, $flipflag); + imagecopyresampled($map128, $tempimg, ($x * 16), ($y * 16), 0, 0, 16, 16, 16, 16); + imagedestroy($tempimg); + //imagecopy($map128, $map16, ($x * 16), ($y * 16), ($tile16 % 32) * 16, (floor($tile16 / 32)) * 16, 16, 16); + } + } + //Save the Map128 tile! + imagecolortransparent($map128, $palone[0]); + imagepng($map128, $savepath."\\".(($i * 16) + $j).".png"); + } +} + +//It is time to start making the level layout! +//First, what is the background color? +fseek($ram, $bgcoffset); +$color = getByte($ram); +$color2 = getByte($ram); +// Genesis pallete entries are words - 0B GR +$red = 16 * ($color2 % 16); +$green = 16 * floor($color2 / 16); +$blue = 16 * ($color % 16); +$bgcolor = "rgb(".$red.",".$green.",".$blue.")"; +//Make a pair of arrays: one for the BG, one for the FG +$bgtiles = array(); +$fgtiles = array(); +//Let's jump to the layout data! +fseek($ram, 0xA478); +$i = 0; +for($i= 0; $i < 16; $i++) +{ + $j = 0; + for($j= 0; $j < 128; $j++) + { + $fgtiles[$i][$j] = getByte($ram); + if($_GET['hidefg'] == 1) $fgtiles[$i][$j] = 0; + } + $j = 0; + for($j= 0; $j < 128; $j++) + { + $bgtiles[$i][$j] = getByte($ram); + if($_GET['hidebg'] == 1) $bgtiles[$i][$j] = 0; + } +} +//Now let's begin outputting HTML. +?> +Ripped Level +"; + $j = 0; + for($j= 0; $j < 128; $j++) + { + echo ""; + } + echo ""; +} +echo "
BG: ".$bgtiles[$i][$j].", FG: ".$fgtiles[$i][$j]."
"; + +//FUNCTIONS +//Read a single byte from the file +function getByte( &$source ) +{ + return ord( fread( $source,1 ) ); +} + +//Read a 16-bit WORD from the file +function getWord( &$source ) +{ + return (getByte( $source ) * 0x100) + getByte( $source ); +} + +//Generate a 16-color pallete +function makePallete( $source, $gd ) +{ + $result = array(); + $i = 0; + for($i= 0; $i < 16; $i++) + { + $color = getByte($source); + $color2 = getByte($source); + // Genesis pallete entries are words - 0B GR + $red = 16 * ($color2 % 16); + $green = 16 * floor($color2 / 16); + $blue = 16 * ($color % 16); + if ($i == 0) $result[$i] = imagecolorallocate( $gd, 255, 0, 255 ); + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + return $result; +} + +//Build a set of 8x8 tiles +function make8x8Tiles( $source, $gd, $pal, $tileAddr ) { + fseek($source, $tileAddr); + $i = 0; + for($i= 0; $i < 48; $i++) + { + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($source); + // Split a byte into nybbles + $leftpixel = floor($byte / 16); + $rightpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($gd, $x + ($j * 8), $y + ($i * 8), $pal[$leftpixel]); + imagesetpixel($gd, $x + 1 + ($j * 8), $y + ($i * 8), $pal[$rightpixel]); + } + } + } + } + return $gd; +} + +//Borrowed from something open source Lightning linked me to. +function image_flip($img, $type){ + $width = imagesx($img); + $height = imagesy($img); + $dest = imagecreatetruecolor($width, $height); + switch($type){ + case 0: + return $img; + break; + case 4096: + for($i=0;$i<$height;$i++){ + imagecopy($dest, $img, 0, ($height - $i - 1), 0, $i, $width, 1); + } + break; + case 2048: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + } + break; + case 6144: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + + } + $buffer = imagecreatetruecolor($width, 1); + for($i=0;$i<($height/2);$i++){ + imagecopy($buffer, $dest, 0, 0, 0, ($height - $i -1), $width, 1); + imagecopy($dest, $dest, 0, ($height - $i - 1), 0, $i, $width, 1); + imagecopy($dest, $buffer, 0, $i, 0, 0, $width, 1); + } + imagedestroy($buffer); + break; + default: + return $img; + break; + } + return $dest; +} + +?> diff --git a/PHP/sadv2_levelrip.php b/PHP/sadv2_levelrip.php new file mode 100644 index 0000000..0896c30 --- /dev/null +++ b/PHP/sadv2_levelrip.php @@ -0,0 +1,377 @@ +>10)&31) << 3; + $blue += $blue >>5; + $green = (($color>>5)&31) << 3; + $green += $green >>5; + $red = (($color)&31) << 3; + $red += $red >>5; + // The above function was written by Justin Aquadero (Retriever II) + if ($i == 0) $result[$i] = imagecolorallocate( $gd, 255, 0, 255 ); + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + return $result; +} + +//Build a set of 8x8 tiles +function make8x8Tiles( $source, $gd, $pal, $tileAddr ) { + fseek($source, $tileAddr); + $i = 0; + for($i= 0; $i < 48; $i++) + { + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($source); + // Split a byte into nybbles + $rightpixel = floor($byte / 16); + $leftpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($gd, $x + ($j * 8), $y + ($i * 8), $pal[$leftpixel]); + imagesetpixel($gd, $x + 1 + ($j * 8), $y + ($i * 8), $pal[$rightpixel]); + } + } + } + } + return $gd; +} + +//Borrowed and modified from something open source Lightning linked me to. +function image_flip($img, $tilexflip, $tileyflip){ + $width = imagesx($img); + $height = imagesy($img); + $dest = imagecreatetruecolor($width, $height); + $type = $tilexflip + ($tileyflip * 2); + switch($type){ + case 0: + return $img; + break; + case 1: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + } + break; + case 2: + for($i=0;$i<$height;$i++){ + imagecopy($dest, $img, 0, ($height - $i - 1), 0, $i, $width, 1); + } + break; + case 3: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + + } + $buffer = imagecreatetruecolor($width, 1); + for($i=0;$i<($height/2);$i++){ + imagecopy($buffer, $dest, 0, 0, 0, ($height - $i -1), $width, 1); + imagecopy($dest, $dest, 0, ($height - $i - 1), 0, $i, $width, 1); + imagecopy($dest, $buffer, 0, $i, 0, 0, $width, 1); + } + imagedestroy($buffer); + break; + default: + return $img; + break; + } + return $dest; +} + +?> diff --git a/PHP/sadv3_levelrip.php b/PHP/sadv3_levelrip.php new file mode 100644 index 0000000..e36c525 --- /dev/null +++ b/PHP/sadv3_levelrip.php @@ -0,0 +1,301 @@ +>10)&31) << 3; + $blue += $blue >>5; + $green = (($color>>5)&31) << 3; + $green += $green >>5; + $red = (($color)&31) << 3; + $red += $red >>5; + // The above function was written by Justin Aquadero (Retriever II) + if ($i == 0) $result[$i] = imagecolorallocate( $gd, 255, 0, 255 ); + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + return $result; +} + +//Build a set of 8x8 tiles +function make8x8Tiles( $source, $gd, $pal, $tileAddr ) { + fseek($source, $tileAddr); + $i = 0; + for($i= 0; $i < 48; $i++) + { + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($source); + // Split a byte into nybbles + $rightpixel = floor($byte / 16); + $leftpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($gd, $x + ($j * 8), $y + ($i * 8), $pal[$leftpixel]); + imagesetpixel($gd, $x + 1 + ($j * 8), $y + ($i * 8), $pal[$rightpixel]); + } + } + } + } + return $gd; +} + +//Borrowed and modified from something open source Lightning linked me to. +function image_flip($img, $tilexflip, $tileyflip){ + $width = imagesx($img); + $height = imagesy($img); + $dest = imagecreatetruecolor($width, $height); + $type = $tilexflip + ($tileyflip * 2); + switch($type){ + case 0: + return $img; + break; + case 1: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + } + break; + case 2: + for($i=0;$i<$height;$i++){ + imagecopy($dest, $img, 0, ($height - $i - 1), 0, $i, $width, 1); + } + break; + case 3: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + + } + $buffer = imagecreatetruecolor($width, 1); + for($i=0;$i<($height/2);$i++){ + imagecopy($buffer, $dest, 0, 0, 0, ($height - $i -1), $width, 1); + imagecopy($dest, $dest, 0, ($height - $i - 1), 0, $i, $width, 1); + imagecopy($dest, $buffer, 0, $i, 0, 0, $width, 1); + } + imagedestroy($buffer); + break; + default: + return $img; + break; + } + return $dest; +} + +?> diff --git a/PHP/sadv_levelrip.php b/PHP/sadv_levelrip.php new file mode 100644 index 0000000..65ed1a7 --- /dev/null +++ b/PHP/sadv_levelrip.php @@ -0,0 +1,331 @@ +>10)&31) << 3; + $blue += $blue >>5; + $green = (($color>>5)&31) << 3; + $green += $green >>5; + $red = (($color)&31) << 3; + $red += $red >>5; + // The above function was written by Justin Aquadero (Retriever II) + if ($i == 0) $result[$i] = imagecolorallocate( $gd, 255, 0, 255 ); + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + return $result; +} + +//Build a set of 8x8 tiles +function make8x8Tiles( $source, $gd, $pal, $tileAddr ) { + fseek($source, $tileAddr); + $i = 0; + for($i= 0; $i < 48; $i++) + { + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($source); + // Split a byte into nybbles + $rightpixel = floor($byte / 16); + $leftpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($gd, $x + ($j * 8), $y + ($i * 8), $pal[$leftpixel]); + imagesetpixel($gd, $x + 1 + ($j * 8), $y + ($i * 8), $pal[$rightpixel]); + } + } + } + } + return $gd; +} + +//Borrowed and modified from something open source Lightning linked me to. +function image_flip($img, $tilexflip, $tileyflip){ + $width = imagesx($img); + $height = imagesy($img); + $dest = imagecreatetruecolor($width, $height); + $type = $tilexflip + ($tileyflip * 2); + switch($type){ + case 0: + return $img; + break; + case 1: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + } + break; + case 2: + for($i=0;$i<$height;$i++){ + imagecopy($dest, $img, 0, ($height - $i - 1), 0, $i, $width, 1); + } + break; + case 3: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + + } + $buffer = imagecreatetruecolor($width, 1); + for($i=0;$i<($height/2);$i++){ + imagecopy($buffer, $dest, 0, 0, 0, ($height - $i -1), $width, 1); + imagecopy($dest, $dest, 0, ($height - $i - 1), 0, $i, $width, 1); + imagecopy($dest, $buffer, 0, $i, 0, 0, $width, 1); + } + imagedestroy($buffer); + break; + default: + return $img; + break; + } + return $dest; +} + +?> diff --git a/PHP/socketrip.php b/PHP/socketrip.php new file mode 100644 index 0000000..5e14b5c --- /dev/null +++ b/PHP/socketrip.php @@ -0,0 +1,234 @@ +Oh crunch.FATALITY: You have to specify a filename with 'file' in the URL!"); +if(!file_exists($file)) die("Oh crunch.FATALITY: The file you specified doesn't exist. Man, I can't work with imaginary data, I need REAL data!"); + +//Next, do we want to save it somewhere specific, or do you want to put it +//in a new directory named from the input file? +$savepath = ""; +$filename = explode(".",$file); +$savepath = $filename[0]; +if(isset($_GET['savepath'])) $savepath = $_GET['savepath']; +if(!file_exists($savepath)) mkdir($savepath); + +//Address Constants +$paloffset = 0x10378; +$map16offset = 0x2478; + +//Make the images to hold the tile data +$tilesone = imagecreatetruecolor(256, 384); +$tilestwo = imagecreatetruecolor(256, 384); +$tilesthree = imagecreatetruecolor(256, 384); +$tilesfour = imagecreatetruecolor(256, 384); + +//Open the savestate, seek to the location of the pallete +$ram = fopen($file, "r"); +fseek($ram, $paloffset); + +//Make the palletes +$palone = makePallete($ram, $tilesone); +$paltwo = makePallete($ram, $tilestwo); +$palthree = makePallete($ram, $tilesthree); +$palfour = makePallete($ram, $tilesfour); + +//Build the 8x8 tile images +$tilesaddr = 0x12478; +$tilesone = make8x8Tiles($ram, $tilesone, $palone, $tilesaddr); +$tilestwo = make8x8Tiles($ram, $tilestwo, $paltwo, $tilesaddr); +$tilesthree = make8x8Tiles($ram, $tilesthree, $palthree, $tilesaddr); +$tilesfour = make8x8Tiles($ram, $tilesfour, $palfour, $tilesaddr); + +//Okay we got the tiles! Let's start building the Map16. +$map16 = imagecreatetruecolor(512, 512); +fseek($ram, $map16offset); +$i = 0; +for($i= 0; $i < 32; $i++) +{ + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 2; $y++) + { + $x = 0; + for($x= 0; $x < 2; $x++) + { + $tile = getWord($ram); + // PCCY XAAA AAAA AAAA + //0110 0000 0000 0000 - 0x6000 - determine pallete + //0 = Pallete 0, 8192 = Pallete 1, 16384 = Pallete 2, 24576 = Pallete 3 + $tilepallete = $tile & 0x6000; + switch($tilepallete) { + case 0: $tilepallete = 0; break; + case 8192: $tilepallete = 1; break; + case 16384: $tilepallete = 2; break; + case 24576: $tilepallete = 3; break; + default: $tilepallete = 0; break; + } + //0001 0000 0000 0000 - 0x1000 - determine Y flip + //0 = No, 4096 = Yes + $tileyflip = $tile & 0x1000; + //0000 1000 0000 0000 - 0x0800 - determine X flip + //0 = No, 2048 = Yes + $tilexflip = $tile & 0x800; + //0000 0111 1111 1111 - 0x07FF - get tile ID + $tileID = $tile & 0x07FF; + //imagecopyresampled($map32, $tilesone, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + $tempimg = imagecreatetruecolor(8,8); + switch($tilepallete) { + case 0: imagecopyresampled($tempimg, $tilesone, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 1: imagecopyresampled($tempimg, $tilestwo, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 2: imagecopyresampled($tempimg, $tilesthree, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + case 3: imagecopyresampled($tempimg, $tilesfour, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + default: imagecopyresampled($tempimg, $tilesone, 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + } + $flipflag = $tileyflip + $tilexflip; + $tempimg = image_flip($tempimg, $flipflag); + imagecopyresampled($map16, $tempimg, ($x * 8) + ($j * 16), ($y * 8) + ($i * 16), 0, 0, 8, 8, 8, 8); + imagedestroy($tempimg); + } + } + } +} + +//Save the Map16 +imagepng($map16, $savepath."\\map16.png"); + +//And now, the Map256. Friggin' gigantic, I know. +$map256 = imagecreatetruecolor(256, 256); +$map256addr = 0x2C78; +fseek($ram, $map256addr); +$i = 0; +for($i= 0; $i < 16; $i++) +{ + $j = 0; + for($j= 0; $j < 8; $j++) + { + $x = 0; + for($x= 0; $x < 16; $x++) + { + $y = 0; + for($y= 0; $y < 16; $y++) + { + $tile16 = getByte($ram); + //imagecopy($map256, $map16, ($x * 16) + ($j * 256), ($y * 16) + ($i * 256), ($tile16 % 32) * 16, (floor($tile16 / 32)) * 16, 16, 16); + imagecopy($map256, $map16, ($x * 16), ($y * 16), ($tile16 % 32) * 16, (floor($tile16 / 32)) * 16, 16, 16); + } + } + //Save the Map256 tile! + imagepng($map256, $savepath."\\".(($i * 8) + $j).".png"); + } +} + +//Output Map16 to make sure we're doing this right. +header('Content-Type: image/png'); +imagepng($map16); + +//FUNCTIONS +//Read a single byte from the file +function getByte( &$source ) +{ + return ord( fread( $source,1 ) ); +} + +//Read a 16-bit WORD from the file +function getWord( &$source ) +{ + return (getByte( $source ) * 0x100) + getByte( $source ); +} + +//Generate a 16-color pallete +function makePallete( $source, $gd ) +{ + $result = array(); + $i = 0; + for($i= 0; $i < 16; $i++) + { + $color = getByte($source); + $color2 = getByte($source); + // Genesis pallete entries are words - 0B GR + $red = 16 * ($color2 % 16); + $green = 16 * floor($color2 / 16); + $blue = 16 * ($color % 16); + if ($i == 0) $result[$i] = imagecolorallocate( $gd, 255, 0, 255 ); + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + return $result; +} + +//Build a set of 8x8 tiles +function make8x8Tiles( $source, $gd, $pal, $tileAddr ) { + fseek($source, $tileAddr); + $i = 0; + for($i= 0; $i < 48; $i++) + { + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($source); + // Split a byte into nybbles + $leftpixel = floor($byte / 16); + $rightpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($gd, $x + ($j * 8), $y + ($i * 8), $pal[$leftpixel]); + imagesetpixel($gd, $x + 1 + ($j * 8), $y + ($i * 8), $pal[$rightpixel]); + } + } + } + } + return $gd; +} + +//Borrowed from something open source Lightning linked me to. +function image_flip($img, $type){ + $width = imagesx($img); + $height = imagesy($img); + $dest = imagecreatetruecolor($width, $height); + switch($type){ + case 0: + return $img; + break; + case 4096: + for($i=0;$i<$height;$i++){ + imagecopy($dest, $img, 0, ($height - $i - 1), 0, $i, $width, 1); + } + break; + case 2048: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + } + break; + case 6144: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + + } + $buffer = imagecreatetruecolor($width, 1); + for($i=0;$i<($height/2);$i++){ + imagecopy($buffer, $dest, 0, 0, 0, ($height - $i -1), $width, 1); + imagecopy($dest, $dest, 0, ($height - $i - 1), 0, $i, $width, 1); + imagecopy($dest, $buffer, 0, $i, 0, 0, $width, 1); + } + imagedestroy($buffer); + break; + default: + return $img; + break; + } + return $dest; +} + +?> \ No newline at end of file diff --git a/PHP/sonic_levelrip.php b/PHP/sonic_levelrip.php new file mode 100644 index 0000000..aa9e206 --- /dev/null +++ b/PHP/sonic_levelrip.php @@ -0,0 +1,301 @@ +Oh crunch.FATALITY: You have to specify a filename with 'file' in the URL!"); +if(!file_exists($file)) die("Oh crunch.FATALITY: The file you specified doesn't exist. Man, I can't work with imaginary data, I need REAL data!"); + +//Next, do we want to save it somewhere specific, or do you want to put it +//in a new directory named from the input file? +$savepath = ""; +$filename = explode(".",$file); +$savepath = $filename[0]; +if(isset($_GET['savepath'])) $savepath = $_GET['savepath']; +if(!file_exists($savepath)) mkdir($savepath); +if(!file_exists($savepath."/high")) mkdir($savepath."/high"); +if(!file_exists($savepath."/low")) mkdir($savepath."/low"); + +//Okay, is this Sonic 1, Sonic 2, or Sonic 3K??? +//Default is Sonic 2. +$game = 2; +$paloffset = 0x11F78; +$bgcoffset = 0x11FB8; +$map16offset = 0xB478; +$layout = 0xA478; +if(isset($_GET['game'])) $game = $_GET['game']; +switch ($game) +{ + case 1: $paloffset = 0x11F78; $bgcoffset = 0x11FB8; $map16offset = 0xD478; $layout = 0xC878; break; + case 2: $paloffset = 0x11F78; $bgcoffset = 0x11FB8; $map16offset = 0xB478; $layout = 0xA478; break; + case 3: $paloffset = 0x12078; $bgcoffset = 0x120B8; $map16offset = 0xB478; $layout = 0xA478; break; + default: $paloffset = 0x11F78; $bgcoffset = 0x11FB8; $map16offset = 0xB478; $layout = 0xA478; break; +} + +//Open the savestate, seek to the location of the pallete +$ram = fopen($file, "r"); +fseek($ram, $paloffset); + +//Make the images to hold the tile data +for($i = 0; $i < 4; $i++) { + $tiles[$i] = imagecreate(256, 512); + $pal[$i] = makeGenPallete($ram, $tiles[$i], TRUE); +} + +//Build the 8x8 tile images +$tilesaddr = 0x12478; +for($i = 0; $i < 4; $i++) { + $bgtiles[$i] = make8x8Tiles($ram, $tiles[$i], $pal[$i], $tilesaddr); +} + +//Okay we got the tiles! Let's start building the Map16. +$map16 = imagecreatetruecolor(512, 512); +$highmap16 = imagecreatetruecolor(512, 512); +$lowmap16 = imagecreatetruecolor(512, 512); +fseek($ram, $map16offset); +$i = 0; +for($i= 0; $i < 32; $i++) +{ + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 2; $y++) + { + $x = 0; + for($x= 0; $x < 2; $x++) + { + $tile = getWord($ram); + // PCCY XAAA AAAA AAAA + //0110 0000 0000 0000 - 0x6000 - determine pallete + //0 = Pallete 0, 8192 = Pallete 1, 16384 = Pallete 2, 24576 = Pallete 3 + $tilepallete = $tile & 0x6000; + switch($tilepallete) { + case 0: $tilepallete = 0; break; + case 8192: $tilepallete = 1; break; + case 16384: $tilepallete = 2; break; + case 24576: $tilepallete = 3; break; + default: $tilepallete = 0; break; + } + //0001 0000 0000 0000 - 0x1000 - determine Y flip + //0 = No, 4096 = Yes + $tileyflip = $tile & 0x1000; + //0000 1000 0000 0000 - 0x0800 - determine X flip + //0 = No, 2048 = Yes + $tilexflip = $tile & 0x800; + //0000 0111 1111 1111 - 0x07FF - get tile ID + $tileID = $tile & 0x07FF; + //imagecopyresampled($map32, $tilesone, ($x * 8) + ($j * 32), ($y * 8) + ($i * 32), ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); break; + $tempimg = imagecreatetruecolor(8,8); + imagecopyresampled($tempimg, $tiles[$tilepallete], 0, 0, ($tileID % 32) * 8, (floor($tileID / 32)) * 8, 8, 8, 8, 8); + $flipflag = $tileyflip + $tilexflip; + $tempimg = image_flip($tempimg, $flipflag); + imagecopyresampled($map16, $tempimg, ($x * 8) + ($j * 16), ($y * 8) + ($i * 16), 0, 0, 8, 8, 8, 8); + if(($tile & 0x8000) == 0x8000) imagecopyresampled($highmap16, $tempimg, ($x * 8) + ($j * 16), ($y * 8) + ($i * 16), 0, 0, 8, 8, 8, 8); + else imagecopyresampled($lowmap16, $tempimg, ($x * 8) + ($j * 16), ($y * 8) + ($i * 16), 0, 0, 8, 8, 8, 8); + imagedestroy($tempimg); + } + } + } +} +// Save the Map16 +imagepng($map16, $savepath."/_map16.png"); + +//And now, the Map128 OR Map256, depending on the game. +if($game != 1) +{ + $map128 = imagecreatetruecolor(128, 128); + $highmap128 = imagecreatetruecolor(128, 128); + $lowmap128 = imagecreatetruecolor(128, 128); + $map128addr = 0x2478; + fseek($ram, $map128addr); + $i = 0; + for($i= 0; $i < 16; $i++) + { + $j = 0; + for($j= 0; $j < 16; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x++) + { + $tile16 = getWord($ram); + //So the format is a bitmask SSTT YXII IIII IIII + //SS and TT are solidity info, Y is Y flip, X is X flip, and II IIII IIII is the Map16 ID + //We only care about the last 3 parts of this + + //determine Y flip + $tileyflip = $tile16 & 0x0800; + //determine X flip + $tilexflip = $tile16 & 0x0400; + //get tile ID + $tileID = $tile16 & 0x03FF; + + //Get the tile, determine its flip + $tempimg = imagecreatetruecolor(16,16); + imagecopyresampled($tempimg, $map16, 0, 0, ($tileID % 32) * 16, (floor($tileID / 32)) * 16, 16, 16, 16, 16); + $hightempimg = imagecreatetruecolor(16,16); + imagecopyresampled($hightempimg, $highmap16, 0, 0, ($tileID % 32) * 16, (floor($tileID / 32)) * 16, 16, 16, 16, 16); + $lowtempimg = imagecreatetruecolor(16,16); + imagecopyresampled($lowtempimg, $lowmap16, 0, 0, ($tileID % 32) * 16, (floor($tileID / 32)) * 16, 16, 16, 16, 16); + + $flipflag = ($tileyflip * 2) + ($tilexflip * 2); + $tempimg = image_flip($tempimg, $flipflag); + $hightempimg = image_flip($hightempimg, $flipflag); + $lowtempimg = image_flip($lowtempimg, $flipflag); + imagecopyresampled($map128, $tempimg, ($x * 16), ($y * 16), 0, 0, 16, 16, 16, 16); + imagecopyresampled($highmap128, $hightempimg, ($x * 16), ($y * 16), 0, 0, 16, 16, 16, 16); + imagecopyresampled($lowmap128, $lowtempimg, ($x * 16), ($y * 16), 0, 0, 16, 16, 16, 16); + imagedestroy($tempimg); + } + } + //Save the Map128 tile! + imagecolortransparent($map128, $pal[0][0]); + imagecolortransparent($highmap128, $pal[0][0]); + imagecolortransparent($lowmap128, $pal[0][0]); + imagepng($map128, $savepath."/".(($i * 16) + $j).".png"); + imagepng($highmap128, $savepath."/high/".(($i * 16) + $j).".png"); + imagepng($lowmap128, $savepath."/low/".(($i * 16) + $j).".png"); + } + } +} +else +{ + $map256 = imagecreatetruecolor(256, 256); + $highmap256 = imagecreatetruecolor(256, 256); + $lowmap256 = imagecreatetruecolor(256, 256); + //imagefill($map256, 0, 0, $pal[0][0]); + //imagecolortransparent($map256, $pal[0][0]); + //imagepng($map256, $savepath."\\0.png"); + $map256addr = 0x2478; + fseek($ram, $map256addr); + $i = 0; + for($i= 0; $i < 9; $i++) + { + $j = 0; + for($j= 0; $j < 8; $j++) + { + $y = 0; + for($y= 0; $y < 16; $y++) + { + $x = 0; + for($x= 0; $x < 16; $x++) + { + $tile16 = getWord($ram); + //So the format is a bitmask SSSY XIII IIII IIII + //SSS is solidity info, Y is Y flip, X is X flip, and III IIII IIII is the Map16 ID + //We only care about the last 3 parts of this + + //0001 0000 0000 0000 - 0x1000 - determine Y flip + //0 = No, 4096 = Yes + $tileyflip = $tile16 & 0x1000; + //0000 1000 0000 0000 - 0x0800 - determine X flip + //0 = No, 2048 = Yes + $tilexflip = $tile16 & 0x0800; + //0000 0111 1111 1111 - 0x07FF - get tile ID + $tileID = $tile16 & 0x07FF; + + //Get the tile, determine its flip + $tempimg = imagecreatetruecolor(16,16); + imagecopyresampled($tempimg, $map16, 0, 0, ($tileID % 32) * 16, (floor($tileID / 32)) * 16, 16, 16, 16, 16); + $hightempimg = imagecreatetruecolor(16,16); + imagecopyresampled($hightempimg, $highmap16, 0, 0, ($tileID % 32) * 16, (floor($tileID / 32)) * 16, 16, 16, 16, 16); + $lowtempimg = imagecreatetruecolor(16,16); + imagecopyresampled($lowtempimg, $lowmap16, 0, 0, ($tileID % 32) * 16, (floor($tileID / 32)) * 16, 16, 16, 16, 16); + + $flipflag = $tileyflip + $tilexflip; + $tempimg = image_flip($tempimg, $flipflag); + $hightempimg = image_flip($hightempimg, $flipflag); + $lowtempimg = image_flip($lowtempimg, $flipflag); + imagecopyresampled($map256, $tempimg, ($x * 16), ($y * 16), 0, 0, 16, 16, 16, 16); + imagecopyresampled($highmap256, $hightempimg, ($x * 16), ($y * 16), 0, 0, 16, 16, 16, 16); + imagecopyresampled($lowmap256, $lowtempimg, ($x * 16), ($y * 16), 0, 0, 16, 16, 16, 16); + imagedestroy($tempimg); + } + } + //Save the Map256 tile! + imagecolortransparent($map256, $pal[0][0]); + imagecolortransparent($highmap256, $pal[0][0]); + imagecolortransparent($lowmap256, $pal[0][0]); + imagepng($map256, $savepath."/".(($i * 8) + $j).".png"); + imagepng($highmap256, $savepath."/high/".(($i * 8) + $j).".png"); + imagepng($lowmap256, $savepath."/low/".(($i * 8) + $j).".png"); + } + } +} + +//It is time to start making the level layout! +// ARE we making a level layout? +if(isset($_GET['map'])) { + //First, what is the background color? + fseek($ram, $bgcoffset); + $color = getByte($ram); + $color2 = getByte($ram); + // Genesis pallete entries are words - 0B GR + $red = 16 * ($color2 % 16); + $green = 16 * floor($color2 / 16); + $blue = 16 * ($color % 16); + $bgcolor = "rgb(".$red.",".$green.",".$blue.")"; + //Make a pair of arrays: one for the BG, one for the FG + $bgtiles = array(); + $fgtiles = array(); + //Let's jump to the layout data! + fseek($ram, $layout); + $i = 0; + for($i= 0; $i < 16; $i++) + { + $j = 0; + for($j= 0; $j < 128; $j++) + { + $fgtiles[$i][$j] = getByte($ram); + if($_GET['hidefg'] == 1) $fgtiles[$i][$j] = 0; + } + $j = 0; + for($j= 0; $j < 128; $j++) + { + $bgtiles[$i][$j] = getByte($ram); + if($_GET['hidebg'] == 1) $bgtiles[$i][$j] = 0; + } + } + //Now let's begin outputting HTML. + ?> + Ripped Level + "; + $j = 0; + for($j= 0; $j < 128; $j++) + { + echo ""; + } + echo ""; + } + echo "
BG: ".$bgtiles[$i][$j].", FG: ".$fgtiles[$i][$j]."
"; +} +// No, then we're done! ...well, almost. How long did it take? LET'S FIND OUT :D +else { +$time_end = microtime(true); +$time = $time_end - $time_start; + +echo "Ripping complete!
Completed in $time seconds!"; +} +?> diff --git a/PHP/sparkrip.php b/PHP/sparkrip.php new file mode 100644 index 0000000..dfa1430 --- /dev/null +++ b/PHP/sparkrip.php @@ -0,0 +1,205 @@ +Completed in $time seconds!"; + +//FUNCTIONS +//Read a single byte from the file +function getByte( &$source ) +{ + return ord( fread( $source,1 ) ); +} + +//Read a 16-bit WORD from the file +function getWord( &$source ) +{ + return (getByte( $source ) * 0x100) + getByte( $source ); +} + +//Generate a 16-color pallete +function makePallete( $source, $gd ) +{ + $result = array(); + $i = 0; + for($i= 0; $i < 16; $i++) + { + $color = getByte($source); + $color2 = getByte($source); + // Genesis pallete entries are words - 0B GR + $red = 16 * ($color2 % 16); + $green = 16 * floor($color2 / 16); + $blue = 16 * ($color % 16); + if ($i == 0) $result[$i] = imagecolorallocate( $gd, 255, 0, 255 ); + else $result[$i] = imagecolorallocate( $gd, $red, $green, $blue ); + } + return $result; +} + +//Build a set of 8x8 tiles +function make8x8Tiles( $source, $gd, $pal, $tileAddr ) { + fseek($source, $tileAddr); + $i = 0; + for($i= 0; $i < 256; $i++) + { + $j = 0; + for($j= 0; $j < 32; $j++) + { + $y = 0; + for($y= 0; $y < 8; $y++) + { + $x = 0; + for($x= 0; $x < 8; $x = $x + 2) + { + $byte = getByte($source); + // Split a byte into nybbles + $leftpixel = floor($byte / 16); + $rightpixel = ($byte % 16); + //Paint the two pixels + imagesetpixel($gd, $x + ($j * 8), $y + ($i * 8), $pal[$leftpixel]); + imagesetpixel($gd, $x + 1 + ($j * 8), $y + ($i * 8), $pal[$rightpixel]); + } + } + } + } + return $gd; +} + +//Borrowed from something open source Lightning linked me to. +function image_flip($img, $type){ + $width = imagesx($img); + $height = imagesy($img); + $dest = imagecreatetruecolor($width, $height); + switch($type){ + case 0: + return $img; + break; + case 4096: + for($i=0;$i<$height;$i++){ + imagecopy($dest, $img, 0, ($height - $i - 1), 0, $i, $width, 1); + } + break; + case 2048: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + } + break; + case 6144: + for($i=0;$i<$width;$i++){ + imagecopy($dest, $img, ($width - $i - 1), 0, $i, 0, 1, $height); + + } + $buffer = imagecreatetruecolor($width, 1); + for($i=0;$i<($height/2);$i++){ + imagecopy($buffer, $dest, 0, 0, 0, ($height - $i -1), $width, 1); + imagecopy($dest, $dest, 0, ($height - $i - 1), 0, $i, $width, 1); + imagecopy($dest, $buffer, 0, $i, 0, 0, $width, 1); + } + imagedestroy($buffer); + break; + default: + return $img; + break; + } + return $dest; +} + +?> diff --git a/PHP/srlp.php b/PHP/srlp.php new file mode 100644 index 0000000..2021bae --- /dev/null +++ b/PHP/srlp.php @@ -0,0 +1,112 @@ +FATALITYHey, the data directory you gave me doesn't exist! TRY AGAIN"); + +// Next, the map data. Default is z11, which is the first act of the first zone. +$stg = "z11"; +if(isset($_GET['level'])) $stg = $_GET['level']; +if(!file_exists($game."/".$stg."_a.mp") || !file_exists($game."/".$stg."_b.mp")) die("FATALITYHey, the map data doesn't exist! TRY AGAIN"); + +// Now, metatile source directory? +$srcdir = $game.$stg."/"; +$level = $stg; +if(isset($_GET['meta'])) +{ + $level = $_GET['meta']; + $srcdir = $game.$_GET['meta']; +} +if(!file_exists($srcdir)) die("FATALITYHey, the metatile directory you gave me doesn't exist! You're supposed to extract the metatiles first! TRY AGAIN"); + +// Palette datas +$pl_file = $game."/".$level.".pl"; + +// Finally, save location! +$savepath = $srcdir; +if(isset($_GET['save'])) $savepath = $_GET['save']; +if(!file_exists($savepath)) mkdir($savepath); + +// Load the mapping data +$amapdata = fopen($game."/".$stg."_a.mp", "r"); +$bmapdata = fopen($game."/".$stg."_b.mp", "r"); + +// How big are the images going to be? +$adimx = getFWord($amapdata); +$adimy = getFWord($amapdata); + +$bdimx = getFWord($bmapdata); +$bdimy = getFWord($bmapdata); + +// SANITY CHECK! +if(($adimx != $bdimx) || ($adimy != $bdimy)) die("FATALITYHey, the map dimensions for layers A and B do not match! TRY AGAIN"); + +// Time to render! +$pl_data = fopen($pl_file, "r"); +$amapimg = imagecreate(($adimx * 64),($adimy * 64)); +$apal = make8BitGBAPallete($pl_data, $amapimg); +fclose($pl_data); +for ($i = 0; $i < $adimy; $i++) { + for ($j = 0; $j < $adimx; $j++) { + $curtile = getFWord($amapdata); + if(!file_exists($srcdir."/".$curtile.".png")) die("FATALITYHey, the metatile (".$srcdir."/".$curtile.".png) doesn't exist! TRY AGAIN"); + $tempimg = imagecreatefrompng($srcdir."/".$curtile.".png"); + imagecopymerge_alpha($amapimg, $tempimg, ($j * 64), ($i * 64), 0, 0, 64, 64, 0); + imagedestroy($tempimg); + } +} + +// Output +imagepng($amapimg, $savepath."/".$stg."_a.png"); +imagedestroy($amapimg); + +// NEXT! +$pl_data = fopen($pl_file, "r"); +$bmapimg = imagecreate(($bdimx * 64),($bdimy * 64)); +$bpal = make8BitGBAPallete($pl_data, $bmapimg); +fclose($pl_data); +for ($i = 0; $i < $bdimy; $i++) { + for ($j = 0; $j < $bdimx; $j++) { + $curtile = getFWord($bmapdata); + if(!file_exists($srcdir."/".$curtile.".png")) die("FATALITYHey, the metatile (".$srcdir."/".$curtile.".png) doesn't exist! TRY AGAIN"); + $tempimg = imagecreatefrompng($srcdir."/".$curtile.".png"); + imagecopymerge_alpha($bmapimg, $tempimg, ($j * 64), ($i * 64), 0, 0, 64, 64, 0); + imagedestroy($tempimg); + } +} + +// Output +imagepng($bmapimg, $savepath."/".$stg."_b.png"); +imagedestroy($bmapimg); + +// Done +fclose($amapdata); +fclose($bmapdata); + +// And we're done! ...well, almost. How long did it take? LET'S FIND OUT :D +$time_end = microtime(true); +$time = $time_end - $time_start; + +echo "Sonic Rush Level ParserRipping complete!
Completed in $time seconds!"; + +?> diff --git a/PHP/sumlp.php b/PHP/sumlp.php new file mode 100644 index 0000000..8442a8f --- /dev/null +++ b/PHP/sumlp.php @@ -0,0 +1,120 @@ +FATALITY: I don't think that's the right BG tileset..."); + $curflag = getByte($bgflagdata); + // Parse flags + if($curflag == "1") $flip = 2048; + else if($curflag == "2") $flip = 4096; + else if($curflag == "3") $flip = 6144; + else $flip = 0; + $tempimg = image_flip(imagecreatefrompng($bgimgdata.$palID."/".$curtile.".png"), $flip); + imagecopymerge_alpha($bgmapimg, $tempimg, ($j * 20), ($i * 20), 0, 0, 20, 20, 0); + imagedestroy($tempimg); + } +} + +// Output +imagecolortransparent($bgmapimg, $bgcolor); +imagepng($bgmapimg, "out/".$src."_".$palID."_bg.png"); + +// NEXT! +$mapimg = imagecreatetruecolor(($fgdimx * 20),($fgdimy * 20)); +$bgcolor = imagecolorallocate($mapimg, 0, 128, 128); +imagefill($mapimg, 0, 0, $bgcolor); +for ($i = 0; $i < $fgdimy; $i++) { + for ($j = 0; $j < $fgdimx; $j++) { + $curtile = getByte($mapdata); + $curflag = getByte($flagdata); + // Parse flags + if($curflag == "1") $flip = 2048; + else if($curflag == "2") $flip = 4096; + else if($curflag == "3") $flip = 6144; + else $flip = 0; + if($curtile != 255) { + if(!file_exists($imgdata.$palID."/".$curtile.".png")) die("FATALITY: I don't think that's the right FG tileset..."); + $tempimg = image_flip(imagecreatefrompng($imgdata.$palID."/".$curtile.".png"), $flip); + imagecopymerge_alpha($mapimg, $tempimg, ($j * 20), ($i * 20), 0, 0, 20, 20, 0); + imagedestroy($tempimg); + } + } +} + +// Output +imagecolortransparent($mapimg, $bgcolor); +imagepng($mapimg, "out/".$src."_".$palID."_fg.png"); + +// Done +fclose($mapdata); +fclose($flagdata); + +// And we're done! ...well, almost. How long did it take? LET'S FIND OUT :D +$time_end = microtime(true); +$time = $time_end - $time_start; + +echo "Ripping complete!
Completed in $time seconds!"; + +?> diff --git a/PHP/sumssa.php b/PHP/sumssa.php new file mode 100644 index 0000000..1f43719 --- /dev/null +++ b/PHP/sumssa.php @@ -0,0 +1,127 @@ + $strdat) { + $bits = explode(" ", $strdat); + if($bits[0] == "start") + $current_entry = $bits[2]; + if($bits[0] == "flags") { + //Recycling libripper which works with real console state data + if($bits[2] == "1") $flip = 2048; + else if($bits[2] == "2") $flip = 4096; + else if($bits[2] == "3") $flip = 6144; + else if($bits[2] == "5") $flip = 270; + else if($bits[2] == "7") $flip = 90; + else $flip = 0; + $spritearr[$current_entry][0] = $flip; + } + if($bits[0] == "xoffset") { + $number = $bits[2]; + if($number > 127) { + $number = -256 + $number; + } + $spritearr[$current_entry][1] = $number; + } + if($bits[0] == "yoffset") { + $number = $bits[2]; + if($number > 127) { + $number = -256 + $number; + } + $spritearr[$current_entry][2] = $number; + } + if($bits[0] == "draw") + $spritearr[$current_entry][3] = $bits[2]; + } + + // Okay now assemble it. + if(isset($_GET['istiles'])) $theimage = imagecreatetruecolor(20,20); + else $theimage = imagecreatetruecolor(256,256); + $bgcolor = imagecolorallocate($theimage, 0, 128, 128); + imagefill($theimage, 0, 0, $bgcolor); + foreach ($spritearr as $entry => $sprite) { + // Get the image dimensions. + $imagepath = $srcdir.$sprite[3]."_".$palID.".png"; + $size = getimagesize($imagepath); + //$tempimg = imagecreatetruecolor($size[0],$size[1]); + $tempimg = image_flip(imagecreatefrompng($imagepath), $sprite[0]); + if($sprite[0] == 90) { + $tempimg = imagerotate($tempimg, 90, 0); + $xsize = $size[1]; + $ysize = $size[0]; + } + else if($sprite[0] == 270) { + $tempimg = image_flip($tempimg, 2048); + $tempimg = imagerotate($tempimg, 270, 0); + $xsize = $size[1]; + $ysize = $size[0]; + } + else { + $xsize = $size[0]; + $ysize = $size[1]; + } + if(isset($_GET['istiles'])) imagecopymerge_alpha($theimage, $tempimg, ($sprite[1]), ($sprite[2]), 0, 0, $xsize, $ysize, 0); + else imagecopymerge_alpha($theimage, $tempimg, (128 + $sprite[1]), (128 + $sprite[2]), 0, 0, $xsize, $ysize, 0); + imagedestroy($tempimg); + } + + // Output + if($useTrans) imagecolortransparent($theimage, $bgcolor); + imagepng($theimage, "out/".$imgn."/".$palID."/".$i.".png"); + // Cleanup + unset($spritearr); +} + +// And we're done! ...well, almost. How long did it take? LET'S FIND OUT :D +$time_end = microtime(true); +$time = $time_end - $time_start; + +echo "Ripping complete!
Completed in $time seconds!"; + +?> diff --git a/sadv2_addr.txt b/sadv2_addr.txt new file mode 100644 index 0000000..8369ea2 --- /dev/null +++ b/sadv2_addr.txt @@ -0,0 +1,117 @@ +------------------------- +Sonic Advance 2 Addresses +------------------------- + +These are a bunch of addresses in the ROM I have +identified while making a script that extracts the +96x96 mapping data from the ROM. + +LEAF FOREST ZONE 1 +Pallete 0x6E9E08 +8x8 Tiles 0x6EA008 +96x96 Mappings 0x6F33D0 + +LEAF FOREST ZONE 2 +Pallete 0x71459C +8x8 Tiles 0x71479C +96x96 Mappings 0x71D474 + +LEAF FOREST ZONE 3 +Pallete 0x73A438 +8x8 Tiles 0x73A638 +96x96 Mappings 0x73B844 + +HOT CRATER ZONE 1 +Pallete 0x73CCB0 +8x8 Tiles 0x73CEB0 +96x96 Mappings 0x74541C + +HOT CRATER ZONE 2 +Pallete 0x763AA0 +8x8 Tiles 0x763CA0 +96x96 Mappings 0x76C690 + +HOT CRATER ZONE 3 +Pallete 0x78FEBC +8x8 Tiles 0x7900BC +96x96 Mappings 0x7913EC + +MUSIC PLANT ZONE 1 +Pallete 0x79279C +8x8 Tiles 0x79299C +96x96 Mappings 0x79BEFC + +MUSIC PLANT ZONE 2 +Pallete 0x7B8E80 +8x8 Tiles 0x7B9080 +96x96 Mappings 0x7C20E0 + +MUSIC PLANT ZONE 3 +Pallete 0x7DB79C +8x8 Tiles 0x7DB99C +96x96 Mappings 0x7DC5DC + +ICE PARADISE ZONE 1 +Pallete 0x7DCB88 +8x8 Tiles 0x7DCD88 +96x96 Mappings 0x7E5E90 + +ICE PARADISE ZONE 2 +Pallete 0x80C594 +8x8 Tiles 0x80C794 +96x96 Mappings 0x8152A4 + +ICE PARADISE ZONE 3 +Pallete 0x834450 +8x8 Tiles 0x834650 +96x96 Mappings 0x835218 + +SKY CANYON ZONE 1 +Pallete 0x835DDC +8x8 Tiles 0x835FDC +96x96 Mappings 0x83CCF8 + +SKY CANYON ZONE 2 +Pallete 0x85DB74 +8x8 Tiles 0x85DD74 +96x96 Mappings 0x864CA8 + +SKY CANYON ZONE 3 +Pallete 0x885AB4 +8x8 Tiles 0x885CB4 +96x96 Mappings 0x88675C + +TECHNO BASE ZONE 1 +Pallete 0x8876F8 +8x8 Tiles 0x8878F8 +96x96 Mappings 0x88CF30 + +TECHNO BASE ZONE 2 +Pallete 0x8A9194 +8x8 Tiles 0x8A9394 +96x96 Mappings 0x8AE210 + +TECHNO BASE ZONE 3 +Pallete 0x8C269C +8x8 Tiles 0x8C289C +96x96 Mappings 0x8C4860 + +EGG UTOPIA ZONE 1 +Pallete 0x8C5724 +8x8 Tiles 0x8C5924 +96x96 Mappings 0x8CD8C4 + +EGG UTOPIA ZONE 2 +Pallete 0x8F7DD0 +8x8 Tiles 0x8F7FD0 +96x96 Mappings 0x900090 + +EGG UTOPIA ZONE 3 +Pallete 0x924E80 +8x8 Tiles 0x925080 +96x96 Mappings 0x9256CC + +XX ZONE +Pallete 0x925CF0 +8x8 Tiles 0x925EF0 +96x96 Mappings 0x9290E8 \ No newline at end of file diff --git a/sadv3_addr.txt b/sadv3_addr.txt new file mode 100644 index 0000000..8e065a4 --- /dev/null +++ b/sadv3_addr.txt @@ -0,0 +1,64 @@ +------------------------- +Sonic Advance 3 Addresses +------------------------- + +These are a bunch of addresses in the ROM I have +identified while making a script that extracts the +96x96 mapping data from the ROM. + +ROUTE 99 +Pallete 0x358650 +8x8 Tiles 0x358850 +96x96 Mappings 0x362D50 + +SONIC FACTORY & CHAO GARDEN +Pallete 0x3946D0 +8x8 Tiles 0x3948D0 +96x96 Mappings 0x3A4D8C + +MINIGAMES & ZONE MAP (1) +Pallete 0x3A9F40 +8x8 Tiles 0x3AA140 +96x96 Mappings 0x3B4640 + +SUNSET HILL +Pallete 0x3FCC84 +8x8 Tiles 0x3FCE84 +96x96 Mappings 0x407384 + +OCEAN BASE +Pallete 0x4588BC +8x8 Tiles 0x458ABC +96x96 Mappings 0x462FBC + +TOY KINGDOM +Pallete 0x491638 +8x8 Tiles 0x491838 +96x96 Mappings 0x49C260 + +TWINKLE SNOW +Pallete 0x4CCC38 +8x8 Tiles 0x4CCE38 +96x96 Mappings 0x4D7A50 + +CYBER TRACK +Pallete 0x50CAD4 +8x8 Tiles 0x50CCD4 +96x96 Mappings 0x51AA3C + +CHAOS ANGEL +Pallete 0x56D224 +8x8 Tiles 0x56D424 +96x96 Mappings 0x579438 + +ALTAR EMERALD +Pallete 0x5B07E0 +8x8 Tiles 0x5B09E0 +96x96 Mappings 0x5BC330 + +SUNSET HILL VS MODE +Pallete 0x5CABC0 +8x8 Tiles 0x5CADC0 +96x96 Mappings 0x5D52C0 + +(1) The listed pallete is for the minigame stages. For the zone maps, use the desired zone's pallete. (i.e. use the pallete listed for Ocean Base to get the Ocean Base Map) \ No newline at end of file