Esempio n. 1
0
 public void Reset()
 {
     var messageStream = new System.IO.MemoryStream();
     var messageWriter = new System.IO.BinaryWriter(messageStream);
     messageWriter.Write(1);
     SendMessage(messageStream.ToArray());
 }
Esempio n. 2
0
        static void CreateSelfSignCertificate(CertOption option)
        {
            var fileName = option.CertFileName;
            var subject = option.Subject;
            var password = option.Password;

            try
            {
                var securePassword = Certificate.ConvertSecureString(password);
                var startDate = DateTime.Now;
                var endDate = startDate.AddYears(option.Years);
                var certData = Certificate.CreateSelfSignCertificatePfx(subject, startDate, endDate, securePassword);

                using (var writer = new System.IO.BinaryWriter(System.IO.File.Open(fileName, System.IO.FileMode.Create)))
                {
                    writer.Write(certData);
                    writer.Flush();
                    writer.Close();
                }
                securePassword = Certificate.ConvertSecureString(password);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 3
0
        public static void Assemble(string infile, string outfile, string origin)
        {
            CurrentNdx = 0;
            AsLength = Convert.ToUInt16(origin, 16);
            IsEnd = false;
            ExecutionAddress = 0;
            LabelTable = new System.Collections.Hashtable(50);

            System.IO.BinaryWriter output;
            System.IO.TextReader input;
            System.IO.FileStream fs = new System.IO.FileStream(outfile, System.IO.FileMode.Create);

            output = new System.IO.BinaryWriter(fs);

            input = System.IO.File.OpenText(infile);
            SourceProgram = input.ReadToEnd();
            input.Close();

            output.Write('B');
            output.Write('3');
            output.Write('2');
            output.Write(Convert.ToUInt16(origin, 16));
            output.Write((ushort)0);
            Parse(output, origin);

            output.Seek(5, System.IO.SeekOrigin.Begin);
            output.Write(ExecutionAddress);
            output.Close();
            fs.Close();
        }
Esempio n. 4
0
        public static void PNGtoBIN(string path_in, string path_out, string[] param = null)
        {
            Image png = Image.FromFile(path_in);
            Bitmap bmp = new Bitmap(png);
            if ((png.Width != 128) && (png.Height != 32))
                return;

            int tiles_w = png.Width / 4;
            int tiles_h = png.Height / 8;
            ushort[] binary = new ushort[256];
            for (int y = 0; y < tiles_h; y++)
            {
                for (int x = 0; x < tiles_w; x++)
                {
                    ushort[] tile = new ushort[2];
                    for (int iY = 0; iY < 8; iY++)
                    {
                        for (int iX = 0; iX < 4; iX++)
                        {
                            Color color = bmp.GetPixel(x * 4 + iX, y * 8 + iY);
                            if (color.R + color.G + color.B > 0x0100)
                                tile[(iY / 4)] |= (ushort)(1 << ((iY % 4) * 4 + iX));
                        }
                    }
                    binary[y * tiles_w * 2 + x * 2 + 0] = tile[0];
                    binary[y * tiles_w * 2 + x * 2 + 1] = tile[1];
                }
            }

            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(System.IO.File.Open(path_out, System.IO.FileMode.Create));
            for (int i = 0; i < 256; i++)
                writer.Write(binary[i]);
            writer.Close();
        }
Esempio n. 5
0
		public static byte[] SerializeVoxelAreaCompactData (VoxelArea v) {
#if !ASTAR_RECAST_CLASS_BASED_LINKED_LIST
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
			
			writer.Write (v.width);
			writer.Write (v.depth);
			writer.Write (v.compactCells.Length);
			writer.Write(v.compactSpans.Length);
			writer.Write(v.areaTypes.Length);
			
			for (int i=0;i<v.compactCells.Length;i++) {
				writer.Write(v.compactCells[i].index);
				writer.Write(v.compactCells[i].count);
			}
			
			for (int i=0;i<v.compactSpans.Length;i++) {
				writer.Write(v.compactSpans[i].con);
				writer.Write(v.compactSpans[i].h);
				writer.Write(v.compactSpans[i].reg);
				writer.Write(v.compactSpans[i].y);
			}
			for (int i=0;i<v.areaTypes.Length;i++) {
				//TODO: RLE encoding
				writer.Write(v.areaTypes[i]);
			}
			writer.Close();
			return stream.ToArray();
#else
			throw new System.NotImplementedException ("This method only works with !ASTAR_RECAST_CLASS_BASED_LINKED_LIST");
#endif
		}
Esempio n. 6
0
		public static byte[] SerializeVoxelAreaData (VoxelArea v) {
#if !ASTAR_RECAST_CLASS_BASED_LINKED_LIST
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
			
			writer.Write (v.width);
			writer.Write (v.depth);
			writer.Write (v.linkedSpans.Length);
			
			for (int i=0;i<v.linkedSpans.Length;i++) {
				writer.Write(v.linkedSpans[i].area);
				writer.Write(v.linkedSpans[i].bottom);
				writer.Write(v.linkedSpans[i].next);
				writer.Write(v.linkedSpans[i].top);
			}
			
			//writer.Close();
			writer.Flush();
			Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
			stream.Position = 0;
			zip.AddEntry ("data",stream);
			System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
			zip.Save(stream2);
			byte[] bytes = stream2.ToArray();
			stream.Close();
			stream2.Close();
			return bytes;
#else
			throw new System.NotImplementedException ("This method only works with !ASTAR_RECAST_CLASS_BASED_LINKED_LIST");
#endif
		}
Esempio n. 7
0
        public bool ByteArrayToFile(string _FileName, byte[] _ByteArray)
        {
            try
            {
                // Open file for reading
                System.IO.FileStream _FileStream =
                   new System.IO.FileStream(_FileName, System.IO.FileMode.Create,
                                            System.IO.FileAccess.Write);
                System.IO.BinaryWriter bw = new System.IO.BinaryWriter(_FileStream);
                // Writes a block of bytes to this stream using data from
                // a byte array.
                bw.Write(_ByteArray, 0, _ByteArray.Length);

                // close file stream
                bw.Close();

                return true;
            }
            catch (Exception _Exception)
            {
                // Error
                Console.WriteLine("Exception caught in process: {0}",
                                  _Exception.ToString());
            }

            // error occured, return false
            return false;
        }
Esempio n. 8
0
 public FormaterBuffer(int size)
 {
     mBuffer = new byte[size];
     mStream = new System.IO.MemoryStream(mBuffer);
     mReader = new System.IO.BinaryReader(mStream);
     mWriter = new System.IO.BinaryWriter(mStream);
 }
Esempio n. 9
0
 public override void BaseField_Leave(object sender, EventArgs e)
 {
     System.IO.BinaryWriter bw = new System.IO.BinaryWriter(meta.MS);
     if (((WinMetaEditor)this.ParentForm).checkSelectionInCurrentTag())
         bw.BaseStream.Position = this.offsetInMap - meta.offset;
     this.tagType = this.cbTagType.Text;
     this.tagName = this.cbTagIdent.Text;
     if (this.tagType == "")
         this.tagType = "null";
     this.tagIndex = map.Functions.ForMeta.FindByNameAndTagType(this.tagType, this.tagName);
     if (this.tagIndex != -1)
         this.identInt32 = map.MetaInfo.Ident[this.tagIndex];
     else
         this.identInt32 = -1;
     if (this.doesHaveTagType == true)
     {
         if (this.tagType != "null")
         {
             List<char> tempList = new List<char>(0);
             tempList.AddRange(this.tagType.ToCharArray(0, 4));
             tempList.TrimExcess();
             tempList.Reverse();
             char[] tempchar = tempList.ToArray();
             bw.Write(tempchar);
         }
         else
         {
             bw.Write((int)-1);
         }
     }
     bw.Write(this.identInt32);
 }
Esempio n. 10
0
 public override byte[] packMe()
 {
     System.IO.BinaryWriter writer = new System.IO.BinaryWriter(new System.IO.MemoryStream());
     writer.Write(message);
     writer.Write(bounced);
     return ((System.IO.MemoryStream)writer.BaseStream).GetBuffer();
 }
Esempio n. 11
0
        public static void split(string input_path, string dir_path, int nb)
        {
            System.IO.FileStream inf = new System.IO.FileStream(input_path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader reader = new System.IO.BinaryReader(inf);
            System.IO.BinaryWriter[] writers = new System.IO.BinaryWriter[nb];
            for (int x = 0; x < nb; x++)
            {
                writers[x] = new System.IO.BinaryWriter(new System.IO.FileStream(dir_path + "/part_" + (x + 1) + ".ACDC",
                                                                    System.IO.FileMode.Create,
                                                                    System.IO.FileAccess.Write));

            }
            int i = 0;
            while (reader.PeekChar() != -1)
            {

                writers[i % nb].Write(reader.ReadChar());

                i++;
            }
            for (int j=0; j<nb; j++)
            {
                writers[j].Close();
            }
            
        }
Esempio n. 12
0
        public override void BaseField_Leave(object sender, EventArgs e)
        {
            System.IO.BinaryWriter bw = new System.IO.BinaryWriter(meta.MS);
            if (((WinMetaEditor)this.ParentForm).checkSelectionInCurrentTag())
                bw.BaseStream.Position = this.offsetInMap - meta.offset;

            bw.Write((short)this.sidIndexer);
            bw.Write((byte) 0);
            bw.Write((byte)map.Strings.Length[this.sidIndexer]);

            /*
            // Check for typed value
            SID sid = (SID)(sender);
            if (sid.comboBox1.Text != map.Strings.Name[sid.sidIndexer])
            {
                for (int i = 0; i < map.Strings.Name.Length; i++)
                    if (map.Strings.Name[i].ToLower() == sid.comboBox1.Text.ToLower())
                    {
                        sid.sidIndexer = i;
                        break;
                    }
                sid.comboBox1.Text = map.Strings.Name[sid.sidIndexer];
            }
            */
            //if (this.AutoSave)
            //    this.Save();
        }
Esempio n. 13
0
 public override byte[] packMe()
 {
     System.IO.BinaryWriter writer = new System.IO.BinaryWriter(new System.IO.MemoryStream());
     writer.Write(frompos);
     writer.Write(topos);
     return ((System.IO.MemoryStream)writer.BaseStream).GetBuffer();
 }
Esempio n. 14
0
		public static byte[] SerializeVoxelAreaCompactData (VoxelArea v) {
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
			
			writer.Write (v.width);
			writer.Write (v.depth);
			writer.Write (v.compactCells.Length);
			writer.Write(v.compactSpans.Length);
			writer.Write(v.areaTypes.Length);
			
			for (int i=0;i<v.compactCells.Length;i++) {
				writer.Write(v.compactCells[i].index);
				writer.Write(v.compactCells[i].count);
			}
			
			for (int i=0;i<v.compactSpans.Length;i++) {
				writer.Write(v.compactSpans[i].con);
				writer.Write(v.compactSpans[i].h);
				writer.Write(v.compactSpans[i].reg);
				writer.Write(v.compactSpans[i].y);
			}
			for (int i=0;i<v.areaTypes.Length;i++) {
				//TODO: RLE encoding
				writer.Write(v.areaTypes[i]);
			}
			writer.Close();
			return stream.ToArray();
		}
Esempio n. 15
0
		public static byte[] SerializeVoxelAreaData (VoxelArea v) {
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
			
			writer.Write (v.width);
			writer.Write (v.depth);
			writer.Write (v.linkedSpans.Length);
			
			for (int i=0;i<v.linkedSpans.Length;i++) {
				writer.Write(v.linkedSpans[i].area);
				writer.Write(v.linkedSpans[i].bottom);
				writer.Write(v.linkedSpans[i].next);
				writer.Write(v.linkedSpans[i].top);
			}
			
			//writer.Close();
			writer.Flush();
			Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
			stream.Position = 0;
			zip.AddEntry ("data",stream);
			System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
			zip.Save(stream2);
			byte[] bytes = stream2.ToArray();
			stream.Close();
			stream2.Close();
			return bytes;
		}
Esempio n. 16
0
 public override void BaseField_Leave(object sender, EventArgs e)
 {
     System.IO.BinaryWriter bw = new System.IO.BinaryWriter(meta.MS);
     if (((WinMetaEditor)this.ParentForm).checkSelectionInCurrentTag())
         bw.BaseStream.Position = this.offsetInMap - meta.offset;
     try
     {
         this.value = int.Parse(this.comboBox1.Text);
     }
     catch
     {
         this.value = this.comboBox1.SelectedIndex;
     }
     switch (this.enumType)
     {
         case 8:
             {
                 bw.Write(Convert.ToByte(this.value));
                 break;
             }
         case 16:
             {
                 bw.Write(Convert.ToInt16(this.value));
                 break;
             }
         case 32:
             {
                 bw.Write(this.value);
                 break;
             }
     }
 }
Esempio n. 17
0
        public void getPdfFile(string fileName)
        {

            using (SqlConnection cn = new SqlConnection(ConnectionString))
            {
                cn.Open();
                using (SqlCommand cmd = new SqlCommand($"select FileSource from PdfDocumentFiles  where Name='{fileName}' ", cn))
                {
                    using (SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.Default))
                    {
                        if (dr.Read())
                        {

                            byte[] fileData = (byte[])dr.GetValue(0);
                            using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite))
                            {
                                using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs))
                                {
                                    bw.Write(fileData);
                                    bw.Close();
                                }
                            }
                        }

                        dr.Close();
                    }
                }

            }
        }
 public ByteBuffer(byte[] data)
 {
     stream = new System.IO.MemoryStream();
     reader = new System.IO.BinaryReader(stream);
     writer = new System.IO.BinaryWriter(stream);
     writer.Write(data);
     stream.Position = 0;
 }
 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();
 }
		public static void Save(string directory, string file,string ext, XCImageCollection images)
		{
			System.IO.BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.Create(directory+"\\"+file+ext));
			foreach(XCImage tile in images)
				bw.Write(tile.Bytes);
			bw.Flush();
			bw.Close();
		}
