コード例 #1
0
        public static byte[] Patch(byte[] data, string code)
        {
            code = code.ToUpper().Trim();
            if (string.IsNullOrEmpty(code))
            {
                return(data);
            }
            if (code.Length != 9 || code[4] != '-')
            {
                throw new GameGenieFormatException(code);
            }
            code = Regex.Replace(code, "[^0-9A-F]", "");
            if (code.Length != 8)
            {
                throw new GameGenieFormatException(code);
            }

            byte value = Convert.ToByte(code.Substring(0, 2), 16);

            code = code.Substring(2);

            var binaryCode = new StringBuilder();

            foreach (char c in code)
            {
                binaryCode.Append(letterValues[c]);
            }
            var decoded = new StringBuilder(new string(' ', binaryCode.Length));

            for (int i = 0; i < binaryCode.Length; i++)
            {
                var c   = codeSeq[i];
                var pos = clearSeq.IndexOf(c);
                decoded[pos] = binaryCode[i];
            }

            SnesGame.SnesRomType romType;
            string gameTitle;

            SnesGame.GetCorrectHeader(data, out romType, out gameTitle);

            UInt32 address = (Convert.ToUInt32(decoded.ToString(), 2)) & 0x3FFFFF;

            if (romType == SnesGame.SnesRomType.LoRom)
            {
                address = address & 0x3FFFF;
            }

            var result = (byte[])data.Clone();

            if (address >= result.Length)
            {
                throw new GameGenieFormatException(code);
            }
            result[address] = value;
            return(result);
        }
コード例 #2
0
 public SnesPresetEditor(SnesGame game)
 {
     InitializeComponent();
     try
     {
         wasCompressed = game.DecompressPossible().Count() > 0;
         if (wasCompressed)
         {
             game.Decompress();
         }
         this.game = game;
         header2   = game.ReadSfromHeader2();
         textBoxPresetID.UnsignedValue = header2.PresetID;
         textBoxExtra.UnsignedValue    = (byte)(header2.Chip);
     }
     catch (Exception ex)
     {
         Tasks.ErrorForm.Show(this, ex);
         Close();
     }
 }
コード例 #3
0
ファイル: SnesPresetEditor.cs プロジェクト: x0rloser/hakchi2
 public SnesPresetEditor(SnesGame game)
 {
     InitializeComponent();
     try
     {
         wasCompressed = game.DecompressPossible().Count() > 0;
         if (wasCompressed)
         {
             game.Decompress();
         }
         this.game            = game;
         header2              = game.ReadSfromHeader2();
         textBoxPresetID.Text = string.Format("{0:X2}{1:X2}", header2.PresetID & 0xFF, (header2.PresetID >> 8) & 0xFF);
         textBoxExtra.Text    = string.Format("{0:X2}", header2.Chip & 0xFF);
     }
     catch (Exception ex)
     {
         Tasks.ErrorForm.Show(this, ex);
         Close();
     }
 }
コード例 #4
0
 public SnesPresetEditor(SnesGame game)
 {
     InitializeComponent();
     try
     {
         wasCompressed = game.DecompressPossible().Count() > 0;
         if (wasCompressed)
         {
             game.Decompress();
         }
         this.game            = game;
         header2              = game.ReadSfromHeader2();
         textBoxPresetID.Text = string.Format("{0:X2}{1:X2}", header2.PresetID & 0xFF, (header2.PresetID >> 8) & 0xFF);
         textBoxExtra.Text    = string.Format("{0:X2}", header2.Chip & 0xFF);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message + ex.StackTrace);
         MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
         Close();
     }
 }