bc-deeplib 1.1.3 → 1.2.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/lib/build.js CHANGED
@@ -70,6 +70,19 @@ async function buildMod({
70
70
  host,
71
71
  port
72
72
  }) {
73
+ if (process.argv.includes('--help') || process.argv.includes('-h')) {
74
+ console.log(`
75
+ Usage: deeplib [options]
76
+
77
+ Options:
78
+ --help, -h Show this help message
79
+ --watch, -w Watch for changes and rebuild
80
+ --serve, -s Serve mod on http://${host}:${port}
81
+ --lib-local, -l Use local build of deeplib
82
+ --debug, -d Enable debug mode
83
+ `.replaceAll('\t', ''));
84
+ return;
85
+ }
73
86
  const cliLocal = !process.env.environment;
74
87
  const cliWatch = process.argv.includes('--watch') || process.argv.includes('-w');
75
88
  const cliServe = process.argv.includes('--serve') || process.argv.includes('-s');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bc-deeplib",
3
- "version": "1.1.3",
3
+ "version": "1.2.0",
4
4
  "author": "dDeepLb",
5
5
  "description": "Library for easier development of BC mods, which strives to be a framework :D",
6
6
  "license": "MIT",
@@ -1,184 +0,0 @@
1
- /**
2
- * A type signifying any unknown function.
3
- * @public
4
- */
5
- declare type AnyFunction = (...args: any) => any;
6
-
7
- /** @public */
8
- declare const bcModSdk: ModSDKGlobalAPI;
9
-
10
- /**
11
- * @public
12
- * A helper to resolve dotted property path to the target type
13
- * @example
14
- * typeof window["a"]["b"]["c"] === GetDotedPathType\<typeof window, "a.b.c"\>
15
- */
16
- declare type GetDotedPathType<Base, DotedKey extends string> = DotedKey extends `${infer Key1}.${infer Key2}`
17
- ? GetDotedPathType<GetDotedPathType<Base, Key1>, Key2>
18
- : DotedKey extends keyof Base
19
- ? Base[DotedKey]
20
- : never;
21
-
22
- /**
23
- * The global API of the SDK
24
- *
25
- * Accessible using the exported value or as `window.bcModSdk`
26
- * @public
27
- */
28
- declare interface ModSDKGlobalAPI {
29
- /** The version of the SDK itself. Attempting to load two different SDK versions will warn, but work as long as `apiVersion` is same. */
30
- readonly version: string;
31
- /** The API version of the SDK itself. Attempting to load two different SDK versions will fail. */
32
- readonly apiVersion: number;
33
- /**
34
- * Register a mod, receiving access to the mod API
35
- * @param info - Info about the mod, necessary to register the mod
36
- * @param options - [OPTIONAL] Options the mod can specify for ModSDK
37
- * @returns The API usable by mod. @see ModSDKModAPI
38
- * @see ModSDKModInfo
39
- */
40
- registerMod(info: ModSDKModInfo, options?: ModSDKModOptions): ModSDKModAPI;
41
- /** Get info about all registered mods */
42
- getModsInfo(): ModSDKModInfo[];
43
- /** Get info about all modified functions */
44
- getPatchingInfo(): Map<string, PatchedFunctionInfo>;
45
- /** Internal API, please **DO NOT USE** */
46
- readonly errorReporterHooks: {
47
- apiEndpointEnter: ((fn: string, mod: string) => () => void) | null;
48
- hookEnter: ((fn: string, mod: string) => () => void) | null;
49
- hookChainExit: ((fn: string, patchMods: ReadonlySet<string>) => () => void) | null;
50
- };
51
- }
52
-
53
- /** @public */
54
- declare interface ModSDKModAPI {
55
- /** Unload this mod, removing any hooks or patches by it. To continue using SDK another call to `registerMod` is required */
56
- unload(): void;
57
- /**
58
- * Hook a BC function
59
- * @template TFunctionName - The name of the hooked function, _e.g._ `"Player.CanChange"`
60
- * @param functionName - Name of function to hook. Can contain dots to change methods in objects (e.g. `Player.CanChange`)
61
- * @param priority - Number used to determinate order hooks will be called in. Higher number is called first
62
- * @param hook - The hook itself to use, @see PatchHook
63
- * @returns Function that can be called to remove this hook
64
- */
65
- hookFunction<TFunctionName extends string>(
66
- functionName: TFunctionName,
67
- priority: number,
68
- hook: PatchHook<GetDotedPathType<typeof globalThis, TFunctionName>>
69
- ): () => void;
70
- /**
71
- * Call original function, bypassing any hooks and ignoring any patches applied by ALL mods.
72
- * @template TFunctionName - The name of the called function, _e.g._ `"Player.CanChange"`
73
- * @param functionName - Name of function to call. Can contain dots to change methods in objects (e.g. `Player.CanChange`)
74
- * @param args - Arguments to use for the call
75
- * @param context - `this` context to use. Defaults to `window`. If calling method of object, then set this to the object itself (e.g. `functionName` = `Player.CanChange` then `context` = `Player`)
76
- */
77
- callOriginal<TFunctionName extends string>(
78
- functionName: TFunctionName,
79
- args: [...Parameters<GetDotedPathType<typeof globalThis, TFunctionName>>],
80
- context?: any
81
- ): ReturnType<GetDotedPathType<typeof globalThis, TFunctionName>>;
82
- /**
83
- * Patch a BC function
84
- *
85
- * **This method is DANGEROUS** to use and has high potential to conflict with other mods.
86
- *
87
- * Only use it if what you are trying to accomplish can't be done easily with `hookFunction`.
88
- *
89
- * This function tranforms BC function to string, replaces patches as pure text and then `eval`uates it.
90
- * If you don't know what this means, please avoid this function.
91
- * @template TFunctionName - The name of the patched function, _e.g._ `"Player.CanChange"`
92
- * @param functionName - Name of function to patch. Can contain dots to change methods in objects (e.g. `Player.CanChange`)
93
- * @param patches - Object in key: value format, where keys are chunks to replace and values are result.
94
- *
95
- * Patches from multiple calls are merged; where key matches the older one is replaced.
96
- * Specifying value of `null` removes patch with this key.
97
- */
98
- patchFunction<TFunctionName extends string>(
99
- functionName: TFunctionName,
100
- patches: GetDotedPathType<typeof globalThis, TFunctionName> extends AnyFunction ? Record<string, string | null> : never
101
- ): void;
102
- /**
103
- * Remove all patches by `patchFunction` from specified function.
104
- * @param functionName - Name of function to patch. Can contain dots to change methods in objects (e.g. `Player.CanChange`)
105
- */
106
- removePatches(functionName: string): void;
107
- /**
108
- * Get hash of original function in CRC32.
109
- *
110
- * The hash is computed from source obtained using `toString` with line endings normalized to LF
111
- * @param functionName - Name of function. Can contain dots to change methods in objects (e.g. `Player.CanChange`)
112
- */
113
- getOriginalHash(functionName: string): string;
114
- }
115
-
116
- /**
117
- * Info about a mod registered within the Mod SDK
118
- * @public
119
- */
120
- declare interface ModSDKModInfo {
121
- /** Short name or abbreviation of the mod */
122
- name: string;
123
- /** Full name of the mod */
124
- fullName: string;
125
- /** Version or other metadata for the mod, visible by other mods */
126
- version: string;
127
- /** Link to public repository with source code for this mod */
128
- repository?: string;
129
- }
130
-
131
- /**
132
- * Additional options mods can optionally give when registering
133
- * @public
134
- */
135
- declare interface ModSDKModOptions {
136
- /**
137
- * [OPTIONAL]
138
- *
139
- * If `true` subsequent calls to `registerMod` will unload old one, replacing it.
140
- *
141
- * If `false` any attempt to register a new mod with same name will fail.
142
- * @default false
143
- */
144
- allowReplace?: boolean;
145
- }
146
-
147
- /**
148
- * Info about a function modified using the API
149
- * @public
150
- */
151
- declare interface PatchedFunctionInfo {
152
- name: string;
153
- /** The original function */
154
- original?: (...args: any[]) => any;
155
- /** CRC32 has of the original function */
156
- originalHash: string;
157
- /** SDK-generated entrypoint that the global function was replaced with */
158
- sdkEntrypoint?: (...args: any[]) => any;
159
- /**
160
- * Entrypoint that SDK collected at the time of calling of the `getPatchingInfo` method.
161
- *
162
- * If the function wasn't overwritten, it should equal `sdkEntrypoint`
163
- */
164
- currentEntrypoint?: (...args: any[]) => any;
165
- /** List of names of mods that hooked this function */
166
- hookedByMods: string[];
167
- /** List of names of mods that patched this function */
168
- patchedByMods: string[];
169
- }
170
-
171
- /**
172
- * This is how hook from mod looks like.
173
- *
174
- * As first argument it receives all arguments the original function received.
175
- *
176
- * As second argument special `next` function that should be used to call original function (or next function in the hook chain).
177
- *
178
- * The return value is then used as return value instead of original one.
179
- * @public
180
- */
181
- declare type PatchHook<TFunction extends AnyFunction = AnyFunction> = (
182
- args: [...Parameters<TFunction>],
183
- next: (args: [...Parameters<TFunction>]) => ReturnType<TFunction>
184
- ) => ReturnType<TFunction>;
@@ -1,4 +0,0 @@
1
- declare const PUBLIC_URL: string;
2
- declare const MOD_VERSION: string;
3
- declare const VERSION_HASH: string;
4
- declare const IS_DEVEL: boolean;