Esempio n. 1
0
        public byte[] getData()
        {
            byte[] result             = new byte[getNumSamples() * channels * (bitDepth / 8)];
            System.IO.MemoryStream ms = new System.IO.MemoryStream(result);
            System.IO.BinaryWriter wr = new System.IO.BinaryWriter(ms);

            if (bitDepth == 16)
            {
                for (int i = 0; i < getNumSamples(); i++)
                {
                    for (int c = 0; c < channels; c++)
                    {
                        //assuming signed
                        wr.Write((short)(samples[c][i] * 32768));
                    }
                }
            }
            else if (bitDepth == 8)
            {
                for (int i = 0; i < getNumSamples(); i++)
                {
                    for (int c = 0; c < channels; c++)
                    {
                        //assuming unsigned
                        wr.Write((byte)(samples[c][i] * 128 + 128));
                    }
                }
            }
            wr.Dispose();
            ms.Dispose();
            return(result);
        }
Esempio n. 2
0
File: Elf.cs Progetto: seb5594/ElfIO
        public void DumpString()
        {
            ElfHDR elfhdr = header;
            ElfPHDR elfphdr;
            ElfSHDR elfshdr;

            // Initialze output file
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(System.IO.File.Create("dump.txt"));

            // Write Elf
            writer.Write(String.Format("****ELF HEADER****\n{0}\n", elfhdr.ToString()));

            // Write PHDR
            writer.Write("****PROGRAM HEADERS****\n");
            for (int i = 0; i < elfhdr.ProgramHeaderCount; i++)
            {
                writer.Write(String.Format("Program[{0}]\n{1}\n", i, programs[i].Header.ToString()));
            }

            // WRITE SHDR
            writer.Write("****SECTION HEADERS****\n");
            for (int i = 0; i < elfhdr.SectionHeaderCount; i++)
            {
                writer.Write(String.Format("Section[{0}]\n{1}\n", i, sections[i].Header.ToString()));
            }

            // Close writer
            writer.Close();
            writer.Dispose();
        }
Esempio n. 3
0
 private void ButtonSave_Click(object sender, EventArgs e)
 {
     if (GenerateOutput)
     {
         try
         {
             if (file.CanWrite)
             {
                 byte[] arr = DataList.ToArray();
                 Writer.Write(DataList.Count);
                 Writer.Write(0xffffffff);
                 Writer.Write(0xffffffff);
                 Writer.Write(0xffffffff);
                 Writer.Write(0xffffffff);
                 Writer.Write(arr);
                 Writer.Write("lf3");
             }
         }
         catch
         {
             MessageBox.Show("Błąd!");
         }
         finally
         {
             MessageBox.Show("Zapisano plik.");
             Writer.Dispose();
         }
     }
 }
Esempio n. 4
0
        private static void SavePasswordToFile(string password, string fileName)
        {
            string value = DESManager.Encrypt(password);

            value = DESManager.Encrypt(value);
            value = DESManager.Encrypt(value);
            value = string.Join(" ", System.Text.RegularExpressions.Regex.Matches(value, @"..").Cast <System.Text.RegularExpressions.Match>().ToList());
            List <string> valueList = new List <string>();
            int           i         = 0;
            int           count     = value.Length / 36;

            for (i = 0; i < count; i++)
            {
                valueList.Add(value.Substring(i * 36, 36));
            }
            valueList.Add(value.Substring(i * 36));
            value = string.Join(Environment.NewLine, valueList);
            byte[] buff = Encoding.UTF8.GetBytes(value);
            System.IO.FileStream   stream = stream = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
            writer.Write(buff);
            writer.Close();
            writer.Dispose();
            stream.Close();
            stream.Dispose();
        }
