コード例 #1
0
ファイル: CheatEdit.cs プロジェクト: wert23239/BizHawk
        public Cheat GetCheat()
        {
            Cheat.COMPARISONTYPE comparisonType = Cheat.COMPARISONTYPE.NONE;
            var domain  = MemoryDomains[DomainDropDown.SelectedItem.ToString()];
            var address = AddressBox.ToRawInt().Value;

            if (address < domain.Size)
            {
                var watch = Watch.GenerateWatch(
                    MemoryDomains[DomainDropDown.SelectedItem.ToString()],
                    AddressBox.ToRawInt().Value,
                    GetCurrentSize(),
                    Watch.StringToDisplayType(DisplayTypeDropDown.SelectedItem.ToString()),
                    BigEndianCheckBox.Checked,
                    NameBox.Text
                    );

                switch (CompareTypeDropDown.SelectedItem.ToString())
                {
                case "": comparisonType = Cheat.COMPARISONTYPE.NONE; break;

                case "=": comparisonType = Cheat.COMPARISONTYPE.EQUAL; break;

                case ">": comparisonType = Cheat.COMPARISONTYPE.GREATER_THAN; break;

                case ">=": comparisonType = Cheat.COMPARISONTYPE.GREATER_THAN_OR_EQUAL; break;

                case "<": comparisonType = Cheat.COMPARISONTYPE.LESS_THAN; break;

                case "<=": comparisonType = Cheat.COMPARISONTYPE.LESS_THAN_OR_EQUAL; break;

                case "!=": comparisonType = Cheat.COMPARISONTYPE.NOT_EQUAL; break;

                default: comparisonType = Cheat.COMPARISONTYPE.NONE; break;
                }

                int?c = CompareBox.ToRawInt() == null ? null : (int?)CompareBox.ToRawInt().Value;


                return(new Cheat(
                           watch,
                           ValueBox.ToRawInt().Value,
                           CompareBox.ToRawInt() == null ? null : (int?)CompareBox.ToRawInt().Value,
                           true,
                           comparisonType
                           ));
            }
            else
            {
                MessageBox.Show(address.ToString() + " is not a valid address for the domain " + domain.Name, "Index out of range", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(Cheat.Separator);
            }
        }
コード例 #2
0
        public bool Load(string path, bool append)
        {
            var file = new FileInfo(path);

            if (file.Exists == false)
            {
                return(false);
            }

            if (!append)
            {
                _currentFileName = path;
            }

            using (var sr = file.OpenText())
            {
                if (!append)
                {
                    Clear();
                }

                string s;
                while ((s = sr.ReadLine()) != null)
                {
                    try
                    {
                        if (s == "----")
                        {
                            _cheatList.Add(Cheat.Separator);
                        }
                        else
                        {
                            int?compare;
                            var size      = WatchSize.Byte;
                            var type      = DisplayType.Hex;
                            var bigendian = false;
                            Cheat.COMPARISONTYPE comparisonType = Cheat.COMPARISONTYPE.NONE;

                            if (s.Length < 6)
                            {
                                continue;
                            }

                            var vals    = s.Split('\t');
                            var address = int.Parse(vals[0], NumberStyles.HexNumber);
                            var value   = int.Parse(vals[1], NumberStyles.HexNumber);

                            if (vals[2] == "N")
                            {
                                compare = null;
                            }
                            else
                            {
                                compare = int.Parse(vals[2], NumberStyles.HexNumber);
                            }

                            var domain  = Global.Emulator.AsMemoryDomains()[vals[3]];
                            var enabled = vals[4] == "1";
                            var name    = vals[5];

                            // For backwards compatibility, don't assume these values exist
                            if (vals.Length > 6)
                            {
                                size      = Watch.SizeFromChar(vals[6][0]);
                                type      = Watch.DisplayTypeFromChar(vals[7][0]);
                                bigendian = vals[8] == "1";
                            }

                            // For backwards compatibility, don't assume these values exist
                            if (vals.Length > 9)
                            {
                                if (!Enum.TryParse <Cheat.COMPARISONTYPE>(vals[9], out comparisonType))
                                {
                                    continue;                                     //Not sure if this is the best answer, could just resort to ==
                                }
                            }

                            var watch = Watch.GenerateWatch(
                                domain,
                                address,
                                size,
                                type,
                                bigendian,
                                name);

                            Add(new Cheat(watch, value, compare, !Global.Config.DisableCheatsOnLoad && enabled, comparisonType));
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }

            Changes = false;
            return(true);
        }