Skip to content

Commit

Permalink
Add instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Davilarek committed Jul 23, 2024
1 parent e3ebef5 commit 9b992da
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api/Patcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class DummyPatcherApi implements IBasePatcherApi {
before<T, A = unknown[]>(target: T, name: string, cb: (args: A, instance: T) => A): () => void {
throw new Error("Method not implemented. This is a dummy class.");
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
instead<T, A extends unknown[] = unknown[], R = unknown>(target: T, name: string, cb: (args: A, orig: ((...args_: A) => R), instance: T) => R): () => void {
throw new Error("Method not implemented. This is a dummy class.");
}
}

export const PatcherApi = DummyPatcherApi;
14 changes: 14 additions & 0 deletions src/common/PatcherApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const implementationStore = {
get before() {
return __requireInternal(targetMod, "PatcherApi", "after")?.bind(undefined, this);
},
get instead() {
return __requireInternal(targetMod, "PatcherApi", "instead")?.bind(undefined, this);
},
};
},
}),
Expand Down Expand Up @@ -56,6 +59,17 @@ const implementationStore = {
});
},
}),
insteadWrapper: new FunctionImplementation({
data: null,
depends: [],
supplies: "instead",
isWrapper: true,
func<T, A extends unknown[] = unknown[], R = unknown>(thisObj: IBasePatcherApi, target: T, name: string, cb: (args: A, orig: ((...args_: A) => R), instance: T) => A): () => void {
return __requireInternal(targetMod, "PatcherApi", "instead", true)!(thisObj.internalId, target, name, (instance_: T, args_: A, orig: ((...args__: A) => R)) => {
return cb(args_, orig, instance_);
});
},
}),
} as { [key: string]: FunctionImplementation };
export {
implementationStore,
Expand Down
3 changes: 3 additions & 0 deletions src/converters/betterdiscord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class BDPatcherApi implements IBasePatcherApi {
get before() {
return createFunctionWithWrapperNeeded("BdApi.Patcher", "before", "beforeWrapper");
}
get instead() {
return createFunctionWithWrapperNeeded("BdApi.Patcher", "instead", "insteadWrapper");
}
}

export function convertFormat(ast: Statement[]) {
Expand Down
3 changes: 3 additions & 0 deletions src/converters/replugged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class RPPatcherApi implements IBasePatcherApi {
get before() {
return createFunctionFromObjectProperty("replugged.Injector.constructor", "beforeWrapper");
}
get instead() {
return createFunctionFromObjectProperty("replugged.Injector.constructor", "insteadWrapper");
}
}

export function convertFormat(ast: Statement[]) {
Expand Down

0 comments on commit 9b992da

Please sign in to comment.