@@ -46,7 +46,6 @@ static GJRewardItem* time1 = nullptr;
4646static GJRewardItem* time2 = nullptr ;
4747static std::optional<arc::mpsc::Sender<ChestMsg>> g_chestTx;
4848
49-
5049void DailyChest::getRewards () {
5150 auto glm = GameLevelManager::sharedState ();
5251 if (glm) {
@@ -121,8 +120,40 @@ void giveChestNotify(bool large) {
121120 });
122121}
123122
123+ #include < Geode/modify/RewardUnlockLayer.hpp>
124+ class $modify(RULHook, RewardUnlockLayer) {
125+ void step2 () {
126+ int tag = m_chestType;
127+ if (g_chestTx) {
128+ if (tag == 1 ) {
129+ (void )g_chestTx->trySend ({
130+ .type = ChestMsg::Type::Opened,
131+ .opened = ChestKind::Small
132+ });
133+ } else if (tag == 2 ) {
134+ (void )g_chestTx->trySend ({
135+ .type = ChestMsg::Type::Opened,
136+ .opened = ChestKind::Large
137+ });
138+ }
139+ }
140+ refreshRewards ();
141+ RewardUnlockLayer::step2 ();
142+ }
143+ };
144+
145+ static void toggleHook (bool value) {
146+ for (auto & hook : geode::Mod::get ()->getHooks ()) {
147+ if (hook->getDisplayName () == " RewardUnlockLayer::step2" ) {
148+ (void )(value ? hook->enable () : hook->disable ());
149+ }
150+ }
151+ }
124152$on_game(Loaded) {
125- if (!Mod::get ()->getSettingValue <bool >(" largeChest" ) && !Mod::get ()->getSettingValue <bool >(" smallChest" )) return ;
153+ if (!Mod::get ()->getSettingValue <bool >(" largeChest" ) && !Mod::get ()->getSettingValue <bool >(" smallChest" )) {
154+ toggleHook (false );
155+ return ;
156+ }
126157 auto [tx, rx] = arc::mpsc::channel<ChestMsg>();
127158 g_chestTx = std::move (tx);
128159 // wait 5 seconds before
@@ -233,38 +264,19 @@ void giveChestNotify(bool large) {
233264 });
234265 listenForSettingChanges<bool >(" smallChest" , [](bool value) {
235266 if (!value && !Mod::get ()->getSettingValue <bool >(" largeChest" )) {
236- if (g_chestTx) {
267+ if (g_chestTx) {
268+ toggleHook (false );
237269 (void )g_chestTx->trySend ({ ChestMsg::Type::Stop });
238270 }
239271 }
240272 });
241273 listenForSettingChanges<bool >(" largeChest" , [](bool value) {
242274 if (!value && !Mod::get ()->getSettingValue <bool >(" smallChest" )) {
243275 if (g_chestTx) {
276+ toggleHook (false );
244277 (void )g_chestTx->trySend ({ ChestMsg::Type::Stop });
245278 }
246279 }
247280 });
248281 refreshRewards ();
249282}
250- #include < Geode/modify/RewardUnlockLayer.hpp>
251- class $modify(RULHook, RewardUnlockLayer) {
252- void step3 () {
253- int tag = m_chestType;
254- if (g_chestTx) {
255- if (tag == 1 ) {
256- (void )g_chestTx->trySend ({
257- .type = ChestMsg::Type::Opened,
258- .opened = ChestKind::Small
259- });
260- } else if (tag == 2 ) {
261- (void )g_chestTx->trySend ({
262- .type = ChestMsg::Type::Opened,
263- .opened = ChestKind::Large
264- });
265- }
266- }
267- refreshRewards ();
268- RewardUnlockLayer::step3 ();
269- }
270- };
0 commit comments