示例#1
0
        public bool ApplyGameGenie(out byte[] gameFileData)
        {
            gameFileData = null;
            if (!string.IsNullOrEmpty(GameGenie))
            {
                var    codes        = GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
                string gameFilePath = GameFilePath;
                if (gameFilePath != null)
                {
                    gameFilePath = gameFilePath.ToLower();
                    byte[] data   = null;
                    int    offset = 0;
                    if (gameFilePath.Contains(".sfrom"))
                    {
                        data   = GameFileData;
                        offset = 48;
                    }
                    else if (gameFilePath.Contains(".sfc") || gameFilePath.Contains(".smc"))
                    {
                        data = GameFileData;
                        if ((data.Length % 1024) != 0)
                        {
                            offset = 512;
                        }
                        else
                        {
                            offset = 0;
                        }
                    }

                    if (data != null)
                    {
                        byte[] rawData = new byte[data.Length - offset];
                        Array.Copy(data, offset, rawData, 0, rawData.Length);

                        foreach (var code in codes)
                        {
                            rawData = GameGeniePatcherSnes.Patch(rawData, code);
                        }

                        Array.Copy(rawData, 0, data, offset, rawData.Length);
                        gameFileData = data;
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#2
0
        public void ApplyGameGenie()
        {
            if (!string.IsNullOrEmpty(GameGenie))
            {
                var codes    = GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
                var nesFiles = Directory.GetFiles(this.GamePath, "*.*", SearchOption.TopDirectoryOnly);
                foreach (var f in nesFiles)
                {
                    byte[] data;
                    var    ext = Path.GetExtension(f).ToLower();
                    int    offset;
                    if (ext == ".sfrom")
                    {
                        data   = File.ReadAllBytes(f);
                        offset = 48;
                    }
                    else if (ext == ".sfc" || ext == ".smc")
                    {
                        data = File.ReadAllBytes(f);
                        if ((data.Length % 1024) != 0)
                        {
                            offset = 512;
                        }
                        else
                        {
                            offset = 0;
                        }
                    }
                    else
                    {
                        continue;
                    }

                    var rawData = new byte[data.Length - offset];
                    Array.Copy(data, offset, rawData, 0, rawData.Length);

                    foreach (var code in codes)
                    {
                        rawData = GameGeniePatcherSnes.Patch(rawData, code);
                    }

                    Array.Copy(rawData, 0, data, offset, rawData.Length);
                    File.WriteAllBytes(f, data);
                }
            }
        }