···11-- Initial release
11+## Core
22+33+- Updated mappings
44+- Fixed using remapped paths as patch finds not working
+165
LICENSE
···11+ GNU LESSER GENERAL PUBLIC LICENSE
22+ Version 3, 29 June 2007
33+44+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
55+ Everyone is permitted to copy and distribute verbatim copies
66+ of this license document, but changing it is not allowed.
77+88+99+ This version of the GNU Lesser General Public License incorporates
1010+the terms and conditions of version 3 of the GNU General Public
1111+License, supplemented by the additional permissions listed below.
1212+1313+ 0. Additional Definitions.
1414+1515+ As used herein, "this License" refers to version 3 of the GNU Lesser
1616+General Public License, and the "GNU GPL" refers to version 3 of the GNU
1717+General Public License.
1818+1919+ "The Library" refers to a covered work governed by this License,
2020+other than an Application or a Combined Work as defined below.
2121+2222+ An "Application" is any work that makes use of an interface provided
2323+by the Library, but which is not otherwise based on the Library.
2424+Defining a subclass of a class defined by the Library is deemed a mode
2525+of using an interface provided by the Library.
2626+2727+ A "Combined Work" is a work produced by combining or linking an
2828+Application with the Library. The particular version of the Library
2929+with which the Combined Work was made is also called the "Linked
3030+Version".
3131+3232+ The "Minimal Corresponding Source" for a Combined Work means the
3333+Corresponding Source for the Combined Work, excluding any source code
3434+for portions of the Combined Work that, considered in isolation, are
3535+based on the Application, and not on the Linked Version.
3636+3737+ The "Corresponding Application Code" for a Combined Work means the
3838+object code and/or source code for the Application, including any data
3939+and utility programs needed for reproducing the Combined Work from the
4040+Application, but excluding the System Libraries of the Combined Work.
4141+4242+ 1. Exception to Section 3 of the GNU GPL.
4343+4444+ You may convey a covered work under sections 3 and 4 of this License
4545+without being bound by section 3 of the GNU GPL.
4646+4747+ 2. Conveying Modified Versions.
4848+4949+ If you modify a copy of the Library, and, in your modifications, a
5050+facility refers to a function or data to be supplied by an Application
5151+that uses the facility (other than as an argument passed when the
5252+facility is invoked), then you may convey a copy of the modified
5353+version:
5454+5555+ a) under this License, provided that you make a good faith effort to
5656+ ensure that, in the event an Application does not supply the
5757+ function or data, the facility still operates, and performs
5858+ whatever part of its purpose remains meaningful, or
5959+6060+ b) under the GNU GPL, with none of the additional permissions of
6161+ this License applicable to that copy.
6262+6363+ 3. Object Code Incorporating Material from Library Header Files.
6464+6565+ The object code form of an Application may incorporate material from
6666+a header file that is part of the Library. You may convey such object
6767+code under terms of your choice, provided that, if the incorporated
6868+material is not limited to numerical parameters, data structure
6969+layouts and accessors, or small macros, inline functions and templates
7070+(ten or fewer lines in length), you do both of the following:
7171+7272+ a) Give prominent notice with each copy of the object code that the
7373+ Library is used in it and that the Library and its use are
7474+ covered by this License.
7575+7676+ b) Accompany the object code with a copy of the GNU GPL and this license
7777+ document.
7878+7979+ 4. Combined Works.
8080+8181+ You may convey a Combined Work under terms of your choice that,
8282+taken together, effectively do not restrict modification of the
8383+portions of the Library contained in the Combined Work and reverse
8484+engineering for debugging such modifications, if you also do each of
8585+the following:
8686+8787+ a) Give prominent notice with each copy of the Combined Work that
8888+ the Library is used in it and that the Library and its use are
8989+ covered by this License.
9090+9191+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
9292+ document.
9393+9494+ c) For a Combined Work that displays copyright notices during
9595+ execution, include the copyright notice for the Library among
9696+ these notices, as well as a reference directing the user to the
9797+ copies of the GNU GPL and this license document.
9898+9999+ d) Do one of the following:
100100+101101+ 0) Convey the Minimal Corresponding Source under the terms of this
102102+ License, and the Corresponding Application Code in a form
103103+ suitable for, and under terms that permit, the user to
104104+ recombine or relink the Application with a modified version of
105105+ the Linked Version to produce a modified Combined Work, in the
106106+ manner specified by section 6 of the GNU GPL for conveying
107107+ Corresponding Source.
108108+109109+ 1) Use a suitable shared library mechanism for linking with the
110110+ Library. A suitable mechanism is one that (a) uses at run time
111111+ a copy of the Library already present on the user's computer
112112+ system, and (b) will operate properly with a modified version
113113+ of the Library that is interface-compatible with the Linked
114114+ Version.
115115+116116+ e) Provide Installation Information, but only if you would otherwise
117117+ be required to provide such information under section 6 of the
118118+ GNU GPL, and only to the extent that such information is
119119+ necessary to install and execute a modified version of the
120120+ Combined Work produced by recombining or relinking the
121121+ Application with a modified version of the Linked Version. (If
122122+ you use option 4d0, the Installation Information must accompany
123123+ the Minimal Corresponding Source and Corresponding Application
124124+ Code. If you use option 4d1, you must provide the Installation
125125+ Information in the manner specified by section 6 of the GNU GPL
126126+ for conveying Corresponding Source.)
127127+128128+ 5. Combined Libraries.
129129+130130+ You may place library facilities that are a work based on the
131131+Library side by side in a single library together with other library
132132+facilities that are not Applications and are not covered by this
133133+License, and convey such a combined library under terms of your
134134+choice, if you do both of the following:
135135+136136+ a) Accompany the combined library with a copy of the same work based
137137+ on the Library, uncombined with any other library facilities,
138138+ conveyed under the terms of this License.
139139+140140+ b) Give prominent notice with the combined library that part of it
141141+ is a work based on the Library, and explaining where to find the
142142+ accompanying uncombined form of the same work.
143143+144144+ 6. Revised Versions of the GNU Lesser General Public License.
145145+146146+ The Free Software Foundation may publish revised and/or new versions
147147+of the GNU Lesser General Public License from time to time. Such new
148148+versions will be similar in spirit to the present version, but may
149149+differ in detail to address new problems or concerns.
150150+151151+ Each version is given a distinguishing version number. If the
152152+Library as you received it specifies that a certain numbered version
153153+of the GNU Lesser General Public License "or any later version"
154154+applies to it, you have the option of following the terms and
155155+conditions either of that published version or of any later version
156156+published by the Free Software Foundation. If the Library as you
157157+received it does not specify a version number of the GNU Lesser
158158+General Public License, you may choose any version of the GNU Lesser
159159+General Public License ever published by the Free Software Foundation.
160160+161161+ If the Library as you received it specifies that a proxy can decide
162162+whether future versions of the GNU Lesser General Public License shall
163163+apply, that proxy's public statement of acceptance of any version is
164164+permanent authorization for you to choose that version for the
165165+Library.
+16-5
README.md
···11<h3 align="center">
22- <img src="./img/wordmark.png" alt="moonlight" />
22+ <picture>
33+ <source media="(prefers-color-scheme: dark)" srcset="./img/wordmark-light.png">
44+ <source media="(prefers-color-scheme: light)" srcset="./img/wordmark.png">
55+ <img src="./img/wordmark.png" alt="moonlight" />
66+ </picture>
3744-<a href="https://discord.gg/FdZBTFCP6F">Discord server</a>
88+<a href="https://moonlight-mod.github.io/using/install">Install</a>
99+\- <a href="https://moonlight-mod.github.io/ext-dev/getting-started">Docs</a>
1010+\- <a href="https://discord.gg/FdZBTFCP6F">Discord server</a>
511\- <a href="https://github.com/moonlight-mod/moonlight">GitHub</a>
66-\- <a href="https://moonlight-mod.github.io/">Docs</a>
712813 <hr />
1414+1515+ <picture>
1616+ <source media="(prefers-color-scheme: dark)" srcset="https://moonlight-mod.github.io/moonbase.png">
1717+ <source media="(prefers-color-scheme: light)" srcset="https://moonlight-mod.github.io/moonbase-light.png">
1818+ <img src="https://moonlight-mod.github.io/moonbase.png" alt="A screenshot of Moonbase, the moonlight UI" />
1919+ </picture>
920</h3>
10211122**moonlight** is yet another Discord client mod, focused on providing a decent user and developer experience.
12231324moonlight is heavily inspired by hh3 (a private client mod) and the projects before it that it is inspired by, namely EndPwn. All core code is original or used with permission from their respective authors where not copyleft.
14251515-**_This is an experimental passion project._** moonlight was not created out of malicious intent nor intended to seriously compete with other mods. Anything and everything is subject to change.
2626+moonlight is a **_passion project_** - things may break from time to time, but we try our best to keep things working in a timely manner.
16271717-moonlight is licensed under the [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html) (`AGPL-3.0-or-later`). See [the documentation](https://moonlight-mod.github.io/) for more information.
2828+moonlight is licensed under the [GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.html) (`LGPL-3.0-or-later`). See [the documentation](https://moonlight-mod.github.io/) for more information.
···11+// https://github.com/electron/asar
22+// http://formats.kaitai.io/python_pickle/
33+import { BinaryReader } from "./util/binary";
44+55+/*
66+ The asar format is kinda bad, especially because it uses multiple pickle
77+ entries. It spams sizes, expecting us to read small buffers and parse those,
88+ but we can just take it all through at once without having to create multiple
99+ BinaryReaders. This implementation might be wrong, though.
1010+1111+ This either has size/offset or files but I can't get the type to cooperate,
1212+ so pretend this is a union.
1313+*/
1414+1515+type AsarEntry = {
1616+ size: number;
1717+ offset: `${number}`; // who designed this
1818+1919+ files?: Record<string, AsarEntry>;
2020+};
2121+2222+export default function extractAsar(file: ArrayBuffer) {
2323+ const array = new Uint8Array(file);
2424+ const br = new BinaryReader(array);
2525+2626+ // two uints, one containing the number '4', to signify that the other uint takes up 4 bytes
2727+ // bravo, electron, bravo
2828+ const _payloadSize = br.readUInt32();
2929+ const _headerSize = br.readInt32();
3030+3131+ const headerStringStart = br.position;
3232+ const headerStringSize = br.readUInt32(); // How big the block is
3333+ const actualStringSize = br.readUInt32(); // How big the string in that block is
3434+3535+ const base = headerStringStart + headerStringSize + 4;
3636+3737+ const string = br.readString(actualStringSize);
3838+ const header: AsarEntry = JSON.parse(string);
3939+4040+ const ret: Record<string, Uint8Array> = {};
4141+ function addDirectory(dir: AsarEntry, path: string) {
4242+ for (const [name, data] of Object.entries(dir.files!)) {
4343+ const fullName = path + "/" + name;
4444+ if (data.files != null) {
4545+ addDirectory(data, fullName);
4646+ } else {
4747+ br.position = base + parseInt(data.offset);
4848+ const file = br.read(data.size);
4949+ ret[fullName] = file;
5050+ }
5151+ }
5252+ }
5353+5454+ addDirectory(header, "");
5555+5656+ return ret;
5757+}
+38-33
packages/core/src/config.ts
···11-import { Config, constants } from "@moonlight-mod/types";
22-import requireImport from "./util/import";
11+import { Config } from "@moonlight-mod/types";
32import { getConfigPath } from "./util/data";
33+import * as constants from "@moonlight-mod/types/constants";
44+import Logger from "./util/logger";
55+66+const logger = new Logger("core/config");
4758const defaultConfig: Config = {
66- extensions: {},
77- repositories: ["https://moonlight-mod.github.io/extensions/repo.json"]
99+ // If you're updating this, update `builtinExtensions` in constants as well
1010+ extensions: {
1111+ moonbase: true,
1212+ disableSentry: true,
1313+ noTrack: true,
1414+ noHideToken: true
1515+ },
1616+ repositories: [constants.mainRepo]
817};
9181010-export function writeConfig(config: Config) {
1111- const fs = requireImport("fs");
1212- const configPath = getConfigPath();
1313- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
1414-}
1515-1616-function readConfigNode(): Config {
1717- const fs = requireImport("fs");
1818- const configPath = getConfigPath();
1919-2020- if (!fs.existsSync(configPath)) {
2121- writeConfig(defaultConfig);
2222- return defaultConfig;
1919+export async function writeConfig(config: Config) {
2020+ try {
2121+ const configPath = await getConfigPath();
2222+ await moonlightNodeSandboxed.fs.writeFileString(configPath, JSON.stringify(config, null, 2));
2323+ } catch (e) {
2424+ logger.error("Failed to write config", e);
2325 }
2424-2525- let config: Config = JSON.parse(fs.readFileSync(configPath, "utf8"));
2626-2727- // Assign the default values if they don't exist (newly added)
2828- config = { ...defaultConfig, ...config };
2929- writeConfig(config);
3030-3131- return config;
3226}
33273434-export function readConfig(): Config {
2828+export async function readConfig(): Promise<Config> {
3529 webPreload: {
3630 return moonlightNode.config;
3731 }
38323939- nodePreload: {
4040- return readConfigNode();
4141- }
3333+ const configPath = await getConfigPath();
3434+ if (!(await moonlightNodeSandboxed.fs.exists(configPath))) {
3535+ await writeConfig(defaultConfig);
3636+ return defaultConfig;
3737+ } else {
3838+ try {
3939+ let config: Config = JSON.parse(await moonlightNodeSandboxed.fs.readFileString(configPath));
4040+ // Assign the default values if they don't exist (newly added)
4141+ config = { ...defaultConfig, ...config };
4242+ await writeConfig(config);
42434343- injector: {
4444- return readConfigNode();
4444+ return config;
4545+ } catch (e) {
4646+ logger.error("Failed to read config, falling back to defaults", e);
4747+ // We don't want to write the default config here - if a user is manually
4848+ // editing their config and messes it up, we'll delete it all instead of
4949+ // letting them fix it
5050+ return defaultConfig;
5151+ }
4552 }
4646-4747- throw new Error("Called readConfig() in an impossible environment");
4853}
···11+import spacepack from "@moonlight-mod/wp/spacepack_spacepack";
22+33+// spacepack.require.m[moonlight.moonmap.modules["discord/modules/menus/web/Menu"]].toString();
44+let code =
55+ spacepack.require.m[
66+ spacepack.findByCode("Menu API only allows Items and groups of Items as children.")[0].id
77+ ].toString();
88+99+const parserSym = code.match(/(?<=_patchMenu\(.,).+?(?=\()/)![0];
1010+1111+code = code.replace(/{(.):\(\)=>./, (orig, e) => `{${e}:()=>${parserSym}`);
1212+const mod = new Function("module", "exports", "require", `(${code}).apply(this, arguments)`);
1313+1414+const exp: any = {};
1515+mod({}, exp, require);
1616+1717+const parser = spacepack.findFunctionByStrings(exp, "Menu API only allows Items and groups of Items as children.")!;
1818+module.exports = parser;
···11{
22+ "$schema": "https://moonlight-mod.github.io/manifest.schema.json",
23 "id": "noHideToken",
44+ "apiLevel": 2,
35 "meta": {
46 "name": "No Hide Token",
55- "tagline": "Disables removal of token from localStorage when opening dev tools",
77+ "tagline": "Prevents you from being logged-out on hard-crash",
88+ "description": "Prevents you from being logged-out on hard-crash by disabling removal of token from localStorage when opening dev tools",
69 "authors": ["adryd"],
710 "tags": ["dangerZone", "development"]
811 }
···11+{
22+ "$schema": "https://moonlight-mod.github.io/manifest.schema.json",
33+ "id": "rocketship",
44+ "apiLevel": 2,
55+ "environment": "desktop",
66+ "meta": {
77+ "name": "Rocketship",
88+ "tagline": "Adds new features when using rocketship",
99+ "description": "**This extension only works on Linux when using rocketship:**\nhttps://github.com/moonlight-mod/rocketship\n\nAdds new features to the Discord Linux client with rocketship, such as a better screensharing experience.",
1010+ "authors": ["NotNite", "Cynosphere", "adryd"],
1111+ "deprecated": true
1212+ }
1313+}
···11+export type AppPanels = {
22+ /**
33+ * Registers a new panel to be displayed around the user/voice controls.
44+ * @param section A unique name for your section
55+ * @param element A React component
66+ */
77+ addPanel: (section: string, element: React.FC<any>) => void;
88+99+ /**
1010+ * @private
1111+ */
1212+ getPanels: (el: React.FC<any>) => React.ReactNode;
1313+};
···11+import {
22+ Menu,
33+ MenuCheckboxItem,
44+ MenuControlItem,
55+ MenuGroup,
66+ MenuRadioItem,
77+ MenuSeparator,
88+ MenuItem,
99+ MenuElement
1010+} from "@moonlight-mod/mappings/discord/components/common/index";
1111+1212+export type ContextMenu = {
1313+ /**
1414+ * Registers a new context menu item for a given context menu type.
1515+ * @param navId The navigation ID for the target context menu (e.g. "user-context", "message")
1616+ * @param item A React component
1717+ * @param anchor An existing item's ID to anchor the new item to
1818+ * @param before Whether to insert the new item before the anchor item
1919+ */
2020+ addItem: (navId: string, item: React.FC<any>, anchor: string | RegExp, before?: boolean) => void;
2121+2222+ MenuCheckboxItem: MenuCheckboxItem;
2323+ MenuControlItem: MenuControlItem;
2424+ MenuGroup: MenuGroup;
2525+ MenuItem: MenuItem;
2626+ MenuRadioItem: MenuRadioItem;
2727+ MenuSeparator: MenuSeparator;
2828+};
2929+3030+export type InternalItem = {
3131+ type: string;
3232+ key?: string;
3333+};
3434+3535+export type InternalSeparator = {
3636+ type: "separator";
3737+ navigable: false;
3838+};
3939+export type InternalGroupStart = {
4040+ type: "groupstart";
4141+ length: number;
4242+ navigable: false;
4343+ props: React.ComponentProps<MenuGroup>;
4444+};
4545+export type InternalGroupEnd = {
4646+ type: "groupend";
4747+} & Omit<InternalGroupStart, "type">;
4848+export type InternalCustomItem = {
4949+ type: "customitem";
5050+ key: any;
5151+ navigable?: boolean;
5252+ render: any;
5353+ props: Extract<React.ComponentProps<MenuItem>, { render: any }>;
5454+};
5555+export type InternalItem_ = {
5656+ type: "item";
5757+ key: any;
5858+ navigable: true;
5959+ label: string;
6060+};
6161+6262+export type EvilItemParser = (el: MenuElement | MenuElement[]) => InternalItem[];
6363+6464+export type { Menu, MenuElement };
+107
packages/types/src/coreExtensions/markdown.ts
···11+// {{{ simple-markdown
22+33+export type SingleASTNode = {
44+ type: string;
55+ [key: string]: any;
66+};
77+88+export type UntypedASTNode = {
99+ [key: string]: any;
1010+};
1111+1212+export type ASTNode = SingleASTNode | Array<SingleASTNode>;
1313+1414+export type Parser = (source: string, state?: State | null | undefined) => Array<SingleASTNode>;
1515+1616+export type ParseFunction = (capture: Capture, nestedParse: Parser, state: State) => UntypedASTNode | ASTNode;
1717+1818+export type Capture =
1919+ | (Array<string> & {
2020+ index: number;
2121+ })
2222+ | (Array<string> & {
2323+ index?: number;
2424+ });
2525+2626+export type State = {
2727+ key?: string | number | undefined;
2828+ inline?: boolean | null | undefined;
2929+ [key: string]: any;
3030+};
3131+3232+export type MatchFunction = {
3333+ regex?: RegExp;
3434+} & ((source: string, state: State, prevCapture: string) => Capture | null | undefined);
3535+3636+export type Output<Result> = (node: ASTNode, state?: State | null | undefined) => Result;
3737+3838+export type SingleNodeOutput<Result> = (node: SingleASTNode, nestedOutput: Output<Result>, state: State) => Result;
3939+4040+// }}}
4141+4242+export type ValidFlags = "g" | "i" | "m" | "s" | "u" | "y" | undefined;
4343+4444+export type MarkdownRule = {
4545+ order: number;
4646+ match: MatchFunction;
4747+ parse: ParseFunction;
4848+ react?: SingleNodeOutput<React.ReactNode>;
4949+};
5050+5151+export type SlateRule =
5252+ | {
5353+ type: "skip";
5454+ }
5555+ | {
5656+ type: "verbatim";
5757+ }
5858+ | {
5959+ type: "inlineObject";
6060+ }
6161+ | {
6262+ type: "inlineStyle";
6363+ before: string;
6464+ after: string;
6565+ };
6666+6767+export type Ruleset =
6868+ | "RULES"
6969+ | "CHANNEL_TOPIC_RULES"
7070+ | "VOICE_CHANNEL_STATUS_RULES"
7171+ | "EMBED_TITLE_RULES"
7272+ | "INLINE_REPLY_RULES"
7373+ | "GUILD_VERIFICATION_FORM_RULES"
7474+ | "GUILD_EVENT_RULES"
7575+ | "PROFILE_BIO_RULES"
7676+ | "AUTO_MODERATION_SYSTEM_MESSAGE_RULES"
7777+ | "NATIVE_SEARCH_RESULT_LINK_RULES";
7878+7979+export type Markdown = {
8080+ rules: Record<string, MarkdownRule>;
8181+ slateRules: Record<string, SlateRule>;
8282+ slateDecorators: Record<string, string>;
8383+ ruleBlacklists: Record<Ruleset, Record<string, boolean>>;
8484+8585+ /**
8686+ * Registers a new Markdown rule with simple-markdown.
8787+ * @param name The name of the rule
8888+ * @param markdown A function that returns simple-markdown rules
8989+ * @param slate A function that returns Slate rules
9090+ * @param decorator A decorator name for Slate
9191+ * @see https://www.npmjs.com/package/simple-markdown#adding-a-simple-extension
9292+ * @see https://docs.slatejs.org/
9393+ */
9494+ addRule: (
9595+ name: string,
9696+ markdown: (rules: Record<string, MarkdownRule>) => MarkdownRule,
9797+ slate: (rules: Record<string, SlateRule>) => SlateRule,
9898+ decorator?: string | undefined
9999+ ) => void;
100100+101101+ /**
102102+ * Blacklist a rule from a ruleset.
103103+ * @param ruleset The ruleset name
104104+ * @param name The rule name
105105+ */
106106+ blacklistFromRuleset: (ruleset: Ruleset, name: string) => void;
107107+};
+17
packages/types/src/coreExtensions/moonbase.ts
···11+export type CustomComponentProps = {
22+ value: any;
33+ setValue: (value: any) => void;
44+};
55+66+export type CustomComponent = React.FC<CustomComponentProps>;
77+88+export type Moonbase = {
99+ /**
1010+ * Registers a custom component for an extension setting.
1111+ * The extension setting must be of type "custom".
1212+ * @param ext The extension ID
1313+ * @param option The setting ID
1414+ * @param component A React component
1515+ */
1616+ registerConfigComponent: (ext: string, option: string, component: CustomComponent) => void;
1717+};
+36
packages/types/src/coreExtensions/notices.ts
···11+import type { Store } from "@moonlight-mod/mappings/discord/packages/flux/Store";
22+33+export type NoticeButton = {
44+ name: string;
55+ onClick: () => boolean; // return true to dismiss the notice after the button is clicked
66+};
77+88+export type Notice = {
99+ element: React.ReactNode;
1010+ color?: string;
1111+ showClose?: boolean;
1212+ buttons?: NoticeButton[];
1313+ onDismiss?: () => void;
1414+};
1515+1616+export type Notices = Store<any> & {
1717+ /**
1818+ * Adds a custom notice to the top of the screen.
1919+ */
2020+ addNotice: (notice: Notice) => void;
2121+2222+ /**
2323+ * Removes the current notice from the top of the screen.
2424+ */
2525+ popNotice: () => void;
2626+2727+ /**
2828+ * @private
2929+ */
3030+ getCurrentNotice: () => Notice | null;
3131+3232+ /**
3333+ * @private
3434+ */
3535+ shouldShowNotice: () => boolean;
3636+};
+71
packages/types/src/coreExtensions/settings.ts
···11+import React, { ReactElement } from "react";
22+import type { Store } from "@moonlight-mod/mappings/discord/packages/flux/Store";
33+44+export type NoticeProps = {
55+ stores: Store<any>[];
66+ element: React.FunctionComponent;
77+};
88+99+export type SettingsSection =
1010+ | { section: "DIVIDER"; pos: number | ((sections: SettingsSection[]) => number) }
1111+ | { section: "HEADER"; label: string; pos: number | ((sections: SettingsSection[]) => number) }
1212+ | {
1313+ section: string;
1414+ label: string;
1515+ color: string | null;
1616+ element: React.FunctionComponent;
1717+ pos: number | ((sections: SettingsSection[]) => number);
1818+ notice?: NoticeProps;
1919+ onClick?: () => void;
2020+ _moonlight_submenu?: () => ReactElement | ReactElement[];
2121+ };
2222+2323+export type Settings = {
2424+ ourSections: SettingsSection[];
2525+ sectionNames: string[];
2626+ sectionMenuItems: Record<string, ReactElement[]>;
2727+2828+ /**
2929+ * Registers a new section in the settings menu.
3030+ * @param section The section ID
3131+ * @param label The label for the section
3232+ * @param element The React component to render
3333+ * @param color A color to use for the section
3434+ * @param pos The position in the settings menu to place the section
3535+ * @param notice A notice to display when in the section
3636+ * @param onClick A custom action to execute when clicked from the context menu
3737+ */
3838+ addSection: (
3939+ section: string,
4040+ label: string,
4141+ element: React.FunctionComponent,
4242+ color?: string | null,
4343+ pos?: number | ((sections: SettingsSection[]) => number),
4444+ notice?: NoticeProps,
4545+ onClick?: () => void
4646+ ) => void;
4747+4848+ /**
4949+ * Adds new items to a section in the settings menu.
5050+ * @param section The section ID
5151+ * @param items The React components to render
5252+ */
5353+ addSectionMenuItems: (section: string, ...items: ReactElement[]) => void;
5454+5555+ /**
5656+ * Places a divider in the settings menu.
5757+ * @param pos The position in the settings menu to place the divider
5858+ */
5959+ addDivider: (pos: number | ((sections: SettingsSection[]) => number) | null) => void;
6060+6161+ /**
6262+ * Places a header in the settings menu.
6363+ * @param pos The position in the settings menu to place the header
6464+ */
6565+ addHeader: (label: string, pos: number | ((sections: SettingsSection[]) => number) | null) => void;
6666+6767+ /**
6868+ * @private
6969+ */
7070+ _mutateSections: (sections: SettingsSection[]) => SettingsSection[];
7171+};
+97
packages/types/src/coreExtensions/spacepack.ts
···11+import { WebpackModule, WebpackModuleFunc, WebpackRequireType } from "../discord";
22+33+export type Spacepack = {
44+ /**
55+ * Given a Webpack module ID, returns the function for the Webpack module.
66+ * Can be double clicked to inspect in DevTools.
77+ * @param module The module ID
88+ * @returns The Webpack module, if found
99+ */
1010+ inspect: (module: number | string) => WebpackModuleFunc | null;
1111+1212+ /**
1313+ * Find Webpack modules based on matches in code.
1414+ * @param args A list of finds to match against
1515+ * @returns The Webpack modules, if found
1616+ */
1717+ findByCode: (...args: (string | RegExp)[]) => WebpackModule[];
1818+1919+ /**
2020+ * Find Webpack modules based on their exports.
2121+ * @deprecated This has race conditions. Consider using findByCode instead.
2222+ * @param args A list of finds to match exports against
2323+ * @returns The Webpack modules, if found
2424+ */
2525+ findByExports: (...args: string[]) => WebpackModule[];
2626+2727+ /**
2828+ * The Webpack require function.
2929+ */
3030+ require: WebpackRequireType;
3131+3232+ /**
3333+ * The Webpack module list.
3434+ * Re-export of require.m.
3535+ */
3636+ modules: Record<string, WebpackModuleFunc>;
3737+3838+ /**
3939+ * The Webpack module cache.
4040+ * Re-export of require.c.
4141+ */
4242+ cache: Record<string, any>;
4343+4444+ /**
4545+ * Finds an object from a module's exports using the given key.
4646+ * @param exports Exports from a Webpack module
4747+ * @param key The key to find with
4848+ * @returns The object, if found
4949+ */
5050+ findObjectFromKey: (exports: Record<string, any>, key: string) => any | null;
5151+5252+ /**
5353+ * Finds an object from a module's exports using the given value.
5454+ * @param exports Exports from a Webpack module
5555+ * @param value The value to find with
5656+ * @returns The object, if found
5757+ */
5858+ findObjectFromValue: (exports: Record<string, any>, value: any) => any | null;
5959+6060+ /**
6161+ * Finds an object from a module's exports using the given key-value pair.
6262+ * @param exports Exports from a Webpack module
6363+ * @param key The key to find with
6464+ * @param value The value to find with
6565+ * @returns The object, if found
6666+ */
6767+ findObjectFromKeyValuePair: (exports: Record<string, any>, key: string, value: any) => any | null;
6868+6969+ /**
7070+ * Finds a function from a module's exports using the given source find.
7171+ * This behaves like findByCode but localized to the exported function.
7272+ * @param exports A module's exports
7373+ * @param strings A list of finds to use
7474+ * @returns The function, if found
7575+ */
7676+ findFunctionByStrings: (
7777+ exports: Record<string, any>,
7878+ ...strings: (string | RegExp)[]
7979+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
8080+ ) => Function | null;
8181+8282+ /**
8383+ * Lazy load a Webpack module.
8484+ * @param find A list of finds to discover a target module with
8585+ * @param chunk A RegExp to match chunks to load
8686+ * @param module A RegExp to match the target Webpack module
8787+ * @returns The target Webpack module
8888+ */
8989+ lazyLoad: (find: string | RegExp | (string | RegExp)[], chunk: RegExp, module: RegExp) => Promise<any>;
9090+9191+ /**
9292+ * Filter a list of Webpack modules to "real" ones from the Discord client.
9393+ * @param modules A list of Webpack modules
9494+ * @returns A filtered list of Webpack modules
9595+ */
9696+ filterReal: (modules: WebpackModule[]) => WebpackModule[];
9797+};
+10-66
packages/types/src/coreExtensions.ts
···11-import { FluxDefault, Store } from "./discord/common/Flux";
22-import WebpackRequire from "./discord/require";
33-import { WebpackModuleFunc } from "./discord/webpack";
44-import { CommonComponents as CommonComponents_ } from "./coreExtensions/components";
55-import { Dispatcher } from "flux";
66-import React from "react";
77-88-export type Spacepack = {
99- inspect: (module: number | string) => WebpackModuleFunc | null;
1010- findByCode: (...args: (string | RegExp)[]) => any[];
1111- findByExports: (...args: string[]) => any[];
1212- require: typeof WebpackRequire;
1313- modules: Record<string, WebpackModuleFunc>;
1414- cache: Record<string, any>;
1515- findObjectFromKey: (exports: Record<string, any>, key: string) => any | null;
1616- findObjectFromValue: (exports: Record<string, any>, value: any) => any | null;
1717- findObjectFromKeyValuePair: (
1818- exports: Record<string, any>,
1919- key: string,
2020- value: any
2121- ) => any | null;
2222- findFunctionByStrings: (
2323- exports: Record<string, any>,
2424- ...strings: (string | RegExp)[]
2525- ) => Function | null;
2626-};
2727-2828-export type NoticeProps = {
2929- stores: Store<any>[];
3030- element: React.FunctionComponent;
3131-};
3232-3333-export type SettingsSection =
3434- | { section: "DIVIDER"; pos: number }
3535- | { section: "HEADER"; label: string; pos: number }
3636- | {
3737- section: string;
3838- label: string;
3939- color: string | null;
4040- element: React.FunctionComponent;
4141- pos: number;
4242- notice?: NoticeProps;
4343- _moonlight_submenu?: () => any;
4444- };
4545-4646-export type Settings = {
4747- ourSections: SettingsSection[];
4848-4949- addSection: (
5050- section: string,
5151- label: string,
5252- element: React.FunctionComponent,
5353- color?: string | null,
5454- pos?: number,
5555- notice?: NoticeProps
5656- ) => void;
5757-5858- addDivider: (pos: number | null) => void;
5959- addHeader: (label: string, pos: number | null) => void;
6060- _mutateSections: (sections: SettingsSection[]) => SettingsSection[];
6161-};
6262-6363-export type CommonReact = typeof import("react");
6464-export type CommonFlux = FluxDefault;
6565-export type CommonComponents = CommonComponents_; // lol
6666-export type CommonFluxDispatcher = Dispatcher<any>;
11+export * as Spacepack from "./coreExtensions/spacepack";
22+export * as Settings from "./coreExtensions/settings";
33+export * as Markdown from "./coreExtensions/markdown";
44+export * as ContextMenu from "./coreExtensions/contextMenu";
55+export * as Notices from "./coreExtensions/notices";
66+export * as Moonbase from "./coreExtensions/moonbase";
77+export * as AppPanels from "./coreExtensions/appPanels";
88+export * as Commands from "./coreExtensions/commands";
99+export * as ComponentEditor from "./coreExtensions/componentEditor";
1010+export * as Common from "./coreExtensions/common";
-57
packages/types/src/discord/common/Flux.ts
···11-/*
22- It seems like Discord maintains their own version of Flux that doesn't match
33- the types on NPM. This is a heavy work in progress - if you encounter rough
44- edges, please contribute!
55-*/
66-77-import { DependencyList } from "react";
88-import { Store as FluxStore } from "flux/utils";
99-import { Dispatcher as FluxDispatcher } from "flux";
1010-import { ComponentConstructor } from "flux/lib/FluxContainer";
1111-1212-export declare abstract class Store<T> extends FluxStore<T> {
1313- static getAll: () => Store<any>[];
1414- getName: () => string;
1515- emitChange: () => void;
1616-}
1717-1818-interface ConnectStores {
1919- <T>(
2020- stores: Store<any>[],
2121- callback: T,
2222- context?: any
2323- ): ComponentConstructor<T>;
2424-}
2525-2626-export type FluxDefault = {
2727- DeviceSettingsStore: any; // TODO
2828- Emitter: any; // @types/fbemitter
2929- OfflineCacheStore: any; // TODO
3030- PersistedStore: any; // TODO
3131- Store: typeof Store;
3232- Dispatcher: typeof FluxDispatcher;
3333- connectStores: ConnectStores;
3434- initialize: () => void;
3535- initialized: Promise<boolean>;
3636- destroy: () => void;
3737- useStateFromStores: UseStateFromStores;
3838- useStateFromStoresArray: UseStateFromStoresArray;
3939- useStateFromStoresObject: UseStateFromStoresObject;
4040-};
4141-4242-interface UseStateFromStores {
4343- <T>(
4444- stores: Store<any>[],
4545- callback: () => T,
4646- deps?: DependencyList,
4747- shouldUpdate?: (oldState: T, newState: T) => boolean
4848- ): T;
4949-}
5050-5151-interface UseStateFromStoresArray {
5252- <T>(stores: Store<any>[], callback: () => T, deps?: DependencyList): T;
5353-}
5454-5555-interface UseStateFromStoresObject {
5656- <T>(stores: Store<any>[], callback: () => T, deps?: DependencyList): T;
5757-}
+40-16
packages/types/src/discord/require.ts
···11-import {
22- Spacepack,
33- CommonReact,
44- CommonFlux,
55- Settings,
66- CommonComponents,
77- CommonFluxDispatcher
88-} from "../coreExtensions";
11+import { AppPanels } from "../coreExtensions/appPanels";
22+import { Commands } from "../coreExtensions/commands";
33+import { ErrorBoundary, Icons } from "../coreExtensions/common";
44+import { DMList, MemberList, Messages } from "../coreExtensions/componentEditor";
55+import { ContextMenu, EvilItemParser } from "../coreExtensions/contextMenu";
66+import { Markdown } from "../coreExtensions/markdown";
77+import { Moonbase } from "../coreExtensions/moonbase";
88+import { Notices } from "../coreExtensions/notices";
99+import { Settings } from "../coreExtensions/settings";
1010+import { Spacepack } from "../coreExtensions/spacepack";
9111012declare function WebpackRequire(id: string): any;
1111-declare function WebpackRequire(id: "spacepack_spacepack"): Spacepack;
1212-declare function WebpackRequire(id: "common_react"): CommonReact;
1313-declare function WebpackRequire(id: "common_flux"): CommonFlux;
1414-declare function WebpackRequire(
1515- id: "common_fluxDispatcher"
1616-): CommonFluxDispatcher;
1717-declare function WebpackRequire(id: "settings_settings"): Settings;
1818-declare function WebpackRequire(id: "common_components"): CommonComponents;
1313+1414+declare function WebpackRequire(id: "appPanels_appPanels"): AppPanels;
1515+1616+declare function WebpackRequire(id: "commands_commands"): Commands;
1717+1818+declare function WebpackRequire(id: "common_ErrorBoundary"): ErrorBoundary;
1919+declare function WebpackRequire(id: "common_icons"): Icons;
2020+2121+declare function WebpackRequire(id: "componentEditor_dmList"): DMList;
2222+declare function WebpackRequire(id: "componentEditor_memberList"): MemberList;
2323+declare function WebpackRequire(id: "componentEditor_messages"): Messages;
2424+2525+declare function WebpackRequire(id: "contextMenu_evilMenu"): EvilItemParser;
2626+declare function WebpackRequire(id: "contextMenu_contextMenu"): ContextMenu;
2727+2828+declare function WebpackRequire(id: "markdown_markdown"): Markdown;
2929+3030+declare function WebpackRequire(id: "moonbase_moonbase"): Moonbase;
3131+3232+declare function WebpackRequire(id: "notices_notices"): Notices;
3333+3434+declare function WebpackRequire(id: "settings_settings"): {
3535+ Settings: Settings;
3636+ default: Settings;
3737+};
3838+3939+declare function WebpackRequire(id: "spacepack_spacepack"): {
4040+ default: Spacepack;
4141+ spacepack: Spacepack;
4242+};
19432044export default WebpackRequire;
···2828 };
29293030export type ExtensionManifest = {
3131+ $schema?: string;
3232+3333+ /**
3434+ * A unique identifier for your extension.
3535+ */
3136 id: string;
3737+3838+ /**
3939+ * A version string for your extension - doesn't need to follow a specific format. Required for publishing.
4040+ */
3241 version?: string;
33424343+ /**
4444+ * The API level this extension targets. If it does not match the current version, the extension will not be loaded.
4545+ */
4646+ apiLevel?: number;
4747+4848+ /**
4949+ * Which environment this extension is capable of running in.
5050+ */
5151+ environment?: ExtensionEnvironment;
5252+5353+ /**
5454+ * Metadata about your extension for use in Moonbase.
5555+ */
3456 meta?: {
5757+ /**
5858+ * A human friendly name for your extension as a proper noun.
5959+ */
3560 name?: string;
6161+6262+ /**
6363+ * A short tagline that appears below the name.
6464+ */
3665 tagline?: string;
6666+6767+ /**
6868+ * A longer description that can use Markdown.
6969+ */
3770 description?: string;
7171+7272+ /**
7373+ * List of authors that worked on this extension - accepts string or object with ID.
7474+ */
3875 authors?: ExtensionAuthor[];
3939- deprecated?: boolean;
7676+7777+ /**
7878+ * A list of tags that are relevant to the extension.
7979+ */
4080 tags?: ExtensionTag[];
8181+8282+ /**
8383+ * The URL to the source repository.
8484+ */
4185 source?: string;
8686+8787+ /**
8888+ * A donation link (or other method of support). If you don't want financial contributions, consider putting your favorite charity here!
8989+ */
9090+ donate?: string;
9191+9292+ /**
9393+ * A changelog to show in Moonbase.
9494+ * Moonbase will show the changelog for the latest version, even if it is not installed.
9595+ */
9696+ changelog?: string;
9797+9898+ /**
9999+ * Whether the extension is deprecated and no longer receiving updates.
100100+ */
101101+ deprecated?: boolean;
42102 };
43103104104+ /**
105105+ * A list of extension IDs that are required for the extension to load.
106106+ */
44107 dependencies?: string[];
108108+109109+ /**
110110+ * A list of extension IDs that the user may want to install.
111111+ */
45112 suggested?: string[];
4646- incompatible?: string[]; // TODO: implement
47113114114+ /**
115115+ * A list of extension IDs that the extension is incompatible with.
116116+ * If two incompatible extensions are enabled, one of them will not load.
117117+ */
118118+ incompatible?: string[];
119119+120120+ /**
121121+ * A list of settings for your extension, where the key is the settings ID.
122122+ */
48123 settings?: Record<string, ExtensionSettingsManifest>;
124124+125125+ /**
126126+ * A list of URLs to bypass CORS for.
127127+ * This is implemented by checking if the start of the URL matches.
128128+ * @example https://moonlight-mod.github.io/
129129+ */
49130 cors?: string[];
131131+132132+ /**
133133+ * A list of URLs to block all requests to.
134134+ * This is implemented by checking if the start of the URL matches.
135135+ * @example https://moonlight-mod.github.io/
136136+ */
137137+ blocked?: string[];
138138+139139+ /**
140140+ * A mapping from CSP directives to URLs to allow.
141141+ * @example { "script-src": ["https://example.com"] }
142142+ */
143143+ csp?: Record<string, string[]>;
50144};
51145146146+export enum ExtensionEnvironment {
147147+ /**
148148+ * The extension will run on both platforms, the host/native modules MAY be loaded
149149+ */
150150+ Both = "both",
151151+152152+ /**
153153+ * Extension will run on desktop only, the host/native modules are guaranteed to load
154154+ */
155155+ Desktop = "desktop",
156156+157157+ /**
158158+ * Currently equivalent to Both
159159+ */
160160+ Web = "web"
161161+}
162162+52163export enum ExtensionLoadSource {
53164 Developer,
54165 Core,
···62173 scripts: {
63174 web?: string;
64175 webPath?: string;
176176+ webpackModules?: Record<string, string>;
65177 nodePath?: string;
66178 hostPath?: string;
179179+ style?: string;
67180 };
68181};
69182···95208export type Patch = {
96209 find: PatchMatch;
97210 replace: PatchReplace | PatchReplace[];
211211+ hardFail?: boolean; // if any patches fail, all fail
98212 prerequisite?: () => boolean;
99213};
100214101215export type ExplicitExtensionDependency = {
102102- ext: string;
216216+ ext?: string;
103217 id: string;
104218};
105219···108222export type ExtensionWebpackModule = {
109223 entrypoint?: boolean;
110224 dependencies?: ExtensionDependency[];
111111- run: WebpackModuleFunc;
225225+ run?: WebpackModuleFunc;
112226};
113227114228export type ExtensionWebExports = {
115229 patches?: Patch[];
116230 webpackModules?: Record<string, ExtensionWebpackModule>;
231231+ styles?: string[];
117232};
118233119234export type IdentifiedPatch = Patch & {
···121236 id: number;
122237};
123238124124-export type IdentifiedWebpackModule = ExtensionWebpackModule &
125125- ExplicitExtensionDependency;
239239+export type IdentifiedWebpackModule = ExtensionWebpackModule & ExplicitExtensionDependency;