Beispiel #1
0
        private static void WriteCryToStream(Cry cry, MemoryStream stream)
        {
            using (var writer = new BinaryWriter(stream, Encoding.ASCII, true))
            {
                // RIFF header
                writer.Write(Encoding.ASCII.GetBytes("RIFF"));
                writer.Write(0);
                writer.Write(Encoding.ASCII.GetBytes("WAVE"));

                // fmt chunk
                writer.Write(Encoding.ASCII.GetBytes("fmt "));
                writer.Write(16);
                writer.Write((ushort)1);
                writer.Write((ushort)1);
                writer.Write(cry.SampleRate);
                writer.Write(cry.SampleRate);
                writer.Write((ushort)1);
                writer.Write((ushort)8);

                // data chunk
                writer.Write(Encoding.ASCII.GetBytes("data"));
                writer.Write(cry.Data.Length);

                foreach (var sample in cry.Data)
                {
                    writer.Write((byte)(sample + 0x80));
                }


                // fix header
                writer.Seek(4, SeekOrigin.Begin);
                writer.Write((int)writer.BaseStream.Length - 8);
            }
        }
Beispiel #2
0
        private void OnGUI()
        {
            menuX = (Screen.width / 2) - 150;
            GUI.Box(new Rect(menuX, menuY - 30, 300, 30), "");
            toolbar = GUI.Toolbar(new Rect(menuX, menuY - 30, 300, 30), toolbar, toolbarLabels);

            if (toolbar == 0)// CURRENCY
            {
                GUI.Box(new Rect(menuX, menuY, 300, 300), "Currency", GUI.skin.window);

                GUI.Label(new Rect(menuX + 25, menuY + 25, 150, 20), "Entropy:");
                entropyAmount = GUI.TextField(new Rect(menuX + 112.5f, menuY + 25, 75, 25), entropyAmount); // User specified entropy

                GUI.Label(new Rect(menuX + 25, menuY + 50, 150, 20), "Idea:");
                ideaAmount = GUI.TextField(new Rect(menuX + 112.5f, menuY + 50, 75, 25), ideaAmount); // User specified idea

                GUI.Label(new Rect(menuX + 25, menuY + 75, 150, 20), "Darwinium:");
                darwiniumAmount = GUI.TextField(new Rect(menuX + 112.5f, menuY + 75, 75, 25), darwiniumAmount); // User specified darwinium

                GUI.Label(new Rect(menuX + 25, menuY + 100, 150, 20), "D:");
                dAmount = GUI.TextField(new Rect(menuX + 112.5f, menuY + 100, 75, 25), dAmount); // User specified d

                if (GUI.Button(new Rect(menuX + 25, menuY + 140, 250, 30), new GUIContent("Add/Sub Amount", "Add or subtract specified amount to/from respective currency.")))
                {
                    try
                    {
                        if (((Double)PerfectSingleton <Calculator> .instance.bank.a) + (Double.Parse(entropyAmount)) > 0 &&
                            ((Double)PerfectSingleton <Calculator> .instance.bank.b) + (Double.Parse(ideaAmount)) > 0 &&
                            ((Double)PerfectSingleton <Calculator> .instance.bank.c) + (Double.Parse(darwiniumAmount)) > 0 &&
                            ((Double)PerfectSingleton <Calculator> .instance.bank.d) + (Double.Parse(dAmount)) > 0)
                        {
                            PerfectSingleton <Calculator> .instance.bank += new Cry(Double.Parse(entropyAmount), Double.Parse(ideaAmount), Double.Parse(darwiniumAmount), Double.Parse(dAmount));
                        }
                    }
                    catch { }
                }
                else if (GUI.Button(new Rect(menuX + 25, menuY + 175, 250, 30), new GUIContent("Set To Amount", "Set respective currency to specified amount.")))
                {
                    try
                    {
                        Cry setTo = new Cry(
                            Double.Parse(entropyAmount) > 0 ? Double.Parse(entropyAmount) : ((Double)PerfectSingleton <Calculator> .instance.bank.a),
                            Double.Parse(ideaAmount) > 0 ? Double.Parse(ideaAmount) : ((Double)PerfectSingleton <Calculator> .instance.bank.b),
                            Double.Parse(darwiniumAmount) > 0 ? Double.Parse(darwiniumAmount) : ((Double)PerfectSingleton <Calculator> .instance.bank.c),
                            Double.Parse(dAmount) > 0 ? Double.Parse(dAmount) : ((Double)PerfectSingleton <Calculator> .instance.bank.d));
                        PerfectSingleton <Calculator> .instance.bank = setTo;
                    }
                    catch { }
                }
            }

            // Tooltip:
            GUI.Label(new Rect(menuX, menuY + 300, 300, 100), GUI.tooltip);
        }
