Commit 351d8549 authored by Derrick Sobodash's avatar Derrick Sobodash

Initial commit.

parent 42f9488f
langrisserpc
===========
This is a series of tools I am writing for working with Langrisser (I or II)
PC. Currently the archive includes the following:
* langpcdump - A script for dumping a Langrisser PC resource (.res) file
to a folder of the same name. Dumps with script symbols.
* langpcbuild - Builds a new Langrisser PC resource file using a folder
using the contents of a specified folder. Accepts script
symbol input and converts ASCII to game format text.
* langpcresdump - As of langpcdump 1.5, you can no longer use that script to
dump non-script resource files. This should be used instead.
Check the individual .php files for more documentation and notes.
langrisserpc
============
Tools for working with the PC games Langrisser I and II
\ No newline at end of file
#!/usr/bin/php -q
<?php
//
// langpcbuild v2.0 for PHP console mode
// (c) 2002, 2003 Derrick Sobodash
//
// This builds a Langrisser (I or II) PC compatable resource file from a
// folder of files. The format has a limit of 16 character filenames
// (including the extension). I didn't bother checking for this because
// the only folder you should be using it on is one generated by
// langpcdump.php
//
// The resource file build will have the same name as the folder it is
// built from.
//
// Updates to 2.0
// Supports up to 0xFFFFFFFF files per archive (the previous 0xFF file
// limit caused errors when building Langrisser II scripts).
// Support for European character (that are available in the LandPC
// font) added to the character map. Thanks to MadMalkav for mapping
// the extended character set.
//
// Updates to 1.5
// Accepts symbols in the input files to process for the game. Accepted
// symbols are:
// <> - End text window <clsr> - Clear text window
// <str1> - String variable <str2> - String variable
// It also passes the script through an English equivalency table when
// building new output.
//
echo ("\nlangpcbuild v2.0 (c) 2003 Derrick Sobodash\n");
set_time_limit(6000000);
if ($argc < 2) { DisplayOptions(); die; }
else { $path = $argv[1]; }
// Simple routine to read in a directory listing and split it to an array
$mydir="";
$orgfile = "$path";
if ($handle = opendir($orgfile)) {
while (false !== ($file = readdir($handle))) {
$mydir .= $orgfile . "/$file\n";
}
closedir($handle);
}
$filelist = split("\n", $mydir);
$i=0;
// Allocate space for the header. Each file entry takes 24 bytes and there's
// a 4 byte file count. We subtract 3 from the count to account for . .. and
// the blank index.
$offset = ((count($filelist) - 3) * 24) + 4;
$bin="";
// .. and . are at the start of the array. Pad in two bytes to skip them
for ($z=2; $z < (count($filelist)-1); $z++) {
// Parse the file name out of the full path
$temp = split("/", $filelist[$z]);
$file[$i] = $temp[count($temp)-1];
print "Reading $file[$i]... ";
$fd = fopen ($filelist[$z], "rb");
$table = TableArray();
$thisfile = "";
for ($g=0; $g < filesize($filelist[$z]); $g++) {
$charchar = fread ($fd, 1);
if($table[hexdec(bin2hex($charchar))] != "") {
$rahcrahc = $charchar;
if ($charchar == "<") {
$test = fread ($fd, 1);
if ($test == ">")
$thisfile .= $charchar . $test;
else {
fseek ($fd, -1, SEEK_CUR);
$test = fread ($fd, 5);
if (($test == "clsr>")||($test == "str1>")||($test == "str2>"))
$thisfile .= $charchar . $test;
}
}
else
$thisfile .= $table[hexdec(bin2hex($charchar))];
}
else if (($charchar == chr(13))||($charchar == chr(10)))
$thisfile .= $charchar;
}
$temp2 = $thisfile;
$temp2 = str_replace("<>" . chr(13) . chr(10) . chr(13) . chr(10), chr(56), $temp2);
$temp2 = str_replace("<str1>", chr(29) . chr(75), $temp2);
$temp2 = str_replace("<str2>", chr(29) . chr(107), $temp2);
$temp2 = str_replace("<clsr>" . chr(13) . chr(10), chr(49), $temp2);
$temp2 = str_replace(chr(13) . chr(10), chr(24) . chr(50), $temp2);
$bin .= $temp2;
//$bin .= fread ($fd, filesize($filelist[$z]));
$size[$i] = strlen($temp2); //filesize($filelist[$z]); //strlen($bin);
$off[$i] = $offset;
// Increment the offset by filesize to keep a running total of where our
// pointer in the binary is.
$offset = $offset + strlen($temp2);
$i++;
fclose($fd);
print "done!\n";
}
unset ($z, $i, $temp);
// Write our file count using little endian addressing to start our header
$header = pack("V*", count($file));
for ($z=0; $z < (count($file)); $z++) {
// The file format only supports a max of 16 character file names
$header .= str_pad($file[$z], 16, chr(0)) . pack("V*", $off[$z]) . pack("V*", $size[$z]);
}
print "done!\n";
print "Writing new resource file... ";
$fo = fopen("$path-a.res", "w");
fputs($fo, $header . $bin . " Generated by langpcbuild v2.0 ");
fclose($fo);
print "done!\n";
echo ("All done!...\n\n");
function DisplayOptions() {
echo ("Builds a Langrisser (I or II) PC resource from a folder\n usage: langpcbuild [input path]\n\n");
}
function TableArray() {
return(array(
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
// ! " # $ & ' ( ) * + , - . /
chr(24), chr(25), chr(26), chr(27), chr(28), chr(29), chr(30), chr(31), chr(16), chr(17), chr(18), chr(19), chr(20), chr(21), chr(22), chr(23),
// 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
chr(8), chr(9), chr(10), chr(11), chr(12), chr(13), chr(14), chr(15), chr(0), chr(1), chr(2), chr(3), chr(4), chr(5), chr(6), chr(7),
// @ A B C D E F G H I J K L M N O
chr(120), chr(121), chr(122), chr(123), chr(124), chr(125), chr(126), chr(127), chr(112),chr(113), chr(114), chr(115), chr(116), chr(117), chr(118), chr(119),
// P Q R S T U V W X Y Z [ \ ] ^ _
chr(104), chr(105), chr(106), chr(107), chr(108), chr(109), chr(110), chr(111), chr(96), chr(97), chr(98), chr(99), chr(100), chr(101), chr(102), chr(103),
// ` a b c d e f g h i j k l m n o
chr(88), chr(89), chr(90), chr(91), chr(92), chr(93), chr(94), chr(95), chr(80), chr(81), chr(82), chr(83), chr(84), chr(85), chr(86), chr(87),
// p q r s t u v w x y z { | } ~
chr(72), chr(73), chr(74), chr(75), chr(76), chr(77), chr(78), chr(79), chr(64), chr(65), chr(66), chr(67), chr(68), chr(69), chr(70), chr(71),
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", chr(0x99), "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", chr(0x87),
"", chr(0xf9), "", "", "", "", "", "", "", chr(0xf1), "", "", "", chr(0xf5), "", "",
"", chr(0xe9), "", chr(0xeb), "", "", "", "", "", "", chr(0xe2), "", "", "", "", "",
"", chr(0xd9), "", "", chr(0xdc), "", "", "", "", chr(0xd1), "", "", "", chr(0xd5), "", "",
"", chr(0xc9), "", chr(0xcb), "", "", chr(0xce), "", "", "", chr(0xc2), "", chr(0xc4), "", "", "" ));
}
?>
#!/usr/bin/php -q
<?php
//
// langpcdump v1.5 for PHP console mode
// (c) 2002, 2003 Derrick Sobodash
//
// This is a dumper for the Langrisser I PC .RES files. They are a simple
// resource format used by the game.
//
// Updates to 1.5
// Added symbols dumping to the script output. Since the Korean is still
// mangled byt he shifting table, this probably won't help you to read the
// dumps. The reason for symbol dumping is to make it easier to match
// the dumps to the Japanese scripts.
// Because of the symbol dumping, this is no longer suitable for dumping
// non-script .res files. Please use langpcresdump for this from now on.
//
echo ("\nlangpcdump v1.0 (c) 2003 Derrick Sobodash\n");
set_time_limit(6000000);
if ($argc < 2) { DisplayOptions(); die; }
else { $infile = $argv[1]; }
$fd = fopen ($infile, "rb");
// Read in the first 4 bytes in little endian ordering to find out how
// many files are in the resource.
$count = hexdec(bin2hex(strrev(fread ($fd, 4))));
$s=0;
// Parse the header
for ($i=4; $i < ($count * 24); $i=$i+24) {
$parse = fread ($fd, 24);
// FILENAME = [16-bits] pad 0x00
$file[$s] = substr($parse, 0, 16);
// OFFSET = [4-Bits] little endian absolute addressing
$pos[$s] = hexdec(bin2hex(strrev(substr($parse, 16, 4))));
// SIZE = [4-Bits] little endian
$len[$s] = hexdec(bin2hex(strrev(substr($parse, 20, 4))));
$s++;
}
unset ($s, $i);
mkdir(substr($infile, 0, -4));
for ($i = 0; $i < $count; $i++) {
print "Dumping $file[$i]... ";
fseek ($fd, $pos[$i], SEEK_SET);
$bin = fread($fd, $len[$i]);
$bin = str_replace(chr(7), "?", $bin);
$bin = str_replace(chr(22), ".", $bin);
$bin = str_replace(chr(24), " ", $bin);
$bin = str_replace(chr(25), "!", $bin);
$bin = str_replace(chr(49), "<clsr>" . chr(13) . chr(10), $bin);
$bin = str_replace(chr(50), chr(13) . chr(10), $bin);
$bin = str_replace(chr(56), "<>" . chr(13) . chr(10) . chr(13) . chr(10), $bin);
$bin = str_replace(chr(29) . chr(75), "<str1>", $bin);
$bin = str_replace(chr(29) . chr(107), "<str2>", $bin);
$fo = fopen(substr($infile, 0, -4) . "/$file[$i]", "w");
fputs($fo, $bin);
fclose($fo);
print "done!\n";
}
fclose($fd);
echo ("All done!...\n\n");
function DisplayOptions() {
echo ("Extracts files from Langrisser I resources to a folder of the same name\n usage: langpcdump [input]\n\n");
}
?>
#!/usr/bin/php -q
<?php
//
// langpcresdump v1.0 for PHP console mode
// (c) 2002, 2003 Derrick Sobodash
//
// This is a dumper for the Langrisser I PC .RES files. They are a simple
// resource format used by the game.
//
echo ("\nlangpcresdump v1.0 (c) 2003 Derrick Sobodash\n");
set_time_limit(6000000);
if ($argc < 2) { DisplayOptions(); die; }
else { $infile = $argv[1]; }
$fd = fopen ($infile, "rb");
// Read in the first 4 bytes in little endian ordering to find out how
// many files are in the resource.
$count = hexdec(bin2hex(strrev(fread ($fd, 4))));
$s=0;
// Parse the header
for ($i=4; $i < ($count * 24); $i=$i+24) {
$parse = fread ($fd, 24);
// FILENAME = [16-bits] pad 0x00
$file[$s] = substr($parse, 0, 16);
// OFFSET = [4-Bits] little endian absolute addressing
$pos[$s] = hexdec(bin2hex(strrev(substr($parse, 16, 4))));
// SIZE = [4-Bits] little endian
$len[$s] = hexdec(bin2hex(strrev(substr($parse, 20, 4))));
$s++;
}
unset ($s, $i);
mkdir(substr($infile, 0, -4));
for ($i = 0; $i < $count; $i++) {
print "Dumping $file[$i]... ";
fseek ($fd, $pos[$i], SEEK_SET);
$bin = fread($fd, $len[$i]);
//$bin = str_replace(chr(56), "<>" . chr(13) . chr(10), $bin);
$fo = fopen(substr($infile, 0, -4) . "/" . str_replace("pct", "pcx", $file[$i]), "w");
fputs($fo, $bin);
fclose($fo);
print "done!\n";
}
fclose($fd);
echo ("All done!...\n\n");
function DisplayOptions() {
echo ("Extracts files from Langrisser I resources to a folder of the same name\n usage: langpcresdump [input]\n\n");
}
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment