Skip to content
Merged
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions types/gimloader/gimloader-tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
interface TestPlugin {
one: number;
}

interface TestLib {
two: string;
}

declare namespace Gimloader {
interface Plugins {
testPlugin: TestPlugin;
}

interface Libraries {
testLib: TestLib;
}
}

GL; // $ExpectType typeof Api
api; // $ExpectType Api

Expand Down Expand Up @@ -25,6 +43,10 @@ GL.rewriter; // $ExpectType Readonly<RewriterApi>
GL.storage; // $ExpectType Readonly<StorageApi>
GL.commands; // $ExpectType Readonly<CommandsApi>

api.plugin("testPlugin").one; // $ExpectType number
api.lib("testLib").two; // $ExpectType string
api.plugin("somethingElse"); // $ExpectType any

// @ts-expect-error
GL.onStop;
// @ts-expect-error
Expand All @@ -49,6 +71,13 @@ api.net.onLoad((type, gamemode) => {});
api.net.modifyFetchRequest("/path/*/thing", (options) => null);
api.net.modifyFetchRequest("/path/*/thing", (options) => options);
api.net.modifyFetchResponse("/path/*/thing", (response) => response);
api.rewriter.runInScope("App", (code, evalCode) => evalCode("something"));
api.rewriter.exposeVar("App", {
check: "someString",
find: /,(.+)=>{/,
callback: (theVar) => {},
multiple: false,
});

api.commands.addCommand({
text: "test",
Expand Down
52 changes: 43 additions & 9 deletions types/gimloader/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2305,7 +2305,7 @@ declare global {
/** Gets the headers of a plugin, such as version, author, and description */
getHeaders(name: string): ScriptHeaders;
/** Gets the exported values of a plugin, if it has been enabled */
get(name: string): any;
get<T extends keyof Gimloader.Plugins>(name: T): Gimloader.Plugins[T];
/**
* @deprecated Use {@link get} instead
* @hidden
Expand Down Expand Up @@ -2342,7 +2342,7 @@ declare global {
/** Gets the headers of a library, such as version, author, and description */
getHeaders(name: string): ScriptHeaders;
/** Gets the exported values of a library */
get(name: string): any;
get<T extends keyof Gimloader.Libraries>(name: T): Gimloader.Libraries[T];
}

class ScopedCommandsApi {
Expand Down Expand Up @@ -2415,6 +2415,23 @@ declare global {
createShared(id: string, value: any): string;
/** Removes the shared value with a certain id created by {@link createShared} */
removeSharedById(id: string): void;
/**
* Runs code in the scope of modules when they are loaded, or when runInScope is called with them already loaded.
* Returning true from the callback will remove the hook.
*/
runInScope(prefix: string | boolean, callback: RunInScopeCallback): () => void;
/** A utility function that exposes a variable based on regex to get its name. */
exposeVar(prefix: string | boolean, exposer: Exposer): () => void;
}

// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
type RunInScopeCallback = (code: string, run: (evalCode: string) => void) => true | void;

interface Exposer {
check?: string;
find: RegExp;
callback: (val: any) => void;
multiple?: boolean;
}

class RewriterApi {
Expand All @@ -2425,10 +2442,10 @@ declare global {
* @param pluginName The name of the plugin creating the hook.
* @param prefix Limits the hook to only running on scripts beginning with this prefix.
* Passing `true` will only run on the index script, and passing `false` will run on all scripts.
* @param callback The function that will modify the code. Should return the modified code. Cannot have side effects.
* @param callback A function that will modify the code, which should return the modified code.
*/
addParseHook(pluginName: string, prefix: string | boolean, callback: (code: string) => string): () => void;
/** Removes all hooks created by a certain plugin */
addParseHook(pluginName: string, prefix: string | boolean, modifier: (code: string) => string): () => void;
/** Removes all parse hooks created by a certain plugin */
removeParseHooks(pluginName: string): void;
/**
* Creates a shared value that can be accessed from any script.
Expand All @@ -2442,6 +2459,15 @@ declare global {
removeShared(pluginName: string): void;
/** Removes the shared value with a certain id created by {@link createShared} */
removeSharedById(pluginName: string, id: string): void;
/**
* Runs code in the scope of modules when they are loaded, or when runInScope is called with them already loaded.
* Returning true from the callback will remove the hook.
*/
runInScope(pluginName: string, prefix: string | boolean, callback: RunInScopeCallback): () => void;
/** Stops all hooks created by {@link runInScope} */
removeRunInScope(pluginName: string): void;
/** A utility function that exposes a variable based on regex to get its name. */
exposeVar(pluginName: string, prefix: string | boolean, exposer: Exposer): () => void;
}

class ScopedPatcherApi {
Expand Down Expand Up @@ -2836,11 +2862,11 @@ declare global {
/** Methods for getting info on libraries */
static libs: Readonly<LibsApi>;
/** Gets the exported values of a library */
static lib: (name: string) => any;
static lib: <T extends keyof Gimloader.Libraries>(name: T) => Gimloader.Libraries[T];
/** Methods for getting info on plugins */
static plugins: Readonly<PluginsApi>;
/** Gets the exported values of a plugin, if it has been enabled */
static plugin: (name: string) => any;
static plugin: <T extends keyof Gimloader.Plugins>(name: T) => Gimloader.Plugins[T];
/** Gimkit's internal react instance */
static get React(): typeof import("react");
/** Gimkit's internal reactDom instance */
Expand Down Expand Up @@ -2909,11 +2935,11 @@ declare global {
/** Methods for getting info on libraries */
libs: Readonly<LibsApi>;
/** Gets the exported values of a library */
lib: (name: string) => any;
lib: <T extends keyof Gimloader.Libraries>(name: T) => Gimloader.Libraries[T];
/** Methods for getting info on plugins */
plugins: Readonly<PluginsApi>;
/** Gets the exported values of a plugin, if it has been enabled */
plugin: (name: string) => any;
plugin: <T extends keyof Gimloader.Plugins>(name: T) => Gimloader.Plugins[T];
/** Gimkit's internal react instance */
get React(): typeof import("react");
/** Gimkit's internal reactDom instance */
Expand All @@ -2935,6 +2961,14 @@ declare global {
*/
openSettingsMenu: (callback: () => void) => void;
}

interface Plugins {
[name: string]: any;
}

interface Libraries {
[name: string]: any;
}
}
const api: Gimloader.Api;
const GL: typeof Gimloader.Api;
Expand Down
Loading