Esempio n. 5
0
 /// <summary>
 /// Closes and Disposes the underlying stream if indicated to do so when constructing the DumpWriter
 /// </summary>
 public void Close()
 {
     if (m_Writer != null)
     {
         m_Writer.Dispose();
     }
 }
 public override void calcbodysize()
 {
     System.IO.BinaryWriter bw = new System.IO.BinaryWriter(new System.IO.MemoryStream());
     ToStream(bw);
     size = Convert.ToInt32(bw.BaseStream.Length);
     bw.Close();
     bw.Dispose();
 }
Esempio n. 7
0
 protected override void OnRecordingStopped()
 {
     lock (_writer) {
         _writer.Dispose();
         _binaryStream.Dispose();
         Parent.Parent.Context.AddRecordedFileToSet(GetRecordLine());
     }
 }
Esempio n. 8
0
    public static void Dispose(System.IO.BinaryWriter writer)
    {
#if NETFX_CORE
        writer.Dispose();
#else
        writer.Close();
#endif
    }
Esempio n. 9
0
        public void Dispose()
        {
            if (mReader != null)
            {
                mReader.Close();
                mReader.Dispose();
                mReader = null;
            }

            if (mWriter != null)
            {
                mWriter.Close();
                mWriter.Dispose();
                mWriter = null;
            }

            if (mStream != null)
            {
                mStream.Close();
                mStream.Dispose();
                mStream = null;
            }
        }
Esempio n. 10
0
        public void saveToWAV(string path)
        {
            // http://soundfile.sapp.org/doc/WaveFormat/
            // https://stackoverflow.com/questions/14659684/creating-a-wav-file-in-c-sharp
            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
            }

            System.IO.FileStream   fs = new System.IO.FileStream(path, System.IO.FileMode.CreateNew);
            System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);

            Console.WriteLine("Chunk ID: " + chunkID);
            Console.WriteLine("Chunk Size: " + chunkSize.ToString());
            Console.WriteLine("Format: " + format);
            Console.WriteLine("Subchunk 1 ID: " + subChunk1ID);
            Console.WriteLine("Subchunk 1 Size: " + subChunk1Size.ToString());
            Console.WriteLine("Audio Format: " + audioFormat.ToString());
            Console.WriteLine("Channels: " + numChannels.ToString());
            Console.WriteLine("Sample Rate: " + sampleRate.ToString());
            Console.WriteLine("Byte Rate: " + byteRate.ToString());
            Console.WriteLine("Block Align: " + blockAlign.ToString());
            Console.WriteLine("Bits Per Sample: " + bitsPerSample.ToString());
            Console.WriteLine("Subchunk 2 ID: " + subChunk2ID);
            Console.WriteLine("Subchunk 2 Size: " + subChunk2Size.ToString());

            bw.Write(System.Text.Encoding.ASCII.GetBytes(chunkID));
            bw.Write(chunkSize);
            bw.Write(System.Text.Encoding.ASCII.GetBytes(format));
            bw.Write(System.Text.Encoding.ASCII.GetBytes(subChunk1ID));
            bw.Write(subChunk1Size);
            bw.Write(audioFormat);
            bw.Write(numChannels);
            bw.Write(sampleRate);
            bw.Write(byteRate);
            bw.Write(blockAlign);
            bw.Write(bitsPerSample);
            bw.Write(System.Text.Encoding.ASCII.GetBytes(subChunk2ID));
            bw.Write(subChunk2Size);
            foreach (short v in data)
            {
                bw.Write(v);
            }

            fs.Close();
            fs.Dispose();
            bw.Close();
            bw.Dispose();
        }
Esempio n. 11
0
        int SystemIOBinaryWriter_m_Dispose(RealStatePtr L, int gen_param_count)
        {
            ObjectTranslator translator = this;


            System.IO.BinaryWriter gen_to_be_invoked = (System.IO.BinaryWriter)translator.FastGetCSObj(L, 1);


            {
                gen_to_be_invoked.Dispose(  );



                return(0);
            }
        }
