Exemple #1
0
        public ShinyRate()
        {
            InitializeComponent();
            if (Main.ExeFSPath == null)
            {
                WinFormsUtil.Alert("No exeFS code to load."); Close();
            }
            string[] files = Directory.GetFiles(Main.ExeFSPath);
            if (!File.Exists(files[0]) || !Path.GetFileNameWithoutExtension(files[0]).Contains("code"))
            {
                WinFormsUtil.Alert("No .code.bin detected."); Close();
            }
            codebin   = files[0];
            exefsData = File.ReadAllBytes(codebin);
            if (exefsData.Length % 0x200 != 0)
            {
                WinFormsUtil.Alert(".code.bin not decompressed. Aborting."); Close();
            }

            // Load instruction set
            byte[] raw = Core.Properties.Resources.asm_mov;
            for (int i = 0; i < raw.Length; i += 4)
            {
                byte[] data = new byte[2];
                Array.Copy(raw, i + 2, data, 0, 2);
                InstructionList.Add(new Instruction(BitConverter.ToUInt16(raw, i), data));
            }

            // Fetch Offset
            byte[] pattern = { 0x01, 0x50, 0x85, 0xE2, 0x05, 0x00, 0x50, 0xE1, 0xDE, 0xFF, 0xFF, 0xCA };
            offset = Util.IndexOfBytes(exefsData, pattern, 0, 0) - 4;
            if (offset < 0)
            {
                WinFormsUtil.Alert("Unable to find PID Generation routine.", "Closing.");
                Close();
            }
            if (exefsData[offset] != 0x23) // already patched
            {
                uint val         = BitConverter.ToUInt16(exefsData, offset);
                var  instruction = InstructionList.Find(z => z.ArgVal == val);
                if (instruction == null)
                {
                    WinFormsUtil.Alert(".code.bin was modified externally.", "Existing value not loaded.");
                }
                else
                {
                    WinFormsUtil.Alert(".code.bin was already patched for shiny rate.", "Loaded existing value.");
                    NUD_Rerolls.Value = instruction.Value;
                }
                modified = true;
            }
            ChangeRerolls(null, null);

            CheckAlwaysShiny();
        }