Testing d2s stats

This commit is contained in:
Hash Borgir 2022-06-28 22:54:27 -06:00
parent 6c4feed124
commit 29063867c5

View File

@ -11,10 +11,9 @@ require_once './config.php';
require_once './_pdo.php';
require_once './src/D2Functions.php';
require_once './src/D2BitReader.php';
require_once './src/D2ByteReader.php';
//require_once './src/D2Item.php';
require_once './src/D2BitReader.php';
require_once './src/D2Item.php';
define('DB_FILE', $_SESSION['modname'] . ".db");
PDO_Connect("sqlite:" . DB_FILE);
@ -27,96 +26,81 @@ $sql = "SELECT code,namestr
UNION SELECT code,namestr
FROM misc
UNION SELECT code,namestr
FROM weapons
";
FROM weapons";
$namestr = PDO_FetchAssoc($sql);
//ddump($namestr);
$sql = "SELECT ID,Stat,CSvBits FROM itemstatcost WHERE Saved=1";
$ISCData = PDO_FetchAll($sql);
foreach ($ISCData as $k => $v) {
$ISC[$v['ID']] = $v;
}
//$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";
//$filePath = "D:\Diablo II\MODS\MedianXL2012\save\Test.d2s";
$fp = fopen($filePath, 'r+b');
$data = file_get_contents($filePath);
$ByteReader = new D2ByteReader($data);
$i_TotalOffset = strpos($data, "JM");
fseek($fp, $i_TotalOffset + 2);
$i_Total = unpack('S*', (fread($fp, 2)))[1];
$gf = strposX($data, 'gf', 1) + 2; // find gf and skip it
$if = strposX($data, 'if', 1);
$len = $if - $gf;
$i_Offsets = [];
for($i=0; $i <= $i_Total; $i++){
$i_Offsets[] = strposX($data, "JM", $i+2);
}
foreach($i_Offsets as $k=>$v){
$itemOffsets[$v] = $i_Offsets[$k+1] - $i_Offsets[$k];
}
array_pop($itemOffsets);
$stats = new D2BitReader($ByteReader->toBits($ByteReader->readh($gf, $len)));
$bits = $stats->getBits();
$cleanbits = substr($bits, 0, -11);
$stats->setBits($cleanbits);
//$items = null;
//$stats->rewind();
//foreach ($ISC as $i) {
// $stat = $i['Stat'];
// $CSvBits = (int) $i['CSvBits'];
//
//$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;
// $id = hexdec($ByteReader->toBytesR($stats->readb(9)));
// $stats->skip($CSvBits);
// $ids[$id] = ($ISC[$id]);
//}
// 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;
$stats->rewind();
for($i=0; $i <= strlen($bits); $i++) {
$id = hexdec($ByteReader->toBytesR($stats->readb(9)));
if (!empty($ISC[$id])){
$val = $stats->readb($ISC[$id]['CSvBits']);
$stat = $ISC[$id]['Stat'];
$values[$stat] = hexdec($ByteReader->toBytesR($val));
}
dump($stored);
}
$values['hitpoints'] = (int) round($values['hitpoints'] / 2048);
$values['maxhp'] = (int) round($values['maxhp'] / 2048);
$values['mana'] = (int) round($values['mana'] / 2048);
$values['maxmana'] = (int) round($values['maxmana'] / 2048);
$values['stamina'] = (int) round($values['stamina'] / 2048);
$values['maxstamina'] = (int) round($values['maxstamina'] / 2048);
$values['killcounter'] = (int) round($values['killcounter'] / 2);
$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]]);
}
var_dump($values);
//array_pop($ids);
//
//$stats->rewind();
//foreach($ids as $k => $v){
// $stat = $v['Stat'];
// $CSvBits = (int) $v['CSvBits'];
// $ValShift = (int) $i['ValShift'];
// $stats->skip(9);
// $values[$stat] = hexdec($ByteReader->toBytesR($stats->readb($CSvBits)));
//}
//$values['hitpoints'] = (int) round($values['hitpoints'] / 2048);
//$values['maxhp'] = (int) round($values['maxhp'] / 2048);
//$values['mana'] = (int) round($values['mana'] / 2048);
//$values['maxmana'] = (int) round($values['maxmana'] / 2048);
//$values['stamina'] = (int) round($values['stamina'] / 2048);
//$values['maxstamina'] = (int) round($values['maxstamina'] / 2048);
//
//dump($values);