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
6 changes: 6 additions & 0 deletions types/gimloader/gimloader-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ api.UI.showModal(document.createElement("div"), {

api.requestReload();
GL.net.gamemode; // $ExpectType string
api.UI.forceReactUpdate();
api.net.gamemode; // $ExpectType string
api.net.onLoad((type, gamemode) => {});
api.net.modifyFetchRequest("/path/*/thing", (options) => null);
Expand All @@ -87,6 +88,11 @@ api.patcher.after(object, "b", (thisVal, args, returnVal) => {
});
// @ts-expect-error
api.patcher.after(object, "a", () => {});
api.patcher.swap(object, "b", function(arg1, args2) {
arg1; // $ExpectType number
args2; // $ExpectType string
return false;
});

// Test commands
api.commands.addCommand({
Expand Down
26 changes: 25 additions & 1 deletion types/gimloader/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,7 @@ declare global {
immediate?: boolean,
): () => void;
onChange(callback: () => void): () => void;
onRemove(callback: () => void): () => void;
};
type CollectionSchema<T, K> = ColyseusMethods & {
onAdd(callback: (value: T, index: K) => void, immediate?: boolean): () => void;
Expand Down Expand Up @@ -2874,6 +2875,8 @@ declare global {
class BaseUIApi {
/** Shows a customizable modal to the user */
showModal(element: HTMLElement | React$1.ReactElement, options?: ModalOptions): void;
/** Forces Gimkit's react tree to fully rerender */
forceReactUpdate(): void;
/**
* Gimkit's notification object, only available when joining or playing a game
*
Expand Down Expand Up @@ -2960,6 +2963,8 @@ declare global {
) => boolean | void;

type PatcherInsteadCallback<T> = (thisVal: any, args: T extends BaseFunction ? Parameters<T> : any[]) => any;

type PatcherSwapCallback<T> = (...args: T extends BaseFunction ? Parameters<T> : any[]) => any;
class PatcherApi {
/**
* Runs a callback after a function on an object has been run
Expand Down Expand Up @@ -2992,6 +2997,16 @@ declare global {
method: K,
callback: PatcherInsteadCallback<O[K]>,
): () => void;
/**
* Replaces a function on an object with another function
* @returns A function to remove the patch
*/
swap<O extends object, K extends FunctionKeys<O>>(
id: string,
object: O,
method: K,
callback: PatcherSwapCallback<O[K]>,
): () => void;
/** Removes all patches with a given id */
unpatchAll(id: string): void;
}
Expand Down Expand Up @@ -3025,10 +3040,19 @@ declare global {
method: K,
callback: PatcherInsteadCallback<O[K]>,
): () => void;
/**
* Replaces a function on an object with another function
* @returns A function to remove the patch
*/
swap<O extends object, K extends FunctionKeys<O>>(
object: O,
method: K,
callback: PatcherSwapCallback<O[K]>,
): () => void;
}

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

interface Exposer {
check?: string;
Expand Down
2 changes: 1 addition & 1 deletion types/gimloader/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/gimloader",
"version": "1.11.9999",
"version": "1.12.9999",
"nonNpm": "conflict",
"nonNpmDescription": "Types for the Gimloader global variables",
"projects": [
Expand Down