cleanups, basic settings functionality
parent
3e06ef0999
commit
701182ab7f
@ -1,35 +1,43 @@
|
||||
// @flow
|
||||
|
||||
const commandsSym = Symbol("__commands");
|
||||
|
||||
function init(obj: Object) {
|
||||
obj.demon.__commands = {}
|
||||
obj.demon.patcher.after("sendMessage", obj.demon.webpack.findByProps("sendMessage"),
|
||||
(args, otherRes) => {
|
||||
let res;
|
||||
for (const key of Reflect.ownKeys(obj.demon.__commands)) {
|
||||
let command = obj.demon.__commands[key]
|
||||
if (args[1].content.split(" ")[0] === ">" + command.name) {
|
||||
res = command.callback(args)
|
||||
break
|
||||
}
|
||||
}
|
||||
if (res !== undefined) args[1].content = res
|
||||
return args
|
||||
}
|
||||
)
|
||||
obj.demon[commandsSym] = {};
|
||||
obj.demon.patcher.after(
|
||||
"sendMessage",
|
||||
obj.demon.webpack.findByProps("sendMessage"),
|
||||
(args, otherRes) => {
|
||||
let res;
|
||||
for (const key of Reflect.ownKeys(obj.demon[commandsSym])) {
|
||||
let command = obj.demon[commandsSym][key];
|
||||
if (args[1].content.split(" ")[0] === ">" + command.name) {
|
||||
res = command.callback(args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (res !== undefined) args[1].content = res;
|
||||
return args;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// command = {
|
||||
// name: "name",
|
||||
// callback: (args)=>"Hello, world!"
|
||||
// }
|
||||
function add(command: {name: string, callback: (args: Array<any>) => string}): ()=>void {
|
||||
let sym = Symbol(command.name);
|
||||
window.demon.__commands[sym] = command;
|
||||
return () => {
|
||||
delete window.demon.__commands[sym];
|
||||
}
|
||||
function add(command: {
|
||||
name: string,
|
||||
callback: (args: Array<any>) => string,
|
||||
}): () => void {
|
||||
let sym = Symbol(command.name);
|
||||
window.demon[commandsSym][sym] = command;
|
||||
return () => {
|
||||
delete window.demon[commandsSym][sym];
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
add: add,
|
||||
init: init
|
||||
}
|
||||
add: add,
|
||||
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
|
||||
import Patcher from "simian"
|
||||
import webpack from "./api/webpack.js"
|
||||
import common from "./api/common.js"
|
||||
import commands from "./api/commands.js"
|
||||
import plugins from "./api/plugins.js"
|
||||
import Patcher from "simian";
|
||||
import webpack from "./api/webpack";
|
||||
import common from "./api/common";
|
||||
import commands from "./api/commands";
|
||||
import plugins from "./api/plugins";
|
||||
import settingsInj from "./api/settingsInjection";
|
||||
|
||||
async function init(obj: Object): Promise<void> {
|
||||
const patcher = new Patcher()
|
||||
obj.demon = {
|
||||
patcher: {
|
||||
monkeyPatch: function(name: string, parentObj: Object, patches: Object): ()=>void {
|
||||
let [upb,upi,upa] = [()=>{},()=>{},()=>{}]
|
||||
if (patches.before !== undefined) upb = patcher.before(
|
||||
name,
|
||||
parentObj,
|
||||
patches.before
|
||||
)
|
||||
if (patches.instead !== undefined) upb = patcher.instead(
|
||||
name,
|
||||
parentObj,
|
||||
patches.instead
|
||||
)
|
||||
if (patches.after !== undefined) upb = patcher.after(
|
||||
name,
|
||||
parentObj,
|
||||
patches.after
|
||||
)
|
||||
return ()=>{
|
||||
upb()
|
||||
upi()
|
||||
upa()
|
||||
}
|
||||
},
|
||||
before: patcher.before,
|
||||
instead: patcher.instead,
|
||||
after: patcher.after
|
||||
},
|
||||
webpack,
|
||||
common,
|
||||
commands: {
|
||||
add: commands.add
|
||||
},
|
||||
__DO_NOT_USE_OR_YOU_WILL_BE_FIRED_UNTO_THE_DEPTHS_OF_HELL: {
|
||||
plugins
|
||||
}
|
||||
}
|
||||
commands.init(obj)
|
||||
plugins.init(obj)
|
||||
const patcher = new Patcher();
|
||||
obj.demon = {
|
||||
patcher: {
|
||||
monkeyPatch: function (
|
||||
name: string,
|
||||
parentObj: Object,
|
||||
patches: Object
|
||||
): () => void {
|
||||
let [upb, upi, upa] = [() => {}, () => {}, () => {}];
|
||||
if (patches.before !== undefined)
|
||||
upb = patcher.before(name, parentObj, patches.before);
|
||||
if (patches.instead !== undefined)
|
||||
upb = patcher.instead(name, parentObj, patches.instead);
|
||||
if (patches.after !== undefined)
|
||||
upb = patcher.after(name, parentObj, patches.after);
|
||||
return () => {
|
||||
upb();
|
||||
upi();
|
||||
upa();
|
||||
};
|
||||
},
|
||||
before: patcher.before,
|
||||
instead: patcher.instead,
|
||||
after: patcher.after,
|
||||
},
|
||||
webpack,
|
||||
common,
|
||||
commands: {
|
||||
add: commands.add,
|
||||
},
|
||||
__DO_NOT_USE_OR_YOU_WILL_BE_FIRED_UNTO_THE_DEPTHS_OF_HELL: {
|
||||
plugins,
|
||||
},
|
||||
settings: {
|
||||
register: settingsInj.registerSettingsEntry,
|
||||
unregister: settingsInj.unregisterSettingsEntry,
|
||||
},
|
||||
};
|
||||
commands.init(obj);
|
||||
plugins.init(obj);
|
||||
settingsInj.init();
|
||||
}
|
||||
|
||||
export default init;
|
||||
|
Loading…
Reference in new issue