d2tools/CharEditor.php

107 lines
3.1 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';
2022-06-26 19:41:06 +00:00
require_once './src/D2ByteReader.php';
2022-06-29 04:54:27 +00:00
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);
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-29 04:54:27 +00:00
FROM weapons";
2022-06-21 13:06:41 +00:00
$namestr = PDO_FetchAssoc($sql);
2022-06-29 04:54:27 +00:00
$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";
2022-06-29 04:54:27 +00:00
//$filePath = "D:\Diablo II\MODS\MedianXL2012\save\Test.d2s";
$data = file_get_contents($filePath);
2022-06-29 04:54:27 +00:00
$ByteReader = new D2ByteReader($data);
2022-06-29 04:54:27 +00:00
$gf = strposX($data, 'gf', 1) + 2; // find gf and skip it
$if = strposX($data, 'if', 1);
$len = $if - $gf;
2022-06-21 13:06:41 +00:00
2022-06-29 04:54:27 +00:00
$stats = new D2BitReader($ByteReader->toBits($ByteReader->readh($gf, $len)));
2022-06-26 19:41:06 +00:00
2022-06-29 04:54:27 +00:00
$bits = $stats->getBits();
$cleanbits = substr($bits, 0, -11);
$stats->setBits($cleanbits);
2022-06-26 19:41:06 +00:00
2022-06-29 04:54:27 +00:00
//$stats->rewind();
//foreach ($ISC as $i) {
// $stat = $i['Stat'];
// $CSvBits = (int) $i['CSvBits'];
2022-06-26 19:41:06 +00:00
//
2022-06-29 04:54:27 +00:00
// $id = hexdec($ByteReader->toBytesR($stats->readb(9)));
// $stats->skip($CSvBits);
// $ids[$id] = ($ISC[$id]);
2022-06-26 19:41:06 +00:00
//}
2022-06-29 04:54:27 +00:00
$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));
}
}
2022-06-29 04:54:27 +00:00
$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);
var_dump($values);
2022-06-29 04:54:27 +00:00
//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);