v50 Steam/Premium information for editors
- v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
- Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.
Editing User:Quietust/rawextract.php
Jump to navigation
Jump to search
Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | <nowiki><? | + | <nowiki><? |
− | + | function decompress ($file) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | function decompress ( | ||
{ | { | ||
$out = tmpfile(); | $out = tmpfile(); | ||
// write 'uncompressed' header | // write 'uncompressed' header | ||
− | fwrite($out, pack('VV', | + | fwrite($out, pack('VV', 0x0509, 0)); |
while (1) | while (1) | ||
{ | { | ||
− | $len = | + | $len = readLong($file); |
if (feof($file)) | if (feof($file)) | ||
break; | break; | ||
− | $block = fread($file, $len); | + | $skip = readShort($file); |
− | fwrite($out, | + | $block = fread($file, $len - 2); |
+ | fwrite($out, gzinflate($block)); | ||
} | } | ||
rewind($out); | rewind($out); | ||
− | |||
− | |||
− | |||
return $out; | return $out; | ||
} | } | ||
Line 125: | Line 21: | ||
{ | { | ||
$x = fread($file, 4); | $x = fread($file, 4); | ||
− | $pck = | + | $pck = unpack('Vdata', $x); |
return $pck['data']; | return $pck['data']; | ||
} | } | ||
Line 131: | Line 27: | ||
{ | { | ||
$x = fread($file, 2); | $x = fread($file, 2); | ||
− | $pck = | + | $pck = unpack('vdata', $x); |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
return $pck['data']; | return $pck['data']; | ||
} | } | ||
− | + | $raw = @fopen('world.dat', 'rb'); | |
− | |||
− | |||
− | |||
− | $raw = @fopen( | ||
if ($raw) | if ($raw) | ||
{ | { | ||
− | $ | + | $sig = readLong($raw); |
− | if | + | if ($sig != 0x0509) |
− | + | die("world.dat file header not found!"); | |
− | + | ||
$comp = readLong($raw); | $comp = readLong($raw); | ||
if ($comp == 1) | if ($comp == 1) | ||
− | $raw = decompress( | + | $raw = decompress($raw); |
elseif ($comp > 0) | elseif ($comp > 0) | ||
die("world.dat file is corrupted!"); | die("world.dat file is corrupted!"); | ||
− | fseek($raw, | + | fseek($raw, 0x92, SEEK_SET); |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
$len = readShort($raw); | $len = readShort($raw); | ||
$world = fread($raw, $len); | $world = fread($raw, $len); | ||
− | + | echo "Listing raws for randomly generated creatures of $world:\n\n"; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | echo " | ||
} | } | ||
else | else | ||
{ | { | ||
− | $raw = @fopen( | + | $raw = @fopen('world.sav', 'rb'); |
if (!$raw) | if (!$raw) | ||
die("Could not open world.dat or world.sav!"); | die("Could not open world.dat or world.sav!"); | ||
− | $ | + | $sig = readLong($raw); |
− | if | + | if ($sig != 0x0509) |
− | + | die("world.sav file header not found!"); | |
− | + | ||
$comp = readLong($raw); | $comp = readLong($raw); | ||
if ($comp == 1) | if ($comp == 1) | ||
− | $raw = decompress( | + | $raw = decompress($raw); |
elseif ($comp > 0) | elseif ($comp > 0) | ||
die("world.sav file is corrupted!"); | die("world.sav file is corrupted!"); | ||
− | fseek($raw, | + | fseek($raw, 0x5E, SEEK_SET); |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
$len = readShort($raw); | $len = readShort($raw); | ||
Line 238: | Line 73: | ||
$len = readShort($raw); | $len = readShort($raw); | ||
$world = fread($raw, $len); | $world = fread($raw, $len); | ||
− | $ | + | echo "Listing raws for randomly generated creatures of $world:\n\n"; |
+ | $skip = readLong($raw); | ||
+ | } | ||
− | + | $numCreatures = readLong($raw); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | for ($i = 0; $i < $numCreatures; $i++) | |
{ | { | ||
− | $ | + | $numLines = readLong($raw); |
− | + | for ($j = 0; $j < $numLines; $j++) | |
− | |||
− | for ($ | ||
{ | { | ||
− | + | $len = readShort($raw); | |
− | + | $str = fread($raw, $len); | |
− | + | echo "$str\n"; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | echo "$ | ||
− | |||
} | } | ||
+ | echo "----------\n"; | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
?></nowiki> | ?></nowiki> |