Beispiel #3
0
        public static void ExportCry(string filename, Cry cry)
        {
            if (cry.Offset == 0)
            {
                return;
            }

            // http://www-mmsp.ece.mcgill.ca/documents/audioformats/wave/wave.html
            // http://soundfile.sapp.org/doc/WaveFormat/
            using (var writer = new BinaryWriter(File.Create(filename)))
            {
                // RIFF header
                writer.Write(Encoding.ASCII.GetBytes("RIFF"));
                // file ID
                writer.Write(0);
                // file size placeholder
                writer.Write(Encoding.ASCII.GetBytes("WAVE"));
                // format
                // fmt chunk
                writer.Write(Encoding.ASCII.GetBytes("fmt "));
                // chunk ID
                writer.Write(16);
                // chunk size, 16 for PCM
                writer.Write((ushort)1);
                // format: 1 = wave_format_pcm
                writer.Write((ushort)1);
                // channel count
                writer.Write(cry.SampleRate);
                // sample rate
                // * 1 * 8 / 8
                writer.Write(cry.SampleRate);
                // SampleRate * NumChannels * BitsPerSample/8
                // * 8 / 8
                writer.Write((ushort)1);
                // NumChannels * BitsPerSample/8
                writer.Write((ushort)8);
                // bits per sample
                // data chunk
                writer.Write(Encoding.ASCII.GetBytes("data"));
                // chunk ID
                writer.Write(cry.Data.Length);
                // chunk size
                foreach (var sample in cry.Data)
                {
                    writer.Write((byte)(sample + 0x80));
                }

                // wave PCM is unsigned unlike GBA PCM which is
                // fix header
                writer.Seek(4, SeekOrigin.Begin);
                writer.Write((int)writer.BaseStream.Length - 8);
            }
        }
Beispiel #4
0
        public static void PlayCry(Cry cry)
        {
            // TODO: we could do this in another thread :O
            if (cry.Offset == 0)
            {
                return;
            }

            using (var stream = new MemoryStream())
            {
                // "save" the cry to a memorystream
                using (var writer = new BinaryWriter(stream, Encoding.ASCII, true))
                {
                    // RIFF header
                    writer.Write(Encoding.ASCII.GetBytes("RIFF"));
                    writer.Write(0);
                    writer.Write(Encoding.ASCII.GetBytes("WAVE"));

                    // fmt chunk
                    writer.Write(Encoding.ASCII.GetBytes("fmt "));
                    writer.Write(16);
                    writer.Write((ushort)1);
                    writer.Write((ushort)1);
                    writer.Write(cry.SampleRate);
                    writer.Write(cry.SampleRate);
                    writer.Write((ushort)1);
                    writer.Write((ushort)8);

                    // data chunk
                    writer.Write(Encoding.ASCII.GetBytes("data"));
                    writer.Write(cry.Data.Length);
                    foreach (var sample in cry.Data)
                    {
                        writer.Write((byte)(sample + 0x80));
                    }

                    // fix header
                    writer.Seek(4, SeekOrigin.Begin);
                    writer.Write((int)writer.BaseStream.Length - 8);
                }

                // play it via a soundplayer
                stream.Seek(0L, SeekOrigin.Begin);


                //using (var player = new SoundPlayer(stream))
                //{
                //    player.Load();
                //    player.Play();
                //}
            }
        }
Beispiel #5
0
        public static Bitmap GetCryImage(Cry cry)
        {
            Bitmap cryImage;

            if (Ini.GetString(MainObject.AppPath + "GBAPGESettings.ini", "Settings", "DisableCryImage", "0") == "1")
            {
                cryImage = new Bitmap(128, 128);
            }
            else
            {
                cryImage = new Bitmap(cry.Data.Length, 128);
                using (var g = Graphics.FromImage(cryImage))
                {
                    for (int i = 1, loopTo = cry.Data.Length - 1; i <= loopTo; i++)
                    {
                        g.DrawLine(Pens.Green, i - 1, 64 + cry.Data[i - 1], i, 64 + cry.Data[i]);
                    }
                }
            }

            return(cryImage);
        }
