AJAX waypoint/quest enable/disable working

This commit is contained in:
Hash Borgir
2023-06-02 04:42:29 -06:00
parent b9f4054028
commit ce83c42701
4 changed files with 111 additions and 113 deletions

View File

@@ -72,8 +72,6 @@ if ($cmd == "wp") {
'diff' => string 'Norm' (length=4)
*/
$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
@@ -82,119 +80,97 @@ if ($cmd == "wp") {
$wpBytesToBits = $ByteReader->toBits($wpBytes);
$BitReader = new D2BitReader($wpBytesToBits);
$BitReader->setBit($g['name'], $g['value']);
$newBits = $BitReader->getBits();
$newBitsToBytes = $ByteReader->bitsToHexString($newBits);
$ByteReader->writeBytes($offset, $newBitsToBytes);
$newFileData = $ByteReader->getData();
$newFileData = $ByteReader->getData();
$fileSaved = file_put_contents($filePath, $newFileData);
$checksum = (shell_exec("bin\d2scs.exe \"$filePath\""));
if ($fileSaved) {
echo "Success";
} else {
echo "Fail";
}
}
/*
* 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)
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',
Each short is 16 bytes.
*
* 0xFEFF = 11111110 11111111
* Short #0 Den of Evil Bit 4 is set when you enter the Den.
*/
if ($cmd == "q") {
$diff = $g['diff'];
if ($diff == "Norm") {
$qArray = array_flip($csData->qNorm);
$questOffset = $qArray[$g['name']];
}
if ($diff == "NM") {
$qArray = array_flip($csData->qNM);
$questOffset = $qArray[$g['name']];
}
if ($diff == "Hell") {
$qArray = array_flip($csData->qHell);
$questOffset = $qArray[$g['name']];
}
// Open the file in binary mode for both reading and writing
$fp = fopen($filePath, "rb+");
if ($g['value']) {
// Set the file pointer position to the quest offset
fseek($fp, $questOffset);
// Write the byte value 0xFE at the current position
fwrite($fp, pack('C', 0xFE));
// Move the file pointer to the next position
fseek($fp, $questOffset + 1);
// 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
fseek($fp, $questOffset);
// Write the byte value 0xFE at the current position
fwrite($fp, pack('C', 0x00));
// Move the file pointer to the next position
fseek($fp, $questOffset + 1);
// Write the byte value 0xFF at the current position
fwrite($fp, pack('C', 0x00));
echo "Quest Not Started Yet!";
}
die();
// Get the POST data
$p = $_GET;
// Loop through each 'quest' element in the POST data and assign the corresponding value from 'dStruct->_qNorm' to 'q'
foreach ($p['quest'] as $k => $v) {
$q[$k] = $dStruct->_qNorm[$k];
$checksum = (shell_exec("bin\d2scs.exe \"$filePath\""));
fclose($fp);
}
$wpNames_flipped = array_values($dStruct->wpNames_flipped);
// Loop through each 'wp' element in the POST data and assign the corresponding value from 'dStruct->_qNorm' to 'w'
foreach ($p['wp'] as $k => $v) {
$w[$k] = $dStruct->_qNorm[$k];
}
// Get the file path from the POST data and replace backslashes /
$filePath = $p['filePath'];
$filePath = str_replace("\\", "\\\\", $filePath);
// Open the file in binary mode for both reading and writing
$fp = fopen($filePath, "rb+");
// Edit quests which are checked to set them as 'Just finished' (FE FF)
foreach ($q as $k => $v) {
// Set the file pointer position to the quest offset
fseek($fp, $v);
// Write the byte value 0xFE at the current position
fwrite($fp, pack('C', 0xFE));
// Move the file pointer to the next position
fseek($fp, $v + 1);
// Write the byte value 0xFF at the current position
fwrite($fp, pack('C', 0xFF));
}
// Array containing the fseek wp offsets
// 5 acts per difficulty
// starts at 641, but we skip two bytes, go to 643, then read next 5 bytes, each byte is a bitfield per act.
$offsets = [
643, 644, 645, 646, 647, // First set of offsets Norm
667, 668, 669, 670, 671, // Second set of offsets NM
691, 692, 693, 694, 695 // Third set of offsets Hell
];
// Determine the value to write based on the condition $p['wp_all'] == "1"
$valueToWrite = ($p['wp_all'] == "1") ? 0xFF : 0x00;
// Loop over each offset in the $offsets array
foreach ($offsets as $offset) {
// Set the file pointer position to the current offset
fseek($fp, $offset);
// Write the value specified by pack('C', $valueToWrite)
fwrite($fp, pack('C', $valueToWrite));
}
$checksum = (shell_exec("bin\d2scs.exe \"$filePath\""));
fclose($fp);
header('Location: /');