diff --git a/tests/launcher_test.py b/tests/launcher_test.py index 7695910f..28ae1933 100644 --- a/tests/launcher_test.py +++ b/tests/launcher_test.py @@ -5981,6 +5981,18 @@ class ModsTest(Tmp): cheat.write_text('[Moon jump]\n04000000 00000000 D65F03C0\n') self.assertEqual(self.mods.code_waiting(self.game), ['Cheats']) # edited since + def test_code_cheats_take_mains_base_from_the_layout(self): + """recomp/layout.py alone decides the modules' bases: tools/cheats.py decodes main's pc-relative code at the + base the layout gives main, the first module of its order, and follows it when it changes.""" + import importlib + import cheats + import layout + self.assertEqual(layout.ORDER[0], 'main') + self.assertEqual(cheats.BASE, layout.FIRST_BASE) + self.addCleanup(importlib.reload, cheats) + with mock.patch.object(layout, 'FIRST_BASE', 0x7100000000): + self.assertEqual(importlib.reload(cheats).BASE, 0x7100000000) + def test_the_mods_code_is_in_the_lift_key_and_not_the_shaders_key(self): import make_game kit = self.tmp / 'kit' diff --git a/tools/cheats.py b/tools/cheats.py index db0c9c58..dca459a7 100644 --- a/tools/cheats.py +++ b/tools/cheats.py @@ -40,11 +40,12 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'recomp')) sys.path.insert(0, str(Path(__file__).resolve().parent)) import flags # noqa: E402 +from layout import FIRST_BASE # noqa: E402 from lifter import Lifter, Unsupported # noqa: E402 from nso import Nso # noqa: E402 from mod_files import cheat_files # noqa: E402 -BASE = 0x7000000000 # main's base in the layout (recomp/layout.py); only pc-relative decoding sees it +BASE = FIRST_BASE # main's base: recomp/layout.py lays main out first (ORDER); only pc-relative decoding sees it NOP = 0xD503201F RET = 0xD65F03C0