From e2046cb1537546bc80f4c2e49259ebd33a0111c1 Mon Sep 17 00:00:00 2001 From: dDeepLb Date: Fri, 24 Apr 2026 20:24:57 +0300 Subject: [PATCH 1/3] adapt cache clearing to top bar DOMification --- src/functions/cacheClearer.ts | 59 ++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/src/functions/cacheClearer.ts b/src/functions/cacheClearer.ts index 20d206e..a93693d 100644 --- a/src/functions/cacheClearer.ts +++ b/src/functions/cacheClearer.ts @@ -30,31 +30,46 @@ export default function cacheClearer(): void { return ret; }); - SDK.hookFunction("ChatRoomMenuClick", HOOK_PRIORITIES.AddBehaviour, (args, next) => { - const ret = next(args); - if (fbcSettings.manualCacheClear) { - const Space = 992 / ChatRoomMenuButtons.length; - for (let B = 0; B < ChatRoomMenuButtons.length; B++) { - if (MouseXIn(1005 + Space * B, Space - 2) && (ChatRoomMenuButtons as ChatRoomMenuButtonsWCE)[B] === "clearCache") { - doClearCaches(); + if (GameVersion === "R127") { + SDK.hookFunction("ChatRoomMenuClick", HOOK_PRIORITIES.AddBehaviour, (args, next) => { + const ret = next(args); + if (fbcSettings.manualCacheClear) { + const Space = 992 / ChatRoomMenuButtons.length; + for (let B = 0; B < ChatRoomMenuButtons.length; B++) { + if (MouseXIn(1005 + Space * B, Space - 2) && (ChatRoomMenuButtons as ChatRoomMenuButtonsWCE)[B] === "clearCache") { + doClearCaches(); + } } } - } - return ret; - }); + return ret; + }); - patchFunction( - "ChatRoomMenuDraw", - { - 'let suffix = "";': `let suffix = ""; - if (name === "clearCache") { - DrawButton(1005 + Space * Number(idx), 2, Space - 2, 60, "", color, null, "[WCE] clear and reload the drawing cache of all characters"); - DrawImage("Icons/Small/Reset.png", 976 + Space * Number(idx) + Space / 2, 4); - continue; - }`, - }, - "manual clearing and reloading of drawing cache" - ); + patchFunction( + "ChatRoomMenuDraw", + { + 'let suffix = "";': `let suffix = ""; + if (name === "clearCache") { + DrawButton(1005 + Space * Number(idx), 2, Space - 2, 60, "", color, null, "[WCE] clear and reload the drawing cache of all characters"); + DrawImage("Icons/Small/Reset.png", 976 + Space * Number(idx) + Space / 2, 4); + continue; + }`, + }, + "manual clearing and reloading of drawing cache" + ); + } else { + // @ts-expect-error bc-stubs doesn't have this function yet + SDK.hookFunction("ChatRoomMenuButtonVisualState", HOOK_PRIORITIES.AddBehaviour, (args, next) => { + if (args[0] !== "clearCache") return next(args); + + return { image: "Icons/Small/Reset.png", state: "Default", hoverText: "[WCE] clear and reload the drawing cache of all characters" }; + }); + + // @ts-expect-error bc-stubs doesn't have this function yet + SDK.hookFunction("ChatRoomMenuPerformAction", HOOK_PRIORITIES.AddBehaviour, (args, next) => { + if (args[0] !== "clearCache") return next(args); + return doClearCaches(); + }); + } async function clearCaches(): Promise { const start = Date.now(); From 78dbd364cced106fcc58c22e66a587793d47ae7b Mon Sep 17 00:00:00 2001 From: Silizia <66546362+KittenApps@users.noreply.github.com> Date: Sat, 9 May 2026 16:09:11 +0200 Subject: [PATCH 2/3] fix types --- src/functions/cacheClearer.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/functions/cacheClearer.ts b/src/functions/cacheClearer.ts index a93693d..203ef12 100644 --- a/src/functions/cacheClearer.ts +++ b/src/functions/cacheClearer.ts @@ -4,7 +4,7 @@ import { patchFunction, SDK, HOOK_PRIORITIES } from "../util/modding"; import { fbcSettings } from "../util/settings"; import { waitFor } from "../util/utils"; -type ChatRoomMenuButtonsWCE = (ChatRoomMenuButton | "clearCache")[]; +type ChatRoomMenuButtonWCE = ChatRoomMenuButton | "clearCache"; export default function cacheClearer(): void { const cacheClearInterval = 1 * 60 * 60 * 1000; @@ -26,17 +26,18 @@ export default function cacheClearer(): void { SDK.hookFunction("ChatRoomMenuBuild", HOOK_PRIORITIES.AddBehaviour, (args, next) => { const ret = next(args); - if (fbcSettings.manualCacheClear) (ChatRoomMenuButtons as ChatRoomMenuButtonsWCE).splice(ChatRoomMenuButtons.indexOf("Cut"), 0, "clearCache"); + if (fbcSettings.manualCacheClear) (ChatRoomMenuButtons as ChatRoomMenuButtonWCE[]).splice(ChatRoomMenuButtons.indexOf("Cut"), 0, "clearCache"); return ret; }); + // ToDo: remove once R128 is out if (GameVersion === "R127") { SDK.hookFunction("ChatRoomMenuClick", HOOK_PRIORITIES.AddBehaviour, (args, next) => { const ret = next(args); if (fbcSettings.manualCacheClear) { const Space = 992 / ChatRoomMenuButtons.length; for (let B = 0; B < ChatRoomMenuButtons.length; B++) { - if (MouseXIn(1005 + Space * B, Space - 2) && (ChatRoomMenuButtons as ChatRoomMenuButtonsWCE)[B] === "clearCache") { + if (MouseXIn(1005 + Space * B, Space - 2) && ChatRoomMenuButtons[B] as ChatRoomMenuButtonWCE === "clearCache") { doClearCaches(); } } @@ -57,16 +58,14 @@ export default function cacheClearer(): void { "manual clearing and reloading of drawing cache" ); } else { - // @ts-expect-error bc-stubs doesn't have this function yet SDK.hookFunction("ChatRoomMenuButtonVisualState", HOOK_PRIORITIES.AddBehaviour, (args, next) => { - if (args[0] !== "clearCache") return next(args); - - return { image: "Icons/Small/Reset.png", state: "Default", hoverText: "[WCE] clear and reload the drawing cache of all characters" }; + if (args[0] as ChatRoomMenuButtonWCE !== "clearCache") return next(args); + const state = "Default" as const; + return { image: "Icons/Small/Reset.png", state, hoverText: "[WCE] clear and reload the drawing cache of all characters" }; }); - // @ts-expect-error bc-stubs doesn't have this function yet SDK.hookFunction("ChatRoomMenuPerformAction", HOOK_PRIORITIES.AddBehaviour, (args, next) => { - if (args[0] !== "clearCache") return next(args); + if (args[0] as ChatRoomMenuButtonWCE !== "clearCache") return next(args); return doClearCaches(); }); } From d4bc3995cd10a7ebb2746c44ecd66517afe33dea Mon Sep 17 00:00:00 2001 From: Silizia <66546362+KittenApps@users.noreply.github.com> Date: Sat, 9 May 2026 16:12:36 +0200 Subject: [PATCH 3/3] fmt --- src/functions/cacheClearer.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/functions/cacheClearer.ts b/src/functions/cacheClearer.ts index 203ef12..f1a4ede 100644 --- a/src/functions/cacheClearer.ts +++ b/src/functions/cacheClearer.ts @@ -37,7 +37,7 @@ export default function cacheClearer(): void { if (fbcSettings.manualCacheClear) { const Space = 992 / ChatRoomMenuButtons.length; for (let B = 0; B < ChatRoomMenuButtons.length; B++) { - if (MouseXIn(1005 + Space * B, Space - 2) && ChatRoomMenuButtons[B] as ChatRoomMenuButtonWCE === "clearCache") { + if (MouseXIn(1005 + Space * B, Space - 2) && (ChatRoomMenuButtons[B] as ChatRoomMenuButtonWCE) === "clearCache") { doClearCaches(); } } @@ -59,13 +59,13 @@ export default function cacheClearer(): void { ); } else { SDK.hookFunction("ChatRoomMenuButtonVisualState", HOOK_PRIORITIES.AddBehaviour, (args, next) => { - if (args[0] as ChatRoomMenuButtonWCE !== "clearCache") return next(args); + if ((args[0] as ChatRoomMenuButtonWCE) !== "clearCache") return next(args); const state = "Default" as const; return { image: "Icons/Small/Reset.png", state, hoverText: "[WCE] clear and reload the drawing cache of all characters" }; }); SDK.hookFunction("ChatRoomMenuPerformAction", HOOK_PRIORITIES.AddBehaviour, (args, next) => { - if (args[0] as ChatRoomMenuButtonWCE !== "clearCache") return next(args); + if ((args[0] as ChatRoomMenuButtonWCE) !== "clearCache") return next(args); return doClearCaches(); }); }