This commit is contained in:
Hash Borgir 2022-05-11 23:29:18 -06:00
parent c4c1622902
commit 5e75c70664
4 changed files with 299 additions and 215 deletions

View File

@ -9,7 +9,7 @@ ob_start();
echo "<pre>";
$filePath = "D:\Diablo II\MODS\ironman-dev\save\Barb.d2s";
$filePath = "D:\Diablo II\MODS\ironman-dev\save\Sorc.d2s";
$fp = fopen($filePath, "rb");
@ -61,7 +61,7 @@ $charData['Filesize'] = round(unpack('l', $data[8])[1] / 1024, 2) . " KB"; //
$charData['CharacterName'] = ($data[20]);
$charData['CharacterStatus'] = array_filter(str_split(strtobits($data[36])));
// $charData['CharacterStatus'] = array_filter(str_split(strtobits($data[36])));
foreach ($charData['CharacterStatus'] as $k => $v) {
$str .= ($characterStatus[$k]) . " ";

View File

@ -89,11 +89,22 @@ if (!isset($_SESSION['modname']) || (!file_exists(APP_DB)) || (!file_exists($_SE
require_once './src/D2TxtParser.php';
require_once './src/D2ItemDesc.php';
require_once './src/D2SaveFile.php';
require_once './src/D2SaveFileStructureData.php';
$chars = new D2SaveFile();
$D2Files = new D2Files();
$charFiles = $D2Files->getSaveFiles();
foreach($charFiles as $charFile){
$charData[] = new D2SaveFile($charFile);
}
// dump($charData[0]->charData);
// dump($charData[1]->charData);
// die();
$idesc = new D2ItemDesc();
$db = new D2Database();
$parser = new D2TxtParser();

View File

@ -6,185 +6,203 @@ require_once 'D2Files.php';
class D2SaveFile {
public $charData;
public $sdata;
public $files;
public $sData;
public function __construct() {
public function __construct($file) {
$this->sdata = new D2SaveFileStructureData();
$this->sData = new D2SaveFileStructureData();
$D2Files = new D2Files();
$this->files = $D2Files->getSaveFiles();
$filePath = $_SESSION['savePath'] . $file;
foreach ($this->files as $f) {
$filePath = $_SESSION['savePath'] . $f;
$fp = fopen($filePath, "rb+");
$fp = fopen($filePath, "rb+");
// read offsets here from sData and put into $data which will be used for charData
// read offsets here from sdata and put into $data which will be used for charData
foreach ($this->sData->offsets as $k => $v) {
fseek($fp, $k);
$data[$k] = fread($fp, $v);
}
$charData['Identifier'] = bin2hex($data[0]);
foreach ($this->sdata->offsets as $k => $v) {
fseek($fp, $k);
$data[$k] = fread($fp, $v);
}
$charData['VersionID'] = $sData->version[unpack('l', $data[4])[1]]; // 96 is v1.10+ - checks out
$charData['Identifier'] = bin2hex($data[0]);
$charData['Filesize'] = round(unpack('l', $data[8])[1] / 1024, 2) . " KB"; // 1.41 KB (1,447 bytes) - checks out
// $charData['Checksum'] = bin2hex($data['12']);
// $charData['Activeweapon'] = unpack('l', $data['16']);
$charData['VersionID'] = $sdata->version[unpack('l', $data[4])[1]]; // 96 is v1.10+ - check out
$charData['CharacterName'] = str_replace("\0", "", $data[20]);
$charData['Filesize'] = round(unpack('l', $data[8])[1] / 1024, 2) . " KB"; // 1.41 KB (1,447 bytes) - checks out
// $charData['Checksum'] = bin2hex($data['12']);
// $charData['Activeweapon'] = unpack('l', $data['16']);
$charData['CharacterName'] = str_replace("\0", "", $data[20]);
// ddump(str_replace("\0x00", '', $charData['CharacterName']));
// ddump(str_replace("\0x00", '', $charData['CharacterName']));
$charData['CharacterStatus'] = array_filter(str_split(strtobits($data[36])));
$charData['CharacterStatus'] = array_filter(str_split(strtobits($data[36])));
foreach ($charData['CharacterStatus'] as $k => $v) {
$str .= ($characterStatus[$k]) . " ";
}
$charData['CharacterStatus'] = $str;
// $charData['Characterprogression'] = bindec($data['37']);
$charData['CharacterClass'] = $this->sdata->class[unpack('C', $data[40])[1]];
$charData['CharacterLevel'] = unpack('C', $data[43])[1];
$charData['Lastplayed'] = gmdate("Y-m-d\TH:i:s\Z", unpack('I', $data[48])[0]);
// $charData['Assignedskills'] = (unpack('i16', $data['56']));
$charData['LeftmousebuttonskillID'] = $this->sdata->skills[unpack('i', $data[120])[1]];
$charData['RightmousebuttonskillID'] = $this->sdata->skills[unpack('i', $data[124])[1]];
$charData['LeftswapmousebuttonskillID'] = $this->sdata->skills[unpack('i', $data[128])[1]];
$charData['RightswapmousebuttonskillID'] = $this->sdata->skills[unpack('i', $data[132])[1]];
// $charData['Charactermenuappearance'] = unpack('i', $data[136]);
$x = str_split(strtobits($data[168]), 8);
$onDifficulty['Norm'] = $x[0][0];
$onDifficulty['NM'] = $x[1][0];
$onDifficulty['Hell'] = $x[2][0];
$charData['Difficulty'] = array_filter($onDifficulty);
//$charData['MapID'] = $data['171'];
//$charData['Mercenarydead'] = unpack('i', $data['177']);
//$charData['MercenaryID'] = $data['179'];
//$charData['MercenaryNameID'] = $data['183'];
//$charData['Mercenarytype'] = $data['185'];
//$charData['Mercenaryexperience'] = $data['187'];
$charData['Quests'][] = $this->getQuestData();
$charData['Waypoints'] = $this->getWaypointsData();
$charData['NPCIntroductions'] = $data[714];
$this->charData[] = $charData;
// ddump($charData);
foreach ($charData['CharacterStatus'] as $k => $v) {
$str .= ($characterStatus[$k]) . " ";
}
// ddump($this->charData);
$charData['CharacterStatus'] = $str;
// $charData['Characterprogression'] = bindec($data['37']);
$charData['CharacterClass'] = $this->sData->class[unpack('C', $data[40])[1]];
$charData['CharacterLevel'] = unpack('C', $data[43])[1];
$charData['Lastplayed'] = gmdate("Y-m-d\TH:i:s\Z", unpack('I', $data[48])[0]);
// $charData['Assignedskills'] = (unpack('i16', $data['56']));
$charData['LeftmousebuttonskillID'] = $this->sData->skills[unpack('i', $data[120])[1]];
$charData['RightmousebuttonskillID'] = $this->sData->skills[unpack('i', $data[124])[1]];
$charData['LeftswapmousebuttonskillID'] = $this->sData->skills[unpack('i', $data[128])[1]];
$charData['RightswapmousebuttonskillID'] = $this->sData->skills[unpack('i', $data[132])[1]];
// $charData['Charactermenuappearance'] = unpack('i', $data[136]);
$x = str_split(strtobits($data[168]), 8);
$onDifficulty['Norm'] = $x[0][0];
$onDifficulty['NM'] = $x[1][0];
$onDifficulty['Hell'] = $x[2][0];
$charData['Difficulty'] = array_filter($onDifficulty);
//$charData['MapID'] = $data['171'];
//$charData['Mercenarydead'] = unpack('i', $data['177']);
//$charData['MercenaryID'] = $data['179'];
//$charData['MercenaryNameID'] = $data['183'];
//$charData['Mercenarytype'] = $data['185'];
//$charData['Mercenaryexperience'] = $data['187'];
$charData['Quests'][] = $this->getQuestData($file);
$charData['Waypoints'] = $this->getWaypointsData($file);
$charData['NPCIntroductions'] = $data[714];
$this->charData = $charData;
unset($this->sData);
return $this->charData;
}
public function getQuestData() {
public function getQuestData($file) {
foreach ($this->files as $f) {
$questsNorm = null;
$questsNM = null;
$questsHell = null;
$questsNorm = null;
$questsNM = null;
$questsHell = null;
$quests = null;
$quests = null;
$filePath = $_SESSION['savePath'] . $f;
$fp = fopen($filePath, "rb+");
$filePath = $_SESSION['savePath'] . $file;
$fp = fopen($filePath, "rb+");
foreach ($this->sdata->qNorm as $k => $v) {
fseek($fp, $k);
$questsNorm[$k] = fread($fp, 2);
}
foreach ($this->sdata->qNM as $k => $v) {
fseek($fp, $k);
$questsNM[$k] = fread($fp, 2);
}
foreach ($this->sdata->qHell as $k => $v) {
fseek($fp, $k);
$questsHell[$k] = fread($fp, 2);
}
foreach ($questsNorm as $k => $v) {
$x = (str_split(strtobits($v), 8));
//if ($x[0][0]) {
$quests['Norm'][$this->sdata->qNorm[$k]] = $x[0][0];
//}
}
foreach ($questsNM as $k => $v) {
$x = array_filter(str_split(strtobits($v), 8));
//if ($x[0][0]) {
$quests['NM'][$this->sdata->qNM[$k]] = $x[0][0];
//}
}
foreach ($questsHell as $k => $v) {
$x = array_filter(str_split(strtobits($v), 8));
//if ($x[0][0]) {
$quests['Hell'][$this->sdata->qHell[$k]] = $x[0][0];
//}
}
return $quests;
foreach ($this->sData->qNorm as $k => $v) {
fseek($fp, $k);
$questsNorm[$k] = fread($fp, 2);
}
foreach ($this->sData->qNM as $k => $v) {
fseek($fp, $k);
$questsNM[$k] = fread($fp, 2);
}
foreach ($this->sData->qHell as $k => $v) {
fseek($fp, $k);
$questsHell[$k] = fread($fp, 2);
}
foreach ($questsNorm as $k => $v) {
$x = (str_split(strtobits($v), 8));
//if ($x[0][0]) {
$quests['Norm'][$this->sData->qNorm[$k]] = $x[0][0];
//}
}
foreach ($questsNM as $k => $v) {
$x = array_filter(str_split(strtobits($v), 8));
//if ($x[0][0]) {
$quests['NM'][$this->sData->qNM[$k]] = $x[0][0];
//}
}
foreach ($questsHell as $k => $v) {
$x = array_filter(str_split(strtobits($v), 8));
//if ($x[0][0]) {
$quests['Hell'][$this->sData->qHell[$k]] = $x[0][0];
//}
}
return $quests;
}
public function getWaypointsData() {
public function getWaypointsData($file) {
foreach ($this->files as $f) {
$filePath = $_SESSION['savePath'] . $f;
$fp = fopen($filePath, "rb+");
$filePath = $_SESSION['savePath'] . $file;
$fp = fopen($filePath, "rb+");
$wp = null;
fseek($fp, $this->sdata->wpOffsetsNorm);
$wp['Norm'] = (strtobits(fread($fp, 5)));
$wp = null;
fseek($fp, $this->sdata->wpOffsetsNM);
$wp['NM'] = (strtobits(fread($fp, 5)));
fseek($fp, $this->sData->wpOffsetsNorm);
$a1 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsNorm + 1);
$a2 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsNorm + 2);
$a3 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsNorm + 3);
$a4 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsNorm + 4);
$a5 = strrev(strtobits(fread($fp, 1)));
$wp['Norm'] = str_split($a1.$a2.$a3.$a4.$a5);
fseek($fp, $this->sData->wpOffsetsNM);
$a1 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsNM + 1);
$a2 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsNM + 2);
$a3 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsNM + 3);
$a4 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsNM + 4);
$a5 = strrev(strtobits(fread($fp, 1)));
$wp['NM'] = str_split($a1.$a2.$a3.$a4.$a5);
fseek($fp, $this->sdata->wpOffsetsHell);
$wp['Hell'] = (strtobits(fread($fp, 5)));
fseek($fp, $this->sData->wpOffsetsHell);
$a1 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsHell + 1);
$a2 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsHell + 2);
$a3 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsHell + 3);
$a4 = strrev(strtobits(fread($fp, 1)));
fseek($fp, $this->sData->wpOffsetsHell + 4);
$a5 = strrev(strtobits(fread($fp, 1)));
$wp['Hell'] = str_split($a1.$a2.$a3.$a4.$a5);
// ddump($wp);
// ddump(str_split($wp['Norm']));
foreach ($wp['Norm'] as $k => $v) {
$waypoints['Norm'][$this->sdata->wpNames[$k]] = $v;
}
foreach ($wp['NM'] as $k => $v) {
$waypoints['NM'][$this->sdata->wpNames[$k]] = $v;
}
foreach ($wp['Hell'] as $k => $v) {
$waypoints['Hell'][$this->sdata->wpNames[$k]] = $v;
}
//ddump($waypoints);
return $wp;
foreach ($wp['Norm'] as $k => $v) {
$waypoints['Norm'][$this->sData->wpNames[$k]] = $v;
}
foreach ($wp['NM'] as $k => $v) {
$waypoints['NM'][$this->sData->wpNames[$k]] = $v;
}
foreach ($wp['Hell'] as $k => $v) {
$waypoints['Hell'][$this->sData->wpNames[$k]] = $v;
}
// ddump($waypoints);
return $waypoints;
}
}

