diff --git a/CharEditor.php b/CharEditor.php index 14ae461..6d3b099 100644 --- a/CharEditor.php +++ b/CharEditor.php @@ -9,7 +9,7 @@ ob_start(); echo "
"; -$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]) . " "; diff --git a/index.php b/index.php index 21ab8cf..1ea5c12 100755 --- a/index.php +++ b/index.php @@ -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(); diff --git a/src/D2SaveFile.php b/src/D2SaveFile.php index 6c5caa6..00f0c75 100644 --- a/src/D2SaveFile.php +++ b/src/D2SaveFile.php @@ -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; } } diff --git a/src/tabs/Chars.php b/src/tabs/Chars.php index 795fe92..71801d5 100644 --- a/src/tabs/Chars.php +++ b/src/tabs/Chars.php @@ -1,5 +1,5 @@ charData); +// ddump($charData); ?> @@ -53,24 +53,21 @@ $form = new Formr\Formr();@@ -80,69 +77,127 @@ echo $tabs;