2022-05-07 12:25:27 +00:00
|
|
|
<?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();
|
|
|
|
|
2022-06-21 01:27:08 +00:00
|
|
|
require_once './config.php';
|
|
|
|
require_once './_pdo.php';
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-21 01:27:08 +00:00
|
|
|
require_once './src/D2Functions.php';
|
|
|
|
require_once './src/D2BitReader.php';
|
2022-06-26 19:41:06 +00:00
|
|
|
require_once './src/D2ByteReader.php';
|
2022-06-21 01:27:08 +00:00
|
|
|
//require_once './src/D2Item.php';
|
2022-05-07 12:25:27 +00:00
|
|
|
|
|
|
|
|
2022-06-21 01:27:08 +00:00
|
|
|
define('DB_FILE', $_SESSION['modname'] . ".db");
|
|
|
|
PDO_Connect("sqlite:" . DB_FILE);
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-21 01:27:08 +00:00
|
|
|
$sql = "SELECT * FROM strings";
|
|
|
|
$strings = PDO_FetchAssoc($sql);
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-21 13:06:41 +00:00
|
|
|
$sql = "SELECT code,namestr
|
|
|
|
FROM armor
|
2022-06-21 01:27:08 +00:00
|
|
|
UNION SELECT code,namestr
|
|
|
|
FROM misc
|
|
|
|
UNION SELECT code,namestr
|
2022-06-21 13:06:41 +00:00
|
|
|
FROM weapons
|
2022-06-21 01:27:08 +00:00
|
|
|
";
|
2022-06-21 13:06:41 +00:00
|
|
|
$namestr = PDO_FetchAssoc($sql);
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-21 01:27:08 +00:00
|
|
|
//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";
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-21 01:27:08 +00:00
|
|
|
$fp = fopen($filePath, 'r+b');
|
|
|
|
$data = file_get_contents($filePath);
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-26 19:41:06 +00:00
|
|
|
$i_TotalOffset = strpos($data, "JM");
|
|
|
|
fseek($fp, $i_TotalOffset + 2);
|
|
|
|
$i_Total = unpack('S*', (fread($fp, 2)))[1];
|
2022-06-21 13:06:41 +00:00
|
|
|
|
2022-06-26 19:41:06 +00:00
|
|
|
$i_Offsets = [];
|
|
|
|
for($i=0; $i <= $i_Total; $i++){
|
|
|
|
$i_Offsets[] = strposX($data, "JM", $i+2);
|
2022-06-21 01:27:08 +00:00
|
|
|
}
|
2022-06-26 19:41:06 +00:00
|
|
|
foreach($i_Offsets as $k=>$v){
|
|
|
|
$itemOffsets[$v] = $i_Offsets[$k+1] - $i_Offsets[$k];
|
2022-06-21 01:27:08 +00:00
|
|
|
}
|
2022-06-26 19:41:06 +00:00
|
|
|
array_pop($itemOffsets);
|
|
|
|
|
|
|
|
|
|
|
|
//$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));
|
|
|
|
// }
|
|
|
|
// $items[] = $item;
|
|
|
|
//}
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-21 01:27:08 +00:00
|
|
|
// ddump($items);
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-21 01:27:08 +00:00
|
|
|
foreach ($items as $_item) {
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-21 01:27:08 +00:00
|
|
|
// dump($_item[19]);
|
|
|
|
// dump($_item);
|
|
|
|
// dump(strtoupper(implode(" ", str_split($_item, 8))));
|
|
|
|
// dump((($_item[36])));
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-21 01:27:08 +00:00
|
|
|
$b = new D2BitReader($_item);
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-21 13:06:41 +00:00
|
|
|
$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);
|
|
|
|
}
|
2022-05-07 12:25:27 +00:00
|
|
|
|
2022-06-21 01:27:08 +00:00
|
|
|
$b->seek(76);
|
|
|
|
$codeBits = str_split($b->read(32), 8);
|
|
|
|
$itemCode = '';
|
|
|
|
foreach ($codeBits as $byte) {
|
|
|
|
$itemCode .= chr(bindec(strrev($byte)));
|
2022-05-07 12:25:27 +00:00
|
|
|
}
|
2022-06-21 01:27:08 +00:00
|
|
|
$itemCode = trim($itemCode);
|
|
|
|
dump($namestr[$itemCode]);
|
|
|
|
dump($strings[$namestr[$itemCode]]);
|
|
|
|
}
|
2022-05-24 06:16:01 +00:00
|
|
|
|