public Wrapper(int id, int memory_location, byte[] data)
 {
     this.id = id;
     this.memory_location = memory_location;
     this.content         = StructUtils.FromBytes <T>(data);
 }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //Utils.Shuffle<BattleWrapper>(allBattles);
            if (randomizebattles.IsChecked.Value)
            {
                float mixedchance = 0;
                if (mixedbots.IsChecked.Value)
                {
                    mixedchance = (float)(mixedslider.Value / 100);
                }
                bool keep_team_structure    = keepstructure.IsChecked.Value;
                bool balanced_medal_level   = balancedlevels.IsChecked.Value;
                bool keep_battle_continuity = battlecontinuity.IsChecked.Value;
                randomizer.RandomizeBattles(keep_team_structure, balanced_medal_level, mixedchance, keep_battle_continuity);
            }
            if (randomizecharacters.IsChecked.Value)
            {
                bool continuity = continuitycheck.IsChecked.Value;
                randomizer.RandomizeCharacters(continuity);
            }
            int amount_of_battles = 0xf5;
            int battle_size       = 0x28;

            for (int i = 0; i <= amount_of_battles; i++)
            {
                int    battle_address = Utils.GetAdressAtPosition(file, memory_offsets[game_id]["Battles"] + 4 * i);
                byte[] battle         = StructUtils.getBytes(allBattles[i].content);
                //byte[] battle = randomizer.GenerateRandomBattle(false).getBytes();
                Array.Copy(battle, 0, file, battle_address, battle_size);
            }
            if (shouldPatch.IsChecked.Value)
            {
                uint   jumpOffset    = 0x104;
                uint   hookOffset    = 0x7f3530;
                uint   trainerOffset = 0x7f3600;
                uint   instr1        = (uint)Utils.GetIntAtPosition(file, (int)jumpOffset);
                uint   instr2        = (uint)Utils.GetIntAtPosition(file, (int)jumpOffset + 4);
                uint   instr3        = (uint)Utils.GetIntAtPosition(file, (int)jumpOffset + 8);
                uint[] jumpPayload   = new uint[]
                {
                    0xE92D8000,                         // push r15
                    0xE51FF004,                         // ldr r15, traineraddr
                    0x08000000 + hookOffset             // hookOffset
                };
                uint[] hookPayload = new uint[]
                {
                    0xE92D4000,                         // push r14
                    0xE3A0E402,                         // mov r14, #0x2000000
                    0xE28EE701,                         // add r14, #40000
                    0xE24EE004,                         // sub r14, #28
                    0xE90E08FF,                         // stmdb [r14], r0-r7, r11
                    0xEB00002D,                         // bl trainerfunc
                    0xE3A0E402,                         // mov r14, #0x2000000
                    0xE28EE701,                         // add r14, #40000
                    0xE24EE028,                         // sub r14, #28
                    0xE89E08FF,                         // ldmia [r14], r0-r7, r11
                    0xE8BD4000,                         // pop r14
                    instr1,                             // --- original instruction #1 ---
                    instr2,                             // --- original instruction #2 ---
                    instr3,                             // --- original instruction #3 ---
                    0xE8BD8000                          // pop r15
                };
                uint[] trainerPayload = new uint[]
                {
                    // Set text_speed to instant
                    0xE3A01403,                         // mov r1, #0x3000000
                    0xE3A000FF,                         // mov r0, #0xFF
                    0xE5C1045A,                         // strb r0, [r1, #0x45A]
                    // Return
                    0xE12FFF1E                          // bx r15
                };
                Dictionary <uint, ushort> codePatches = new Dictionary <uint, ushort>
                {
                    // Instant Character Popup
                    { 0x3F5F6, 0x3008 },
                    { 0x3F600, 0xDC08 }
                };
                WritePayload(file, jumpOffset, jumpPayload);
                WritePayload(file, hookOffset, hookPayload);
                WritePayload(file, trainerOffset, trainerPayload);
                WritePatches(file, codePatches);
            }

            byte[] blacklist = new byte[] { 1, 3, 6, 7, 8,
                                            14, 15, 17, 18,
                                            19, 20, 22, 23,
                                            25, 26, 27, 28,
                                            39, 40, 45, 50,
                                            57, 66, 72, 75,
                                            77, 80, 81, 82,
                                            84, 90, 91, 92,
                                            96, 100, 101, 104,
                                            110, 115, 117, 118 };

            if (randomizeStarter.IsChecked.Value)
            {
                byte randomBot = (byte)new Random().Next(0, 0x78);
                while (blacklist.Contains(randomBot))
                {
                    randomBot = (byte)new Random().Next(0, 0x78);
                }
                int offset = memory_offsets[game_id]["Starter"];
                for (int i = 0; i < 4; i++)
                {
                    file[offset + 4 * i] = randomBot;
                }
                if (IdTranslator.isFemale(randomBot))
                {
                    file[offset + 16] = 1;
                }
                file[memory_offsets[game_id]["Equipped"]]       = randomBot;
                file[memory_offsets[game_id]["Equipped"] + 0xE] = (byte)(randomBot * 2 + 1);
            }

            File.WriteAllBytes("randomized.gba", file);
        }