Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions PEANUTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Banana Native ships several releases a day, so this fork is kept as a **thin ove
- `android/app/src/main/java/dev/peanuts/` — launcher side: the `Presentation` on the second display, its view, the JNI bridge.
- `dm/peanuts/` — host side: companion package loader, guest readers, tick, input injection (plain C).
- `peanuts/` — companion packages, docs, tests, `scripts/`.
- `android/app/src/main/java/io/github/davdxpx/mistel/` — Mistel's MIT library for `.mncf` cheat files (`io.github.davdxpx.mistel.mncf`), a copy of
Mistel's `format/lib/java` that is never edited here: `peanuts/scripts/mncf-vendor.sh` copies it with its LICENSE and `MISTEL.sha256` (the commit and
every file's hash), and `peanuts/tests/test_mncf_vendor.py` fails on any change to the copy. Fixes go to Mistel first.
2. **Hooks into upstream files are one-liners, each tagged `PEANUTS`.** A hook is a call-out to Peanuts code, never logic.
Allowed hook sites (keep this list current):
- `android/app/src/main/java/dev/nxnative/android/GameActivity.java` — create/destroy the companion `Presentation`; (2026-11-13) one line in
Expand Down
5 changes: 5 additions & 0 deletions android/NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ atomics in `AstOptimizer.cs`, of else-ifs for SPIR-V and of TMML's negative LOD,

