Ejemplo n.º 1
0
        public CheatDetailsForm(Cheat cheat, bool isNew)
        {
            InitializeComponent();

            this.cheat = cheat;
            this.isNew = isNew;
        }
Ejemplo n.º 2
0
        public static Cheat ParseGameGenieCode(string gameGenieCode)
        {
            if (!IsValidGameGenieCode(gameGenieCode))
            {
                return(null);
            }

            byte[] nybbles = new byte[gameGenieCode.Length];
            for (int index = 0; index < gameGenieCode.Length; index++)
            {
                nybbles[index] = gameGenieCharToNybble[gameGenieCode[index]];
            }

            Cheat newCheat = new Cheat();

            newCheat.Address = DecodeGameGenieCodeAddress(nybbles);

            if (gameGenieCode.Length == 6)
            {
                newCheat.Value = (byte)(((nybbles[1] & 7) << 4) | ((nybbles[0] & 8) << 4) | (nybbles[0] & 7) | (nybbles[5] & 8));
            }
            else // 8
            {
                newCheat.Value           = (byte)(((nybbles[1] & 7) << 4) | ((nybbles[0] & 8) << 4) | (nybbles[0] & 7) | (nybbles[7] & 8));
                newCheat.CompareValue    = (byte)(((nybbles[7] & 7) << 4) | ((nybbles[6] & 8) << 4) | (nybbles[6] & 7) | (nybbles[5] & 8));
                newCheat.NeedsComparison = true;
            }

            newCheat.Description = "Game Genie Code: " + gameGenieCode;

            return(newCheat);
        }
Ejemplo n.º 3
0
        private void OnValidatingGameGenieCode(object sender, CancelEventArgs cancelEventArgs)
        {
            string gameGenieCode = gameGenieCodeTextBox.Text.Trim().ToUpper();

            if (gameGenieCode.Length > 0 && !Cheat.IsValidGameGenieCode(gameGenieCode))
            {
                errorProvider.SetError(gameGenieCodeTextBox, "Invalid Game Genie code");
                cancelEventArgs.Cancel = true;
            }
        }