View File

@ -1,5 +1,5 @@
<?php
$form = new Formr\Formr();
$form = new Formr\Formr('bootstrap4');
/*
@ -20,7 +20,7 @@ $form = new Formr\Formr();
following disclaimer in the documentation and/or other
materials provided with the distribution.
* This software must not be used for commercial purposes
* This software must not be used for commercial purposes
* without my consent. Any sales or commercial use are prohibited
* without my express knowledge and consent.
@ -42,7 +42,7 @@ $form = new Formr\Formr();
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// dump($chars->charData);
// ddump($charData);
?>
@ -53,24 +53,21 @@ $form = new Formr\Formr();
<ul class="nav nav-tabs" id="CTabs" role="tablist">
<?php
$tabs = '';
$counter = 1;
foreach ($chars->charData as $k => $c) {
if ($k == 0) {
$active = "active";
} else {
$active = "";
}
$tabs .= <<<EOT
<?php
foreach ($charData as $c) {
$tabs = '';
// ddump($c);
$tabs .= <<<EOT
<li class="nav-item" role="presentation">
<a class="nav-link btn btn-outline-danger $active" style="background: #ddd; border: 1px solid #888;" id="{$c['CharacterName']}-tab" data-toggle="tab" href="#{$c['CharacterName']}" role="tab" aria-controls="{$c['CharacterName']}" aria-selected="true"><img height="64" width="" src="img/chars/{$c['CharacterClass']}.gif">{$c['CharacterName']}</a>
</li>
<a class="nav-link btn btn-outline-danger" style="background: #ddd; border: 1px solid #888;" id="{$c->charData['CharacterName']}-tab" data-toggle="tab" href="#{$c->charData['CharacterName']}" role="tab" aria-controls="{$c->charData['CharacterName']}" aria-selected="true"><img height="64" width="" src="img/chars/{$c->charData['CharacterClass']}.gif">{$c->charData['CharacterName']}</a>
</li>
EOT;
}
echo $tabs;
?>
echo $tabs;
}
?>
</ul>
@ -80,69 +77,127 @@ echo $tabs;
<div class="tab-content" id="CTabContent">
<?php
foreach ($c['Quests'] as $quest) {
foreach ($quest as $q) {
foreach ($q as $k => $v) {
$quest .= "$k = $v<br>";
}
}
}
<?php
foreach ($charData as $c) {
foreach ($c->charData['Quests'] as $quest) {
foreach ($quest as $q) {
foreach ($q as $k => $v) {
$quest .= "$k = $v<br>";
}
}
}
$wps = null;
foreach ($c->charData['Waypoints'] as $waypoints) {
foreach ($waypoints as $k => $v) {
$wps .= "$k = $v<br>";
}
}
$option = '';
if ($c->charData['CharacterClass'] == 'Amazon'){
$option .= "<option value='Amazon' selected>Amazon</option>";
} else {
$option .= "<option value='Amazon'>Amazon</option>";
}
if ($c->charData['CharacterClass'] == 'Assassin'){
$option .= "<option value='Assassin' selected>Assassin</option>";
} else {
$option .= "<option value='Assassin'>Assassin</option>";
}
if ($c->charData['CharacterClass'] == 'Barbarian'){
$option .= "<option value='Barbarian' selected>Barbarian</option>";
} else {
$option .= "<option value='Barbarian'>Barbarian</option>";
}
if ($c->charData['CharacterClass'] == 'Druid'){
$option .= "<option value='Druid' selected>Druid</option>";
} else {
$option .= "<option value='Druid'>Druid</option>";
}
if ($c->charData['CharacterClass'] == 'Paladin'){
$option .= "<option value='Paladin' selected>Paladin</option>";
} else {
$option .= "<option value='Paladin'>Paladin</option>";
}
if ($c->charData['CharacterClass'] == 'Necromancer'){
$option .= "<option value='Necromancer' selected>Necromancer</option>";
} else {
$option .= "<option value='Necromancer'>Necromancer</option>";
}
if ($c->charData['CharacterClass'] == 'Sorceress'){
$option .= "<option value='Sorceress' selected>Sorceress</option>";
} else {
$option .= "<option value='Sorceress'>Sorceress</option>";
}
$radio = '';
if ($c->charData['Difficulty']['Norm'] == 1){
$radio .= '<input checked type="radio" id="DifficultyNormal" name="Difficulty" value="Normal">Normal<br>';
} else {
$radio .= '<input type="radio" id="DifficultyNormal" name="Difficulty" value="Normal">Normal<br>';
}
if ($c->charData['Difficulty']['NM'] == 1){
$radio .= '<input checked type="radio" id="DifficultyNM" name="Difficulty" value="NM">NM<br>';
} else {
$radio .= '<input type="radio" id="DifficultyNM" name="Difficulty" value="NM">NM<br>';
}
if ($c->charData['Difficulty']['Hell'] == 1){
$radio .= '<input checked type="radio" id="DifficultyHell" name="Difficulty" value="Hell">Hell<br>';
} else {
$radio .= '<input type="radio" id="DifficultyHell" name="Difficulty" value="Hell">Hell<br>';
}
// dump($c['Waypoints']);
$tabContent .= <<<EOT
<div style="background: white;" class="tab-pane fade" id="{$c->charData['CharacterName']}" role="tabpanel" aria-labelledby="{$c->charData['CharacterName']}-tab">
<h1 style="margin: 15px;">{$c->charData['CharacterName']}</h1>
foreach ($chars->charData as $k => $c) {
if ($k == 0) {
$active = "active show";
} else {
$active = "";
}
// dump($c['Waypoints']);
$tabContent .= <<<EOT
<div style="background: white;" class="tab-pane fade $active" id="{$c['CharacterName']}" role="tabpanel" aria-labelledby="{$c['CharacterName']}-tab">
<h1 style="margin: 15px;">{$c['CharacterName']}</h1>
<div class="container" style="font-size: 14px;">
<div class="row">
<div class="col">
<img src="/img/chars/{$c['CharacterClass']}.gif">
<img src="/img/chars/{$c->charData['CharacterClass']}.gif">
</div>
<div class="col">
<input type="text" id="ChracterName" name="ChracterName" maxlength="16" value="{$c['CharacterName']}">
<input type="text" id="ChracterName" name="ChracterName" maxlength="16" value="{$c->charData['CharacterName']}">
<select id='CharacterClass'>
<option value="Amazon">Amazon</option>
<option value="Assassin">Assassin</option>
<option value="Barbarian">Barbarian</option>
<option value="Druid">Druid</option>
<option value="Paladin">Paladin</option>
<option value="Necromancer">Necromancer</option>
<option value="Sorceress">Sorceress</option>
$option
</select>
<input type="number" id="CharacterLevel">
<input type="radio" id="DifficultyNormal" name="Difficulty" value="Normal">Normal<br>
<input type="radio" id="DifficultyNM" name="Difficulty" value="Normal">NM<br>
<input type="radio" id="DifficultyHell" name="Difficulty" value="Normal">Hell<br>
{$c['Waypoints']['Norm']}<br>
{$c['Waypoints']['NM']}<br>
{$c['Waypoints']['Hell']}<br>
</div>
<div class="col">$quest</div>
<div class="col">Col 3</div>
<div>
<input style="border: 1px solid black;width: 34px;" type="number" id="CharacterLevel" value="{$c->charData['CharacterLevel']}">: Char Lvl<br>
$radio
</div>
</div>
<div class="col"><h2>Quests</h2>$quest</div>
<div class="col"><h2>Waypoints</h2>$wps</div>
</div>
</div>
</div>
EOT;
}
echo $tabContent;
?>
echo $tabContent;
}
?>
</div>