Beispiel #6
0
        public static bool SaveCry(Cry crytosave, int cryTable)
        {
            if (crytosave.Offset == 0)
            {
                return(false);
            }
            // var lookup = new byte[] { 0x0, 0x1, 0x4, 0x9, 0x10, 0x19, 0x24, 0x31, 0xC0, 0xCF, 0xDC, 0xE7, 0xF0, 0xF7, 0xFC, 0xFF };
            var lookup = new sbyte[] { 0, 1, 4, 9, 16, 25, 36, 49, -64, -49, -36, -25, -16, -9, -4, -1 };

            crytosave.Compressed = false;

            // copy cry data to be written
            var data = new List <byte>();

            if (crytosave.Compressed)
            {
                //Interaction.MsgBox("This should not be enabled!");
                Environment.Exit(0);
            }

            // ' data is compressed in blocks of 1 + 0x20 bytes at a time
            // ' first byte is normal signed PCM data
            // ' following 0x20 bytes are compressed based on previous value
            // ' (for a value not in lookup table, closest value will be chosen instead)
            // 'Console.WriteLine("compressed");

            // ' each block has 0x40 samples
            // Dim blockCount = crytosave.Data.Length / &H40
            // If crytosave.Data.Length Mod &H40 > 0 Then
            // blockCount += 1
            // End If

            // ' truncates the length of the last block
            // ' so we don't waste space
            // Dim lastBlockSize = crytosave.Data.Length - crytosave.Data.Length / &H40 * &H40
            // If lastBlockSize = 0 Then
            // lastBlockSize = &H21
            // Else
            // lastBlockSize = 1 + (lastBlockSize / 2) + (If(lastBlockSize Mod 2 = 0, 0, 1))
            // End If

            // Dim blocks = New Byte(blockCount - 1)() {}
            // For n As Integer = 0 To blockCount - 1
            // ' create new block
            // If n < blockCount - 1 Then
            // blocks(n) = New Byte(32) {}
            // Else
            // blocks(n) = New Byte(lastBlockSize - 1) {}
            // End If

            // Dim i As Integer = n * &H40
            // Dim k As Integer = 0

            // If i < crytosave.Data.Length Then
            // ' set first value
            // blocks(n)(k) = BitConverter.GetBytes(crytosave.Data(i))(0)
            // End If

            // k = k + 1

            // Dim pcm As SByte

            // If i < crytosave.Data.Length Then

            // pcm = crytosave.Data(i)

            // End If

            // i = i + 1

            // Dim j As Integer = 1
            // While j < &H40 And i < crytosave.Data.Length
            // ' get current sample
            // Dim sample As SByte = crytosave.Data(i)

            // i = i + 1

            // ' difference between previous sample and this
            // Dim diff As Integer = sample - pcm

            // ' check for a perfect match in lookup table
            // Dim lookupI = -1
            // For x As Integer = 0 To 15
            // If lookup(x) = diff Then
            // lookupI = x
            // Exit For
            // End If
            // Next

            // ' search for the closest match in the table
            // If lookupI = -1 Then
            // Dim bestDiff As Integer = 255
            // For x As Integer = 0 To 15
            // If Math.Abs(CInt(lookup(x)) - diff) < bestDiff Then
            // lookupI = x
            // bestDiff = Math.Abs(lookup(x) - diff)
            // End If
            // Next
            // End If

            // ' set value in block
            // ' on an odd value, increase position in block
            // If j Mod 2 = 0 Then
            // blocks(n)(k) = blocks(n)(k) Or CByte(lookupI << 4)
            // Else
            // blocks(n)(k) = blocks(n)(k) Or CByte(lookupI)

            // k = k + 1

            // End If

            // ' set previous
            // pcm = sample
            // j += 1
            // End While
            // Next

            // For n As Integer = 0 To blockCount - 1
            // data.AddRange(blocks(n))
            // Next
            else
            {
                // uncompressed, copy directly to data
                // Console.WriteLine("uncompressed");
                foreach (var s in crytosave.Data)
                {
                    data.Add((byte)(s & 0xFF));
                }
            }

            //// determine if cry requires repointing
            //if (crytosave.Size < data.Count)
            //{
            //    var result = MessageBox.Show("The Cry will be written to free space and the pointer will be repointed. Would you like to do that?", "Repoint?", MessageBoxButtons.YesNo);
            //    if (result == DialogResult.Yes)
            //    {
            //        var result2 = MessageBox.Show("Fill the old cry with free space?", "Delete old cry?", MessageBoxButtons.YesNo);
            //        if (result2 == DialogResult.Yes)
            //        {
            //            string argData = Conversions.ToString(MainObject.MakeFreeSpaceString(crytosave.Size + 16));
            //            HexFunctions.WriteHEX(ref MainObject.LoadedRom, ref crytosave.Offset, ref argData);
            //        }

            //        // set new cry offset
            //        crytosave.Offset = (int)modSearchFreeSpace.SearchFreeSpaceFourAligned(MainObject.LoadedRom, 0xFF, data.Count, Conversions.ToLong("&H" + INI.GetString(Conversions.ToString(MainObject.GetIniFileLocation()), MainObject.Header, "StartSearchingForSpaceOffset", "800000")));
            //    }
            //    else
            //    {
            //        return false;
            //    }
            //}

            // write cry


            string LocalReverseHex()
            {
                var argHexData = Strings.Right("0000" + (ushort)(crytosave.Compressed ? 1 : 0), 4); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argData1 = LocalReverseHex();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref crytosave.Offset, ref argData1);
            string LocalReverseHex1()
            {
                var argHexData = Strings.Right("0000" + (ushort)(crytosave.Looped ? 0x4000 : 0), 4); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argStart = crytosave.Offset + 2;
            var argData2 = LocalReverseHex1();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart, ref argData2);
            string LocalReverseHex2()
            {
                var argHexData = Strings.Right("00000000" + (crytosave.SampleRate << 10), 8); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argStart1 = crytosave.Offset + 4;
            var argData3  = LocalReverseHex2();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart1, ref argData3);
            string LocalReverseHex3()
            {
                var argHexData = Strings.Right("00000000" + crytosave.LoopStart, 8); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argStart2 = crytosave.Offset + 8;
            var argData4  = LocalReverseHex3();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart2, ref argData4);
            string LocalReverseHex4()
            {
                var argHexData = Strings.Right("00000000" + (crytosave.Data.Length - 1), 8); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argStart3 = crytosave.Offset + 12;
            var argData5  = LocalReverseHex4();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart3, ref argData5);

            // WriteHEX(LoadedROM, crytosave.Offset, ReverseHEX(VB.Right("0000" & CUShort(If(crytosave.Compressed, 1, 0)), 4)))
            // WriteHEX(LoadedROM, crytosave.Offset + 2, ReverseHEX(VB.Right("0000" & CUShort(If(crytosave.Looped, &H4000, 0)), 4)))
            // WriteHEX(LoadedROM, crytosave.Offset + 4, ReverseHEX(VB.Right("00000000" & (crytosave.SampleRate << 10), 8)))
            // WriteHEX(LoadedROM, crytosave.Offset + 8, ReverseHEX(VB.Right("00000000" & (crytosave.LoopStart), 8)))
            // WriteHEX(LoadedROM, crytosave.Offset + 12, ReverseHEX(VB.Right("00000000" & (crytosave.Data.Length - 1), 8)))

            var tempbuff  = ByteFunctions.ByteArrayToHexString(data.ToArray());
            var argStart4 = crytosave.Offset + 16;

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart4, ref tempbuff);

            // write cry table entry

            // WriteHEX(LoadedROM, cryTable + (crytosave.Index * 12), ReverseHEX(If(crytosave.Compressed, "00003C20", "00003C00")))
            // WriteHEX(LoadedROM, cryTable + (crytosave.Index * 12) + 4, ReverseHEX(VB.Right("00000000" & Hex(crytosave.Offset), 8)))
            // WriteHEX(LoadedROM, cryTable + (crytosave.Index * 12) + 8, "FF00FF")


            // rom.WriteUInt16(CUShort(If(Cry.Compressed, 1, 0)))
            // rom.WriteUInt16(CUShort(If(Cry.Looped, &H4000, 0)))
            // rom.WriteInt32(Cry.SampleRate << 10)
            // rom.WriteInt32(Cry.LoopStart)
            // rom.WriteInt32(Cry.Data.Length - 1)
            // rom.WriteBytes(data.ToArray())

            // ' write cry table entry
            // rom.Seek(cryTable + Cry.Index * 12)
            // rom.WriteUInt32(If(Cry.Compressed, &H3C20UI, &H3C00UI))
            // rom.WritePointer(Cry.Offset)
            // rom.WriteUInt32(&HFF00FFUI)

            // ' write growl table entry
            // rom.Seek(growlTable + Cry.Index * 12)
            // rom.WriteUInt32(If(Cry.Compressed, &H3C30UI, &H3C00UI))
            // ' !!! not sure if 00 should be used for uncompressed
            // rom.WritePointer(Cry.Offset)
            // rom.WriteUInt32(&HFF00FFUI)
            return(true);
        }
