D2SaveFile to D2Char rename

This commit is contained in:
Hash Borgir 2022-06-20 20:21:28 -06:00
parent 822e3dcbd8
commit 2e15b906a9
6 changed files with 122 additions and 170 deletions

View File

@ -88,8 +88,8 @@ if (!isset($_SESSION['modname']) || (!file_exists(APP_DB)) || (!file_exists($_SE
require_once './src/D2Files.php';
require_once './src/D2TxtParser.php';
require_once './src/D2ItemDesc.php';
require_once './src/D2SaveFile.php';
require_once './src/D2SaveFileStructureData.php';
require_once './src/D2Char.php';
require_once './src/D2CharStructureData.php';
$D2Files = new D2Files();
@ -97,7 +97,7 @@ if (!isset($_SESSION['modname']) || (!file_exists(APP_DB)) || (!file_exists($_SE
foreach($charFiles as $charFile){
$charData[] = new D2SaveFile($charFile);
$charData[] = new D2Char($charFile); // $charData goes into chars.php tab
}
@ -141,8 +141,8 @@ if (!isset($_SESSION['modname']) || (!file_exists(APP_DB)) || (!file_exists($_SE
if (!empty($_POST)) {
// save db name from post into conf file... why?
require_once './src/D2SaveFile.php';
$saver = new D2SaveFile();
require_once './src/D2Char.php';
$saver = new D2Char();
// process post
// combine armor/weapon codes

View File

@ -17,10 +17,10 @@ require_once "./src/D2Database.php";
require_once './src/D2Files.php';
require_once './src/D2TxtParser.php';
require_once './src/D2ItemDesc.php';
require_once './src/D2SaveFile.php';
require_once './src/D2SaveFileStructureData.php';
require_once './src/D2Char.php';
require_once './src/D2CharStructureData.php';
$dStruct = new D2SaveFileStructureData();
$dStruct = new D2CharStructureData();
$p = $_POST;

View File

@ -1,65 +1,62 @@
<?php
require_once 'D2SaveFileStructureData.php';
require_once 'D2CharStructureData.php';
require_once 'D2Files.php';
class D2SaveFile {
class D2Char {
public $charData;
public $sData;
public $cData;
private $sData;
public function __construct($file) {
$this->sData = new D2SaveFileStructureData();
$this->sData = new D2CharStructureData();
$filePath = $_SESSION['savepath'] . $file;
$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 cData
foreach ($this->sData->offsets as $k => $v) {
fseek($fp, $k);
$data[$k] = fread($fp, $v);
}
$charData['Identifier'] = bin2hex($data[0]);
$charData['VersionID'] = $sData->version[unpack('l', $data[4])[1]]; // 96 is v1.10+ - checks out
$cData['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']);
$cData['VersionID'] = $sData->version[unpack('l', $data[4])[1]]; // 96 is v1.10+ - checks out
$charData['CharacterName'] = str_replace("\0", "", $data[20]);
$cData['Filesize'] = round(unpack('l', $data[8])[1] / 1024, 2) . " KB"; // 1.41 KB (1,447 bytes) - checks out
// $cData['Checksum'] = bin2hex($data['12']);
// $cData['Activeweapon'] = unpack('l', $data['16']);
// ddump(str_replace("\0x00", '', $charData['CharacterName']));
$cData['CharacterName'] = str_replace("\0", "", $data[20]);
// ddump(str_replace("\0x00", '', $cData['CharacterName']));
$charData['CharacterStatus'] = array_filter(str_split(strtobits($data[36])));
$cData['CharacterStatus'] = array_filter(str_split(strtobits($data[36])));
foreach ($charData['CharacterStatus'] as $k => $v) {
foreach ($cData['CharacterStatus'] as $k => $v) {
$str .= ($characterStatus[$k]) . " ";
}
$charData['CharacterStatus'] = $str;
$cData['CharacterStatus'] = $str;
// $charData['Characterprogression'] = bindec($data['37']);
// $cData['Characterprogression'] = bindec($data['37']);
$charData['CharacterClass'] = $this->sData->class[unpack('C', $data[40])[1]];
$cData['CharacterClass'] = $this->sData->class[unpack('C', $data[40])[1]];
$charData['CharacterLevel'] = unpack('C', $data[43])[1];
$cData['CharacterLevel'] = unpack('C', $data[43])[1];
$charData['Lastplayed'] = gmdate("Y-m-d\TH:i:s\Z", unpack('I', $data[48])[0]);
$cData['Lastplayed'] = gmdate("Y-m-d\TH:i:s\Z", unpack('I', $data[48])[0]);
// $charData['Assignedskills'] = (unpack('i16', $data['56']));
// $cData['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]];
$cData['LeftmousebuttonskillID'] = $this->sData->skills[unpack('i', $data[120])[1]];
$cData['RightmousebuttonskillID'] = $this->sData->skills[unpack('i', $data[124])[1]];
$cData['LeftswapmousebuttonskillID'] = $this->sData->skills[unpack('i', $data[128])[1]];
$cData['RightswapmousebuttonskillID'] = $this->sData->skills[unpack('i', $data[132])[1]];
// $charData['Charactermenuappearance'] = unpack('i', $data[136]);
// $cData['Charactermenuappearance'] = unpack('i', $data[136]);
$x = str_split(strtobits($data[168]), 8);
@ -67,28 +64,28 @@ class D2SaveFile {
$onDifficulty['NM'] = $x[1][0];
$onDifficulty['Hell'] = $x[2][0];
$charData['Difficulty'] = array_filter($onDifficulty);
$cData['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'];
//$cData['MapID'] = $data['171'];
//$cData['Mercenarydead'] = unpack('i', $data['177']);
//$cData['MercenaryID'] = $data['179'];
//$cData['MercenaryNameID'] = $data['183'];
//$cData['Mercenarytype'] = $data['185'];
//$cData['Mercenaryexperience'] = $data['187'];
$charData['Quests'][] = $this->getQuestData($file);
$cData['Quests'][] = $this->getQuestData($file);
$charData['Waypoints'] = $this->getWaypointsData($file);
$charData['NPCIntroductions'] = $data[714];
$cData['Waypoints'] = $this->getWaypointsData($file);
$cData['NPCIntroductions'] = $data[714];
$charData['filePath'] = $filePath;
$cData['filePath'] = $filePath;
$this->charData = $charData;
$this->cData = $cData;
unset($this->sData);
return $this->charData;
return $this->cData;
}
public function getQuestData($file) {

View File

@ -2,9 +2,9 @@
require_once 'D2BitReader.php';
class D2Item {
class D2CharItem {
private string $_bits;
private string $bits;
public $basename = ''; //name of the base item
public $item_name = ''; //name string
public $item_rank = ''; //normal/exceptional/elite
@ -93,13 +93,15 @@ class D2Item {
public function __construct(string $bits){
if ($bit == '') return false;
if ($bits == '') return false;
$this->bits = $bits;
$this->parseItem();
return $this->parseItem();
}
public function parseItem(){}
public function parseItem(){
}
}

View File

@ -10,10 +10,7 @@ ob_start();
define('DB_FILE', $_SESSION['modname'] . ".db");
PDO_Connect("sqlite:" . DB_FILE);
class D2SaveFileStructureData {
class D2CharStructureData {
public $skills;
public $class = [
@ -206,92 +203,48 @@ class D2SaveFileStructureData {
public $wpOffsetsNorm = 643;
public $wpOffsetsNM = 667;
public $wpOffsetsHell = 691;
public $wpRawNames = [
0 => 'Act 1 - Town',
1 => 'Act 1 - Wilderness 2',
2 => 'Act 1 - Wilderness 3',
3 => 'Act 1 - Wilderness 4',
4 => 'Act 1 - Wilderness 5',
5 => 'Act 1 - Courtyard 1',
6 => 'Act 1 - Jail 1',
7 => 'Act 1 - Courtyard 2',
8 => 'Act 1 - Catacombs 2',
9 => 'Act 2 - Town',
10 => 'Act 2 - Desert 2',
11 => 'Act 2 - Desert 3',
12 => 'Act 2 - Desert 4',
13 => 'Act 2 - Valley of the Kings',
14 => 'Act 2 - Sewer 1 B',
15 => 'Act 2 - Basement 1',
16 => 'Act 2 - Tomb 2 B',
17 => 'Act 2 - Arcane',
18 => 'Act 3 - Town',
19 => 'Act 3 - Jungle 1',
20 => 'Act 3 - Jungle 2',
21 => 'Act 3 - Jungle 3',
22 => 'Act 3 - Kurast 1',
23 => 'Act 3 - Kurast 2',
24 => 'Act 3 - Kurast 3',
25 => 'Act 3 - Travincal',
26 => 'Act 3 - Mephisto 2',
27 => 'Act 4 - Town',
28 => 'Act 4 - Mesa 3',
29 => 'Act 4 - Lava 1',
30 => 'Act 5 - Town',
31 => 'Act 5 - Barricade 1',
32 => 'Act 5 - Barricade 2',
33 => 'Act 5 - Ice Cave 1',
34 => 'Act 5 - Ice Cave 2',
35 => 'Act 5 - Barricade Snow',
36 => 'Act 5 - Ice Cave 3',
37 => 'Act 5 - Temple 2',
38 => 'Act 5 - Baal Temple 2'
];
public $wpNames = [
0 => 'Rogue_Encampment',
1 => 'Cold_Plains',
2 => 'Stony_Field',
3 => 'Dark_Wood',
4 => 'Black_Marsh',
5 => 'Outer_Cloister',
6 => 'Jail_level_1',
7 => 'Inner_Cloister',
8 => 'Catacombs_level_2',
9 => 'Lut_Gholein',
10 => 'Sewers_level_2',
11 => 'Dry_Hills',
12 => 'Halls_of_the_Dead_level_2',
13 => 'Far_Oasis',
14 => 'Lost_City',
15 => 'Palace_Cellar_level_1',
16 => 'Arcane_Sanctuary',
17 => 'Canyon_of_the_Magi',
18 => 'Kurast_Docks',
19 => 'Spider_Forest',
20 => 'Great_Marsh',
21 => 'Flayer_Jungle',
22 => 'Lower_Kurast',
23 => 'Kurast_Bazaar',
24 => 'Upper_Kurast',
25 => 'Travincal',
26 => 'Durance_of_Hate_level_2',
27 => 'Pandemonium_Fortress',
28 => 'City_of_the_Damned',
29 => 'River_of_Flames',
30 => 'Harrogath',
31 => 'Frigid_Highlands',
32 => 'Arreat_Plateau',
33 => 'Crystalline_Passage',
34 => 'Halls_of_Pain',
35 => 'Glacial_Trail',
36 => 'Frozen_Tundra',
37 => "The_Ancients_Way",
38 => 'Worldstone_Keep_level_2'
];
0 => 'Act 1 - Rogue_Encampment',
1 => 'Act 1 - Cold_Plains',
2 => 'Act 1 - Stony_Field',
3 => 'Act 1 - Dark_Wood',
4 => 'Act 1 - Black_Marsh',
5 => 'Act 1 - Outer_Cloister',
6 => 'Act 1 - Jail_level_1',
7 => 'Act 1 - Inner_Cloister',
8 => 'Act 1 - Catacombs_level_2',
9 => 'Act 2 - Lut_Gholein',
10 => 'Act 2 - Sewers_level_2',
11 => 'Act 2 - Dry_Hills',
12 => 'Act 2 - Halls_of_the_Dead_level_2',
13 => 'Act 2 - Far_Oasis',
14 => 'Act 2 - Lost_City',
15 => 'Act 2 - Palace_Cellar_level_1',
16 => 'Act 2 - Arcane_Sanctuary',
17 => 'Act 2 - Canyon_of_the_Magi',
18 => 'Act 3 - Kurast_Docks',
19 => 'Act 3 - Spider_Forest',
20 => 'Act 3 - Great_Marsh',
21 => 'Act 3 - Flayer_Jungle',
22 => 'Act 3 - Lower_Kurast',
23 => 'Act 3 - Kurast_Bazaar',
24 => 'Act 3 - Upper_Kurast',
25 => 'Act 3 - Travincal',
26 => 'Act 3 - Durance_of_Hate_level_2',
27 => 'Act 4 - Pandemonium_Fortress',
28 => 'Act 4 - City_of_the_Damned',
29 => 'Act 4 - River_of_Flames',
30 => 'Act 5 - Harrogath',
31 => 'Act 5 - Frigid_Highlands',
32 => 'Act 5 - Arreat_Plateau',
33 => 'Act 5 - Crystalline_Passage',
34 => 'Act 5 - Halls_of_Pain',
35 => 'Act 5 - Glacial_Trail',
36 => 'Act 5 - Frozen_Tundra',
37 => "Act 5 - The_Ancients_Way",
38 => 'Act 5 - Worldstone_Keep_level_2'
];
public $_qNorm;
public $_qNM;

View File

@ -62,7 +62,7 @@ $form = new Formr\Formr();
$tabs .= <<<EOT
<li class="nav-item" role="presentation">
<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>
<a class="nav-link btn btn-outline-danger" style="background: #ddd; border: 1px solid #888;" id="{$c->cData['CharacterName']}-tab" data-toggle="tab" href="#{$c->cData['CharacterName']}" role="tab" aria-controls="{$c->cData['CharacterName']}" aria-selected="true"><img height="64" width="" src="img/chars/{$c->cData['CharacterClass']}.gif">{$c->cData['CharacterName']}</a>
</li>
EOT;
echo $tabs;
@ -81,7 +81,7 @@ EOT;
foreach ($charData as $c) {
$quests = null;
foreach ($c->charData['Quests'] as $quest) {
foreach ($c->cData['Quests'] as $quest) {
foreach ($quest as $difficulty => $q) {
$quests .= "<h2>$difficulty</h2>";
foreach ($q as $k => $v) {
@ -100,7 +100,7 @@ EOT;
$wps = null;
$wps .= "<input type='radio' value='1' name='wp_all' id='wp_all'><label style='font-size: 1.3em;color:green;' for='wp_all'>Enable All Waypoints</label><br><input type='radio' value='0' name='wp_all' id='wp_all_off'><label style='font-size: 1.3em; color: red;' for='wp_all_off'>Disable All Waypoints</label><hr>";
foreach ($c->charData['Waypoints'] as $diff => $waypoints) {
foreach ($c->cData['Waypoints'] as $diff => $waypoints) {
$wps .= "<h2>$diff</h2>";
array_pop($waypoints);
foreach ($waypoints as $k => $v) {
@ -122,64 +122,64 @@ EOT;
$option = '';
if ($c->charData['CharacterClass'] == 'Amazon'){
if ($c->cData['CharacterClass'] == 'Amazon'){
$option .= "<option value='Amazon' selected>Amazon</option>";
} else {
$option .= "<option value='Amazon'>Amazon</option>";
}
if ($c->charData['CharacterClass'] == 'Assassin'){
if ($c->cData['CharacterClass'] == 'Assassin'){
$option .= "<option value='Assassin' selected>Assassin</option>";
} else {
$option .= "<option value='Assassin'>Assassin</option>";
}
if ($c->charData['CharacterClass'] == 'Barbarian'){
if ($c->cData['CharacterClass'] == 'Barbarian'){
$option .= "<option value='Barbarian' selected>Barbarian</option>";
} else {
$option .= "<option value='Barbarian'>Barbarian</option>";
}
if ($c->charData['CharacterClass'] == 'Druid'){
if ($c->cData['CharacterClass'] == 'Druid'){
$option .= "<option value='Druid' selected>Druid</option>";
} else {
$option .= "<option value='Druid'>Druid</option>";
}
if ($c->charData['CharacterClass'] == 'Paladin'){
if ($c->cData['CharacterClass'] == 'Paladin'){
$option .= "<option value='Paladin' selected>Paladin</option>";
} else {
$option .= "<option value='Paladin'>Paladin</option>";
}
if ($c->charData['CharacterClass'] == 'Necromancer'){
if ($c->cData['CharacterClass'] == 'Necromancer'){
$option .= "<option value='Necromancer' selected>Necromancer</option>";
} else {
$option .= "<option value='Necromancer'>Necromancer</option>";
}
if ($c->charData['CharacterClass'] == 'Sorceress'){
if ($c->cData['CharacterClass'] == 'Sorceress'){
$option .= "<option value='Sorceress' selected>Sorceress</option>";
} else {
$option .= "<option value='Sorceress'>Sorceress</option>";
}
$radio = '';
if ($c->charData['Difficulty']['Norm'] == 1){
if ($c->cData['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){
if ($c->cData['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){
if ($c->cData['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>';
@ -187,12 +187,12 @@ EOT;
if ($c->charData['Quests'][0]['Norm']["DenOfEvil"]) $a1q1 = "checked";
if ($c->charData['Quests'][0]['Norm']["SistersBurialGrounds"]) $a1q2 = "checked";
if ($c->charData['Quests'][0]['Norm']["TheSearchForCain"]) $a1q3 = "checked";
if ($c->charData['Quests'][0]['Norm']["TheForgottenTower"]) $a1q4 = "checked";
if ($c->charData['Quests'][0]['Norm']["ToolsOfTheTrade"]) $a1q5 = "checked";
if ($c->charData['Quests'][0]['Norm']["SistersToTheSlaughter"]) $a1q6 = "checked";
if ($c->cData['Quests'][0]['Norm']["DenOfEvil"]) $a1q1 = "checked";
if ($c->cData['Quests'][0]['Norm']["SistersBurialGrounds"]) $a1q2 = "checked";
if ($c->cData['Quests'][0]['Norm']["TheSearchForCain"]) $a1q3 = "checked";
if ($c->cData['Quests'][0]['Norm']["TheForgottenTower"]) $a1q4 = "checked";
if ($c->cData['Quests'][0]['Norm']["ToolsOfTheTrade"]) $a1q5 = "checked";
if ($c->cData['Quests'][0]['Norm']["SistersToTheSlaughter"]) $a1q6 = "checked";
@ -202,20 +202,20 @@ EOT;
// 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">
<div style="background: white;" class="tab-pane fade" id="{$c->cData['CharacterName']}" role="tabpanel" aria-labelledby="{$c->cData['CharacterName']}-tab">
<form method="POST" action="/saveCharacter.php">
<input type="hidden" name="filePath" id="filePath" value="{$c->charData['filePath']}">
<input type="hidden" name="filePath" id="filePath" value="{$c->cData['filePath']}">
<div class="container" style="font-size: 14px;">
<div class="row">
<div class="col">
<h1 style="margin: 15px;">{$c->charData['CharacterName']}</h1>
<h1 style="margin: 15px;">{$c->cData['CharacterName']}</h1>
<input class="btn btn-danger" style="" type="submit" value="Save Character">
<img src="/img/chars/{$c->charData['CharacterClass']}.gif"><br>
<input type="text" id="ChracterName" name="ChracterName" maxlength="16" value="{$c->charData['CharacterName']}">
<img src="/img/chars/{$c->cData['CharacterClass']}.gif"><br>
<input type="text" id="ChracterName" name="ChracterName" maxlength="16" value="{$c->cData['CharacterName']}">
<select id='CharacterClass'>
$option
</select>
<input style="border: 1px solid black;width: 34px;" type="number" id="CharacterLevel" value="{$c->charData['CharacterLevel']}"><br>
<input style="border: 1px solid black;width: 34px;" type="number" id="CharacterLevel" value="{$c->cData['CharacterLevel']}"><br>
$radio
</div>
<div class="col"><h2>Quests</h2>