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>"; 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"); $fp = fopen($filePath, "rb");
@ -61,7 +61,7 @@ $charData['Filesize'] = round(unpack('l', $data[8])[1] / 1024, 2) . " KB"; //
$charData['CharacterName'] = ($data[20]); $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) { foreach ($charData['CharacterStatus'] as $k => $v) {
$str .= ($characterStatus[$k]) . " "; $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/D2TxtParser.php';
require_once './src/D2ItemDesc.php'; require_once './src/D2ItemDesc.php';
require_once './src/D2SaveFile.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(); $idesc = new D2ItemDesc();
$db = new D2Database(); $db = new D2Database();
$parser = new D2TxtParser(); $parser = new D2TxtParser();

View File

@ -6,185 +6,203 @@ require_once 'D2Files.php';
class D2SaveFile { class D2SaveFile {
public $charData; public $charData;
public $sdata; public $sData;
public $files;
public function __construct() { public function __construct($file) {
$this->sdata = new D2SaveFileStructureData(); $this->sData = new D2SaveFileStructureData();
$D2Files = new D2Files(); $filePath = $_SESSION['savePath'] . $file;
$this->files = $D2Files->getSaveFiles();
foreach ($this->files as $f) { $fp = fopen($filePath, "rb+");
$filePath = $_SESSION['savePath'] . $f;
$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) { $charData['VersionID'] = $sData->version[unpack('l', $data[4])[1]]; // 96 is v1.10+ - checks out
fseek($fp, $k);
$data[$k] = fread($fp, $v);
}
$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 // ddump(str_replace("\0x00", '', $charData['CharacterName']));
// $charData['Checksum'] = bin2hex($data['12']);
// $charData['Activeweapon'] = unpack('l', $data['16']);
$charData['CharacterName'] = str_replace("\0", "", $data[20]);
// 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) { foreach ($charData['CharacterStatus'] as $k => $v) {
$str .= ($characterStatus[$k]) . " "; $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);
} }
// 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; return $this->charData;
} }
public function getQuestData() { public function getQuestData($file) {
foreach ($this->files as $f) {
$questsNorm = null; $questsNorm = null;
$questsNM = null; $questsNM = null;
$questsHell = null; $questsHell = null;
$quests = null; $quests = null;
$filePath = $_SESSION['savePath'] . $f; $filePath = $_SESSION['savePath'] . $file;
$fp = fopen($filePath, "rb+"); $fp = fopen($filePath, "rb+");
foreach ($this->sdata->qNorm as $k => $v) { foreach ($this->sData->qNorm as $k => $v) {
fseek($fp, $k); fseek($fp, $k);
$questsNorm[$k] = fread($fp, 2); $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->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'] . $file;
$filePath = $_SESSION['savePath'] . $f; $fp = fopen($filePath, "rb+");
$fp = fopen($filePath, "rb+");
$wp = null; $wp = null;
fseek($fp, $this->sdata->wpOffsetsNorm);
$wp['Norm'] = (strtobits(fread($fp, 5)));
fseek($fp, $this->sdata->wpOffsetsNM); fseek($fp, $this->sData->wpOffsetsNorm);
$wp['NM'] = (strtobits(fread($fp, 5))); $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); fseek($fp, $this->sData->wpOffsetsHell);
$wp['Hell'] = (strtobits(fread($fp, 5))); $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) { foreach ($wp['Norm'] as $k => $v) {
$waypoints['Norm'][$this->sdata->wpNames[$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['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 <?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 following disclaimer in the documentation and/or other
materials provided with the distribution. 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 consent. Any sales or commercial use are prohibited
* without my express knowledge and consent. * without my express knowledge and consent.
@ -42,7 +42,7 @@ $form = new Formr\Formr();
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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"> <ul class="nav nav-tabs" id="CTabs" role="tablist">
<?php <?php
$tabs = ''; foreach ($charData as $c) {
$counter = 1;
foreach ($chars->charData as $k => $c) { $tabs = '';
if ($k == 0) { // ddump($c);
$active = "active";
} else { $tabs .= <<<EOT
$active = "";
}
$tabs .= <<<EOT
<li class="nav-item" role="presentation"> <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> <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> </li>
EOT; EOT;
} echo $tabs;
echo $tabs; }
?> ?>
</ul> </ul>
@ -80,69 +77,127 @@ echo $tabs;
<div class="tab-content" id="CTabContent"> <div class="tab-content" id="CTabContent">
<?php <?php
foreach ($c['Quests'] as $quest) { foreach ($charData as $c) {
foreach ($quest as $q) {
foreach ($q as $k => $v) { foreach ($c->charData['Quests'] as $quest) {
$quest .= "$k = $v<br>"; 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="container" style="font-size: 14px;">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<img src="/img/chars/{$c['CharacterClass']}.gif"> <img src="/img/chars/{$c->charData['CharacterClass']}.gif">
</div> </div>
<div class="col"> <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'> <select id='CharacterClass'>
<option value="Amazon">Amazon</option> $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>
</select> </select>
<input type="number" id="CharacterLevel"> <div>
<input type="radio" id="DifficultyNormal" name="Difficulty" value="Normal">Normal<br> <input style="border: 1px solid black;width: 34px;" type="number" id="CharacterLevel" value="{$c->charData['CharacterLevel']}">: Char Lvl<br>
<input type="radio" id="DifficultyNM" name="Difficulty" value="Normal">NM<br> $radio
<input type="radio" id="DifficultyHell" name="Difficulty" value="Normal">Hell<br> </div>
</div>
{$c['Waypoints']['Norm']}<br> <div class="col"><h2>Quests</h2>$quest</div>
{$c['Waypoints']['NM']}<br> <div class="col"><h2>Waypoints</h2>$wps</div>
{$c['Waypoints']['Hell']}<br>
</div>
<div class="col">$quest</div>
<div class="col">Col 3</div>
</div> </div>
</div> </div>
</div> </div>
EOT; EOT;
}
echo $tabContent; echo $tabContent;
?> }
?>
</div> </div>