Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 38 additions & 24 deletions src/functions/cacheClearer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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;
Expand All @@ -26,35 +26,49 @@

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;
});

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();
// ToDo: remove once R128 is out

Check warning on line 33 in src/functions/cacheClearer.ts

View workflow job for this annotation

GitHub Actions / lint

eslint(no-warning-comments)

Unexpected 'todo' comment: 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[B] as ChatRoomMenuButtonWCE) === "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 {
SDK.hookFunction("ChatRoomMenuButtonVisualState", HOOK_PRIORITIES.AddBehaviour, (args, next) => {
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);
return doClearCaches();
});
}

async function clearCaches(): Promise<void> {
const start = Date.now();
Expand Down
Loading