zois-core 2.2.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/icons/toast-themes/abdl/bottle.svg +10 -0
- package/dist/assets/icons/toast-themes/abdl/diaper.svg +11 -0
- package/dist/assets/icons/toast-themes/abdl/heart.svg +7 -0
- package/dist/assets/icons/toast-themes/abdl/sparkle.svg +5 -0
- package/dist/assets/icons/toast-themes/abdl/star.svg +5 -0
- package/dist/assets/icons/toast-themes/abdl/teddy.svg +18 -0
- package/dist/assets/icons/toast-themes/anime/error.svg +20 -0
- package/dist/assets/icons/toast-themes/anime/info.svg +20 -0
- package/dist/assets/icons/toast-themes/anime/success.svg +16 -0
- package/dist/assets/icons/toast-themes/anime/warning.svg +19 -0
- package/dist/changelogs.js +628 -295
- package/dist/cssVars.js +46 -0
- package/dist/dialogs.js +523 -83
- package/dist/events.js +28 -6
- package/dist/index.js +27 -70
- package/dist/localization.js +250 -40
- package/dist/messaging.js +1 -1
- package/dist/migration.js +37 -0
- package/dist/modules/baseModule.js +110 -0
- package/dist/modules/index.js +4 -0
- package/dist/modules/loadingStrategy.js +20 -0
- package/dist/modules/moduleContext.js +56 -0
- package/dist/modules/modulesManager.js +175 -0
- package/dist/{modSdk.js → patching.js} +33 -9
- package/dist/rpc.js +139 -0
- package/dist/scripts/zois-core.js +14 -14
- package/dist/settings.js +90 -0
- package/dist/settingsDialog.js +1361 -0
- package/dist/shard-modules/{attributesModule.js → attributes.js} +2 -2
- package/dist/shard-modules/{shardModule.js → base.js} +2 -2
- package/dist/shard-modules/{centerModule.js → center.js} +4 -2
- package/dist/shard-modules/{clickModule.js → click.js} +2 -2
- package/dist/shard-modules/{counterUpModule.js → counterUp.js} +2 -2
- package/dist/shard-modules/{dynamicClassModule.js → dynamicClass.js} +2 -2
- package/dist/shard-modules/index.js +9 -9
- package/dist/shard-modules/{multiClickModule.js → multiClick.js} +2 -2
- package/dist/shard-modules/{styleModule.js → style.js} +2 -2
- package/dist/shard-modules/{typeModule.js → type.js} +2 -2
- package/dist/shards/backNextButton.js +173 -0
- package/dist/shards/{shard.js → base.js} +15 -15
- package/dist/shards/{buttonShard.js → button.js} +30 -52
- package/dist/shards/{cardShard.js → card.js} +4 -4
- package/dist/shards/{checkboxShard.js → checkbox.js} +6 -13
- package/dist/shards/{containerShard.js → container.js} +2 -2
- package/dist/shards/extensionsStorageBar.js +377 -0
- package/dist/shards/fileInput.js +180 -0
- package/dist/shards/flexContainer.js +30 -0
- package/dist/shards/gridContainer.js +34 -0
- package/dist/shards/{imageShard.js → image.js} +8 -6
- package/dist/shards/index.js +17 -13
- package/dist/shards/{inputShard.js → input.js} +4 -4
- package/dist/shards/{inputListShard.js → inputList.js} +22 -4
- package/dist/shards/select.js +201 -0
- package/dist/shards/svg.js +28 -0
- package/dist/shards/{tabsShard.js → tabs.js} +18 -19
- package/dist/shards/{textShard.js → text.js} +4 -4
- package/dist/shared.js +215 -0
- package/dist/styles.css +0 -51
- package/dist/subscreens/customTranslations.js +239 -0
- package/dist/subscreens/languageDetails.js +194 -0
- package/dist/subscreens/localization.js +115 -0
- package/dist/toast-themes/abdl.js +419 -0
- package/dist/toast-themes/anime.js +483 -0
- package/dist/toast-themes/base.js +40 -0
- package/dist/toast-themes/cyber.js +538 -0
- package/dist/toast-themes/default.js +282 -0
- package/dist/toastThemesDialog.js +274 -0
- package/dist/toasts.js +195 -174
- package/dist/types/cssVars.d.ts +1 -0
- package/dist/types/dialogs.d.ts +46 -18
- package/dist/types/events.d.ts +11 -2
- package/dist/types/global.d.ts +4 -3
- package/dist/types/index.d.ts +12 -19
- package/dist/types/localization.d.ts +25 -3
- package/dist/types/migration.d.ts +6 -0
- package/dist/types/modules/baseModule.d.ts +108 -0
- package/dist/types/modules/index.d.ts +4 -0
- package/dist/types/modules/loadingStrategy.d.ts +7 -0
- package/dist/types/modules/moduleContext.d.ts +9 -0
- package/dist/types/modules/modulesManager.d.ts +23 -0
- package/dist/types/{modSdk.d.ts → patching.d.ts} +2 -3
- package/dist/types/rpc.d.ts +72 -0
- package/dist/types/settings.d.ts +19 -0
- package/dist/types/settingsDialog.d.ts +4 -0
- package/dist/types/shard-modules/{attributesModule.d.ts → attributes.d.ts} +2 -2
- package/dist/types/shard-modules/{shardModule.d.ts → base.d.ts} +2 -2
- package/dist/types/shard-modules/{centerModule.d.ts → center.d.ts} +2 -1
- package/dist/types/shard-modules/{clickModule.d.ts → click.d.ts} +2 -2
- package/dist/types/shard-modules/{counterUpModule.d.ts → counterUp.d.ts} +2 -2
- package/dist/types/shard-modules/{dynamicClassModule.d.ts → dynamicClass.d.ts} +2 -2
- package/dist/types/shard-modules/index.d.ts +9 -9
- package/dist/types/shard-modules/{multiClickModule.d.ts → multiClick.d.ts} +2 -2
- package/dist/types/shard-modules/{styleModule.d.ts → style.d.ts} +2 -2
- package/dist/types/shard-modules/{typeModule.d.ts → type.d.ts} +2 -2
- package/dist/types/shards/{backNextButtonShard.d.ts → backNextButton.d.ts} +4 -3
- package/dist/types/shards/{shard.d.ts → base.d.ts} +3 -2
- package/dist/types/shards/{buttonShard.d.ts → button.d.ts} +6 -6
- package/dist/types/shards/{cardShard.d.ts → card.d.ts} +3 -3
- package/dist/types/shards/{checkboxShard.d.ts → checkbox.d.ts} +5 -5
- package/dist/types/shards/{containerShard.d.ts → container.d.ts} +2 -2
- package/dist/types/shards/extensionsStorageBar.d.ts +28 -0
- package/dist/types/shards/fileInput.d.ts +10 -0
- package/dist/types/shards/flexContainer.d.ts +14 -0
- package/dist/types/shards/gridContainer.d.ts +18 -0
- package/dist/types/shards/{imageShard.d.ts → image.d.ts} +2 -2
- package/dist/types/shards/index.d.ts +17 -13
- package/dist/types/shards/{inputShard.d.ts → input.d.ts} +3 -3
- package/dist/types/shards/{inputListShard.d.ts → inputList.d.ts} +3 -2
- package/dist/types/shards/{selectShard.d.ts → select.d.ts} +6 -4
- package/dist/types/shards/svg.d.ts +11 -0
- package/dist/types/shards/{tabsShard.d.ts → tabs.d.ts} +3 -6
- package/dist/types/shards/{textShard.d.ts → text.d.ts} +3 -3
- package/dist/types/shared.d.ts +7 -0
- package/dist/types/subscreens/customTranslations.d.ts +10 -0
- package/dist/types/subscreens/languageDetails.d.ts +14 -0
- package/dist/types/subscreens/localization.d.ts +5 -0
- package/dist/types/toast-themes/abdl.d.ts +9 -0
- package/dist/types/toast-themes/anime.d.ts +9 -0
- package/dist/types/toast-themes/base.d.ts +39 -0
- package/dist/types/toast-themes/cyber.d.ts +10 -0
- package/dist/types/toast-themes/default.d.ts +9 -0
- package/dist/types/toastThemesDialog.d.ts +1 -0
- package/dist/types/toasts.d.ts +48 -36
- package/dist/types/ui.d.ts +128 -49
- package/dist/types/validation.d.ts +5 -0
- package/dist/ui.js +414 -79
- package/dist/validation.js +79 -1
- package/dist/wardrobe.js +2 -2
- package/package.json +36 -14
- package/dist/core-subscreen/coreSubscreen.js +0 -81
- package/dist/core-subscreen/developmentSubscreen.js +0 -22
- package/dist/core-subscreen/generalSubscreen.js +0 -23
- package/dist/core-subscreen/mainSubscreen.js +0 -58
- package/dist/core-subscreen/shards/coreButtonShard.js +0 -30
- package/dist/core-subscreen/shards/coreCheckboxShard.js +0 -33
- package/dist/core-subscreen/shards/coreInputListShard.js +0 -38
- package/dist/core-subscreen/shards/coreSelectShard.js +0 -17
- package/dist/core-subscreen/shards/coreTextShard.js +0 -9
- package/dist/core-subscreen/shards/index.js +0 -5
- package/dist/core-subscreen/toastsSubscreen.js +0 -111
- package/dist/core.js +0 -192
- package/dist/shards/backNextButtonShard.js +0 -99
- package/dist/shards/selectShard.js +0 -131
- package/dist/shards/svgShard.js +0 -29
- package/dist/types/core-subscreen/coreSubscreen.d.ts +0 -15
- package/dist/types/core-subscreen/developmentSubscreen.d.ts +0 -5
- package/dist/types/core-subscreen/generalSubscreen.d.ts +0 -5
- package/dist/types/core-subscreen/mainSubscreen.d.ts +0 -6
- package/dist/types/core-subscreen/shards/coreButtonShard.d.ts +0 -5
- package/dist/types/core-subscreen/shards/coreCheckboxShard.d.ts +0 -6
- package/dist/types/core-subscreen/shards/coreInputListShard.d.ts +0 -6
- package/dist/types/core-subscreen/shards/coreSelectShard.d.ts +0 -5
- package/dist/types/core-subscreen/shards/coreTextShard.d.ts +0 -4
- package/dist/types/core-subscreen/shards/index.d.ts +0 -5
- package/dist/types/core-subscreen/toastsSubscreen.d.ts +0 -5
- package/dist/types/core.d.ts +0 -18
- package/dist/types/shards/svgShard.d.ts +0 -12
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hookFunction as registerHookFunction,
|
|
3
|
+
patchFunction as registerPatchFunction
|
|
4
|
+
} from "../patching";
|
|
5
|
+
import { logger } from "../logging";
|
|
6
|
+
class ModuleContext {
|
|
7
|
+
cleanups = /* @__PURE__ */ new Set();
|
|
8
|
+
disposed = false;
|
|
9
|
+
registerCleanup(cleanup) {
|
|
10
|
+
let active = true;
|
|
11
|
+
const dispose = () => {
|
|
12
|
+
if (!active) return;
|
|
13
|
+
active = false;
|
|
14
|
+
this.cleanups.delete(dispose);
|
|
15
|
+
try {
|
|
16
|
+
cleanup();
|
|
17
|
+
} catch (error) {
|
|
18
|
+
logger.error("Failed to remove module hook or patch:", error);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
this.cleanups.add(dispose);
|
|
22
|
+
return dispose;
|
|
23
|
+
}
|
|
24
|
+
hookFunction(functionName, priority, hook) {
|
|
25
|
+
if (this.disposed) {
|
|
26
|
+
throw new Error("ModuleContext has already been disposed");
|
|
27
|
+
}
|
|
28
|
+
const removeHook = registerHookFunction(
|
|
29
|
+
functionName,
|
|
30
|
+
priority,
|
|
31
|
+
hook
|
|
32
|
+
);
|
|
33
|
+
return this.registerCleanup(removeHook);
|
|
34
|
+
}
|
|
35
|
+
patchFunction(functionName, patches) {
|
|
36
|
+
if (this.disposed) {
|
|
37
|
+
throw new Error("ModuleContext has already been disposed");
|
|
38
|
+
}
|
|
39
|
+
const removePatch = registerPatchFunction(
|
|
40
|
+
functionName,
|
|
41
|
+
patches
|
|
42
|
+
);
|
|
43
|
+
return this.registerCleanup(removePatch);
|
|
44
|
+
}
|
|
45
|
+
dispose() {
|
|
46
|
+
if (this.disposed) return;
|
|
47
|
+
this.disposed = true;
|
|
48
|
+
for (const cleanup of [...this.cleanups].reverse()) {
|
|
49
|
+
cleanup();
|
|
50
|
+
}
|
|
51
|
+
this.cleanups.clear();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
ModuleContext
|
|
56
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { logger } from "../logging";
|
|
2
|
+
import { ModuleContext } from "./moduleContext";
|
|
3
|
+
import {
|
|
4
|
+
getLoadingStrategy
|
|
5
|
+
} from "./loadingStrategy";
|
|
6
|
+
import { MOD_DATA } from "../index";
|
|
7
|
+
class ModulesManager {
|
|
8
|
+
modules = /* @__PURE__ */ new Map();
|
|
9
|
+
initialized = /* @__PURE__ */ new Set();
|
|
10
|
+
loaded = /* @__PURE__ */ new Set();
|
|
11
|
+
contexts = /* @__PURE__ */ new Map();
|
|
12
|
+
registerModules() {
|
|
13
|
+
const modules = Object.values(MOD_DATA.modules ?? {}).map((Module) => {
|
|
14
|
+
return new Module();
|
|
15
|
+
});
|
|
16
|
+
for (const module of modules) {
|
|
17
|
+
const name = module.constructor.name;
|
|
18
|
+
if (this.modules.has(name)) {
|
|
19
|
+
logger.error(`Module "${name}" is already registered`);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
this.modules.set(name, module);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
get(name) {
|
|
26
|
+
const module = this.modules.get(name);
|
|
27
|
+
if (module === void 0) return null;
|
|
28
|
+
return Object.freeze(module);
|
|
29
|
+
}
|
|
30
|
+
getAll() {
|
|
31
|
+
return [...this.modules.values().map((m) => Object.freeze(m))];
|
|
32
|
+
}
|
|
33
|
+
getLoaded() {
|
|
34
|
+
return [...this.loaded].map((name) => this.get(name)).filter((module) => module !== null);
|
|
35
|
+
}
|
|
36
|
+
isInitialized(name) {
|
|
37
|
+
return this.initialized.has(name);
|
|
38
|
+
}
|
|
39
|
+
isLoaded(name) {
|
|
40
|
+
return this.loaded.has(name);
|
|
41
|
+
}
|
|
42
|
+
init(name) {
|
|
43
|
+
const module = this.get(name);
|
|
44
|
+
if (!module || !module.enabled || this.initialized.has(name)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
module.onInit();
|
|
49
|
+
this.initialized.add(name);
|
|
50
|
+
return true;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
logger.error(`Module "${name}" failed during "init":`, error);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
load(name) {
|
|
57
|
+
const module = this.get(name);
|
|
58
|
+
if (!module || !module.enabled || this.loaded.has(name)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const strategy = getLoadingStrategy(module.constructor);
|
|
62
|
+
if (strategy === void 0) {
|
|
63
|
+
logger.error(`Module "${name}" does not have a LoadingStrategy decorator`);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (!this.initialized.has(name)) {
|
|
67
|
+
if (!this.init(name)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const context = new ModuleContext();
|
|
72
|
+
try {
|
|
73
|
+
module.onLoad(context);
|
|
74
|
+
this.contexts.set(name, context);
|
|
75
|
+
this.loaded.add(name);
|
|
76
|
+
return true;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
logger.error(`Module "${name}" failed during "load":`, error);
|
|
79
|
+
context.dispose();
|
|
80
|
+
logger.log(`Disposed ${name}'s context`);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
loadByStrategy(strategy) {
|
|
85
|
+
const loaded = [];
|
|
86
|
+
const failed = [];
|
|
87
|
+
for (const [name, module] of this.modules) {
|
|
88
|
+
const moduleStrategy = getLoadingStrategy(module.constructor);
|
|
89
|
+
if (moduleStrategy === void 0) {
|
|
90
|
+
logger.error(`Module "${name}" does not have a LoadingStrategy decorator`);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (moduleStrategy !== strategy) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (this.load(name)) loaded.push(name);
|
|
97
|
+
else failed.push(name);
|
|
98
|
+
}
|
|
99
|
+
logger.log(`Loaded modules during ${strategy} phase (${loaded.length}):`, loaded);
|
|
100
|
+
logger.log(`Failed modules during ${strategy} phase (${failed.length}):`, failed);
|
|
101
|
+
}
|
|
102
|
+
unload(name) {
|
|
103
|
+
const module = this.get(name);
|
|
104
|
+
if (!module || !this.loaded.has(name)) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
let success = true;
|
|
108
|
+
try {
|
|
109
|
+
module.onUnload();
|
|
110
|
+
} catch (error) {
|
|
111
|
+
logger.error(`Module "${name}" failed during "unload":`, error);
|
|
112
|
+
success = false;
|
|
113
|
+
} finally {
|
|
114
|
+
this.contexts.get(name)?.dispose();
|
|
115
|
+
this.contexts.delete(name);
|
|
116
|
+
this.loaded.delete(name);
|
|
117
|
+
}
|
|
118
|
+
return success;
|
|
119
|
+
}
|
|
120
|
+
reload(name) {
|
|
121
|
+
const module = this.modules.get(name);
|
|
122
|
+
if (!module || !module.enabled || !this.loaded.has(name)) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (!this.unload(name)) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
module.onReload();
|
|
130
|
+
} catch (error) {
|
|
131
|
+
logger.error(`Module "${name}" failed during "reload":`, error);
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
return this.load(name);
|
|
135
|
+
}
|
|
136
|
+
safeword(name) {
|
|
137
|
+
if (name !== void 0) {
|
|
138
|
+
const module = this.modules.get(name);
|
|
139
|
+
if (!module || !this.loaded.has(name)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
module.onSafeword();
|
|
144
|
+
} catch (error) {
|
|
145
|
+
logger.error(`Module "${name}" failed during "safeword":`, error);
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
for (const [moduleName, module] of this.modules) {
|
|
150
|
+
if (!this.loaded.has(moduleName)) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
module.onSafeword();
|
|
155
|
+
} catch (error) {
|
|
156
|
+
logger.error(`Module "${moduleName}" failed during "safeword":`, error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
unloadAll() {
|
|
161
|
+
for (const name of [...this.loaded]) {
|
|
162
|
+
this.unload(name);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
reloadAll() {
|
|
166
|
+
for (const name of [...this.loaded]) {
|
|
167
|
+
this.reload(name);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const modulesManager = new ModulesManager();
|
|
172
|
+
export {
|
|
173
|
+
ModulesManager,
|
|
174
|
+
modulesManager
|
|
175
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import bcModSdk from "bondage-club-mod-sdk";
|
|
2
1
|
import { MOD_DATA } from "./index";
|
|
3
2
|
import { logger } from "./logging";
|
|
3
|
+
import { modulesManager } from "./modules";
|
|
4
|
+
import { getSettings } from "./settings";
|
|
5
|
+
import { keydownManager } from "./ui";
|
|
4
6
|
var HookPriority = /* @__PURE__ */ ((HookPriority2) => {
|
|
5
7
|
HookPriority2[HookPriority2["OBSERVE"] = 0] = "OBSERVE";
|
|
6
8
|
HookPriority2[HookPriority2["ADD_BEHAVIOR"] = 1] = "ADD_BEHAVIOR";
|
|
@@ -10,13 +12,32 @@ var HookPriority = /* @__PURE__ */ ((HookPriority2) => {
|
|
|
10
12
|
return HookPriority2;
|
|
11
13
|
})(HookPriority || {});
|
|
12
14
|
let modSdk;
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
function initModSdk() {
|
|
16
|
+
const coreSettings = getSettings();
|
|
17
|
+
try {
|
|
18
|
+
modSdk = bcModSdk.registerMod(
|
|
19
|
+
{
|
|
20
|
+
name: MOD_DATA.name,
|
|
21
|
+
fullName: MOD_DATA.fullName,
|
|
22
|
+
version: MOD_DATA.version,
|
|
23
|
+
repository: MOD_DATA.repository
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
allowReplace: coreSettings.allowReplaceModSdk ?? false
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
hookFunction("GameKeyDown", 1 /* ADD_BEHAVIOR */, (args, next) => {
|
|
30
|
+
if (keydownManager.handleKeydown(args[0].key)) return true;
|
|
31
|
+
return next(args);
|
|
32
|
+
});
|
|
33
|
+
hookFunction("ChatRoomSafewordRevert", 0 /* OBSERVE */, (args, next) => {
|
|
34
|
+
modulesManager.safeword();
|
|
35
|
+
return next(args);
|
|
36
|
+
});
|
|
37
|
+
logger.log(`Initialized mod sdk. allowReplace: ${coreSettings.allowReplaceModSdk ?? false}`);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
logger.error("Failed to initialize mod sdk:", e);
|
|
40
|
+
}
|
|
20
41
|
}
|
|
21
42
|
function hookFunction(functionName, priority, hook) {
|
|
22
43
|
if (!modSdk) throw new Error("zois-core is not registered");
|
|
@@ -32,8 +53,11 @@ function patchFunction(functionName, patches) {
|
|
|
32
53
|
if (!modSdk) throw new Error("zois-core is not registered");
|
|
33
54
|
try {
|
|
34
55
|
modSdk.patchFunction(functionName, patches);
|
|
56
|
+
return () => removePatches(functionName);
|
|
35
57
|
} catch (e) {
|
|
36
58
|
logger.error(e);
|
|
59
|
+
return () => {
|
|
60
|
+
};
|
|
37
61
|
}
|
|
38
62
|
}
|
|
39
63
|
function callOriginal(target, args) {
|
|
@@ -62,11 +86,11 @@ function removePatches(functionName) {
|
|
|
62
86
|
export {
|
|
63
87
|
HookPriority,
|
|
64
88
|
callOriginal,
|
|
65
|
-
createModSdk,
|
|
66
89
|
findModByName,
|
|
67
90
|
getLoadedMods,
|
|
68
91
|
getOriginalHash,
|
|
69
92
|
hookFunction,
|
|
93
|
+
initModSdk,
|
|
70
94
|
modSdk,
|
|
71
95
|
patchFunction,
|
|
72
96
|
removePatches
|
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { MOD_DATA } from ".";
|
|
2
|
+
import { logger } from "./logging";
|
|
3
|
+
import { modulesManager } from "./modules";
|
|
4
|
+
const createdBuses = /* @__PURE__ */ new Map();
|
|
5
|
+
function parseRPCAddress(address) {
|
|
6
|
+
const separator = address.indexOf(":");
|
|
7
|
+
if (separator <= 0 || separator === address.length - 1 || address.indexOf(":", separator + 1) !== -1) {
|
|
8
|
+
throw new Error(`Invalid RPC address "${address}"`);
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
addonKey: address.slice(0, separator),
|
|
12
|
+
functionName: address.slice(separator + 1)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
class RPCBus {
|
|
16
|
+
#id;
|
|
17
|
+
endpoints = /* @__PURE__ */ new Map();
|
|
18
|
+
/**
|
|
19
|
+
* Returns the unique identifier of this RPC bus.
|
|
20
|
+
*/
|
|
21
|
+
get id() {
|
|
22
|
+
return this.#id;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates an RPC bus instance.
|
|
26
|
+
*
|
|
27
|
+
* @param id - Unique addon identifier.
|
|
28
|
+
*/
|
|
29
|
+
constructor(id) {
|
|
30
|
+
this.#id = id;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Registers a remote function that can be called by other addons.
|
|
34
|
+
*
|
|
35
|
+
* The function name and its payload and result types must be
|
|
36
|
+
* declared in RPCFunctionMap.
|
|
37
|
+
*
|
|
38
|
+
* @param name - Name of the remote function.
|
|
39
|
+
* @param handler - Function executed when a remote call is received.
|
|
40
|
+
* @returns A function that unregisters the remote function.
|
|
41
|
+
* @throws {Error} If the function name is invalid or already registered.
|
|
42
|
+
*/
|
|
43
|
+
expose(name, handler) {
|
|
44
|
+
const functionName = name;
|
|
45
|
+
if (!functionName.trim() || functionName.includes(":")) {
|
|
46
|
+
throw new Error(`Invalid RPC function name "${functionName}"`);
|
|
47
|
+
}
|
|
48
|
+
if (this.endpoints.has(functionName)) {
|
|
49
|
+
throw new Error(`RPC function "${functionName}" is already registered`);
|
|
50
|
+
}
|
|
51
|
+
const registeredHandler = (payload, sender) => {
|
|
52
|
+
return handler(payload, sender);
|
|
53
|
+
};
|
|
54
|
+
this.endpoints.set(functionName, registeredHandler);
|
|
55
|
+
return () => {
|
|
56
|
+
if (this.endpoints.get(functionName) === registeredHandler) {
|
|
57
|
+
this.endpoints.delete(functionName);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Calls a remote function registered by another addon.
|
|
63
|
+
*
|
|
64
|
+
* The address must follow the "addon_key:functionName" format.
|
|
65
|
+
* Payload and result types are inferred from RPCFunctionMap.
|
|
66
|
+
*
|
|
67
|
+
* @param address - Addon identifier and function name.
|
|
68
|
+
* @param args - Function payload and optional timeout in milliseconds.
|
|
69
|
+
* @returns A promise containing the remote function result.
|
|
70
|
+
* @throws {Error} If the address is invalid, the addon or function
|
|
71
|
+
* cannot be found, or the call times out.
|
|
72
|
+
*/
|
|
73
|
+
async call(address, ...args) {
|
|
74
|
+
const { addonKey, functionName } = parseRPCAddress(address);
|
|
75
|
+
const [payload, timeoutMs = 1e4] = args;
|
|
76
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
77
|
+
throw new Error("Timeout must be greater than zero");
|
|
78
|
+
}
|
|
79
|
+
const targetBus = createdBuses.get(addonKey);
|
|
80
|
+
if (!targetBus) {
|
|
81
|
+
throw new Error(`RPCBus "${addonKey}" not found`);
|
|
82
|
+
}
|
|
83
|
+
const handler = targetBus.endpoints.get(functionName);
|
|
84
|
+
if (!handler) {
|
|
85
|
+
throw new Error(`RPC function "${address}" not found`);
|
|
86
|
+
}
|
|
87
|
+
let timeout;
|
|
88
|
+
try {
|
|
89
|
+
const execution = Promise.resolve().then(() => {
|
|
90
|
+
return handler(payload, this.id);
|
|
91
|
+
});
|
|
92
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
93
|
+
timeout = setTimeout(() => {
|
|
94
|
+
reject(new Error(`RPC call "${address}" timed out`));
|
|
95
|
+
}, timeoutMs);
|
|
96
|
+
});
|
|
97
|
+
return await Promise.race([
|
|
98
|
+
execution,
|
|
99
|
+
timeoutPromise
|
|
100
|
+
]);
|
|
101
|
+
} finally {
|
|
102
|
+
if (timeout !== void 0) {
|
|
103
|
+
clearTimeout(timeout);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function getRPCBus(id) {
|
|
109
|
+
if (typeof id !== "string" || id.trim() === "") {
|
|
110
|
+
throw new Error("id must be a non-empty string");
|
|
111
|
+
}
|
|
112
|
+
if (id.includes(":")) {
|
|
113
|
+
throw new Error('id must not contain ":"');
|
|
114
|
+
}
|
|
115
|
+
if (createdBuses.has(id)) {
|
|
116
|
+
throw new Error(`RPCBus with id "${id}" already exists`);
|
|
117
|
+
}
|
|
118
|
+
const bus = new RPCBus(id);
|
|
119
|
+
createdBuses.set(id, bus);
|
|
120
|
+
return bus;
|
|
121
|
+
}
|
|
122
|
+
let rpcBus = null;
|
|
123
|
+
function initRPCBus() {
|
|
124
|
+
try {
|
|
125
|
+
rpcBus = window.ZOIS_CORE.getRPCBus(MOD_DATA.name);
|
|
126
|
+
rpcBus?.expose("getModule", (payload) => {
|
|
127
|
+
return modulesManager.get(payload);
|
|
128
|
+
});
|
|
129
|
+
logger.log("Initialized RPCBus");
|
|
130
|
+
} catch (e) {
|
|
131
|
+
logger.error("Failed to initialize RPCBus:", e);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
RPCBus,
|
|
136
|
+
getRPCBus,
|
|
137
|
+
initRPCBus,
|
|
138
|
+
rpcBus
|
|
139
|
+
};
|