Example #1
0
        static void Main(string[] args)
        {
            romNames = new Dictionary<Mother3Version, string>()
            {
                [Mother3Version.Japanese] = "mother3_jp",
                [Mother3Version.English10] = "mother3_en_v10",
                [Mother3Version.English11] = "mother3_en_v11",
                [Mother3Version.English12] = "mother3_en_v12"
            };

            Mother3Version currentVersion = Mother3Version.English12;

            ByteArraySource source = new ByteArraySource(romNames[currentVersion] + ".gba");

            RomSettings settings;
            if (currentVersion == Mother3Version.Japanese)
            {
                settings = new RomSettings(Path.Combine("Settings", romNames[currentVersion] + ".json"));
            }
            else
            {
                settings = new RomSettings(Path.Combine("Settings", "mother3_jp.json"),
                    Path.Combine("Settings", romNames[currentVersion] + ".json"));
            }

            Mother3Rom rom = new Mother3Rom(source, settings);

            TextModule text = new TextModule(rom);
            text.WriteModule(romNames[currentVersion]);
        }
Example #2
0
        public TextModule(Mother3Rom rom)
        {
            // Text bank
            ReadTextBank(rom);

            // Main script
            ReadMainScript(rom);
        }
Example #3
0
 protected StringReader(Mother3Rom rom)
 {
     controlCodes = rom.Settings.ControlCodes;
     if (controlCodes == null)
     {
         throw new Exception("The control codes collection is null");
     }
 }
        public EnglishStringReader(Mother3Rom rom) : base(rom)
        {
            charLookup = rom.Settings.CharLookup;
            if (charLookup == null)
            {
                throw new Exception("The character lookup is null");
            }

            encodingParameters = rom.Settings.ScriptEncoding;
        }
Example #5
0
        private void ReadItems(Mother3Rom rom)
        {
            IMother3Reader reader = new Mother3Reader(rom);

            TableInfo info = rom.Settings.DataTables["Items"];
            reader.Position = info.Address;

            Items = new List<Item>();
            for (int i = 0; i < info.Count; i++)
                Items.Add(reader.ReadItem());
        }
        public Mother3Reader(Mother3Rom rom)
        {
            reader = new GbaReader(rom.Source);
            this.rom = rom;

            switch (rom.Settings.Version)
            {
                case Mother3Version.Japanese:
                case Mother3Version.None:
                case Mother3Version.Invalid:
                    stringReader = new JapaneseStringReader(rom);
                    break;

                case Mother3Version.English10:
                case Mother3Version.English11:
                case Mother3Version.English12:
                    stringReader = new EnglishStringReader(rom);
                    break;

                default:
                    throw new Exception("Unrecognized ROM version");
            }
        }
Example #7
0
 public DataModule(Mother3Rom rom)
 {
     ReadItems(rom);
 }
Example #8
0
        private void ReadTextBank(Mother3Rom rom)
        {
            Mother3Reader reader = new Mother3Reader(rom);
            reader.Position = rom.Settings.BankAddresses["TextTable"];
            int[] pointers = reader.ReadOffsetTable();

            RoomDescriptions = ReadOffsetText(rom, pointers[0], pointers[1], false);
            ItemNames = ReadTableText(rom, pointers[2]);
            ItemDescriptions = ReadOffsetText(rom, pointers[3], pointers[4], false);
            CharacterNames = ReadTableText(rom, pointers[5]);
            PartyCharacterNames = ReadTableText(rom, pointers[6]);
            EnemyNames = ReadTableText(rom, pointers[7], bugContext: 1);
            PsiNames = ReadTableText(rom, pointers[8]);
            PsiDescriptions = ReadOffsetText(rom, pointers[9], pointers[10], false);
            Statuses = ReadTableText(rom, pointers[11]);
            DefaultNames = ReadTableText(rom, pointers[12]);
            SpecialText = ReadTableText(rom, pointers[13]);
            SkillDescriptions = ReadOffsetText(rom, pointers[14], pointers[15], false);
        }
Example #9
0
        private Dictionary<int, string> ReadTableText(Mother3Rom rom, int offset, int bugContext = 0)
        {
            if (offset == 0)
            {
                return null;
            }

            Mother3Reader reader = new Mother3Reader(rom);
            reader.Position = offset;

            FixedTableHeader header = reader.ReadFixedTableHeader();

            if (bugContext == 1)
            {
                // Bug in English versions 1.0 through 1.2 -- one of the entries is
                // missing from the table, so the header's entry count is too high by one
                switch (rom.Settings.Version)
                {
                    case Mother3Version.English10:
                    case Mother3Version.English11:
                    case Mother3Version.English12:
                        header = new FixedTableHeader(header.EntryLength, header.Count - 1);
                        break;
                }
            }

            Dictionary<int, string> text = new Dictionary<int, string>();

            for (int i = 0; i < header.Count; i++)
            {
                text.Add(i, reader.ReadCodedString(header.EntryLength));
            }

            return text;
        }
Example #10
0
        private Dictionary<int, string> ReadOffsetText(Mother3Rom rom, int tableOffset, int textOffset, bool dialog)
        {
            Mother3Reader reader = new Mother3Reader(rom);

            reader.Position = tableOffset;
            int[] pointers = reader.ReadMiniOffsetTable(textOffset);

            Dictionary<int, string> text = new Dictionary<int, string>();

            for (int i = 0; i < pointers.Length; i++)
            {
                reader.Position = pointers[i];

                if (pointers[i] != 0)
                {
                    if (dialog)
                    {
                        text.Add(i, reader.ReadDialogString());
                    }
                    else
                    {
                        text.Add(i, reader.ReadCodedString());
                    }
                }
            }

            return text;
        }
Example #11
0
        private void ReadMainScript(Mother3Rom rom)
        {
            // The main script is technically part of the map bank, but it makes more sense here
            Mother3Reader reader = new Mother3Reader(rom);
            reader.Position = rom.Settings.BankAddresses["Maps.MainScript"];
            int[] pointers = reader.ReadOffsetTable();

            MainScript = new Dictionary<int, Dictionary<int, string>>();

            int entryCount = pointers.Length / 2;

            Parallel.For(0, entryCount, parallelOptions, i =>
            {
                int miniOffsetPointer = pointers[i * 2];
                int textPointer = pointers[i * 2 + 1];

                if (miniOffsetPointer != 0 && textPointer != 0)
                {
                    MainScript.Add(i, ReadOffsetText(rom, miniOffsetPointer, textPointer, true));
                }
            });

            // Attempt to order the script entries (they'll be out of order due to the threading)
            var list = MainScript.ToList();
            list.Sort((a, b) => a.Key.CompareTo(b.Key));
            MainScript = list.ToDictionary(kv => kv.Key, kv => kv.Value);
        }
 public JapaneseStringReader(Mother3Rom rom) : base(rom)
 {
     charLookup = rom.Settings.CharLookup;
 }