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.
Difference between revisions of "User:Quietust/rawextract.php"
Jump to navigation
Jump to search
(Created page with ' <nowiki><? function readLong ($file) { $x = fread($file, 4); $pck = unpack('Vdata', $x); return $pck['data']; } function readShort ($file) { $x = fread($file, 2); $pck = un…') |
(new and improved: now supports compressed world files) |
||
Line 1: | Line 1: | ||
<nowiki><? | <nowiki><? | ||
+ | function decompress ($file) | ||
+ | { | ||
+ | $out = tmpfile(); | ||
+ | // write 'uncompressed' header | ||
+ | fwrite($out, pack('VV', 0x0509, 0)); | ||
+ | while (1) | ||
+ | { | ||
+ | $len = readLong($file); | ||
+ | if (feof($file)) | ||
+ | break; | ||
+ | // not sure what this is, but it isn't part of the compressed data | ||
+ | $unk = readShort($file); | ||
+ | $block = fread($file, $len - 2); | ||
+ | fwrite($out, gzinflate($block)); | ||
+ | } | ||
+ | rewind($out); | ||
+ | return $out; | ||
+ | } | ||
+ | |||
function readLong ($file) | function readLong ($file) | ||
{ | { | ||
Line 18: | Line 37: | ||
$sig = readLong($raw); | $sig = readLong($raw); | ||
− | if ($sig != | + | if ($sig != 0x0509) |
− | die("world.dat file | + | die("world.dat file header not found!"); |
$comp = readLong($raw); | $comp = readLong($raw); | ||
− | if ($comp | + | if ($comp == 1) |
− | die("world.dat file is | + | $raw = decompress($raw); |
+ | elseif ($comp > 0) | ||
+ | die("world.dat file is corrupted!"); | ||
fseek($raw, 0x92, SEEK_SET); | fseek($raw, 0x92, SEEK_SET); | ||
Line 44: | Line 65: | ||
echo "----------\n"; | echo "----------\n"; | ||
} | } | ||
− | ?> | + | ?></nowiki> |
− | </nowiki> |
Revision as of 21:32, 29 April 2010
<? function decompress ($file) { $out = tmpfile(); // write 'uncompressed' header fwrite($out, pack('VV', 0x0509, 0)); while (1) { $len = readLong($file); if (feof($file)) break; // not sure what this is, but it isn't part of the compressed data $unk = readShort($file); $block = fread($file, $len - 2); fwrite($out, gzinflate($block)); } rewind($out); return $out; } function readLong ($file) { $x = fread($file, 4); $pck = unpack('Vdata', $x); return $pck['data']; } function readShort ($file) { $x = fread($file, 2); $pck = unpack('vdata', $x); return $pck['data']; } $raw = fopen('world.dat', 'rb'); if (!$raw) die("world.dat file not found!"); $sig = readLong($raw); if ($sig != 0x0509) die("world.dat file header not found!"); $comp = readLong($raw); if ($comp == 1) $raw = decompress($raw); elseif ($comp > 0) die("world.dat file is corrupted!"); fseek($raw, 0x92, SEEK_SET); $len = readShort($raw); $str = fread($raw, $len); echo "Listing raws for randomly generated creatures of $str:\n\n"; $numCreatures = readLong($raw); for ($i = 0; $i < $numCreatures; $i++) { $numLines = readLong($raw); for ($j = 0; $j < $numLines; $j++) { $len = readShort($raw); $str = fread($raw, $len); echo "$str\n"; } echo "----------\n"; } ?>