ajaxify d2s editor

This commit is contained in:
Hash Borgir
2023-06-02 20:43:18 -06:00
parent ce83c42701
commit 81f1199a96
6 changed files with 223 additions and 70 deletions

View File

@@ -254,6 +254,7 @@ WHERE sk.charclass = '$class'";
foreach ($skills as $k => $v) {
if ($this->skillData[$k]['String']) {
$cData['skills'][$k] = [
'id' => $this->skillData[$k]['Id'],
'skill' => $this->skillData[$k]['String'],
'points' => $v,
'page' => $this->skillData[$k]['SkillPage'],
@@ -373,12 +374,23 @@ WHERE sk.charclass = '$class'";
public function setChar(string $stat, mixed $val, mixed $val2 = null) {
switch ($stat) {
case 'CharacterName':
if (strlen($val) < 1 || strlen($val) > 15) {
return false;
}
$pack = $this->ByteReader->bitsToHexString($this->ByteReader->toBits(pack('Z16', $val)));
$this->ByteReader->writeBytes(20, $pack);
rename($this->filePath, $_SESSION['savepath'] . "$val.d2s");
$this->data = $this->ByteReader->getData();
$this->save();
// file is not being saved, and copied before being saved, hence the bug, fixed
$fileName = pathinfo($this->filePath, PATHINFO_FILENAME);
$originalFileNames = glob($_SESSION['savepath'] . $fileName . '*');
foreach ($originalFileNames as $originalFileName) {
$newFileName = $_SESSION['savepath'] . $val . '.' . pathinfo($originalFileName, PATHINFO_EXTENSION);
if ($originalFileName !== $newFileName) {
copy($originalFileName, $newFileName);
unlink($originalFileName);
}
}
break;
case "CharacterClass":
@@ -398,6 +410,7 @@ WHERE sk.charclass = '$class'";
if ($val > 99) {
$val = 99;
}
$this->ByteReader->writeByte(43, $val);
$this->setStat('level', $val);
@@ -443,6 +456,21 @@ WHERE sk.charclass = '$class'";
$this->save();
break;
case 'Difficulty':
switch ($val) {
case "Normal":
$this->data[168] = pack('C', 255); // 1000 0000 MSB = Difficulty
break;
case "NM":
$this->data[169] = pack('C', 255);
break;
case "Hell":
$this->data[170] = pack('C', 255);
break;
}
break;
case 'LeftmousebuttonskillID':
$this->ByteReader->writeBytes(120, dechex($val));
break;