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

@@ -36,6 +36,11 @@ require_once './src/D2ItemDesc.php';
require_once './src/D2Char.php';
require_once './src/D2CharStructureData.php';
require_once './src/D2ByteReader.php';
require_once './src/D2BitReader.php';
require_once './src/D2Item.php';
require_once './src/D2Char.php';
PDO_Connect("sqlite:" . DB_FILE);
// Create an instance of D2CharStructureData class
$csData = new D2CharStructureData();
@@ -45,8 +50,7 @@ $cmd = $g['cmd'];
// Get the file path from the POST data and replace backslashes /
$filePath = $g['filePath'];
$filePath = str_replace("\\", "\\\\", $filePath);
//$filePath = str_replace("\\", "\\\\", $filePath);
// Handle the WP check/uncheck
if ($cmd == "wp") {
$diff = $g['diff'];
@@ -74,7 +78,7 @@ if ($cmd == "wp") {
$fileContents = file_get_contents($filePath); // Read the contents of the file
$ByteReader = new D2ByteReader($fileContents); // Create a new instance of D2ByteReader with the file data
$fileData = $ByteReader->getData(); // Get the data from the ByteReader instance
$fileData = $ByteReader->getData(); // Get the data from the ByteReader instance
$wpBytes = $ByteReader->read($offset, 5, 1);
$wpBytesToBits = $ByteReader->toBits($wpBytes);
@@ -100,22 +104,22 @@ if ($cmd == "wp") {
/*
* array (size=5)
'cmd' => string 'q' (length=1)
'name' => string 'Sisters_Burial_Grounds' (length=29)
'value' => string '1' (length=1)
'filePath' => string 'D:\\Diablo II\\MODS\\ironman-dev\\save\\Sorc.d2s' (length=48)
'diff' => string 'Norm' (length=4)
'cmd' => string 'q' (length=1)
'name' => string 'Sisters_Burial_Grounds' (length=29)
'value' => string '1' (length=1)
'filePath' => string 'D:\\Diablo II\\MODS\\ironman-dev\\save\\Sorc.d2s' (length=48)
'diff' => string 'Norm' (length=4)
At each quest offset, read a short, 2 bytes.
347 => 'Den_Of_Evil',
349 => 'Sisters_Burial_Grounds',
351 => 'Tools_Of_The_Trade',
353 => 'The_Search_For_Cain',
355 => 'The_Forgotten_Tower',
357 => 'Sisters_To_The_Slaughter',
347 => 'Den_Of_Evil',
349 => 'Sisters_Burial_Grounds',
351 => 'Tools_Of_The_Trade',
353 => 'The_Search_For_Cain',
355 => 'The_Forgotten_Tower',
357 => 'Sisters_To_The_Slaughter',
Each short is 16 bytes.
*
*
* 0xFEFF = 11111110 11111111
* Short #0 Den of Evil Bit 4 is set when you enter the Den.
@@ -153,7 +157,7 @@ if ($cmd == "q") {
// Write the byte value 0xFF at the current position
fwrite($fp, pack('C', 0xFF));
echo "Quest Just Finished, Collect Reward!";
} else {
// Set the file pointer position to the quest offset
@@ -167,10 +171,75 @@ if ($cmd == "q") {
// Write the byte value 0xFF at the current position
fwrite($fp, pack('C', 0x00));
echo "Quest Not Started Yet!";
}
$checksum = (shell_exec("bin\d2scs.exe \"$filePath\""));
fclose($fp);
}
$cmd = $_GET['cmd'];
$name = $_GET['name'];
$value = $_GET['value'];
$char = new D2Char(basename($filePath));
switch ($cmd) {
case "CharacterName":
// Handle CharacterName command
// Validate the character name length
if (strlen($value) < 2 || strlen($value) > 15) {
echo "Character name must be between 2 and 15 characters long.";
// You can handle the error case accordingly (e.g., return an error response)
// Additional validation checks can be added here as needed
} else {
// Validate the character name format
$pattern = '/^[A-Za-z0-9_-]+$/'; // Regular expression pattern for allowed characters
if (!preg_match($pattern, $value)) {
echo "\nCharacter name contains invalid characters. Only alphabets, numbers, underscore, and dash are allowed.";
// Handle the error case accordingly
} else {
// The character name is valid, proceed with further processing
$char->setChar($cmd, $value);
echo "\nCharacter Name and filename Changed";
}
}
echo "\nHandling CharacterName command - Name: $value, File Path: $filePath";
break;
case "CharacterClass":
// Handle CharacterClass command
$char->setChar($cmd, $value);
echo "Handling CharacterClass command - Class: $value, File Path: $filePath";
break;
case "CharacterLevel":
// Handle CharacterLevel command
$char->setChar($cmd, $value);
echo "Handling CharacterLevel command - Level: $value, File Path: $filePath";
break;
// handle difficulty wierdly
case "Normal":
$char->setChar("Difficulty", $value);
echo "Handling Difficulty command - Difficulty: $value, File Path: $filePath";
break;
case "NM":
$char->setChar("Difficulty", $value);
echo "Handling Difficulty command - Difficulty: $value, File Path: $filePath";
break;
case "Hell":
$char->setChar("Difficulty", $value);
echo "Handling Difficulty command - Difficulty: $value, File Path: $filePath";
break;
// skills
case "skills":
//var_dump($char->cData);
$char->setSkill($name, $value);
echo "Handling skills command - Skill: $name, Value: $value, File Path: $filePath";
break;
default:
// Handle unknown command
echo "Unknown command: $cmd";
break;
}