d2tools/CharEditor.php

110 lines
2.4 KiB
PHP
Raw Normal View History

<?php
error_reporting(E_ERROR | E_PARSE);
set_time_limit(-1);
ini_set('max_input_time', '-1');
ini_set('max_execution_time', '0');
session_start();
ob_start();
require_once './config.php';
require_once './_pdo.php';
require_once './src/D2Functions.php';
require_once './src/D2BitReader.php';
//require_once './src/D2Item.php';
define('DB_FILE', $_SESSION['modname'] . ".db");
PDO_Connect("sqlite:" . DB_FILE);
$sql = "SELECT * FROM strings";
$strings = PDO_FetchAssoc($sql);
$sql = "SELECT code,namestr
FROM armor
UNION SELECT code,namestr
FROM misc
UNION SELECT code,namestr
FROM weapons
";
$namestr = PDO_FetchAssoc($sql);
//ddump($namestr);
//$filePath = "D:\Diablo II\MODS\ironman-dev\save\Aldur.d2s";
$filePath = "D:\Diablo II\MODS\ironman-dev\save\Sorc.d2s";
//$filePath = "D:\Diablo II\MODS\MedianXL2012\save\Lok.d2s";
//$filePath = "D:\Diablo II\MODS\MedianXL2012\save\Pal.d2s";
$fp = fopen($filePath, 'r+b');
$data = file_get_contents($filePath);
$i_offset = strpos($data, "JM");
fseek($fp, $i_offset + 2);
$i_total = unpack('S*', (fread($fp, 2)))[1];
$items = null;
$offset = $i_offset + 4; // JM00
$first_item_offset = strposX($data, "JM", 2);
$second_item_offset = strposX($data, "JM", 3);
$item_size = $second_item_offset - $first_item_offset;
for ($i = 2; $i <= $i_total; $i++) {
fseek($fp, strposX($data, 'JM', $i));
$_items[] = unpack('C*', fread($fp, 21));
}
foreach ($_items as $_item) {
$item = null;
foreach ($_item as $i_bytes) {
$item .= strrev(str_pad(decbin($i_bytes), 8, 0, STR_PAD_LEFT));
// $item .= (str_pad(dechex($i_bytes), 2, 0, STR_PAD_LEFT));
}
$items[] = $item;
}
// ddump($items);
foreach ($items as $_item) {
// dump($_item[19]);
// dump($_item);
// dump(strtoupper(implode(" ", str_split($_item, 8))));
// dump((($_item[36])));
$b = new D2BitReader($_item);
//$b->bseek(27);
//dump($b->bread(1));
$b->seek(76);
// dump($b->bread(32));
$codeBits = str_split($b->read(32), 8);
$itemCode = '';
foreach ($codeBits as $byte) {
// dump(strrev($byte));
//dump(sprintf('%c', bindec($byte)));
$itemCode .= chr(bindec(strrev($byte)));
}
$itemCode = trim($itemCode);
dump($namestr[$itemCode]);
dump($strings[$namestr[$itemCode]]);
// dump($strings[trim($itemCode)]);
}