-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.ts
57 lines (45 loc) · 1.56 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/** @noSelfInFile */
declare var main: () => void;
declare var config: () => void;
const oldMain = main;
const oldConfig = config;
type scriptHookSignature = () => void;
const hooksMainBefore: scriptHookSignature[] = [];
const hooksMainAfter: scriptHookSignature[] = [];
const hooksConfigBefore: scriptHookSignature[] = [];
const hooksConfigAfter: scriptHookSignature[] = [];
export const executeHooksMainBefore = () => hooksMainBefore.forEach((func) => func());
export const executeHooksMainAfter = () => hooksMainAfter.forEach((func) => func());
export function hookedMain() {
executeHooksMainBefore();
oldMain();
executeHooksMainAfter();
}
export const executeHooksConfigBefore = () => hooksConfigBefore.forEach((func) => func());
export const executeHooksConfigAfter = () => hooksConfigAfter.forEach((func) => func());
export function hookedConfig() {
executeHooksConfigBefore();
oldConfig();
executeHooksConfigAfter();
}
main = hookedMain;
config = hookedConfig;
export enum W3TS_HOOK {
MAIN_BEFORE = "main::before",
MAIN_AFTER = "main::after",
CONFIG_BEFORE = "config::before",
CONFIG_AFTER = "config::after"
}
const entryPoints: { [key: string]: scriptHookSignature[]; } = {
[W3TS_HOOK.MAIN_BEFORE]: hooksMainBefore,
[W3TS_HOOK.MAIN_AFTER]: hooksMainAfter,
[W3TS_HOOK.CONFIG_BEFORE]: hooksConfigBefore,
[W3TS_HOOK.CONFIG_AFTER]: hooksConfigAfter,
};
export function addScriptHook(entryPoint: string, hook: scriptHookSignature): boolean {
if (!(entryPoint in entryPoints)) {
return false;
}
entryPoints[entryPoint].push(hook);
return true;
}