Ejemplo n.º 4
0
        public bool AddCheat(Cheat cheat)
        {
            if (cheats.ContainsKey(cheat.Address))
            {
                MessageBox.Show("A cheat is already patched at address: " + Hex.Format(cheat.Address), "Add Cheat", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            cheats[cheat.Address] = cheat;
            PatchCheats();
            return(true);
        }
Ejemplo n.º 5
0
        private void OnCheatNewManualEntry(object sender, EventArgs eventArgs)
        {
            Cheat            newCheat         = new Cheat();
            CheatDetailsForm cheatDetailsForm = new CheatDetailsForm(newCheat, true);

            if (cheatDetailsForm.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            cheatSystem.AddCheat(newCheat);

            UpdateCheatListBox();
        }
Ejemplo n.º 6
0
        public void PatchCheats()
        {
            if (oldProcessorReadByte != null)
            {
                UnpatchCheats();
            }

            this.oldProcessorReadByte = processor.ReadByte;

            processor.ReadByte = (address) =>
            {
                // check for patched cheat at givne address
                Cheat cheat = null;
                cheats.TryGetValue(address, out cheat);

                // if no cheat, just go through
                if (cheat == null)
                {
                    return(oldProcessorReadByte(address));
                }

                // if cheat not active, just go through
                if (!cheat.Active)
                {
                    return(oldProcessorReadByte(address));
                }

                // if cheat is substitute only, apply substitution
                if (!cheat.NeedsComparison)
                {
                    return(cheat.Value);
                }

                // otherwise, compare unpatched value before applying
                byte unpatchedValue = oldProcessorReadByte(address);
                if (cheat.CompareValue == unpatchedValue)
                {
                    return(cheat.Value);
                }
                else
                {
                    return(unpatchedValue);
                }
            };
        }
Ejemplo n.º 7
0
        public void Load(string filename)
        {
            string[] lines = null;
            try
            {
                lines = File.ReadAllLines(filename);
            }
            catch (Exception exception)
            {
                MessageBox.Show(
                    "Unable to load cheat file. Reason: " + exception.Message,
                    "Load Cheat File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            cheats.Clear();
            foreach (string line in lines)
            {
                try
                {
                    string trimmedLine = line.Trim();
                    if (trimmedLine == "" ||
                        trimmedLine.StartsWith("//") ||
                        trimmedLine.StartsWith("#"))
                    {
                        continue;
                    }

                    Cheat cheat = Cheat.Parse(trimmedLine);
                    cheats[cheat.Address] = cheat;
                }
                catch (Exception exception)
                {
                    MessageBox.Show(
                        "Unable to parse line:\r" + line + "\rReason: " + exception.Message,
                        "Load Cheat File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (cheats.Count > 0)
            {
                PatchCheats();
            }
        }
Ejemplo n.º 8
0
        private void OnCreateCheatMenuItem(object sender, EventArgs eventArgs)
        {
            if (resultListBox.SelectedIndex < 0)
            {
                return;
            }

            Cheat newCheat = new Cheat();

            newCheat.Address = Convert.ToUInt16(
                resultListBox.SelectedItem.ToString().Substring(0, 4), 16);
            CheatDetailsForm cheatDetailsForm = new CheatDetailsForm(newCheat, false);

            if (cheatDetailsForm.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            cheatSystem.AddCheat(newCheat);
        }
Ejemplo n.º 9
0
        public bool AddCheat(string gameGenieCode)
        {
            gameGenieCode = gameGenieCode.Trim().ToUpper();

            if (!Cheat.IsValidGameGenieCode(gameGenieCode))
            {
                MessageBox.Show("Invalid Game Genie code", "Add Game Genie Code", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            Cheat gameGenieCheat = Cheat.ParseGameGenieCode(gameGenieCode);

            if (cheats.ContainsKey(gameGenieCheat.Address))
            {
                MessageBox.Show("A cheat is already patched at address: " + Hex.Format(gameGenieCheat.Address), "Add Game Genie Code", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            cheats[gameGenieCheat.Address] = gameGenieCheat;
            PatchCheats();
            return(true);
        }
Ejemplo n.º 10
0
        public static Cheat Parse(string line)
        {
            string[] tokens = line.Split(new char[] { ':' });
            if (tokens.Length < 4 || tokens.Length > 5)
            {
                throw new FormatException(
                          "Cheat must consist of 4 or 5 elements separated by a semicolom");
            }

            for (int index = 0; index < tokens.Length; index++)
            {
                tokens[index] = tokens[index].Trim();
            }

            Cheat cheat = new Cheat();

            string prefix = tokens[0].ToUpper();

            if (prefix != "S" && prefix != "SC")
            {
                throw new FormatException("Unsupported cheat prefix: " + prefix);
            }
            cheat.NeedsComparison = prefix == "SC";

            try
            {
                ushort address = Convert.ToUInt16(tokens[1], 16);
                cheat.Address = address;
            }
            catch (Exception)
            {
                throw new FormatException("Invalid address: " + tokens[1]);
            }

            try
            {
                byte value = Convert.ToByte(tokens[2], 16);
                cheat.Value = value;
            }
            catch (Exception)
            {
                throw new FormatException("Invalid cheat value: " + tokens[2]);
            }

            if (cheat.NeedsComparison)
            {
                try
                {
                    byte compareValue = Convert.ToByte(tokens[3], 16);
                    cheat.CompareValue = compareValue;

                    cheat.Description = tokens[4];
                }
                catch (Exception)
                {
                    throw new FormatException("Invalid compare value: " + tokens[3]);
                }
            }
            else
            {
                cheat.Description = tokens[3];
            }

            return(cheat);
        }