Beispiel #7
0
        public static Cry ImportCry(string filename, Cry cryToLoad)
        {
            // If Cry.Offset = 0 Then
            // Return
            // End If

            // load a wave file
            using (var reader = new BinaryReader(File.OpenRead(filename)))
            {
                // read RIFF header
                if (reader.ReadUInt32() != 0x46464952L)
                {
                    throw new Exception("This is not a WAVE file!");
                }

                if (reader.ReadInt32() + 8 != reader.BaseStream.Length)
                {
                    throw new Exception("Invalid file length!");
                }

                if (reader.ReadUInt32() != 0x45564157L)
                {
                    throw new Exception("This is not a WAVE file!");
                }

                // read fmt chunk
                if (reader.ReadUInt32() != 0x20746D66L)
                {
                    throw new Exception("Expected fmt chunk!");
                }

                if (reader.ReadInt32() != 16)
                {
                    throw new Exception("Invalid fmt chunk!");
                }

                if (reader.ReadInt16() != 1)
                {
                    // only PCM format allowed
                    throw new Exception("Cry must be in PCM format!");
                }

                if (reader.ReadInt16() != 1)
                {
                    // only 1 channel allowed
                    throw new Exception("Cry cannot have more than one channel!");
                }

                cryToLoad.SampleRate = reader.ReadInt32();
                if (reader.ReadInt32() != cryToLoad.SampleRate)
                {
                    throw new Exception("Invalid fmt chunk!");
                }

                reader.ReadUInt16();
                var bitsPerSample = reader.ReadUInt16();
                if (bitsPerSample != 8)
                {
                    // for now, only 8 bit PCM data
                    throw new Exception("Cries must be 8-bit WAVE files! Got {bitsPerSample}-bit instead.");
                }

                // data chunk
                if (reader.ReadUInt32() != 0x61746164L)
                {
                    throw new Exception("Expected data chunk!!");
                }

                var dataSize = reader.ReadInt32();
                cryToLoad.Data = new sbyte[dataSize];
                for (int i = 0, loopTo = dataSize - 1; i <= loopTo; i++)
                {
                    // read 8-bit unsigned PCM and convert to GBA signed form
                    cryToLoad.Data[i] = (sbyte)(reader.ReadByte() - 128);
                }
            }

            // resetting some other properties just in case
            cryToLoad.Looped    = false;
            cryToLoad.LoopStart = 0;
            return(cryToLoad);
        }
