Skip to content

Commit

Permalink
long needed undoAll
Browse files Browse the repository at this point in the history
  • Loading branch information
doggybootsy committed Jun 23, 2022
1 parent bf95397 commit 28a647e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drdiscord",
"version": "1.0.2",
"version": "1.0.3",
"dependencies": {
"asar": "^3.1.0",
"electron-devtools-installer": "^3.2.0",
Expand Down
21 changes: 19 additions & 2 deletions src/main/patcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = new class rawPatcher {
Symbol = Symbol("DrApi")
patches = {}
hook(module, fn) {
if (!module[fn]) module[fn] = function() {}
const original = module[fn]
Expand Down Expand Up @@ -45,18 +46,34 @@ module.exports = new class rawPatcher {
const hook = this.hook(mod, fn)
const obj = { callback, id }
hook.before.add(obj)
return () => hook.after.delete(obj)

this.patches[id] ??= []
this.patches[id].push(() => hook.before.delete(obj))

return () => hook.before.delete(obj)
}
instead(id, mod, fn, callback) {
const hook = this.hook(mod, fn)
const obj = { callback, id }
hook.instead.add(obj)
return () => hook.after.delete(obj)

this.patches[id] ??= []
this.patches[id].push(() => hook.instead.delete(obj))

return () => hook.instead.delete(obj)
}
after(id, mod, fn, callback) {
const hook = this.hook(mod, fn)
const obj = { callback, id }
hook.after.add(obj)

this.patches[id] ??= []
this.patches[id].push(() => hook.after.delete(obj))

return () => hook.after.delete(obj)
}
unpatchAll(id) {
this.patches[id] ??= []
for (const undo of this.patches[id]) undo()
}
}

0 comments on commit 28a647e

Please sign in to comment.