Esempio n. 21
0
        // ***** Start pairing (play sound)*****
        private void button1_Click(object sender, EventArgs e)
        {
            if (clsHvcw.GenerateSound(textSSID.Text, textPassword.Text, txtToken) == true)
            {
                // Read sound file
                byte[] buf = System.IO.File.ReadAllBytes(clsHvcw.SoundFile);

                // Stop when sound playing
                if (player != null)
                    StopSound();

                player = new System.Media.SoundPlayer();

                // Wav header definition
                WAVHDR wavHdr = new WAVHDR();

                uint fs = 8000;

                wavHdr.formatid = 0x0001;                                       // PCM uncompressed
                wavHdr.channel = 1;                                             // ch=1 mono
                wavHdr.fs = fs;                                                 // Frequency
                wavHdr.bytespersec = fs * 2;                                    // 16bit
                wavHdr.blocksize = 2;                                           // 16bit mono so block size (byte/sample x # of channels) is 2
                wavHdr.bitspersample = 16;                                      // bit/sample
                wavHdr.size = (uint)buf.Length;                                 // Wave data byte number
                wavHdr.fileSize = wavHdr.size + (uint)Marshal.SizeOf(wavHdr);   // Total byte number

                // Play sound through memory stream
                System.IO.MemoryStream memoryStream = new System.IO.MemoryStream((int)wavHdr.fileSize);
                System.IO.BinaryWriter bWriter = new System.IO.BinaryWriter(memoryStream);

                // Write Wav header
                foreach (byte b in wavHdr.getByteArray())
                {
                    bWriter.Write(b);
                }
                // Write PCM data
                foreach (byte data in buf)
                {
                    bWriter.Write(data);
                }
                bWriter.Flush();

                memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                player.Stream = memoryStream;

                // Async play
                player.Play();

                // Wait until sound playing is over with following:
                // player.PlaySync();
            }
            else
            {
                MessageBox.Show("Pairing sound creation failed", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 22
0
 public override byte[] GetMessageBody()
 {
     System.IO.MemoryStream ms = new System.IO.MemoryStream ();
     System.IO.BinaryWriter bw = new System.IO.BinaryWriter (ms);
     bw.Write (userData.Length);
     foreach (var ud in userData)
         bw.Write (ud.GetMessageBody ());
     return ms.ToArray ();
 }
Esempio n. 23
0
 public void WriteZippedResources()
 {
     using (var binWriter = new System.IO.BinaryWriter(this.fileSystem.File.OpenWrite(MyDhtmlResourceSet.ZippedResources.LocalPath)))
     {
         binWriter.Write(Properties.Resources.Pickles_BaseDhtmlFiles);
         binWriter.Flush();
         binWriter.Close();
     }
 }
Esempio n. 24
0
 public void SaveToFile(string fileName)
 {
     using(var writer = new System.IO.BinaryWriter(System.IO.File.OpenWrite(fileName)))
     {
         writer.Write(_header);
         writer.Write(_bytes);
         writer.Flush();
     }
 }
Esempio n. 25
0
 public byte[] Serialize()
 {
     using (System.IO.MemoryStream MS =  new System.IO.MemoryStream ()) {
         using (System.IO.BinaryWriter BW = new System.IO.BinaryWriter (MS, System.Text.Encoding.Unicode)) {
             BW.Write (connectionString);
         }
         return MS.ToArray ();
     }
 }
		public void Save ( System.IO.Stream stream ) {
			var writer = new System.IO.BinaryWriter ( stream );
			writer.Write (dict.Count);
			foreach (KeyValuePair<string,ZipEntry> pair in dict) {
				writer.Write (pair.Key);
				writer.Write (pair.Value.bytes.Length);
				writer.Write (pair.Value.bytes);
			}
		}
Esempio n. 27
0
 /// <summary>
 /// 将Base64编码字符串解码并存储到一个文件中
 /// </summary>
 /// <param name="Base64String">经过Base64编码后的字符串</param>
 /// <param name="strSaveFileName">要输出的文件路径,如果文件存在,将被重写</param>
 /// <returns>如果操作成功,则返回True</returns>
 public static bool DecodingFileFromString(string Base64String, string strSaveFileName)
 {
     System.IO.FileStream fs = new System.IO.FileStream(strSaveFileName, System.IO.FileMode.Create);
     System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
     bw.Write(Convert.FromBase64String(Base64String));
     //bw.Write(Convert.ToBase64String)
     bw.Close();
     fs.Close();
     return true;
 }
Esempio n. 28
0
        static void Main(string[] args)
        {
            var options = new SwitchOptions();
            if (!CommandLine.ParseArguments(args, options))
                return;

            try
            {
                            if (String.IsNullOrEmpty(options.outFile))
                            {
                                Console.WriteLine("You must supply an outfile.");
                                return;
                            }

                            var source = new System.IO.StreamReader(options.inFile);
                            var lexed = new LexResult();
                            var r = Lexer.Lex(source, lexed);
                            if (r == 0x00)
                            {
                                var destination = System.IO.File.Open(options.outFile, System.IO.FileMode.Create);
                                var writer = new System.IO.BinaryWriter(destination);
                                r = Assembler.Assemble(lexed, writer);
                                writer.Flush();
                                destination.Flush();
                                writer.Close();
                            }
                            Console.WriteLine("Finished with code " + r);
            }
            /*case "emulate":
                        {
                            var source = System.IO.File.Open(options.inFile, System.IO.FileMode.Open);
                            var emulator = new IN8();
                            source.Read(emulator.MEM, 0, 0xFFFF);

                            // Attach devices
                            var teletypeTerminal = new TT3();
                            emulator.AttachHardware(teletypeTerminal, 0x04);

                            while (emulator.STATE_FLAGS == 0x00) emulator.Step();

                            Console.WriteLine(String.Format("Finished in state {0:X2}", emulator.STATE_FLAGS));
                            Console.WriteLine(String.Format("{0:X2} {1:X2} {2:X2} {3:X2} {4:X2} {5:X2} {6:X2} {7:X2}",
                                emulator.A, emulator.B, emulator.C, emulator.D, emulator.E, emulator.H, emulator.L, emulator.O));
                            Console.WriteLine(String.Format("{0:X4} {1:X4} {2:X8}", emulator.IP, emulator.SP, emulator.CLOCK));
                            break;
                        }
                }
            }*/
            catch (Exception e)
            {
                Console.WriteLine("An error occured.");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Esempio n. 29
0
    static System.IO.FileStream fs; //файловый поток - (запись/чтение) в файл двоичных данных

    #endregion Fields

    #region Methods

    static void Main()
    {
        enc = System.Text.Encoding.GetEncoding(1251);

         fs = new System.IO.FileStream("log.txt", System.IO.FileMode.Create , System.IO.FileAccess.Write ); //на запись
         bw = new System.IO.BinaryWriter(fs, enc);    //инициализация файловым потоком, с указанием рабочей кодировки

         //по умолчанию запись идет в кодировке utf8
         SayFile("{0} - {1} - {2}", "Hello", "File", "Приветик");
         fs.Close();
    }
Esempio n. 30
0
 public DebuggerServer(DebugService ds)
 {
     this.ds = ds;
     bw      = new System.IO.BinaryWriter(sendStream);
 }
Esempio n. 31
0
 public override void Pack(IInternalPersistent parent, System.IO.BinaryWriter writer)
 {
     base.Pack(parent, writer);
     writer.Write(Address);
 }
Esempio n. 32
0
 public virtual void Serialize(System.IO.BinaryWriter aWriter)
 {
 }
Esempio n. 33
0
 public override void SendExtraAI(System.IO.BinaryWriter writer)
 {
     writer.Write(this.target);
 }
Esempio n. 34
0
 /// <summary>
 /// Serialize
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="writer"></param>
 public void Pack(IInternalPersistent parent, System.IO.BinaryWriter writer)
 {
     writer.Write(StartBlockAddress);
     writer.Write(EndBlockAddress);
     writer.Write(Count);
 }
Esempio n. 35
0
        public void RepackFolder(string path, bool newFormat)
        {
            newUnpack = newFormat;
            string[] files  = System.IO.Directory.GetFiles(path, "*.*", System.IO.SearchOption.AllDirectories);
            string   folder = System.IO.Path.GetDirectoryName(path);
            string   file   = folder + "\\" + System.IO.Path.GetFileName(path) + ".dat";

            NameOfFile = file.ToLower();
            string tmpFile = folder + "\\" + System.IO.Path.GetFileName(path) + ".tmp";

            System.IO.FileStream   fsTmp = new System.IO.FileStream(tmpFile, System.IO.FileMode.Create);
            System.IO.FileStream   fs2   = new System.IO.FileStream(file, System.IO.FileMode.Create);
            System.IO.BinaryWriter bw    = new System.IO.BinaryWriter(fs2);
            int           offset         = 0;
            ArchiveHeader header         = new ArchiveHeader();

            foreach (string i in files)
            {
                byte[]     buffer = PackFile(i, out int uncompressedSize, out int compressedSize);
                FileHeader f      = new FileHeader()
                {
                    Name           = i.Replace(path + "\\", ""),
                    Offset         = offset,
                    Size           = uncompressedSize,
                    EncryptedSize  = buffer.Length,
                    CompressedSize = compressedSize
                };
                fsTmp.Write(buffer, 0, buffer.Length);
                header.Files.Add(f.Name, f);
                offset += buffer.Length;
            }

            System.IO.MemoryStream ms  = new System.IO.MemoryStream();
            System.IO.BinaryWriter bw2 = new System.IO.BinaryWriter(ms);
            foreach (FileHeader i in header.Files.Values)
            {
                bw2.Write(i.Name.Length);
                bw2.Write(Encoding.Unicode.GetBytes(i.Name));
                ms.Position++;
                bw2.Write((byte)1);
                bw2.Write((byte)1);
                ms.Position++;
                bw2.Write(i.Size);
                bw2.Write(i.CompressedSize);
                bw2.Write(i.EncryptedSize);
                bw2.Write(i.Offset);
                ms.Position += 60;
            }
            fsTmp.Flush();
            byte[] table = ms.ToArray();
            header.TableSize           = table.Length;
            table                      = packAndEncrypt(table);
            header.TableCompressedSize = table.Length;

            bw.Write(0x45534f55);
            bw.Write(0x424c4144);
            bw.Write((byte)2);

            fs2.Position = 21;
            bw.Write(header.Files.Count);
            bw.Write((byte)1);
            bw.Write((byte)1);
            fs2.Position = 89;
            bw.Write(header.TableCompressedSize);
            bw.Write(header.TableSize);
            bw.Write(table);
            bw.Write((int)(fs2.Position + 4));

            fsTmp.Position = 0;
            foreach (FileHeader i in header.Files.Values)
            {
                byte[] buf = new byte[i.EncryptedSize];
                fsTmp.Read(buf, 0, i.EncryptedSize);
                bw.Write(buf);
            }
            fsTmp.Close();
            bw.Flush();
            fs2.Flush();
            fs2.Close();
            System.IO.File.Delete(tmpFile);
        }
Esempio n. 36
0
        private void    LoadHeightMap(System.IO.FileInfo _FileName)
        {
            try {
                panelParameters.Enabled = false;

                // Dispose of existing resources
                if (m_BitmapSource != null)
                {
                    m_BitmapSource.Dispose();
                }
                m_BitmapSource = null;

                if (m_TextureTarget_CPU != null)
                {
                    m_TextureTarget_CPU.Dispose();
                }
                m_TextureTarget_CPU = null;
                if (m_TextureTarget0 != null)
                {
                    m_TextureTarget0.Dispose();
                }
                m_TextureTarget0 = null;
                if (m_TextureTarget1 != null)
                {
                    m_TextureTarget1.Dispose();
                }
                m_TextureTarget1 = null;
                if (m_TextureSource != null)
                {
                    m_TextureSource.Dispose();
                }
                m_TextureSource = null;

                // Load the source image assuming it's in linear space
                m_SourceFileName = _FileName;
                m_BitmapSource   = new ImageUtility.Bitmap(_FileName, m_ProfileLinear);
                outputPanelInputHeightMap.Image = m_BitmapSource;

                W = m_BitmapSource.Width;
                H = m_BitmapSource.Height;

                // Build the source texture
                RendererManaged.PixelsBuffer SourceHeightMap = new RendererManaged.PixelsBuffer(W * H * 4);
                using (System.IO.BinaryWriter Wr = SourceHeightMap.OpenStreamWrite())
                    for (int Y = 0; Y < H; Y++)
                    {
                        for (int X = 0; X < W; X++)
                        {
                            Wr.Write(m_BitmapSource.ContentXYZ[X, Y].y);
                        }
                    }

                m_TextureSource = new RendererManaged.Texture2D(m_Device, W, H, 1, 1, RendererManaged.PIXEL_FORMAT.R32_FLOAT, false, false, new RendererManaged.PixelsBuffer[] { SourceHeightMap });

                // Build the target UAV & staging texture for readback
                m_TextureTarget0    = new RendererManaged.Texture2D(m_Device, W, H, 1, 1, RendererManaged.PIXEL_FORMAT.R32_FLOAT, false, true, null);
                m_TextureTarget1    = new RendererManaged.Texture2D(m_Device, W, H, 1, 1, RendererManaged.PIXEL_FORMAT.R32_FLOAT, false, true, null);
                m_TextureTarget_CPU = new RendererManaged.Texture2D(m_Device, W, H, 1, 1, RendererManaged.PIXEL_FORMAT.R32_FLOAT, true, false, null);

                panelParameters.Enabled = true;
                buttonGenerate.Focus();
            } catch (Exception _e) {
                MessageBox("An error occurred while opening the image:\n\n", _e);
            }
        }
Esempio n. 37
0
 public void Save(System.IO.BinaryWriter writer)
 {
 }
Esempio n. 38
0
 /// <summary>
 /// Serializes a the Attributes stored in this Instance to the BinaryStream
 /// </summary>
 /// <param name="writer">The Stream the Data should be stored to</param>
 /// <remarks>
 /// Be sure that the Position of the stream is Proper on
 /// return (i.e. must point to the first Byte after your actual File)
 /// </remarks>
 public void Serialize(System.IO.BinaryWriter writer)
 {
     writer.Write(unknown1);
     writer.Write(unknown2);
 }
Esempio n. 39
0
 protected override void DoSerialize(System.IO.BinaryWriter writer)
 {
     writer.Write(rot);
     writer.Write(guid);
 }
Esempio n. 40
0
 public override void Serialize(System.IO.BinaryWriter aWriter)
 {
     aWriter.Write((byte)JSONNodeType.String);
     aWriter.Write(m_Data);
 }
Esempio n. 41
0
        public static void createIpsFromCSV(int nRegisters, int sizeRegisters, int address, Dictionary <String, Byte> inputTBL)
        {
            List <String> inputStr = CSV_Manager.openFixedSizedTableCSV();

            if (inputStr.Count != nRegisters)
            {
                return;
            }

            List <Byte> byteStream = new List <Byte>();
            Byte        addressL   = (Byte)((address >> 0x00) & 0x0000FF);
            Byte        addressM   = (Byte)((address >> 0x08) & 0x0000FF);
            Byte        addressH   = (Byte)((address >> 0x10) & 0x0000FF);
            Byte        sizeL      = (Byte)(((nRegisters * sizeRegisters) >> 0x00) & 0x0000FF);
            Byte        sizeH      = (Byte)(((nRegisters * sizeRegisters) >> 0x08) & 0x0000FF);

            byteStream.Add(0x50);     //P
            byteStream.Add(0x41);     //A
            byteStream.Add(0x54);     //T
            byteStream.Add(0x43);     //C
            byteStream.Add(0x48);     //H

            byteStream.Add(addressH); //address H
            byteStream.Add(addressM); //address M
            byteStream.Add(addressL); //address L
            byteStream.Add(sizeH);    //size H
            byteStream.Add(sizeL);    //size L

            foreach (String item in inputStr)
            {
                byteStream.AddRange(parseStringList(item, inputTBL, sizeRegisters)); //Byte table
            }

            byteStream.Add(0x45); //E
            byteStream.Add(0x4F); //O
            byteStream.Add(0x46); //F

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter   = "IPS File|*.ips";
            saveFileDialog.Title    = "Choose a IPS file";
            saveFileDialog.FileName = "newTable" + address.ToString("X6");

            /* Show the Dialog */
            if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (saveFileDialog.FileName != "")
                {
                    System.IO.FileStream   fs = (System.IO.FileStream)saveFileDialog.OpenFile();
                    System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);

                    try
                    {
                        bw.Write(byteStream.ToArray());
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Error writing the file: \r\n" + e.ToString(), "Error");
                    }

                    bw.Close();
                    fs.Close();
                }
            }
        }
 public override void Write(System.IO.BinaryWriter stream)
 {
     stream.Write(protocolVersion);
     WriteBytes(stream, salt);
     WriteBytes(stream, new byte[10240]);
 }
Esempio n. 43
0
 public override void Pack(IInternalPersistent parent, System.IO.BinaryWriter writer)
 {
     writer.Write(CollectionName);
     writer.Write(Filename);
     writer.Write(ServerSystemFilename);
 }
Esempio n. 44
0
 protected abstract void SerializeLocation(LocationType l, System.IO.BinaryWriter stream);
Esempio n. 45
0
 /// <inheritdoc/>
 void IFileSystem.WriteBinary(System.IO.Stream stream, byte[] bytes)
 {
     using var bw = new System.IO.BinaryWriter(stream);
     bw.Write(bytes);
 }
Esempio n. 46
0
 //UPGRADE_TODO: Class 'java.io.DataOutputStream' was converted to 'System.IO.BinaryWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataOutputStream'"
 public override void  metaWriteExternal(System.IO.BinaryWriter out_Renamed)
 {
     ExtWrapTagged.writeTag(out_Renamed, val == null?new System.Object():val);
 }
Esempio n. 47
0
 /// <summary>
 /// Writes the _header.
 /// </summary>
 /// <param name="writer">The writer.</param>
 public override void WriteHeader(System.IO.BinaryWriter writer)
 {
     Header.Size = (uint)Length;
     Header.Write(writer);
 }
Esempio n. 48
0
 /// <summary>
 /// Serializes a the Attributes stored in this Instance to the BinaryStream
 /// </summary>
 /// <param name="writer">The Stream the Data should be stored to</param>
 /// <remarks>
 /// Be sure that the Position of the stream is Proper on
 /// return (i.e. must point to the first Byte after your actual File)
 /// </remarks>
 public override void Serialize(System.IO.BinaryWriter writer)
 {
     writer.Write(version);
 }
        /// <summary>
        /// Recebe um arquivo.
        /// </summary>
        /// <returns>Nome do arquivo.</returns>
        /// <param name="p_endpoint">Ponto de comunicação.</param>
        /// <exception cref="Spartacus.Net.Exception">Exceção pode ocorrer quando não conseguir receber o arquivo.</exception>
        public string RecvFile(int p_endpoint)
        {
            System.IO.FileStream   v_file;
            System.IO.BinaryWriter v_writer;
            Spartacus.Net.Packet   v_packetrecv, v_packetsend;
            int v_numpackets, v_sequence;

            try
            {
                // recebendo nome do arquivo
                v_packetrecv = this.Recv(p_endpoint);

                if (v_packetrecv.v_type != Spartacus.Net.PacketType.FILE)
                {
                    return(null);
                }

                v_file = new System.IO.FileStream(v_packetrecv.GetString(), System.IO.FileMode.Create, System.IO.FileAccess.Write);

                v_writer = new System.IO.BinaryWriter(v_file);

                // enviando ack
                v_packetsend = new Spartacus.Net.Packet(Spartacus.Net.PacketType.ACK, "");
                this.Send(p_endpoint, v_packetsend);

                // recebendo primeiro pacote de dados do arquivo
                v_packetrecv = this.Recv(p_endpoint);

                v_sequence   = 0;
                v_numpackets = v_packetrecv.v_numpackets;

                // se a sequencia estah errada, entao precisa tratar um erro
                // if (v_packet.v_sequence != v_sequence)

                v_writer.Write(v_packetrecv.v_data);

                // enviando ack
                v_packetsend = new Spartacus.Net.Packet(Spartacus.Net.PacketType.ACK, v_sequence, v_numpackets, "");
                this.Send(p_endpoint, v_packetsend);

                v_sequence++;
                while (v_sequence < v_numpackets)
                {
                    // recebendo pacote
                    v_packetrecv = this.Recv(p_endpoint);

                    // se a sequencia estah errada, entao precisa tratar um erro
                    // if (v_packet.v_sequence != v_sequence)

                    // se o numero de pacotes estah errado, entao precisa tratar um erro
                    // if (v_packet.v_numpackets != v_numpackets)

                    // acumulando conteudo dos dados do pacote na string
                    v_writer.Write(v_packetrecv.v_data);

                    // enviando ack
                    v_packetsend = new Spartacus.Net.Packet(Spartacus.Net.PacketType.ACK, v_sequence, v_numpackets, "");
                    this.Send(p_endpoint, v_packetsend);

                    v_sequence++;
                }

                v_writer.Flush();
                v_writer.Close();

                return(v_file.Name);
            }
            catch (Spartacus.Net.Exception e)
            {
                throw e;
            }
            catch (System.Exception e)
            {
                throw new Spartacus.Net.Exception(e);
            }
        }
Esempio n. 50
0
        public void SaveToStream(System.IO.Stream aData)
        {
            var W = new System.IO.BinaryWriter(aData);

            Serialize(W);
        }
Esempio n. 51
0
 /* (non-Javadoc)
  * @see org.javarosa.core.util.externalizable.Externalizable#writeExternal(java.io.DataOutputStream)
  */
 //UPGRADE_TODO: Class 'java.io.DataOutputStream' was converted to 'System.IO.BinaryWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataOutputStream'"
 public virtual void writeExternal(System.IO.BinaryWriter out_Renamed)
 {
     ExtUtil.write(out_Renamed, new ExtWrapTagged(e));
 }
Esempio n. 52
0
 public virtual void Serialize(System.IO.BinaryWriter stream)
 {
     SerializeLocation(CurrentPos.Value, stream);
 }
Esempio n. 53
0
        protected override void Update()
        {
            this.activeWormWalkers.RemoveAll((GameObject o) => o == null);
            this.activeWormTrees.RemoveAll((GameObject o) => o == null);
            this.activeWormSingle.RemoveAll((GameObject o) => o == null);
            this.activeWormAngels.RemoveAll((GameObject o) => o == null);
            if (this.activeWormWalkers.Count > 0 || this.activeWormAngels.Count > 0 || this.activeWormTrees.Count > 0)
            {
                this.anyFormSpawned = true;
            }
            else
            {
                this.anyFormSpawned = false;
            }
            if (this.activeWormSingle.Count == 0 && this.init)
            {
                if (GameSetup.IsMpServer || GameSetup.IsSinglePlayer)
                {
                    long Exp;
                    switch (ModSettings.difficulty)
                    {
                    case ModSettings.Difficulty.Easy:
                        Exp = 5000;
                        break;

                    case ModSettings.Difficulty.Veteran:
                        Exp = 20000;
                        break;

                    case ModSettings.Difficulty.Elite:
                        Exp = 100000;
                        break;

                    case ModSettings.Difficulty.Master:
                        Exp = 3000000;
                        break;

                    case ModSettings.Difficulty.Challenge1:
                        Exp = 50000000;
                        break;

                    case ModSettings.Difficulty.Challenge2:
                        Exp = 100000000;
                        break;

                    case ModSettings.Difficulty.Challenge3:
                        Exp = 500000000;
                        break;

                    case ModSettings.Difficulty.Challenge4:
                        Exp = 1000000000;
                        break;

                    case ModSettings.Difficulty.Challenge5:
                        Exp = 5000000000;
                        break;

                    default:
                        Exp = 10000000000;
                        break;
                    }
                    if (GameSetup.IsMpServer)
                    {
                        using (System.IO.MemoryStream answerStream = new System.IO.MemoryStream())
                        {
                            using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(answerStream))
                            {
                                w.Write(10);
                                w.Write(Exp);
                                w.Close();
                            }
                            Network.NetworkManager.SendLine(answerStream.ToArray(), Network.NetworkManager.Target.Everyone);
                            answerStream.Close();
                        }
                    }
                    else
                    {
                        ModdedPlayer.instance.AddKillExperience(Exp);
                    }
                    int itemCount = UnityEngine.Random.Range(15, 26);
                    for (int i = 0; i < itemCount; i++)
                    {
                        Network.NetworkManager.SendItemDrop(ItemDataBase.GetRandomItem(Exp), LocalPlayer.Transform.position + Vector3.up * 2);
                    }
                }
                UnityEngine.Object.Destroy(base.gameObject);
            }
        }
Esempio n. 54
0
 public override void save(System.IO.BinaryWriter Data)
 {
     Data.Write(type.typeID);
     Data.Write(time);
 }
 protected override void WriteID(System.IO.BinaryWriter writer)
 {
     FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);
     writer.Write(Item.KnownFolder.ToByteArray());
 }
Esempio n. 56
0
 public override void BinaryWriteValue(System.IO.BinaryWriter writer, string value)
 {
     writer.Write(value);
 }
Esempio n. 57
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. 58
0
 public void WriteTo(System.IO.BinaryWriter writer)
 {
     writer.Write(Id);
     writer.Write(Score);
 }
Esempio n. 59
0
        /* public static void exportCompressedImage(System.IO.BinaryReader br, long address, int headerOffset, int type, bool unheaded = false)
         * {
         *  //Dummy.exportCompressedImage(0x031E83, br, headerOffset, 4); // Chocobo Haryuu and PJs
         *
         *  List<Byte> picture = Compressor.uncompress(address, br, headerOffset, unheaded);
         *  System.Drawing.Bitmap newBitmap = new System.Drawing.Bitmap(0, 0);
         *
         *  //System.IO.File.WriteAllBytes("DummyImage.smc", picture.ToArray());
         *
         *  switch (type)
         *  {
         *      case 01:
         *          newBitmap = Transformations.transform1bpp(picture, 0, picture.Count);
         *          ManageBMP.exportBPM("1bpp", newBitmap, Palettes.palette1b);
         *          break;
         *      case 02:
         *          newBitmap = Transformations.transform2bpp(picture, 0, picture.Count);
         *          ManageBMP.exportBPM("2bpp", newBitmap, Palettes.palette2b);
         *          break;
         *      case 03:
         *          newBitmap = Transformations.transform3bpp(picture, 0, picture.Count);
         *          ManageBMP.exportBPM("3bpp", newBitmap, Palettes.palette3b);
         *          break;
         *      case 04:
         *          newBitmap = Transformations.transform4b(picture, 0, picture.Count);
         *          ManageBMP.exportBPM("4bpp", newBitmap, Palettes.palette4b);
         *          break;
         *      default:
         *          break;
         *  };
         * }
         */



        /* public static void injectImage(System.IO.BinaryWriter bw, long address, int headerOffset, int type, int imageSize, int maxCompSize, bool unheaded = false)
         * {
         *  //Dummy.injectImage(bw, 0x105C0A, headerOffset, 0x04, 0x1400, 0x0BF5); // New Title
         *
         *  List<Byte> newBytes = new List<Byte>();
         *  Byte size00 = BitConverter.GetBytes(imageSize)[1];
         *  Byte size01 = BitConverter.GetBytes(imageSize)[0];
         *
         *  System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
         *  openFileDialog.Filter = "PNG File|*.png|BMP File|*.bmp";
         *  openFileDialog.Title = "Choose a file";
         *
         *  // Show the Dialog
         *  if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         *  {
         *      if (openFileDialog.FileName != "")
         *      {
         *          try
         *          {
         *              System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(openFileDialog.FileName);
         *              int size = bitmap.Width * bitmap.Height;
         *              byte[] bitmapPixels = new byte[size];
         *
         *              // Open it to edit
         *              System.Drawing.Imaging.BitmapData data = bitmap.LockBits(
         *                  new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
         *                  System.Drawing.Imaging.ImageLockMode.WriteOnly,
         *                  System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
         *
         *              // Recover the original values (now lost because of the conversion)
         *              for (int i = 0; i < size; i++)
         *              {
         *                  bitmapPixels[i] = System.Runtime.InteropServices.Marshal.ReadByte(data.Scan0, i);
         *              }
         *
         *              int nColumns = (int)Math.Truncate(128.0 / 8);
         *              size = (size - (size % ((8 * nColumns) * 8)));
         *              if (size == imageSize * 2)
         *              {
         *                  switch (type)
         *                  {
         *                      case 01:
         *                          newBytes = InvertingTransformations.import1bpp(bitmapPixels, 8, 8, size);
         *                          break;
         *                      case 02:
         *                          newBytes = InvertingTransformations.import2bpp(bitmapPixels, 8, 8, size);
         *                          break;
         *                      case 03:
         *                          newBytes = InvertingTransformations.import3bpp(bitmapPixels, 8, 8, size);
         *                          break;
         *                      case 04:
         *                          newBytes = InvertingTransformations.import4bpp(bitmapPixels, 8, 8, size);
         *                          break;
         *                      default:
         *                          break;
         *                  };
         *              }
         *              else
         *              {
         *                  newBytes = new List<Byte>();
         *              }
         *          }
         *          catch (Exception error)
         *          {
         *              System.Windows.Forms.MessageBox.Show("Error reading the file: " + error.ToString(), "Error");
         *          }
         *      }
         *  }
         *
         *  openFileDialog.Dispose();
         *  openFileDialog = null;
         *
         *  newBytes = Compressor.compress(newBytes, null);
         *  newBytes.Insert(0, BitConverter.GetBytes(imageSize)[1]);
         *  newBytes.Insert(0, BitConverter.GetBytes(imageSize)[0]);
         *
         *  if(!unheaded)
         *    newBytes.Insert(0, 0x02);
         *
         *  if (newBytes.Count <= maxCompSize)
         *  {
         *      try
         *      {
         *          bw.BaseStream.Position = address + headerOffset;
         *
         *          foreach (Byte item in newBytes)
         *          {
         *              bw.BaseStream.WriteByte(item);
         *          }
         *
         *          System.Windows.Forms.MessageBox.Show("Operation done successfully.", "Info");
         *      }
         *      catch (Exception e)
         *      {
         *          System.Windows.Forms.MessageBox.Show("Error writing the file: " + e.ToString(), "Error");
         *      }
         *  }
         *  else
         *  {
         *      System.Windows.Forms.MessageBox.Show("Compressed data is bigger than expected.", "Error");
         *  }
         * }
         */



        public static void injectNewTitleOAM(System.IO.BinaryWriter bw, int headerOffset)
        {
            List <Byte> newTable = new List <byte>()
            {
                //  Ac    AX    AY    TL    Fl    B1    B2
                //----------------------------------------
                0x40, 0x58, 0xB8, 0x80, 0x38, 0x00, 0x00, // (C)
                0x8F, 0x10, 0x00, 0x81, 0x38, 0x00, 0x00, // S
                0x8F, 0x08, 0x00, 0x82, 0x38, 0x00, 0x00, // Q
                0x8F, 0x08, 0x00, 0x83, 0x38, 0x00, 0x00, // U
                0x8F, 0x08, 0x00, 0x84, 0x38, 0x00, 0x00, // A
                0x8F, 0x08, 0x00, 0x85, 0x38, 0x00, 0x00, // R
                0x8F, 0x08, 0x00, 0x86, 0x38, 0x00, 0x00, // E
                0x8F, 0x10, 0x00, 0x87, 0x38, 0x00, 0x00, // 19
                0x8F, 0x08, 0x00, 0x88, 0x38, 0x00, 0x00, // 92
                0x49, 0x20, 0x00, 0x00, 0x0C, 0x08, 0x00, // Dragon
                0x8F, 0x10, 0x00, 0x02, 0x0C, 0x20, 0x00,
                0x8F, 0x10, 0x00, 0x04, 0x0C, 0x80, 0x00,
                0x8F, 0x10, 0x00, 0x06, 0x0C, 0x00, 0x02,
                0x8F, 0x10, 0x00, 0x08, 0x0C, 0x00, 0x08,
                0x8F, 0x10, 0x00, 0x0A, 0x0C, 0x00, 0x20,
                0x8F, 0x10, 0x00, 0x0C, 0x0C, 0x00, 0x80,
                0x8F, 0xA0, 0x10, 0x20, 0x0C, 0x02, 0x00,
                0x8F, 0x10, 0x00, 0x22, 0x0C, 0x08, 0x00,
                0x8F, 0x10, 0x00, 0x24, 0x0C, 0x20, 0x00,
                0x8F, 0x10, 0x00, 0x26, 0x0C, 0x80, 0x00,
                0x8F, 0x10, 0x00, 0x28, 0x0C, 0x00, 0x02,
                0x8F, 0x10, 0x00, 0x2A, 0x0C, 0x00, 0x08,
                0x8F, 0x10, 0x00, 0x2C, 0x0C, 0x00, 0x20,
                0x8F, 0x10, 0x00, 0x2E, 0x0C, 0x00, 0x80,
                0x8F, 0x90, 0x10, 0x40, 0x0C, 0x02, 0x00,
                0x8F, 0x10, 0x00, 0x42, 0x0C, 0x08, 0x00,
                0x8F, 0x10, 0x00, 0x44, 0x0C, 0x20, 0x00,
                0x8F, 0x10, 0x00, 0x46, 0x0C, 0x80, 0x00,
                0x8F, 0x10, 0x00, 0x48, 0x0C, 0x00, 0x02,
                0x8F, 0x10, 0x00, 0x4A, 0x0C, 0x00, 0x08,
                0x8F, 0x10, 0x00, 0x4C, 0x0C, 0x00, 0x20,
                0x8F, 0x10, 0x00, 0x4E, 0x0C, 0x00, 0x80,
                0x8F, 0x90, 0x10, 0x60, 0x0C, 0x02, 0x00,
                0x8F, 0x10, 0x00, 0x62, 0x0C, 0x08, 0x00,
                0x8F, 0x10, 0x00, 0x64, 0x0C, 0x20, 0x00,
                0x8F, 0x10, 0x00, 0x66, 0x0C, 0x80, 0x00,
                0x8F, 0x10, 0x00, 0x68, 0x0C, 0x00, 0x02,
                0x8F, 0x10, 0x00, 0x6A, 0x0C, 0x00, 0x08,
                0x8F, 0x10, 0x00, 0x6C, 0x0C, 0x00, 0x20,
                0x8F, 0x10, 0x00, 0x6E, 0x0C, 0x00, 0x80,
                0x8F, 0x10, 0xE0, 0x0E, 0x0C, 0x02, 0x00,
                0x70, 0x69, 0xC2, 0x8A, 0x38, 0x00, 0x00, // noisecross
                0x8F, 0x08, 0x00, 0x8B, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x8C, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x8D, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x8E, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x8F, 0x38, 0x00, 0x00,
                0x76, 0x69, 0xCB, 0x9A, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x9B, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x9C, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x9D, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x9E, 0x38, 0x00, 0x00,
                0x8F, 0x08, 0x00, 0x9F, 0x38, 0x00, 0x00,
                0x7C, 0xA0, 0xC7, 0x97, 0x38, 0x00, 0x00, // 2015
                0x8F, 0x08, 0x00, 0x98, 0x38, 0x00, 0x00,
                0x80
            };
            int imageSize = newTable.Count;

            newTable = Compressor.compress(newTable, null);

            newTable.Insert(0, BitConverter.GetBytes(imageSize)[1]);
            newTable.Insert(0, BitConverter.GetBytes(imageSize)[0]);
            newTable.Insert(0, 0x02);

            if (newTable.Count <= 0x450)
            {
                try
                {
                    bw.BaseStream.Position = 0x105C0A + headerOffset;

                    foreach (Byte item in newTable)
                    {
                        bw.BaseStream.WriteByte(item);
                    }

                    System.Windows.Forms.MessageBox.Show("Operation done successfully.", "Info");
                }
                catch (Exception e)
                {
                    System.Windows.Forms.MessageBox.Show("Error writing the file: " + e.ToString(), "Error");
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Compressed data is bigger than expected.", "Error");
            }
        }
Esempio n. 60
-1
 public BufferStream(System.IO.Stream stream, bool littleEndian)
 {
     LittleEndian = littleEndian;
     mReader = new System.IO.BinaryReader(stream);
     mWriter = new System.IO.BinaryWriter(stream);
     mStream = stream;
 }