d2tools/CharEditor.php

123 lines
3.0 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';
2022-06-26 19:41:06 +00:00
require_once './src/D2ByteReader.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);
2022-06-21 13:06:41 +00:00
$sql = "SELECT code,namestr
FROM armor
UNION SELECT code,namestr
FROM misc
UNION SELECT code,namestr
2022-06-21 13:06:41 +00:00
FROM weapons
";
2022-06-21 13:06:41 +00:00
$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);
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-26 19:41:06 +00:00
foreach($i_Offsets as $k=>$v){
$itemOffsets[$v] = $i_Offsets[$k+1] - $i_Offsets[$k];
}
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;
//}
// 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);
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);
}
$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]]);
}