From ce83c427010d875e94bb57a2f1dba180846bfc1e Mon Sep 17 00:00:00 2001 From: Hash Borgir Date: Fri, 2 Jun 2023 04:42:29 -0600 Subject: [PATCH] AJAX waypoint/quest enable/disable working --- res/app.js | 22 ++++++ saveCharacter.php | 148 +++++++++++++++--------------------- src/D2CharStructureData.php | 52 ++++++------- src/tabs/Chars.php | 2 +- 4 files changed, 111 insertions(+), 113 deletions(-) diff --git a/res/app.js b/res/app.js index 36a8c74..e156821 100755 --- a/res/app.js +++ b/res/app.js @@ -352,7 +352,29 @@ $(document).ready(function () { }); }); + $(".qcheck").change(function () { + // Toggle the value between 0 and 1 + var value = $(this).is(":checked") ? 1 : 0; + // Get the name of the checkbox + var name = $(this).attr("name"); + + // Get the name of the difficulty + var diff = $(this).attr("diff"); + + // Get the value of the input named "filePath" + var filePath = $("input[name='filePath']").val(); + + // Construct the URL for the GET request + var url = "/saveCharacter.php?cmd=q&name=" + name + "&value=" + value + "&filePath=" + filePath + "&diff=" + diff; + + + // Send the GET request + $.get(url, function (response) { + // Handle the response if needed + console.log(response); + }); + }); });// end document.ready \ No newline at end of file diff --git a/saveCharacter.php b/saveCharacter.php index a0add26..a3244f1 100644 --- a/saveCharacter.php +++ b/saveCharacter.php @@ -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: /'); diff --git a/src/D2CharStructureData.php b/src/D2CharStructureData.php index 0b36fd0..aa77e90 100644 --- a/src/D2CharStructureData.php +++ b/src/D2CharStructureData.php @@ -181,39 +181,39 @@ class D2CharStructureData { * @var string[] */ public $qNorm = [ - 345 => 'introWarriv', + //345 => 'introWarriv', 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', - 359 => 'traveledToAct2', - 361 => 'introJerhyn', + //359 => 'traveledToAct2', + //361 => 'introJerhyn', 363 => 'Radaments_Lair', 365 => 'TheHoradric_Staff', 367 => 'Tainted_Sun', 369 => 'Arcane_Sanctuary', 371 => 'The_Summoner', 373 => 'The_Seven_Tombs', - 375 => 'traveledToAct3', - 377 => 'introHratli', + //375 => 'traveledToAct3', + //377 => 'introHratli', 379 => 'LamEsens_Tome', 381 => 'Khalims_Will', 383 => 'Blade_Of_The_Old_Religion', 385 => 'The_Golden_Bird', 387 => 'The_Blackened_Temple', 389 => 'The_Guardian', - 391 => 'traveledtoAct4', - 393 => 'introToAct4', + //391 => 'traveledtoAct4', + //393 => 'introToAct4', 395 => 'The_Fallen_Angel', 397 => 'Terrors_End', 399 => 'Hell_Forge', - 401 => 'traveledToAct5', + //401 => 'traveledToAct5', //403 => 'empty31', //405 => 'empty32', //407 => 'empty33', - 409 => 'completedTerrorsEnd', + //409 => 'completedTerrorsEnd', //411 => 'empty21', //413 => 'empty22', 415 => 'Siege_On_Harrogath', @@ -229,39 +229,39 @@ class D2CharStructureData { * @var string[] */ public $qNM = [ - 441 => 'introWarrivNM', + //441 => 'introWarrivNM', 443 => 'Den_Of_Evil_NM', 445 => 'Sisters_Burial_Grounds_NM', 447 => 'Tools_Of_The_Trade_NM', 449 => 'The_Search_For_Cain_NM', 451 => 'The_Forgotten_Tower_NM', 453 => 'Sisters_To_The_Slaughter_NM', - 455 => 'traveledToAct2', - 457 => 'introJerhyn', + //455 => 'traveledToAct2', + //457 => 'introJerhyn', 459 => 'Radaments_Lair_NM', 461 => 'The_Horadric_Staff_NM', 463 => 'Tainted_Sun_NM', 465 => 'Arcane_Sanctuary_NM', 467 => 'The_Summoner_NM', 469 => 'The_SevenTombs_NM', - 471 => 'traveledToAct3', - 473 => 'introHratli', + //471 => 'traveledToAct3', + //473 => 'introHratli', 475 => 'Lam_Esens_Tome_NM', 477 => 'Khalims_Will_NM', 479 => 'Blade_Of_The_OldReligion_NM', 481 => 'The_Golden_Bird_NM', 483 => 'The_Blackened_Temple_NM', 485 => 'The_Guardian_NM', - 487 => 'traveledtoAct4', - 489 => 'introToAct4', + //487 => 'traveledtoAct4', + //489 => 'introToAct4', 491 => 'The_Fallen_Angel_NM', 493 => 'Terrors_End_NM', 495 => 'Hell_Forge_NM', - 497 => 'traveledToAct5', + //497 => 'traveledToAct5', //499 => 'empty31', //501 => 'empty32', //503 => 'empty33', - 505 => 'completedTerrorsEnd', + //505 => 'completedTerrorsEnd', //507 => 'empty21', //509 => 'empty22', 511 => 'Siege_On_Harrogath', @@ -277,35 +277,35 @@ class D2CharStructureData { * @var string[] */ public $qHell = [ - 537 => 'introWarriv', + //537 => 'introWarriv', 539 => 'Den_Of_Evil_Hell', 541 => 'Sisters_Burial_Grounds_Hell', 543 => 'Tools_Of_The_Trade_Hell', 545 => 'The_Search_For_Cain_Hell', 547 => 'The_Forgotten_Tower_Hell', 549 => 'Sisters_To_The_Slaughter_Hell', - 551 => 'traveledToAct2', - 553 => 'introJerhyn', + //551 => 'traveledToAct2', + //553 => 'introJerhyn', 555 => 'Radaments_Lair_Hell', 557 => 'The_Horadric_Staff_Hell', 559 => 'Tainted_Sun_Hell', 561 => 'Arcane_Sanctuary_Hell', 563 => 'The_Summoner_Hell', 565 => 'The_SevenTombs_Hell', - 567 => 'traveledToAct3', - 569 => 'introHratli', + //567 => 'traveledToAct3', + //569 => 'introHratli', 571 => 'Lam_Esens_Tome_Hell', 573 => 'KhalimsWill_Hell', 575 => 'Blade_Of_The_Old_Religion_Hell', 577 => 'The_Golden_Bird_Hell', 579 => 'The_Blackened_Temple_Hell', 581 => 'The_Guardian_Hell', - 583 => 'traveledtoAct4', - 585 => 'introToAct4', + //583 => 'traveledtoAct4', + //585 => 'introToAct4', 587 => 'The_Fallen_Angel_Hell', 589 => 'Terrors_End_Hell', 591 => 'Hell_Forge_Hell', - 593 => 'traveledToAct5', + //593 => 'traveledToAct5', //595 => 'empty31', //597 => 'empty32', //599 => 'empty33', diff --git a/src/tabs/Chars.php b/src/tabs/Chars.php index b237788..55339f6 100644 --- a/src/tabs/Chars.php +++ b/src/tabs/Chars.php @@ -32,7 +32,7 @@ EOT; $kD = str_replace([" NM", " Hell"], "", $kD); $checked = ($v == 1) ? 'checked' : ''; - $quests .= ""; + $quests .= ""; $quests .= "
"; } }