Esempio n. 12
0
        public byte[] serialize(Commands.Command c)
        {
            System.IO.MemoryStream m = new System.IO.MemoryStream();
            System.IO.BinaryWriter b = new System.IO.BinaryWriter(m);
            string t = c.GetType().FullName;

            b.Write(Encoding.UTF8.GetByteCount(t));
            b.Write(Encoding.UTF8.GetBytes(t));

            string d = Newtonsoft.Json.JsonConvert.SerializeObject(c);

            b.Write(Encoding.UTF8.GetByteCount(d));
            b.Write(Encoding.UTF8.GetBytes(d));
            b.Flush();
            byte[] output = m.ToArray();
            b.Dispose();
            m.Dispose();


            return(output);
        }
        static int _m_Dispose(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                System.IO.BinaryWriter gen_to_be_invoked = (System.IO.BinaryWriter)translator.FastGetCSObj(L, 1);



                {
                    gen_to_be_invoked.Dispose(  );



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Esempio n. 14
0
 public void writetofile()
 {
     Byte[] checkBytes = System.IO.File.ReadAllBytes(filelocation);
     if (checkBytes[0x10] != 0x00 && checkBytes[0x10] != 0x01)
     {
         MessageBox.Show("Critical Error, file has not decrypted! aborting...", "Error", MessageBoxButtons.OK);
         return;
     }
     System.IO.BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.OpenWrite(filelocation));
     if (gender != 0xff)
     {
         bw.Seek(0x284e0, System.IO.SeekOrigin.Begin);
         bw.Write((byte)gender);
         bw.Seek(0x284f4, System.IO.SeekOrigin.Begin);
         bw.Write((byte)0x01);
     }
     if (rainmakerrank != 0xff)
     {
         bw.Seek(0x2B238, System.IO.SeekOrigin.Begin);
         bw.Write((byte)rainmakerrank);
     }
     if (splatzonesrank != 0xff)
     {
         bw.Seek(0x2B244, System.IO.SeekOrigin.Begin);
         bw.Write((byte)splatzonesrank);
     }
     if (towercontrolrank != 0xff)
     {
         bw.Seek(0x2B250, System.IO.SeekOrigin.Begin);
         bw.Write((byte)towercontrolrank);
     }
     if (clamblitzrank != 0xff)
     {
         bw.Seek(0x2B25C, System.IO.SeekOrigin.Begin);
         bw.Write((byte)clamblitzrank);
     }
     bw.Dispose();
     MessageBox.Show("Done!", "", MessageBoxButtons.OK);
 }
Esempio n. 15
0
        public bool Save()
        {
            System.IO.BinaryWriter bw = null;
            System.IO.FileStream   fs = null;
            string path = null;

            try
            {
#if DEBUG
                path = "settings.dat";
#else
                path = System.IO.Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                    "Clocks");

                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                path = System.IO.Path.Combine(path, "settings.dat");
#endif
                fs = new System.IO.FileStream(
                    path, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read);
                bw = new System.IO.BinaryWriter(fs);

                bw.Write(cfA);
                bw.Write(cfR);
                bw.Write(cfG);
                bw.Write(cfB);

                bw.Write(fgA);
                bw.Write(fgR);
                bw.Write(fgG);
                bw.Write(fgB);

                bw.Write(autoload);
                bw.Write(showSeconds);

                bw.Write(x);
                bw.Write(y);
                bw.Write(topMost);

                bw.Flush();
            }
            catch (Exception ex)
            {
#if DEBUG
//                System.Windows.MessageBox.Show("path "+path+"\nerr "+ ex.Message);
#endif
                return(false);
            }
            finally
            {
                if (bw != null)
                {
                    bw.Dispose();
                }
            }

            return(true);
        }
Esempio n. 16
0
 void IDisposable.Dispose()
 {
     stream.Dispose();
 }