Beispiel #8
0
        public static Cry LoadCry(int index, int cryTable)
        {
            var cryToLoad = new Cry();

            // If ledrom Is Nothing Then
            // Return False
            // End If

            // load cry table entry
            // ledrom.Seek(cryTable + index * 12)

            // Dim someValue = ledrom.ReadInt32()
            // Dim cryOffset = ledrom.ReadPointer()
            // Dim cryShape = ledrom.ReadInt32()

            string LocalReadHex()
            {
                var argStart2 = cryTable + index * 12; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex()
            {
                var argHexData = "hs114971a3962f4785bb1199029f740d9a()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var someValue = int.Parse(LocalReverseHex(), System.Globalization.NumberStyles.HexNumber);

            string LocalReadHex1()
            {
                var argStart2 = cryTable + index * 12 + 4; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex1()
            {
                var argHexData = "hs42097b91af9a4cb7bf85297615b2b82c()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var cryOffset = int.Parse(LocalReverseHex1(), System.Globalization.NumberStyles.HexNumber) - 0x8000000;

            string LocalReadHex2()
            {
                var argStart2 = cryTable + index * 12 + 8; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex2()
            {
                var argHexData = "hs636c588e252f49388e9b7cfd50d62ae5()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var cryShape = int.Parse(LocalReverseHex2(), System.Globalization.NumberStyles.HexNumber);


            // If cryOffset = 0 Then
            // Return False
            // End If

            // load cry data
            // ledrom.Seek(cryOffset)

            cryToLoad.Offset = cryOffset;
            cryToLoad.Index  = index;


            // CryToLoad.Compressed = ledrom.ReadUInt16() = &H1
            // CryToLoad.Looped = ledrom.ReadUInt16() = &H4000
            // CryToLoad.SampleRate = ledrom.ReadInt32() >> 10
            // CryToLoad.LoopStart = ledrom.ReadInt32()
            // CryToLoad.Size = ledrom.ReadInt32() + 1

            string LocalReadHex3()
            {
                var argStart2 = cryOffset + 0; var argLength = 2; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex3()
            {
                var argHexData = "hs228b8612293b47259bd1ddc81cc475da()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            cryToLoad.Compressed = short.Parse(LocalReverseHex3(), System.Globalization.NumberStyles.HexNumber) == 0x1;
            string LocalReadHex4()
            {
                var argStart2 = cryOffset + 2; var argLength = 2; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex4()
            {
                var argHexData = "hs1356c430d68a4b5c97b50286fa9e623c()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            cryToLoad.Looped = short.Parse(LocalReverseHex4(), System.Globalization.NumberStyles.HexNumber) == 0x4000;
            string LocalReadHex5()
            {
                var argStart2 = cryOffset + 4; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex5()
            {
                var argHexData = "hsdf6fddefae014a00ae3654bb21c3d239()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            cryToLoad.SampleRate = int.Parse(LocalReverseHex5(), System.Globalization.NumberStyles.HexNumber) >> 10;
            string LocalReadHex6()
            {
                var argStart2 = cryOffset + 8; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex6()
            {
                var argHexData = "hs8b94dd1b930547378b53e2d5ed2df7c4()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            cryToLoad.LoopStart = int.Parse(LocalReverseHex6(), System.Globalization.NumberStyles.HexNumber);
            string LocalReadHex7()
            {
                var argStart2 = cryOffset + 12; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex7()
            {
                var argHexData = "hs29971bab56db428e81f7e305c6e4d9da()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            cryToLoad.Size = int.Parse(LocalReverseHex7(), System.Globalization.NumberStyles.HexNumber) + 1;
            if (!cryToLoad.Compressed)
            {
                // uncompressed, 1 sample per 1 byte of size
                cryToLoad.Data = new sbyte[cryToLoad.Size];
                for (int g = 0, loopTo = cryToLoad.Size - 1; g <= loopTo; g++)
                {
                    string LocalReadHex8()
                    {
                        var argStart2 = cryOffset + 16 + g; var argLength = 1; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
                    }

                    cryToLoad.Data[g] = (sbyte)ByteFunctions.ByteToSignedInteger(Conversions.ToByte("&H" + LocalReadHex8()));
                }
            }
            else
            {
                // compressed, a bit of a hassle
                var lookup = new sbyte[] { 0, 1, 4, 9, 16, 25, 36, 49, -64, -49, -36, -25, -16, -9, -4, -1 };

                var   start     = cryOffset + 16;
                var   offtrack  = cryOffset + 16;
                var   alignment = 0;
                var   size      = 0;
                sbyte pcmLevel  = 0;
                var   data      = new List <sbyte>();
                while (true)
                {
                    if (alignment == 0)
                    {
                        var argLength = 1;
                        pcmLevel  = (sbyte)ByteFunctions.ByteToSignedInteger(Conversions.ToByte("&H" + HexFunctions.ReadHex(ref MainObject.LoadedRom, ref offtrack, ref argLength)));
                        offtrack += 1;
                        data.Add(pcmLevel);
                        alignment = 0x20;
                    }

                    var argLength1 = 1;
                    var input      = Conversions.ToByte("&H" + HexFunctions.ReadHex(ref MainObject.LoadedRom, ref offtrack, ref argLength1));
                    offtrack += 1;
                    if (alignment < 0x20)
                    {
                        // first nybble
                        pcmLevel += lookup[input >> 4];
                        data.Add(pcmLevel);
                    }

                    // second nybble
                    pcmLevel += lookup[input & 0xF];
                    data.Add(pcmLevel);

                    // exit when currentSize >= cry.Size
                    size += 2;
                    if (size >= cryToLoad.Size)
                    {
                        break;
                    }

                    alignment -= 1;
                }

                cryToLoad.Data = data.ToArray();
                // bytes needed to recompress
                cryToLoad.Size = offtrack - start;
            }

            return(cryToLoad);
        }
Beispiel #9
0
 /// <summary>
 /// 猫叫方法
 /// </summary>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 public void OnCry(EventArgs e)
 {
     Cry?.Invoke(this, e);
 }