示例#1
0
            public unsafe void Save(string path, byte[] src)
            {
                if (path == null)
                {
                    path = this._ROMPath;
                }
                ushort num = (ushort)510;

                if (this._ROMType != SNES.ROMFile.ROMTypes.LoROM)
                {
                    if (this._ROMType != SNES.ROMFile.ROMTypes.SuperFX)
                    {
                        goto label_11;
                    }
                }
                for (int index = 0; index < 32732; ++index)
                {
                    num += (ushort)src[index];
                }
                for (int index = 32736; index < src.Length; ++index)
                    num += (ushort)src[index];
                fixed(byte *numPtr = &src[32732])
                * (int *)numPtr = (int)num << 16 | (int)num ^ (int)ushort.MaxValue;

label_11:
                try
                {
                    FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);
                    if ((int)this._HasHeader != 0)
                    {
                        fileStream.Write(this._HeaderBuf, 0, 512);
                    }
                    fileStream.Write(src, 0, src.Length);
                    fileStream.Close();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    this._LastError = SNES.ROMFile.LastErrors.CouldntOpenROMForWriting;
                    throw new SNES.ROMFile.UnableToWriteException();
                }
                this._ROMBuf[0].CopyFrom(src, 0, src.Length);
            }
示例#2
0
            public unsafe bool Open(string path)
            {
                if (!File.Exists(path))
                {
                    this._LastError = SNES.ROMFile.LastErrors.CouldntOpenROMForReading;
                    return(false);
                }
                else
                {
                    try
                    {
                        byte[] source = File.ReadAllBytes(path);
                        int    num1   = 0;
                        int    num2   = 0;
                        switch (source.Length & (int)short.MaxValue)
                        {
                        case 0:
                            num2 += 3;
                            break;

                        case 512:
                            num1 += 2;
                            break;
                        }
                        uint num3 = 0U;
                        for (int index = 0; index < 512; ++index)
                        {
                            num3 += (uint)source[index];
                        }
                        if (num3 < 2500U)
                        {
                            num1 += 2;
                        }
                        int[] numArray = new int[4];
                        int   num4     = 0;
                        fixed(byte *numPtr = source)
                        {
                            int num5 = numArray[0] = this.ROMTypeScore(numPtr + 32704);

                            if (num5 < (numArray[1] = this.ROMTypeScore(numPtr + 65472)))
                            {
                                num5 = numArray[1];
                                num4 = 1;
                            }
                            if (num5 < (numArray[2] = this.ROMTypeScore(numPtr + 33216)))
                            {
                                num5 = numArray[2];
                                num4 = 2;
                            }
                            if (num5 < (numArray[3] = this.ROMTypeScore(numPtr + 65984)))
                            {
                                num4 = 3;
                            }
                        }
                        if (num4 >= 2)
                        {
                            num1 += 2;
                        }
                        this._HasHeader = num1 > num2 ? (ushort)512 : (ushort)0;
                        if ((int)this._HasHeader != 0)
                        {
                            Array.Copy((Array)source, (Array)this._HeaderBuf, 512);
                        }
                        this._ROMType = numArray[(int)this._HasHeader == 0 ? 1 : 3] > numArray[(int)this._HasHeader == 0 ? 0 : 2] ? SNES.ROMFile.ROMTypes.HiROM : SNES.ROMFile.ROMTypes.LoROM;
                        uint num6 = (uint)(1 << (int)source[(this.AddressSNEStoPC(65495U) + (uint)this._HasHeader)] + 10);
                        if (num6 < 524288U || 4194304U < num6)
                        {
                            throw new SNES.ROMFile.InvalidROMException();
                        }
                        uint num7 = (uint)source.Length - (uint)this._HasHeader;
                        if (num7 > num6)
                        {
                            throw new SNES.ROMFile.InvalidROMException();
                        }
                        this._ROMBuf = new VariableByte[num6];
                        this.ROM[0].CopyFrom(source, (int)this._HasHeader, (int)num7);
                        if (this._ROMType == SNES.ROMFile.ROMTypes.LoROM)
                        {
                            if (((int)this.ROM[32726].u8 & 240) == 16)
                            {
                                this._ROMType = SNES.ROMFile.ROMTypes.SuperFX;
                                if (num6 > 2097152U)
                                {
                                    throw new SNES.ROMFile.InvalidROMException();
                                }
                            }
                        }
                    }
                    catch (SNES.ROMFile.InvalidROMException ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        this._LastError = SNES.ROMFile.LastErrors.InvalidROM;
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        this._LastError = SNES.ROMFile.LastErrors.Exception;
                        return(false);
                    }
                    this._ROMPath = path;
                    return(true);
                }
            }