This repository was archived by the owner on Feb 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Add Patcher API #11
Open
Davilarek
wants to merge
11
commits into
main
Choose a base branch
from
feat-patcher
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Patcher API #11
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ae5fb8b
Start adding Patcher API
Davilarek 57d630f
Add basic patcher api
Davilarek a251540
Improve description of `internalId`
Davilarek 52d4283
Use `for ... of ...` instead of for index
Davilarek 75f11cd
Remove most of debug code
Davilarek c53d194
Make `removeASTLocation` take `Standardized`
Davilarek 908865a
Fix build
Davilarek 16401a0
Use `ImportDeclaration` instead of `Standardized` in `importStatements`
Davilarek e3ebef5
Add `before`
Davilarek 9b992da
Add `instead`
Davilarek 7136f09
Remove redundant `continue`
Davilarek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| { | ||
| "cSpell.words": [ | ||
| "replugged" | ||
| "replugged", | ||
| "unpatch" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| export interface IBasePatcherApi { | ||
| internalId: string | undefined; /* NOT ON REPLUGGED, on BD it's the "caller" for Patcher functions */ | ||
| unpatchAll(): void; | ||
| after<T, A = unknown[], R = unknown>(target: T, name: string, cb: (args: A, res: R, instance: T) => R): () => void; | ||
| } | ||
|
|
||
| class DummyPatcherApi implements IBasePatcherApi { | ||
| internalId: string | undefined; | ||
| unpatchAll(): void { | ||
| throw new Error("Method not implemented. This is a dummy class."); | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| after<T, A = unknown[], R = unknown>(target: T, name: string, cb: (args: A, res: R, instance: T) => R): () => void { | ||
| throw new Error("Method not implemented. This is a dummy class."); | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| 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; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { FunctionImplementation, __requireInternal } from "./index.js"; | ||
| import { IModImplementation } from "../api/ModImplementation.js"; | ||
| import { IBasePatcherApi } from "../api/Patcher.js"; | ||
| export let targetMod: IModImplementation; | ||
|
|
||
| const implementationStore = { | ||
| Patcher_constructor: new FunctionImplementation({ | ||
| data: null, | ||
| depends: [], | ||
| supplies: "constructor_", | ||
| isWrapper: true, | ||
| asImmediatelyInvokedFunctionExpression: true, | ||
| func() { | ||
| return { | ||
| internalId: Date.now().toString(), | ||
| get after() { | ||
| return __requireInternal(targetMod, "PatcherApi", "after")?.bind(undefined, this); | ||
| }, | ||
| get unpatchAll() { | ||
| return __requireInternal(targetMod, "PatcherApi", "unpatchAll")?.bind(undefined, this); | ||
| }, | ||
| get before() { | ||
| return __requireInternal(targetMod, "PatcherApi", "after")?.bind(undefined, this); | ||
| }, | ||
| get instead() { | ||
| return __requireInternal(targetMod, "PatcherApi", "instead")?.bind(undefined, this); | ||
| }, | ||
| }; | ||
| }, | ||
| }), | ||
| afterWrapper: new FunctionImplementation({ | ||
| data: null, | ||
| depends: [], | ||
| supplies: "after", | ||
| isWrapper: true, | ||
| func<T, A = unknown[], R = unknown>(thisObj: IBasePatcherApi, target: T, name: string, cb: (args: A, res: R, instance: T) => R): () => void { | ||
| return __requireInternal(targetMod, "PatcherApi", "after", true)!(thisObj.internalId, target, name, (instance_: T, args_: A, res_: R) => { | ||
| return cb(args_, res_, instance_); | ||
| }); | ||
| }, | ||
| }), | ||
| unpatchAllWrapper: new FunctionImplementation({ | ||
| data: null, | ||
| depends: [], | ||
| supplies: "unpatchAll", | ||
| isWrapper: true, | ||
| func(thisObj: IBasePatcherApi) { | ||
| return __requireInternal(targetMod, "PatcherApi", "unpatchAll", true)!(thisObj.internalId); | ||
| }, | ||
| }), | ||
| beforeWrapper: new FunctionImplementation({ | ||
| data: null, | ||
| depends: [], | ||
| supplies: "before", | ||
| isWrapper: true, | ||
| func<T, A = unknown[]>(thisObj: IBasePatcherApi, target: T, name: string, cb: (args: A, instance: T) => A): () => void { // in replugged callback needs to return arguments. what happens in BD? | ||
| return __requireInternal(targetMod, "PatcherApi", "before", true)!(thisObj.internalId, target, name, (instance_: T, args_: A) => { | ||
| return cb(args_, instance_); | ||
| }); | ||
| }, | ||
| }), | ||
| 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, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,40 @@ | ||
| import { Statement } from "@babel/types"; | ||
| import { IModImplementation } from "../api/ModImplementation.js"; | ||
| import { createFunctionFromObjectProperty } from "../api/RuntimeGenerators.js"; | ||
| import { createFunctionFromObjectProperty, createFunctionWithWrapperNeeded } from "../api/RuntimeGenerators.js"; | ||
| import { IBaseWebpackApi } from "../api/Webpack.js"; | ||
| import { IBasePatcherApi } from "../api/Patcher.js"; | ||
|
|
||
| class BDWebpackApi implements IBaseWebpackApi { | ||
| get getModule() { | ||
| return createFunctionFromObjectProperty("BdApi.Webpack", "getModule"); | ||
| } | ||
| } | ||
|
|
||
| class BDPatcherApi implements IBasePatcherApi { | ||
| get constructor_() { | ||
| return createFunctionWithWrapperNeeded("undefined", "undefined", "Patcher_constructor") as any; | ||
| } | ||
| internalId!: string; | ||
| get unpatchAll() { | ||
| return createFunctionWithWrapperNeeded("BdApi.Patcher", "unpatchAll", "unpatchAllWrapper"); | ||
| } | ||
| get after() { | ||
| return createFunctionWithWrapperNeeded("BdApi.Patcher", "after", "afterWrapper"); | ||
| } | ||
| get before() { | ||
| return createFunctionWithWrapperNeeded("BdApi.Patcher", "before", "beforeWrapper"); | ||
| } | ||
| get instead() { | ||
| return createFunctionWithWrapperNeeded("BdApi.Patcher", "instead", "insteadWrapper"); | ||
| } | ||
| } | ||
|
|
||
| export function convertFormat(ast: Statement[]) { | ||
| return ast; | ||
| } | ||
|
|
||
| export default { | ||
| WebpackApi: new BDWebpackApi(), | ||
| PatcherApi: BDPatcherApi.prototype, | ||
| importsForbidden: true, | ||
| } as IModImplementation; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.