Esempio n. 17
0
        public void DumpString()
        {
            ElfHDR  elfhdr = header;
            ElfPHDR elfphdr;
            ElfSHDR elfshdr;

            // Initialze output file
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(System.IO.File.Create("dump.txt"));

            // Write Elf
            writer.Write("****ELF HEADER****\n");
            writer.Write(String.Format("ID: {0}\nType: {1}\nMachine: {2}\nVersion: {3}\nEntryPoint: 0x{4:X8}\nPHOffset: 0x{5:X8}\nSHOffset: 0x{6:X8}\nFlags: 0x{7:X4}\nHeaderSize: 0x{8:X2}\nPHSize: 0x{9:X2}\nPHCount: 0x{10:X2}\nSHSize: 0x{11:X2}\nSHCount: 0x{12:X2}\nStringTable: 0x{13:X2}\n\n",
                                       BitConverter.ToString(elfhdr.Identification),
                                       elfhdr.Type.ToString(),
                                       elfhdr.MachineType.ToString(),
                                       elfhdr.Version.ToString(),
                                       elfhdr.EntryPoint,
                                       elfhdr.ProgramHeaderOffset,
                                       elfhdr.SectionHeaderOffset,
                                       elfhdr.Flags,
                                       elfhdr.HeaderSize,
                                       elfhdr.ProgramHeaderSize,
                                       elfhdr.ProgramHeaderCount,
                                       elfhdr.SectionHeaderSize,
                                       elfhdr.SectionHeaderCount,
                                       elfhdr.StringTable));

            // Write PHDR
            writer.Write("****PROGRAM HEADERS****\n");
            for (int i = 0; i < elfhdr.ProgramHeaderCount; i++)
            {
                elfphdr = programs[i].Header;
                writer.Write(String.Format("Program[{10}]\nType = {0}\nFlags = {1}\nOffset = 0x{2:X8} => 0x{8:X8} => 0x{9:X8}\nVaddr = 0x{3:X8}\nPaddr = 0x{4:X8}\nFilesz = 0x{5:X8}\nMemsz = 0x{6:X8}\nAlign = 0x{7:X8}\n\n",
                                           elfphdr.Type.ToString(),
                                           elfphdr.Flags.ToString(),
                                           elfphdr.FileOffset,
                                           elfphdr.VirtualAddress,
                                           elfphdr.PhysicalAddress,
                                           elfphdr.FileSize,
                                           elfphdr.MemorySize,
                                           elfphdr.Align,
                                           elfphdr.FileOffset + elfphdr.FileSize,
                                           (elfphdr.FileOffset + elfphdr.FileSize + elfphdr.Align - 1) & ~(elfphdr.Align - 1),
                                           i));
            }

            // WRITE SHDR
            writer.Write("****SECTION HEADERS****\n");
            for (int i = 0; i < elfhdr.SectionHeaderCount; i++)
            {
                elfshdr = sections[i].Header;
                writer.Write(String.Format("Section[{12}]\nName: 0x{0:X4}\nType: {1}\nFlags: {2}\nAddress: 0x{3:X8}\nOffset: 0x{4:X8} => 0x{10:X8} => 0x{11:X8}\nSize: 0x{5:X8}\nLink: 0x{6:X4}\nInfo: 0x{7:X4}\nAlign: 0x{8:X8}\nEntries: 0x{9:X8}\n\n",
                                           elfshdr.Name,
                                           elfshdr.Type.ToString(),
                                           elfshdr.Flags.ToString(),
                                           elfshdr.Address,
                                           elfshdr.FileOffset,
                                           elfshdr.Size,
                                           elfshdr.Link,
                                           elfshdr.Info,
                                           elfshdr.Align,
                                           elfshdr.EntrySize,
                                           elfshdr.FileOffset + elfshdr.Size,
                                           (elfshdr.FileOffset + elfshdr.Size + elfshdr.Align - 1) & ~(elfshdr.Align - 1),
                                           i));
            }

            // Close writer
            writer.Close();
            writer.Dispose();
        }