The six default Miis (`mii_defs` in `dm/host/hle_mii.c`, `MiiStore.DEFAULTS` in the launcher's Mii editor) are the console's default Mii parameters as [Ryujinx](https://github.com/Ryubing/Ryujinx) (MIT, Copyright (c) Ryujinx Team and Contributors) and [Eden](https://git.eden-emu.dev/eden-emu/eden) (`src/core/hle/service/mii/types/raw_data.cpp`, GPL-3.0-or-later) hold them, converted to CharInfo values; the MIT permission notice is in [dm/third_party/ryujinx/LICENSE.txt](../dm/third_party/ryujinx/LICENSE.txt). Thanks to them. <!-- PEANUTS -->

The launcher reads, checks and writes cheat files in the Mistel Native Cheat Format (`.mncf`, packs `.mncp`) with the Java library of
[Mistel](https://github.com/davdxpx/mistel)'s `format/` folder by davdxpx and the Mistel contributors (MIT: "Copyright (c) 2026 davdxpx and the Mistel contributors"),
copied unchanged into `android/app/src/main/java/io/github/davdxpx/mistel/` with its permission notice there (`LICENSE`) and the commit it came from (`MISTEL.sha256`).
Only that folder of Mistel is MIT; nothing of its GPL parts is in this repository. <!-- PEANUTS -->

The launcher draws the Miis (`android/app/src/main/java/dev/peanuts/mii/`) with the colour tables and the face's layout of [vee](https://github.com/j0lol/vee) by Jo Null (MIT or Apache-2.0, used here under MIT: "Copyright (c) Jo Null"), which took them from the decompilation of the Wii U's face library (FFL), and `MiiPixels.java` ports the BC4, BC5 and BC7 decoders of [bcdec](https://github.com/iOrange/bcdec) by Sergii Kudlai (MIT: "Copyright (c) 2022 Sergii Kudlai"); the MIT permission notice is in [LICENSE](../LICENSE). The Mii parts themselves are read from the player's own firmware at run time and are no part of this code. Thanks to them. <!-- PEANUTS -->

Animal Crossing: New Horizons' 60 fps choice (Game settings, Frame rate cap) uses ["ACNH 60 FPS + SpeedFix"](https://github.com/tmouh/acnh-60fps) v1.4.5 by tmouh, under the Creative Commons Attribution-NonCommercial 4.0 International licence ([CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/)): its main code patch for 3.0.3, converted to the rewriter's cut rows, and its four changed game files, converted to rows of changed bytes that the app applies to the player's own files (no game file is shipped). The mod's content is unchanged; `dm/games/01006F8002326000/speedfix60/NOTICE.md` says what was converted and how. The NonCommercial term applies to that data. Thanks to tmouh. <!-- PEANUTS -->
Expand Down
527 changes: 486 additions & 41 deletions android/app/src/jvmtest/java/dev/peanuts/mods/CheatLoaderJvmTest.java

Large diffs are not rendered by default.

137 changes: 108 additions & 29 deletions android/app/src/main/java/dev/nxnative/android/CheatsBridge.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -912,9 +912,10 @@ private void cheatsEnv(String id, Pack pack, File packDir, List<String> env) {
File folder = CheatsUi.folder(this, id), shipped = Cheats.packFile(packDir, build);
try {
// PEANUTS begin: was Cheats.install(shipped, folder, build, Prefs.cheatsOn(this, id)): the enabled mods' cheat files are in the one list too (ModCheats),
// the cheats a mod's own .enabled turns on are on the first time they are listed, and a mod's file that cannot be read is a note, not a start without cheats
// the cheats a mod's own .enabled turns on are on the first time they are listed, and a mod's file that cannot be read is a note, not a start without cheats;
// the player's sources are .mncf files, made ready for this build with the game's own main from the pack (dev.peanuts.mods.MncfBuild)
java.util.Set<String> con = Prefs.cheatsOn(this, id); int con0 = con.size(); List<String> cnotes = new ArrayList<>();
List<Cheats.Entry> l = ModCheats.install(shipped, folder, build, con, cheatMods, cnotes);
List<Cheats.Entry> l = ModCheats.install(shipped, folder, build, con, cheatMods, cnotes, CheatsBridge.known(this, id, getIntent().getStringExtra("name"), packDir.getPath()), CheatsBridge.game(id, build, packDir.getPath()));
if (con.size() != con0) Prefs.cheatsOn(this, id, con);
for (String n : cnotes) unknownNotes.add("[nxlaunch] Cheats: " + n);
// PEANUTS end
Expand Down
22 changes: 18 additions & 4 deletions android/app/src/main/java/dev/nxnative/android/ModCheats.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import dev.peanuts.mods.CheatFile;
import dev.peanuts.mods.CheatSources;
import dev.peanuts.mods.MncfBuild;
import dev.peanuts.mods.MncfConvert;

/**
* PEANUTS: the one merged cheat file a start hands the host (DM_CHEATS), from the game's cheat sources (dev.peanuts.mods.CheatSources: the cheats that come
Expand All @@ -29,6 +31,9 @@
* <li>A mod's file that cannot be read is left out with a note; the other cheats are installed.</li>
* <li>Upstream's earlier imports (&lt;folder&gt;/imported/) become sources first (CheatSources.migrate); a toggle kept as "Name (imported)" is given the cheat's new
* key as well.</li>
* <li>The player's sources are .mncf files (CheatSources): each is made ready for the build that runs (dev.peanuts.mods.MncfBuild, with the game's own main
* from the pack) and goes into the merged file as Atmosphère code, which the host runs as before. Sources an earlier version kept as Atmosphère files
* become .mncf first (CheatSources.upgrade).</li>
* </ul>
*/
final class ModCheats {
Expand Down Expand Up @@ -100,9 +105,10 @@ static List<ModFile> of(List<File> modCheatDirs, String build, List<String> note
* The merge's blocks: the app's file (shipped) and the player's sources (CheatSources.blocks), upstream's imported files of this build that are still in
* imported/ (each as a source of its own, by its file name), then the mods' files; textEnd as CheatFile.parse takes it
*/
static List<CheatSources.Block> blocks(String shipped, File folder, String build, List<ModFile> mods, long textEnd) {
static List<CheatSources.Block> blocks(String shipped, File folder, MncfBuild.Game g, List<ModFile> mods, long textEnd, boolean make) {
Boolean appOn = CheatSources.appEnabled(folder);
List<CheatSources.Block> blocks = CheatSources.blocks(folder, shipped, appOn == null || appOn, build, textEnd);
List<CheatSources.Block> blocks = CheatSources.blocks(folder, shipped, appOn == null || appOn, g, textEnd, make);
String build = g.build;
try {
for (Cheats.Named n : Cheats.importedOf(folder, build)) blocks.add(new CheatSources.Block(IMPORTED + n.label, n.label, true, CheatFile.parse(n.text, textEnd)));
} catch (IOException e) { /* an imported file that cannot be read: left out, as a source's */ }
Expand Down Expand Up @@ -131,10 +137,18 @@ static void legacyKeys(Set<String> on, List<CheatSources.Source> moved, CheatSou
* added to: the cheats a mod's own .enabled names, the first time they enter the list, and an earlier import's renamed keys (the caller keeps on when it grew)
*/
static List<Cheats.Entry> install(File shipped, File folder, String build, Set<String> on, List<File> modCheatDirs, List<String> notes) throws IOException {
return install(shipped, folder, build, on, modCheatDirs, notes, new MncfConvert.Known(folder.getName(), null, null, null, null, null), new MncfBuild.Game(folder.getName(), build, null, null));
}

/** The same; known: what a conversion of an earlier file knows (CheatsBridge.known), g: the game for the .mncf sources (its pack: the game's own main) */
static List<Cheats.Entry> install(File shipped, File folder, String build, Set<String> on, List<File> modCheatDirs, List<String> notes, MncfConvert.Known known, MncfBuild.Game g) throws IOException {
List<ModFile> mods = of(modCheatDirs, build, notes);
List<CheatSources.Source> moved = CheatSources.migrate(folder, System.currentTimeMillis());
List<CheatSources.Source> moved = CheatSources.migrate(folder, System.currentTimeMillis(), known);
CheatSources.upgrade(folder, known);
String s = shipped != null ? new String(Files.readAllBytes(shipped.toPath()), StandardCharsets.UTF_8) : "";
CheatSources.Merged m = CheatSources.merge(blocks(s, folder, build, mods, -1), dev.peanuts.mods.CheatValues.read(folder)); // with the numbers set in the game's Mods tab
List<CheatSources.Block> blocks = blocks(s, folder, g, mods, -1, true);
if (notes != null) for (CheatSources.Block b : blocks) if (b.error != null) notes.add("the cheat file of " + b.name + " cannot be used (" + b.error + ")");
CheatSources.Merged m = CheatSources.merge(blocks, dev.peanuts.mods.CheatValues.read(folder)); // with the numbers set in the game's Mods tab
legacyKeys(on, moved, m);
if (!folder.isDirectory() && !folder.mkdirs()) throw new IOException("cannot create " + folder);
File[] old = folder.listFiles((d, n) -> n.endsWith(".txt") || n.endsWith(".enabled"));
Expand Down
72 changes: 70 additions & 2 deletions android/app/src/main/java/dev/peanuts/mods/CheatFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ private CheatFile() {}

public static final int NAME_MAX = 127; // a header's name, as the host cuts it (CHEAT_NAME_MAX)

/** A number the player sets for a cheat (the in-game Mods tab's field): the file's own, the range, and the cheat's code lines for a number */
public interface Number {
long own();
long min();
long max();
/** Shown after the number ("coins"), null for none */
String unit();
/** The cheat's code lines writing v (v inside min and max); null when it cannot be written */
List<String> lines(long v);
}

/** What a cheat does, from its opcodes. label: the chip's word */
public enum Kind {
CODE("Code"), DATA("Data"), VALUE("Value"), UNSUPPORTED("Not supported");
Expand All @@ -54,15 +65,25 @@ public static final class Cheat {
public final boolean pointers; // reads a pointer chain (opcode 5)
public final int valueWord, valueWidth; // Value: the index of the number's first word in words, and its width in bytes; else -1, 0
public final long[] words;
public final MncfBuild.Cheat mncf; // the .mncf cheat this one is, for the build that runs (MncfBuild); null for a cheat of an Atmosphère file
public final Number number; // the number the player sets in the in-game tab (Part F's field), null when it has none

Cheat(String name, String key, String group, boolean master, List<String> lines, long[] words, Shape s) { this(name, key, group, master, lines, words, s, null, null); }

Cheat(String name, String key, String group, boolean master, List<String> lines, long[] words, Shape s) {
Cheat(String name, String key, String group, boolean master, List<String> lines, long[] words, Shape s, MncfBuild.Cheat mncf, MncfBuild.Ready ready) {
this.name = name; this.key = key; this.group = group; this.master = master; this.lines = Collections.unmodifiableList(lines); this.words = words;
kind = s.kind; hold = Collections.unmodifiableList(s.hold); why = s.why; codePlaces = s.codePlaces; pointers = s.pointers;
valueWord = s.valueWord; valueWidth = s.valueWidth;
this.mncf = mncf;
if (mncf != null && mncf.value != null && ready != null && !mncf.refused()) number = CheatValues.mncf(ready, mncf, lines);
else number = CheatValues.plainValue(this) ? CheatValues.atmosphere(this) : null;
}

public boolean switchable() { return !master && kind != Kind.UNSUPPORTED; }

/** The .mncf reason it cannot run here (Appendix B, or runtime:&lt;why&gt;), null for one that can and for an Atmosphère cheat */
public String reason() { return mncf == null ? null : mncf.reason; }

/** The hold chip's words: "Hold ZL", "Hold B or ZL"; null without a key-press condition */
public String holdLabel() { return hold.isEmpty() ? null : "Hold " + String.join(" or ", hold); }

Expand All @@ -86,6 +107,7 @@ public static final class Parsed {
public final List<String> restores = new ArrayList<>(); // the hidden "Restore Code" entries
public final List<String> titles = new ArrayList<>(); // the file's title labels (TID=, BID=)
public String build; // a first line "build <ID>": its first 16 hex digits, upper case; else null
public MncfBuild.Ready mncf; // the .mncf file these cheats are of, made ready for the build (MncfBuild); null for an Atmosphère file

/** The cheats a player may switch (not the Not supported ones) */
public int switchable() { int n = 0; for (Cheat c : cheats) if (c.switchable()) n++; return n; }
Expand Down Expand Up @@ -223,6 +245,44 @@ public static Parsed parse(String text, long textEnd) {
return p;
}

/**
* An .mncf file made ready for the build (MncfBuild.Ready) as the page and the tab read a file: its cheats in the file's order with their groups, their
* Atmosphère code for this build (kind and hold buttons from it, as for any file), the refused ones as Not supported with their reason; masters apart;
* the file's authors as its credit. Names are made unique as parse makes them ("Name #2"), so a converted file keeps the keys its Atmosphère file had
*/
public static Parsed fromMncf(MncfBuild.Ready r, long textEnd) {
Parsed p = new Parsed();
p.mncf = r;
if (r.file != null) for (String a : r.file.authors()) p.credits.add(a);
Map<String, Integer> seen = new HashMap<>();
for (MncfBuild.Cheat c : r.cheats) {
String name = c.name.length() > NAME_MAX ? c.name.substring(0, NAME_MAX) : c.name;
int dup = seen.merge(name, 1, Integer::sum) - 1;
String key = dup == 0 ? name : name + " #" + (dup + 1);
List<Long> ws = new ArrayList<>();
for (String l : c.lines) if (codeLine(l)) words(l, ws);
long[] w = new long[ws.size()];
for (int i = 0; i < w.length; i++) w[i] = ws.get(i);
Shape s = c.refused() ? refusedShape(c.reason) : classify(w, textEnd);
String group = c.group;
Cheat x = new Cheat(name, key, group, c.master, new ArrayList<>(c.lines), w, s, c, r);
if (c.master) { // not a switch; a refused one is left out (the cheats that require it say why: requires:<id>)
if (!c.refused()) p.masters.add(x);
continue;
}
p.cheats.add(x);
if (!group.isEmpty() && !p.groups.contains(group)) p.groups.add(group);
}
return p;
}

private static Shape refusedShape(String reason) {
Shape s = new Shape();
s.kind = Kind.UNSUPPORTED;
s.why = reason;
return s;
}

/** No code, or only end / else words (opcode 2): what cheatslips puts under a group heading */
static boolean noop(long[] w) {
for (long x : w) if ((x >>> 28) != 2) return false;
Expand Down Expand Up @@ -369,8 +429,16 @@ static String buttons(long mask) {
/** What a cheat changes, in the player's words, for the bottom screen and its details (no developer terms: UI-RULES 5) */
public static String describe(Cheat c) { return describe(c, c.value()); }

/** The same, a Value cheat writing value (the number set in the in-game Mods tab, CheatValues) */
/** The same, a Value cheat writing value (the number set in the in-game Mods tab, CheatValues); an .mncf cheat's own words (its about) first */
public static String describe(Cheat c, long value) {
if (c.mncf != null && c.mncf.refused()) return MncfWords.reason(c.mncf.reason, c.mncf) + " It stays off.";
String d = describeKind(c, value);
if (c.number != null && c.kind != Kind.VALUE) d += " Its number is " + value + (c.number.unit() == null ? "" : " " + c.number.unit()) + ".";
String about = c.mncf == null || c.mncf.about == null ? null : c.mncf.about.trim();
return about == null || about.isEmpty() ? d : (about.matches(".*[.!?]$") ? about : about + ".") + " " + d;
}

private static String describeKind(Cheat c, long value) {
String hold = c.hold.isEmpty() ? null : String.join(" or ", c.hold);
switch (c.kind) {
case UNSUPPORTED:
Expand Down
Loading