From 2e15b906a988de6e4c94314b8f4a81da0e2d483c Mon Sep 17 00:00:00 2001 From: Hash Borgir Date: Mon, 20 Jun 2022 20:21:28 -0600 Subject: [PATCH] D2SaveFile to D2Char rename --- index.php | 10 +- saveCharacter.php | 6 +- src/{D2SaveFile.php => D2Char.php} | 83 ++++++----- src/{D2Item.php => D2CharItem.php} | 12 +- ...uctureData.php => D2CharStructureData.php} | 131 ++++++------------ src/tabs/Chars.php | 50 +++---- 6 files changed, 122 insertions(+), 170 deletions(-) rename src/{D2SaveFile.php => D2Char.php} (64%) rename src/{D2Item.php => D2CharItem.php} (94%) rename src/{D2SaveFileStructureData.php => D2CharStructureData.php} (73%) diff --git a/index.php b/index.php index 72ef92c..c1d480c 100755 --- a/index.php +++ b/index.php @@ -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 diff --git a/saveCharacter.php b/saveCharacter.php index fd03d99..da076d7 100644 --- a/saveCharacter.php +++ b/saveCharacter.php @@ -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; diff --git a/src/D2SaveFile.php b/src/D2Char.php similarity index 64% rename from src/D2SaveFile.php rename to src/D2Char.php index fb6edf8..4569bd9 100644 --- a/src/D2SaveFile.php +++ b/src/D2Char.php @@ -1,65 +1,62 @@ 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) { diff --git a/src/D2Item.php b/src/D2CharItem.php similarity index 94% rename from src/D2Item.php rename to src/D2CharItem.php index 686235a..29f8207 100644 --- a/src/D2Item.php +++ b/src/D2CharItem.php @@ -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(){ + + } } diff --git a/src/D2SaveFileStructureData.php b/src/D2CharStructureData.php similarity index 73% rename from src/D2SaveFileStructureData.php rename to src/D2CharStructureData.php index a0f4b2b..b1d6242 100644 --- a/src/D2SaveFileStructureData.php +++ b/src/D2CharStructureData.php @@ -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; diff --git a/src/tabs/Chars.php b/src/tabs/Chars.php index 7ff7ae2..8c6297b 100644 --- a/src/tabs/Chars.php +++ b/src/tabs/Chars.php @@ -62,7 +62,7 @@ $form = new Formr\Formr(); $tabs .= << - {$c->charData['CharacterName']} + {$c->cData['CharacterName']} 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 .= "

$difficulty

"; foreach ($q as $k => $v) { @@ -100,7 +100,7 @@ EOT; $wps = null; $wps .= "

"; - foreach ($c->charData['Waypoints'] as $diff => $waypoints) { + foreach ($c->cData['Waypoints'] as $diff => $waypoints) { $wps .= "

$diff

"; 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 .= ""; } else { $option .= ""; } - if ($c->charData['CharacterClass'] == 'Assassin'){ + if ($c->cData['CharacterClass'] == 'Assassin'){ $option .= ""; } else { $option .= ""; } - if ($c->charData['CharacterClass'] == 'Barbarian'){ + if ($c->cData['CharacterClass'] == 'Barbarian'){ $option .= ""; } else { $option .= ""; } - if ($c->charData['CharacterClass'] == 'Druid'){ + if ($c->cData['CharacterClass'] == 'Druid'){ $option .= ""; } else { $option .= ""; } - if ($c->charData['CharacterClass'] == 'Paladin'){ + if ($c->cData['CharacterClass'] == 'Paladin'){ $option .= ""; } else { $option .= ""; } - if ($c->charData['CharacterClass'] == 'Necromancer'){ + if ($c->cData['CharacterClass'] == 'Necromancer'){ $option .= ""; } else { $option .= ""; } - if ($c->charData['CharacterClass'] == 'Sorceress'){ + if ($c->cData['CharacterClass'] == 'Sorceress'){ $option .= ""; } else { $option .= ""; } $radio = ''; - if ($c->charData['Difficulty']['Norm'] == 1){ + if ($c->cData['Difficulty']['Norm'] == 1){ $radio .= 'Normal
'; } else { $radio .= 'Normal
'; } - if ($c->charData['Difficulty']['NM'] == 1){ + if ($c->cData['Difficulty']['NM'] == 1){ $radio .= 'NM
'; } else { $radio .= 'NM
'; } - if ($c->charData['Difficulty']['Hell'] == 1){ + if ($c->cData['Difficulty']['Hell'] == 1){ $radio .= 'Hell
'; } else { $radio .= 'Hell
'; @@ -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 .= << +
- +
-

{$c->charData['CharacterName']}

+

{$c->cData['CharacterName']}

-
- +
+ -
+
$radio

Quests