Esempio n. 18
0
        public void Pack(string in_path, string out_path, string KOMFileName)
        {
            bool use_XoR = false;

            if (System.IO.File.Exists(in_path + "\\XoRNeeded.dummy"))
            {
                use_XoR = true;
                System.IO.File.Delete(in_path + "\\XoRNeeded.dummy");
            }
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(System.IO.File.Create(out_path), System.Text.Encoding.ASCII);
            int entry_count = 0;
            int crc_size    = 0;

            Els_kom_Core.Classes.KOMStream kOMStream = new Els_kom_Core.Classes.KOMStream();
            kOMStream.ReadCrc(in_path + "\\crc.xml", out byte[] crc_data, ref entry_count, ref crc_size);
            kOMStream.Dispose();
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(in_path);
            int offset = 0;

            System.Collections.Generic.List <Els_kom_Core.Classes.EntryVer> entries = new System.Collections.Generic.List <Els_kom_Core.Classes.EntryVer>();
            foreach (var fi in di.GetFiles())
            {
                entry_count++;
                byte[] file_data    = System.IO.File.ReadAllBytes(in_path + "\\" + fi.Name);
                int    originalsize = file_data.Length;
                if (use_XoR)
                {
                    byte[] xorkey = System.Text.Encoding.UTF8.GetBytes("\xa9\xa9\xa9\xa9\xa9\xa9\xa9\xa9\xa9\xa9");
                    Els_kom_Core.Classes.BlowFish.XorBlock(ref file_data, xorkey);
                }
                byte[] compressedData;
                try
                {
                    Els_kom_Core.Classes.ZlibHelper.CompressData(file_data, out compressedData);
                }
                catch (Els_kom_Core.Classes.Zlib.ZStreamException)
                {
                    throw new Els_kom_Core.Classes.PackingError("failed with zlib compression of entries.");
                }
                int compressedSize = compressedData.Length;
                offset += compressedSize;
                entries.Add(new Els_kom_Core.Classes.EntryVer(compressedData, fi.Name, originalsize, compressedSize, offset));
            }
            if (use_XoR)
            {
                byte[] xorkey = System.Text.Encoding.UTF8.GetBytes("\xa9\xa9\xa9\xa9\xa9\xa9\xa9\xa9\xa9\xa9");
                Els_kom_Core.Classes.BlowFish.XorBlock(ref crc_data, xorkey);
            }
            byte[] compressedcrcData;
            try
            {
                Els_kom_Core.Classes.ZlibHelper.CompressData(crc_data, out compressedcrcData);
            }
            catch (Els_kom_Core.Classes.Zlib.ZStreamException)
            {
                throw new Els_kom_Core.Classes.PackingError("failed with zlib compression of crc.xml.");
            }
            int compressedcrc = compressedcrcData.Length;

            offset += compressedcrc;
            entries.Add(new Els_kom_Core.Classes.EntryVer(compressedcrcData, "crc.xml", crc_size, compressedcrc, offset));
            writer.Write(KOMHeaderString.ToCharArray(), 0, KOMHeaderString.Length);
            writer.BaseStream.Position = 52;
            writer.Write(entry_count);
            writer.Write(1);
            foreach (var entry in entries)
            {
                writer.Write(entry.name.ToCharArray(), 0, entry.name.Length);
                int seek_amount = 60 - entry.name.Length;
                writer.BaseStream.Position += seek_amount;
                writer.Write(entry.uncompressed_size);
                writer.Write(entry.compressed_size);
                writer.Write(entry.relative_offset);
            }
            foreach (var entry in entries)
            {
                writer.Write(entry.entrydata, 0, entry.compressed_size);
            }
            writer.Dispose();
        }
Esempio n. 19
0
        public byte[] getData()
        {
            byte[] result = new byte[getNumSamples() * channels * (bitDepth / 8)];
            System.IO.MemoryStream ms = new System.IO.MemoryStream(result);
            System.IO.BinaryWriter wr = new System.IO.BinaryWriter(ms);

            if (bitDepth == 16) {
                for (int i = 0; i < getNumSamples(); i++) {
                    for (int c = 0; c < channels; c++) {
                        //assuming signed
                        wr.Write((short)(samples[c][i] * 32768));
                    }
                }
            } else if (bitDepth == 8) {
                for (int i = 0; i < getNumSamples(); i++) {
                    for (int c = 0; c < channels; c++) {
                        //assuming unsigned
                        wr.Write((byte)(samples[c][i] * 128 + 128));
                    }
                }
            }
            wr.Dispose();
            ms.Dispose();
            return result;
        }
