From 96c2d2e8dd70951520198ebf0d9a4b4a02242c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=9F=E9=9B=B2?= Date: Tue, 23 Dec 2025 21:32:33 +0800 Subject: [PATCH] fix(casino): Fix game freeze when disable Manipulate Rig Slot Machines (#794) * fix: Fix disable Manipulate Rig Slot Machines freeze the game check spin state also while on diasble fix issue #791 * Revert "fix: Fix disable Manipulate Rig Slot Machines freeze the game" This reverts commit 1af78f95a3ccc13cd0904527affefcb784029e44. * fix: Fix disable Manipulate Rig Slot Machines freeze the game now we must ensure result [3,9] also we should ensure we are write slots_random_results_table at a "safe period", nomatter enable or reset while disable. fix issue #791 * chore: remove redundant script host check If script host changes while waiting for the reset timing for slots_random_results_table, there is no need to perform the reset process. --- src/game/features/recovery/Casino.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/game/features/recovery/Casino.cpp b/src/game/features/recovery/Casino.cpp index b396d7d..a930543 100644 --- a/src/game/features/recovery/Casino.cpp +++ b/src/game/features/recovery/Casino.cpp @@ -5,6 +5,7 @@ #include "game/gta/Stats.hpp" #include "core/commands/ListCommand.hpp" #include "game/backend/Tunables.hpp" +#include "core/backend/ScriptMgr.hpp" #include @@ -18,6 +19,7 @@ namespace YimMenu::Features int slots_random_results_table = 1350; std::set slots_blacklist = {9, 21, 22, 87, 152}; int spin_state_var = 1668; + std::set spin_state_whitelist = {8, 14}; virtual void OnTick() override { @@ -41,14 +43,15 @@ namespace YimMenu::Features if (*ScriptLocal("casino_slots"_J, slots_random_results_table + slots_iter).As() != 6) { needs_run = true; + break; } } } - if (needs_run && *spin_state >= 8 && *spin_state <= 15) + if (needs_run) { for (int slots_iter = 3; slots_iter <= 196; ++slots_iter) { - if (!slots_blacklist.contains(slots_iter)) + if (!slots_blacklist.contains(slots_iter) && spin_state_whitelist.contains(*spin_state)) { int slot_result = 6; *ScriptLocal("casino_slots"_J, slots_random_results_table + slots_iter).As() = slot_result; @@ -58,7 +61,7 @@ namespace YimMenu::Features } } - virtual void OnDisable() override +virtual void OnDisable() override { if (Scripts::SafeToModifyFreemodeBroadcastGlobals() && SCRIPT::GET_NUMBER_OF_THREADS_RUNNING_THE_SCRIPT_WITH_THIS_HASH("casino_slots"_J)) { @@ -70,13 +73,24 @@ namespace YimMenu::Features Scripts::ForceScriptHost(Scripts::FindScriptThread("casino_slots"_J)); } + int* spin_state = ScriptLocal("casino_slots"_J, spin_state_var).As(); + // waiting for reset until next time using + while (!spin_state_whitelist.contains(*spin_state)) + { + ScriptMgr::Yield(); + spin_state = ScriptLocal("casino_slots"_J, spin_state_var).As(); + if (spin_state == nullptr){ + return; + } + } + for (int slots_iter = 3; slots_iter <= 196; ++slots_iter) { if (!slots_blacklist.contains(slots_iter)) { int slot_result = 6; std::srand(static_cast(std::time(0)) + slots_iter); - slot_result = std::rand() % 7; // Generates a pseudo random number between 0 and 7 + slot_result = 3 + std ::rand() % 7; // Generates a pseudo random number [3,9] *ScriptLocal("casino_slots"_J, slots_random_results_table + slots_iter).As() = slot_result; } } @@ -85,4 +99,4 @@ namespace YimMenu::Features }; static CasinoManipulateRigSlotMachines _CasinoManipulateRigSlotMachines{"casinomanipulaterigslotmachines", "Manipulate Rig Slot Machines", "Lets you win the Rig Slot Machines every time"}; -} \ No newline at end of file +}