forked from Demon/demoncord
cleanups, basic settings functionality
parent
3e06ef0999
commit
701182ab7f
@ -1,35 +1,43 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
|
const commandsSym = Symbol("__commands");
|
||||||
|
|
||||||
function init(obj: Object) {
|
function init(obj: Object) {
|
||||||
obj.demon.__commands = {}
|
obj.demon[commandsSym] = {};
|
||||||
obj.demon.patcher.after("sendMessage", obj.demon.webpack.findByProps("sendMessage"),
|
obj.demon.patcher.after(
|
||||||
(args, otherRes) => {
|
"sendMessage",
|
||||||
let res;
|
obj.demon.webpack.findByProps("sendMessage"),
|
||||||
for (const key of Reflect.ownKeys(obj.demon.__commands)) {
|
(args, otherRes) => {
|
||||||
let command = obj.demon.__commands[key]
|
let res;
|
||||||
if (args[1].content.split(" ")[0] === ">" + command.name) {
|
for (const key of Reflect.ownKeys(obj.demon[commandsSym])) {
|
||||||
res = command.callback(args)
|
let command = obj.demon[commandsSym][key];
|
||||||
break
|
if (args[1].content.split(" ")[0] === ">" + command.name) {
|
||||||
}
|
res = command.callback(args);
|
||||||
}
|
break;
|
||||||
if (res !== undefined) args[1].content = res
|
}
|
||||||
return args
|
}
|
||||||
}
|
if (res !== undefined) args[1].content = res;
|
||||||
)
|
return args;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// command = {
|
// command = {
|
||||||
// name: "name",
|
// name: "name",
|
||||||
// callback: (args)=>"Hello, world!"
|
// callback: (args)=>"Hello, world!"
|
||||||
// }
|
// }
|
||||||
function add(command: {name: string, callback: (args: Array<any>) => string}): ()=>void {
|
function add(command: {
|
||||||
let sym = Symbol(command.name);
|
name: string,
|
||||||
window.demon.__commands[sym] = command;
|
callback: (args: Array<any>) => string,
|
||||||
return () => {
|
}): () => void {
|
||||||
delete window.demon.__commands[sym];
|
let sym = Symbol(command.name);
|
||||||
}
|
window.demon[commandsSym][sym] = command;
|
||||||
|
return () => {
|
||||||
|
delete window.demon[commandsSym][sym];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
add: add,
|
add: add,
|
||||||
init: init
|
init: init,
|
||||||
}
|
};
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
// @flow
|
||||||
|
|
||||||
|
import webpack from "./webpack";
|
||||||
|
|
||||||
|
const settingsSym = Symbol("__settings");
|
||||||
|
|
||||||
|
const settingsView = webpack.find(m => m.default && m.default.displayName === "SettingsView");
|
||||||
|
|
||||||
|
type getPredicateSectionsEntry =
|
||||||
|
| {
|
||||||
|
section: "HEADER",
|
||||||
|
label: string,
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
section: "DIVIDER",
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
section: string,
|
||||||
|
label: string,
|
||||||
|
component: Function,
|
||||||
|
};
|
||||||
|
|
||||||
|
function patch(args: mixed, ret: getPredicateSectionsEntry[]) {
|
||||||
|
const processedEntries = window.demon[settingsSym].entries.map((e) => ({
|
||||||
|
section: "DEMON_SETTINGS_LOADER_" + e.name,
|
||||||
|
label: e.name,
|
||||||
|
element: e.component,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const injectionIndex =
|
||||||
|
2 + ret.findIndex((section) => section.section === "Game Activity");
|
||||||
|
ret.splice(
|
||||||
|
injectionIndex,
|
||||||
|
0,
|
||||||
|
{ section: "HEADER", label: "Demon" },
|
||||||
|
...processedEntries,
|
||||||
|
{ section: "DIVIDER" }
|
||||||
|
);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
window.demon[settingsSym] = {
|
||||||
|
patch: window.demon.patcher.after(
|
||||||
|
"getPredicateSections",
|
||||||
|
settingsView.default.prototype,
|
||||||
|
patch
|
||||||
|
),
|
||||||
|
entries: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// debug
|
||||||
|
window.demonunpatch = window.demon[settingsSym].patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
function unInit(obj: Object) {
|
||||||
|
window.demon[settingsSym].patch();
|
||||||
|
delete window.demon[settingsSym];
|
||||||
|
}
|
||||||
|
|
||||||
|
function unregisterSettingsEntry(name: string) {
|
||||||
|
let s = window.demon[settingsSym];
|
||||||
|
s.entries = s.entries.filter((e) => e.name !== name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function registerSettingsEntry(name: string, component: Function): () => void {
|
||||||
|
window.demon[settingsSym].entries.push({ name, component });
|
||||||
|
return () => unregisterSettingsEntry(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { init, unInit, registerSettingsEntry, unregisterSettingsEntry };
|
@ -1,52 +1,53 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import Patcher from "simian"
|
import Patcher from "simian";
|
||||||
import webpack from "./api/webpack.js"
|
import webpack from "./api/webpack";
|
||||||
import common from "./api/common.js"
|
import common from "./api/common";
|
||||||
import commands from "./api/commands.js"
|
import commands from "./api/commands";
|
||||||
import plugins from "./api/plugins.js"
|
import plugins from "./api/plugins";
|
||||||
|
import settingsInj from "./api/settingsInjection";
|
||||||
|
|
||||||
async function init(obj: Object): Promise<void> {
|
async function init(obj: Object): Promise<void> {
|
||||||
const patcher = new Patcher()
|
const patcher = new Patcher();
|
||||||
obj.demon = {
|
obj.demon = {
|
||||||
patcher: {
|
patcher: {
|
||||||
monkeyPatch: function(name: string, parentObj: Object, patches: Object): ()=>void {
|
monkeyPatch: function (
|
||||||
let [upb,upi,upa] = [()=>{},()=>{},()=>{}]
|
name: string,
|
||||||
if (patches.before !== undefined) upb = patcher.before(
|
parentObj: Object,
|
||||||
name,
|
patches: Object
|
||||||
parentObj,
|
): () => void {
|
||||||
patches.before
|
let [upb, upi, upa] = [() => {}, () => {}, () => {}];
|
||||||
)
|
if (patches.before !== undefined)
|
||||||
if (patches.instead !== undefined) upb = patcher.instead(
|
upb = patcher.before(name, parentObj, patches.before);
|
||||||
name,
|
if (patches.instead !== undefined)
|
||||||
parentObj,
|
upb = patcher.instead(name, parentObj, patches.instead);
|
||||||
patches.instead
|
if (patches.after !== undefined)
|
||||||
)
|
upb = patcher.after(name, parentObj, patches.after);
|
||||||
if (patches.after !== undefined) upb = patcher.after(
|
return () => {
|
||||||
name,
|
upb();
|
||||||
parentObj,
|
upi();
|
||||||
patches.after
|
upa();
|
||||||
)
|
};
|
||||||
return ()=>{
|
},
|
||||||
upb()
|
before: patcher.before,
|
||||||
upi()
|
instead: patcher.instead,
|
||||||
upa()
|
after: patcher.after,
|
||||||
}
|
},
|
||||||
},
|
webpack,
|
||||||
before: patcher.before,
|
common,
|
||||||
instead: patcher.instead,
|
commands: {
|
||||||
after: patcher.after
|
add: commands.add,
|
||||||
},
|
},
|
||||||
webpack,
|
__DO_NOT_USE_OR_YOU_WILL_BE_FIRED_UNTO_THE_DEPTHS_OF_HELL: {
|
||||||
common,
|
plugins,
|
||||||
commands: {
|
},
|
||||||
add: commands.add
|
settings: {
|
||||||
},
|
register: settingsInj.registerSettingsEntry,
|
||||||
__DO_NOT_USE_OR_YOU_WILL_BE_FIRED_UNTO_THE_DEPTHS_OF_HELL: {
|
unregister: settingsInj.unregisterSettingsEntry,
|
||||||
plugins
|
},
|
||||||
}
|
};
|
||||||
}
|
commands.init(obj);
|
||||||
commands.init(obj)
|
plugins.init(obj);
|
||||||
plugins.init(obj)
|
settingsInj.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default init;
|
export default init;
|
||||||
|
Loading…
Reference in new issue