Esempio n. 20
0
        /*public static void mapDecypher(System.IO.BinaryReader br, int headerOffset, int id)
         * {
         *  /*
         *  09 1115 used in $C0/591A (DC2D84,((00:1115 & 0x3F (6 bits)) * 4) + DC/2E24)                 First  [4bpp 8x8] Graphics load
         *  .. .... used in $C0/596A (DC2D84,(Invert_Bytes((00:1115..16 & 0FC0) * 4) * 4) + DC/2E24)    Second [4bpp 8x8] Graphics load
         *  0A 1116 used in $C0/59D7 (DC2D84,((00:1116..7 & 03F0)/4) + DC/2E24)                         Third  [4bpp 8x8] Graphics load
         *  0B 1117 used in $C0/5A45 (DC0000,((00:1117 & #$FC) / 2) + DC/0024)                                 [2bpp 8x8] Graphics load
         *
         *  0C 1118 used in $C0/5877 (CB0000,(((00:1118 & 0x03FF) - 1) * 2) + CB...CC.../0000???)              [unheaded Type02] (I.e. CC/344B) -> Bytemap decompressed in 7F:0000
         *  0D 1119 used in $C0/588D (if (((00:1119 & 0x0FFC) / 4) - 1) == 0xFFFF => 0-> 7F0000:7F0FFF)        [unheaded Type02] -> Bytemap ???? decompressed in 7F:1000 ????
         *  0E 111A used in $C0/58B6 (CB0000,(((00:111A & 0x3FF0)/16) - 1) * 2) + CB...CC.../0000???)          [unheaded Type02] (I.e. CC/344B) -> Bytemap ???? decompressed in 7F:2000 ????
         *  0F 111B "
         *
         *  16 1122 Used in $C0/58DB (Sent 0x100 bytes C3BB00,([17] * 0x0100 [16]) (i.e. C3:C400) -> to 00:0C00 [Palette])
         *  //
         *
         *  int offset = 0;
         *  br.BaseStream.Position = 0x0E9C00 + headerOffset + (id * 0x1A);
         *  List<Byte> mapDescriptors = br.ReadBytes(0x1A).ToList();
         *
         *
         *
         *  br.BaseStream.Position = 0x03BB00 + headerOffset + (mapDescriptors[0x16] + mapDescriptors[0x17] * 0x0100);
         *  Byte[]  bytePal = br.ReadBytes(0x0100);
         *  Color[] palette = new Color[0x0100];
         *  for (int i = 0; i < 0x0100; i += 2)
         *  {
         *      int color = bytePal[i] + bytePal[i + 1] * 0x0100;
         *      int r = ((color /    1) % 32) * 8;
         *      int g = ((color /   32) % 32) * 8;
         *      int b = ((color / 1024) % 32) * 8;
         *      r = r + r / 32;
         *      g = g + g / 32;
         *      b = b + b / 32;
         *
         *      palette[i] = Color.FromArgb(r, g, b);
         *  }
         *
         *  br.BaseStream.Position = 0x1C2D84 + headerOffset + ((mapDescriptors[0x09] & 0x3F) * 4);
         *  offset = br.ReadByte() + (br.ReadByte() * 0x0100) + (br.ReadByte() * 0x010000) + 0x1C2E24 + headerOffset;
         *  br.BaseStream.Position = offset;
         *  Bitmap firstBitmap = Transformations.transform4b(br.ReadBytes(0x2000).ToList(), 0, 0x2000);
         *  ManageBMP.exportBPM("firstBitmap.png", firstBitmap, palette);
         *
         *  br.BaseStream.Position = 0x1C2D84 + headerOffset + ((((mapDescriptors[0x09] & 0xC0) / 4)  + (mapDescriptors[0x0A] & 0x0F)) * 4);
         *  offset = br.ReadByte() + (br.ReadByte() * 0x0100) + (br.ReadByte() * 0x010000) + 0x1C2E24 + headerOffset;
         *  br.BaseStream.Position = offset;
         *  Bitmap secondBitmap = Transformations.transform4b(br.ReadBytes(0x2000).ToList(), 0, 0x2000);
         *  ManageBMP.exportBPM("secondBitmap.png", secondBitmap, palette);
         *
         *  br.BaseStream.Position = 0x1C2D84 + headerOffset + (((mapDescriptors[0x0A] + (mapDescriptors[0x0B] * 0x0100)) & 0x03F0) / 4);
         *  offset = br.ReadByte() + (br.ReadByte() * 0x0100) + (br.ReadByte() * 0x010000) + 0x1C2E24 + headerOffset;
         *  br.BaseStream.Position = offset;
         *  Bitmap thirdBitmap = Transformations.transform4b(br.ReadBytes(0x2000).ToList(), 0, 0x2000);
         *  ManageBMP.exportBPM("thirdBitmap.png", thirdBitmap, palette);
         *
         *  br.BaseStream.Position = 0x1C0000 + headerOffset + ((mapDescriptors[0x0B] & 0xFC) / 2);
         *  offset = br.ReadByte() + (br.ReadByte() * 0x0100) + 0x1C0024 + headerOffset;
         *  br.BaseStream.Position = offset;
         *  Bitmap forthBitmap = Transformations.transform2bpp(br.ReadBytes(0x2000).ToList(), 0, 0x1000);
         *  ManageBMP.exportBPM("forthBitmap.png", forthBitmap, Palettes.palette2b);
         * }
         */



        public static void editSRM()
        {
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
            openFileDialog.Filter = "SRM File|*.srm";
            openFileDialog.Title  = "Choose a file";

            /* Show the Dialog */
            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (openFileDialog.FileName != "")
                {
                    System.IO.FileStream   fs = new System.IO.FileStream(openFileDialog.FileName, System.IO.FileMode.Open);
                    System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs, new UnicodeEncoding());
                    System.IO.BinaryReader br = new System.IO.BinaryReader(fs, new UnicodeEncoding());

                    // Compare checksum
                    int accumulator = 0;
                    //int currrentChecksum = 0;

                    // Edit items
                    bw.BaseStream.Position = 0x0140;
                    for (int i = 0; i < 0x100; i++)
                    {
                        bw.BaseStream.WriteByte(BitConverter.GetBytes(i)[0]);
                    }
                    for (int i = 0; i < 0x100; i++)
                    {
                        bw.BaseStream.WriteByte(0x08);
                    }

                    br.BaseStream.Position = 0x0000;

                    for (int i = 0; i < 0x300; i++)
                    {
                        accumulator += br.ReadByte() + br.ReadByte() * 0x0100;
                        if (accumulator > 0xFFFF)
                        {
                            accumulator -= 0xFFFF;                       // or(0x010000)
                        }
                    }

                    /*
                     * FFVI
                     *
                     * for(int i = 0 ; i < 0x09FE ; i++) {
                     *      accumulator += br.ReadByte() + br.ReadByte() * 0x0100;
                     *      if (accumulator > 0xFFFF) accumulator -= 0xFFFF; // or(0x010000)
                     * }
                     *
                     * bw.BaseStream.Position = 0x09FE;
                     * bw.BaseStream.WriteByte(BitConverter.GetBytes(accumulator)[0]);
                     * bw.BaseStream.WriteByte(BitConverter.GetBytes(accumulator)[1]);
                     */

                    bw.BaseStream.Position = 0x1FF0;
                    //currrentChecksum = br.ReadByte() + br.ReadByte() * 0x0100;
                    //System.Windows.Forms.MessageBox.Show(currrentChecksum.ToString("X4"), accumulator.ToString("X4"));
                    bw.BaseStream.WriteByte(BitConverter.GetBytes(accumulator)[0]);
                    bw.BaseStream.WriteByte(BitConverter.GetBytes(accumulator)[1]);

                    bw.Close();
                    bw.Dispose();
                    br.Close();
                    br.Dispose();
                    fs.Close();
                    fs.Dispose();
                }
            }

            openFileDialog.Dispose();
            openFileDialog = null;
        }
