mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2024-11-30 04:26:03 +00:00
116 lines
2.7 KiB
PHP
116 lines
2.7 KiB
PHP
<?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->seek(58);
|
|
$parent = bindec(strrev($b->read(3)));
|
|
if ($parent == 0) {
|
|
$b->seek(73);
|
|
$_stored = bindec(strrev($b->read(3)));
|
|
switch ($_stored) {
|
|
case 0:
|
|
$stored = ''; // item is not stored, check bit 58
|
|
break;
|
|
case 1:
|
|
$stored = 'Inventory';
|
|
break;
|
|
case 4:
|
|
$stored = 'Horadric Cube';
|
|
break;
|
|
case 5:
|
|
$stored = 'Stash';
|
|
break;
|
|
}
|
|
dump($stored);
|
|
}
|
|
|
|
$b->seek(76);
|
|
$codeBits = str_split($b->read(32), 8);
|
|
$itemCode = '';
|
|
foreach ($codeBits as $byte) {
|
|
$itemCode .= chr(bindec(strrev($byte)));
|
|
}
|
|
$itemCode = trim($itemCode);
|
|
dump($namestr[$itemCode]);
|
|
dump($strings[$namestr[$itemCode]]);
|
|
}
|
|
|