Esempio n. 21
0
        public static Task <byte[]> Create(short Width, short Height, byte[] data, bool useAlpha)
        {
            return(Task <byte[]> .Run(() => {
                System.IO.MemoryStream bmp = new System.IO.MemoryStream();
                System.IO.BinaryWriter bw = new System.IO.BinaryWriter(bmp);

                if (useAlpha)
                {
                    // WindowsBitmap
                    // bitmapヘッダ
                    bw.Write((byte)'B');
                    bw.Write((byte)'M');
                    bw.Write((int)14 + 40 + Width * 4 * Height);
                    bw.Write((short)0);
                    bw.Write((short)0);
                    bw.Write((int)14 + 40);
                    // 情報ヘッダ
                    bw.Write((int)40);
                    bw.Write((int)Width);
                    bw.Write((int)Height);
                    bw.Write((short)1);
                    bw.Write((short)32);
                    bw.Write((int)0);
                    bw.Write((int)Width *Height * 4);
                    bw.Write((int)3780);
                    bw.Write((int)3780);
                    bw.Write((int)0);
                    bw.Write((int)0);
                    // イメージブロック
                    for (int h = Height - 1; h >= 0; --h)
                    {
                        for (int w = 0; w < Width * 4; w += 4)
                        {
                            bw.Write(data[h * Width * 4 + w]);     // B値
                            bw.Write(data[h * Width * 4 + w + 1]); // G値
                            bw.Write(data[h * Width * 4 + w + 2]); // R値
                            bw.Write(data[h * Width * 4 + w + 3]); // α値
                        }
                    }
                }
                else
                {
                    // OS/2Bitmap
                    // bitmapヘッダ
                    int widthFiller = (Width * 3) % 4;
                    widthFiller = widthFiller == 0 ? 0 : 4 - widthFiller;
                    bw.Write((byte)'B');
                    bw.Write((byte)'M');
                    bw.Write((int)14 + 12 + (Width * 3 + widthFiller) * Height);
                    bw.Write((short)0);
                    bw.Write((short)0);
                    bw.Write((int)14 + 12);
                    // 情報ヘッダ
                    bw.Write((int)12);
                    bw.Write((short)Width);
                    bw.Write((short)Height);
                    bw.Write((short)1);
                    bw.Write((short)24);
                    // イメージブロック
                    for (int h = Height - 1; h >= 0; --h)
                    {
                        for (int w = 0; w < Width * 4; w += 4)
                        {
                            bw.Write(data[h * Width * 4 + w]);     // B値
                            bw.Write(data[h * Width * 4 + w + 1]); // G値
                            bw.Write(data[h * Width * 4 + w + 2]); // R値
                                                                   //bw.Write(data[h * Width * 4 + w + 3]); α値は捨てる
                        }
                        for (int w = 0; w < widthFiller; ++w)
                        {
                            bw.Write((byte)0); // 4バイト境界調整
                        }
                    }
                }

                bw.Flush();
                bw.Dispose();
                return bmp.ToArray();
            }));
        }
        //save
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length < 5)
            {
                MessageBox.Show("too short nbame");
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog();
            if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;

            ResourceCollectorXNA.Engine.EngineLevel level = GameEngine.Instance.gameLevel;
            level.FillContent();

            System.IO.BinaryWriter bw = new System.IO.BinaryWriter(new System.IO.FileStream(sfd.FileName, System.IO.FileMode.OpenOrCreate));
            level.levelContent.savebody(bw);
            bw.Flush();
            bw.Close();
            bw.Dispose();
        }