public void UnSerialize() { try { using (IOReader reader = new IOReader(m_input, Endian.Big)) { this.m_dwVersion = reader.ReadUInt(); this.m_dwDirectoryEntries = reader.ReadUInt(); this.m_dwPreloadEntries = reader.ReadUInt(); this.m_dwAlignment = reader.ReadUInt(); this.m_lPreloadDirectory = new List<PreloadEntry>((int)this.m_dwPreloadEntries); PreloadEntry entry; for (int i = 0; i < this.m_dwPreloadEntries;i++ ) { entry = new PreloadEntry(); entry.PreloadIndex = i; entry.Length = reader.ReadInt(); entry.Offset = reader.ReadInt(); this.m_lPreloadDirectory.Add(entry); } int j = 0; for (int i = 0; i < this.m_dwDirectoryEntries; i++) { ushort iPre = reader.ReadUShort(); if (iPre == 0xFFFF) continue; PreloadDirectory[j].ZipIndex = i; j++; } this.m_dwEntriesStart = (int)reader.BaseStream.Position; } } catch { } }
public string GameName() { try { IO = GetIO(); IO.BaseStream.Position = (int)Offsets.TitleName; byte[] b = IO.ReadBytes(0x80); IO.Close(); Buffer = null; string ss = ""; //naw return Encoding.Unicode.GetString(b); IO = new IOReader(new System.IO.MemoryStream(b)); for (int i = 0; i < b.Length; i += 2) { char c = (char)IO.ReadUInt16(true); if (c != '\0') { ss += c; } } IO.Close(); return(ss); } catch { Close(); return(""); } }
/// <summary> /// Reads velocity and mass. /// </summary> /// <param name="reader"></param> public override void Deserialize(IOReader reader) { base.Deserialize(reader); Velocity = reader.ReadVector2(); Mass = reader.ReadSingle(); }
/// <summary> /// Called when the entity is being loaded from disk. /// Override this to read any data that you saved when overriding the <see cref="Serialize(BinaryWriter)"/> /// method. Data must be written and read in the same order. /// </summary> /// <param name="reader"></param> public virtual void Deserialize(IOReader reader) { if (SerializeName) { Name = reader.ReadString(); } Bounds = reader.ReadBounds(); }
public void Deserialize(IOReader reader) { // Read segment count. ushort segments = reader.ReadUInt16(); Debug.Log($"Reading {segments} segments..."); (int count, Tile tile)[] compressed = new(int, Tile)[segments];
public override void Deserialize(IOReader reader) { base.Deserialize(reader); // Read tile positions. TileX = reader.ReadInt32(); TileY = reader.ReadInt32(); TileZ = reader.ReadInt32(); }
private IOReader GetFileDiskIO() { try { IO.Close(); } catch { } IO = new IOReader(xFile.GetStream()); return(IO); }
public byte[] DeviceID() { try { IO = GetIO(); IO.BaseStream.Position = (int)Offsets.DeviceID; byte[] buffer = IO.ReadBytes(0x14); IO.Close(); return(buffer); } catch { Close(); return(new byte[0x14]); } }
private IOReader GetIO() { try { IO.Close(); } catch { } CheckBuffer(); IO = new IOReader(new System.IO.MemoryStream(Buffer)); //IO = new IOReader(xFile.GetStream()); return(IO); }
public uint TitleID() { try { IO = GetIO(); IO.BaseStream.Position = (int)Offsets.TitleID; uint ui = IO.ReadUInt32(true); IO.Close(); return(ui); } catch { Close(); return(0); } }
public byte[] ProfileID() { try { IO = GetIO(); IO.BaseStream.Position = (int)Offsets.ProfileID; byte[] buffer = IO.ReadBytes(0x8); IO.Close(); return(buffer); } catch { Close(); return(new byte[8]); } }
private void CheckBuffer() { try { if (Buffer == null) { IO = new IOReader(xFile.GetStream()); Buffer = IO.ReadBytes(0x2200); //Close our IO IO.Close(); } } catch { Close(); } }
public void DeserializeAllNew(IOReader reader) { ClearEntities(); // Read name map... Type[] blankParams = new Type[0]; object[] blankArgs = new object[0]; int count = reader.ReadInt32(); Type[] types = new Type[count]; ConstructorInfo[] constructors = new ConstructorInfo[count]; for (int i = 0; i < count; i++) { string typeName = reader.ReadString(); Type t = Type.GetType(typeName, false, false); if (t == null) { throw new Exception($"Entity of type {typeName} could not be found, so cannot be loaded from disk! Reading cannot continue because data length is unknown."); } var constructor = t.GetConstructor(blankParams); if (constructor == null) { throw new Exception($"Entity of type {typeName} does not have a no-parameter constructor, so cannot be loaded. Reading cannot continue since data length is unknown."); } types[i] = t; constructors[i] = constructor; } count = reader.ReadInt32(); for (int i = 0; i < count; i++) { ushort typeMapIndex = reader.ReadUInt16(); var constructor = constructors[typeMapIndex]; var obj = constructor.Invoke(blankArgs); // No need to register: Entities should auto register, especially since the default constructor is being used. Entity e = obj as Entity; e.Deserialize(reader); } }
public byte[] Magic() { try { if (xFile.IsDeleted) { return(new byte[4]); } // We didn't return the null array, so let's boogie IO = xFile.Drive.GetIO(); IO.BaseStream.Position = new Misc().GetBlockOffset(xFile.StartingCluster, xFile); byte[] Header = IO.ReadBytes(0x200); byte[] buffer = new byte[] { Header[0], Header[1], Header[2], Header[3] }; IO.Close(); return(buffer); } catch { Close(); return(new byte[4]); } }
static void Main(string[] args) { VICE vice = new VICE(); using (IOReader reader = new IOReader(File.OpenRead("test.nuc"))) { byte[] temp = new byte[reader.BaseStream.Length]; int bytesLeft = (int)reader.BaseStream.Length; while (bytesLeft >= 8) { byte[] tmp = new byte[8]; byte[] buffer = reader.ReadBytes(8); vice.Decrypt("SDhfi878", ref buffer, ref tmp); bytesLeft -= 8; Array.Copy(tmp, temp, 8); } File.WriteAllBytes("out.nut", temp); } }
public bool UnSerialize(IOReader reader) { try { if (reader.ReadUInt() != m_dwSignature) return false; this.m_wDiskNumber = reader.ReadUShort(); this.m_wDiskNumberCDir = reader.ReadUShort(); this.m_wNumCDirEntries = reader.ReadUShort(); this.m_wTotalCDirEntries = reader.ReadUShort(); this.m_dwSizeOfCDir = reader.ReadUInt(); this.m_dwStartOfCDir = reader.ReadUInt(); this.m_wCommentLen = reader.ReadUShort(); this.m_Comment = Encoding.ASCII.GetString(reader.ReadBytes(this.m_wCommentLen)); return true; } catch { return false; } }
public string DisplayName() { try { IO = GetIO(); IO.BaseStream.Position = (int)Offsets.DisplayName; string ss = ""; for (int i = 0; i < 0x80; i += 2) { char c = (char)IO.ReadUInt16(true); if (c != '\0') { ss += c; } } IO.Close(); return(ss); } catch { Close(); return(""); } }
//------------------------------------------------------------------------------------- static public int Load(string filename, ShaderType shaderType, bool fCheckErrors = true) { int shaderName = 0; IOReader file = null; try { file = new IOReader(filename); string shaderText = file.ReadToEnd(); shaderName = Compile(shaderType, shaderText, fCheckErrors); } catch (IOException e) { Console.WriteLine("Shader.File IO Exception: " + e.Message); } if (file != null) { file.Close(); } return(shaderName); }
public void UnSerialize(IOReader reader) { base.UnSerialize(reader); }
public void UnSerialize(IOReader reader) { base.UnSerialize(reader); this.NumResources = reader.ReadUInt(); }
public void UnSerialize(IOReader reader) { base.UnSerialize(reader); this.Depth = reader.ReadUShort(); }
public void UnSerialize(IOReader reader) { this.Width = reader.ReadUShort(); this.Height = reader.ReadUShort(); this.Flags = (VTFFlags)reader.ReadInt(); this.NumFrames = reader.ReadUShort(); this.StartFrame = reader.ReadUShort(); this.Reflectivity.UnSerialize(reader); this.BumpScale = reader.ReadFloat(); this.ImageFormat = (VTFImageFormat)reader.ReadInt(); this.NumMipLevels = reader.ReadByte(); this.LowResImgFmt = (VTFImageFormat)reader.ReadInt(); this.LowResImgWidth = reader.ReadByte(); this.LowResImgHeight = reader.ReadByte(); }
public void UnSerialize(IOReader reader) { this.TypeIdent = reader.ReadUInt(); this.VersionMajor = reader.ReadUInt(); this.VersionMinor = reader.ReadUInt(); this.HeaderSize = reader.ReadUInt(); }
public void UnSerialize(IOReader reader) { this.eType = reader.ReadInt(); this.flags = (ResourceEntryTypeFlag)eType; this.ID = ASCIIEncoding.ASCII.GetBytes(eType.UnMakeID()); this.resData =reader.ReadUInt(); }
/// <summary> /// Adds a file to the zip /// </summary> /// <param name="fileName">input file name</param> public void AddFile(string fileName) { using (IOReader reader = new IOReader(File.OpenRead(fileName))) { byte[] fileBuf = reader.ReadAllBytes(); CentralDirectoryEntry entry = new CentralDirectoryEntry(); entry.FileName = FixupPath(fileName); entry.FileSize = (uint)fileBuf.Length; entry.FileData = fileBuf; ZipFile file = new ZipFile(entry, this.m_lZipDirectory.Count + 1); this.m_lZipDirectory.Add(file); this.m_lZipDirectory.Sort(); } }
public bool UnSerialize(IOReader reader) { try { if (reader.ReadUInt() != m_dwSignature) return false; this.m_wVersionMadeBy = reader.ReadUShort(); this.m_wVersionMadeBy = reader.ReadUShort(); this.m_wGeneralBitFlag = reader.ReadUShort(); this.m_wCompressionMethod = reader.ReadUShort(); this.m_wLastModTime = reader.ReadUShort(); this.m_wLastModDate = reader.ReadUShort(); this.m_dwCRC32 = reader.ReadUInt(); this.m_dwCompressedSize = reader.ReadUInt(); this.m_dwUnCompressedSize = reader.ReadUInt(); this.m_wFilenameLen = reader.ReadUShort(); this.m_wExtraFieldLen = reader.ReadUShort(); this.m_wCommentLen = reader.ReadUShort(); this.m_wDiskNumber = reader.ReadUShort(); this.m_wInternalArrtib = reader.ReadUShort(); this.m_wExternalArrtib = reader.ReadUInt(); this.m_dwOffsetLocalFile = reader.ReadUInt(); this.m_sFileName = ASCIIEncoding.ASCII.GetString(reader.ReadBytes(this.m_wFilenameLen)); return true; } catch { return false; } }
public void UnSerialize(IOReader reader) { // Make sure we are reading big endian reader.ByteOrder = Endian.Big; this.Flags = (VTFFlags)reader.ReadInt(); this.Width = reader.ReadUShort(); this.Height = reader.ReadUShort(); this.Depth = reader.ReadUShort(); this.NumFrames = reader.ReadUShort(); this.PreloadSize = reader.ReadUShort(); this.MipSkipCount = reader.ReadByte(); this.NumResources = reader.ReadByte(); this.Reflectivity.UnSerialize(reader); this.BumpScale = reader.ReadFloat(); this.ImageFormat = (VTFImageFormat)reader.ReadInt(); this.LowResImgSmple = reader.ReadBytes(4); this.CompressedSize = reader.ReadUInt(); }
/// <summary> /// ZipPackageFile constructor /// </summary> /// <param name="input">stream with zip file</param> public ZipPackageFile(Stream input) { m_zipReader = new IOReader(input); }
public override void Update() { if (Input.KeyDown(Keys.F11)) { Screen.ToggleFullscreen(); } if (Input.KeyPressed(Keys.F)) { for (int i = 0; i < 50; i++) { var e = new TestEntity(); e.Center = Input.MouseWorldPos; e.Velocity = Rand.UnitCircle() * Rand.Range(0.25f, 10f) * Tile.SIZE; } } if (Input.KeyDown(Keys.M)) { using (FileStream fs = new FileStream(@"C:\Users\James.000\Desktop\Chunk.txt", FileMode.Create, FileAccess.Write)) { using (IOWriter w = new IOWriter(fs)) { Layer.GetChunk(0, 0).Serialize(w); Debug.Log($"Written {w.Length} bytes."); } } } if (Input.KeyDown(Keys.NumPad0)) { using (FileStream fs = new FileStream(@"C:\Users\James.000\Desktop\Entities.txt", FileMode.Create, FileAccess.Write)) { using (IOWriter w = new IOWriter(fs)) { JEngine.Entities.SerializeAll(w); Debug.Log($"Written {w.Length} bytes for entities."); } } } if (Input.KeyDown(Keys.NumPad1)) { using (FileStream fs = new FileStream(@"C:\Users\James.000\Desktop\Entities.txt", FileMode.Open, FileAccess.Read)) { using (IOReader w = new IOReader(fs)) { JEngine.Entities.DeserializeAllNew(w); Debug.Log($"Read {w.Length} bytes for entities."); } } } if (Input.KeyDown(Keys.N)) { using (FileStream fs = new FileStream(@"C:\Users\James.000\Desktop\Chunk.txt", FileMode.OpenOrCreate, FileAccess.Read)) { using (IOReader r = new IOReader(fs)) { Layer.GetChunk(0, 0).Deserialize(r); Debug.Log($"Read {r.Length} bytes."); } } } if (Input.KeyDown(Keys.Y)) { var e = new TestActive(); e.Center = Input.MouseWorldPos; e.Velocity = Rand.UnitCircle() * Rand.Range(1f, 5f); } if (Input.KeyPressed(Keys.L)) { float r = Tile.SIZE * 5; foreach (var entity in JEngine.Entities.GetAllInRange(Input.MouseWorldPos, r)) { entity.Destroy(); } } if (Input.KeyDown(Keys.Space)) { System.GC.Collect(); } if (Input.KeyDown(Keys.T)) { var missile = new MissileEntity(); missile.Position = Input.MouseWorldPos - missile.Size * 0.5f; } var p = JEngine.TileMap.PixelToTileCoords((int)Input.MouseWorldPos.X, (int)Input.MouseWorldPos.Y); if (Input.KeyPressed(Keys.V)) { JEngine.TileMap.SetTile(p.X, p.Y, 1, new Tile(2, ColorCache.EnsureColor(Color.White))); } if (Input.KeyDown(Keys.B)) { Layer.SetTile(p.X, p.Y, 1, new Tile(4, ColorCache.EnsureColor(Color.White))); } const int MAX_PER_FRAME = 5; int count = 0; foreach (var chunk in Layer.GetLoadedChunks()) { if (chunk != null) { if (chunk.EntityCount != 0) { chunk.FlagAsNeeded(); } if (chunk.TimeSinceNeeded > CHUNK_UNLOAD_TIME && chunk.FramesSinceNeeded > 2) { toBin.Add(chunk.ID); continue; } if (chunk.TimeSinceRendered > CHUNK_UNLOAD_TIME && chunk.FramesSinceRendered > 2) { chunk.UnloadGraphics(); } chunk.Decay(Time.unscaledDeltaTime); if (chunk.RequiresRedraw && count < MAX_PER_FRAME && chunk.Graphics.Texture != null) { count++; RequestRenderTargetDraw(new TargetRenderRequest(chunk.Graphics.Texture, true) { CustomData = chunk }); } } } foreach (var id in toBin) { Layer.UnloadChunk(id); } toBin.Clear(); }
public override void Deserialize(IOReader reader) { base.Deserialize(reader); ItemStack = reader.ReadItemStack(); }
/// <summary> /// Creates a zip /// </summary> /// <param name="dir">directory to construct from</param> /// <param name="output">output zip</param> public void CreateZip(string dir, string output) { string[] fileEntries = Directory.GetFiles(dir,"*.*",SearchOption.AllDirectories); CentralDirectoryEntry entry; ZipFile file; this.m_lZipDirectory = new List<ZipFile>(fileEntries.Length); foreach (string fileName in fileEntries) { using (IOReader reader = new IOReader(File.OpenRead(fileName))) { entry = new CentralDirectoryEntry(); entry.FileData = reader.ReadAllBytes(); entry.FileName = fileName.Substring(dir.Length + 1); file = new ZipFile(entry); this.m_lZipDirectory.Add(file); } } GetGame(); this.m_lZipDirectory.Sort(); Save(output, false); }
/// <summary> /// Updates a file's data /// </summary> /// <param name="index">index of original file</param> /// <param name="fileName">name of file on disc</param> public void UpdateFile(int index, string fileName) { using (IOReader reader = new IOReader(File.OpenRead(fileName))) UpdateFile(index,reader.ReadAllBytes()); }
private void ImportDataSet(string fileName) { var biz = new ProductLDBiz(); using (var document = SpreadsheetDocument.Open(fileName, false)) { var wbPart = document.WorkbookPart; var theSheet = wbPart.Workbook.Descendants <Sheet>().FirstOrDefault(); var wsPart = (WorksheetPart)(wbPart.GetPartById(theSheet.Id)); var count = wsPart.Worksheet.Descendants <Row>().Count(); for (var i = 2; i <= count; i++) { var product = new ProductLD { Code = IOReader.GetCellValue(document, theSheet, "A" + i), Name = IOReader.GetCellValue(document, theSheet, "B" + i), }; decimal number = 0; var price = IOReader.GetCellValue(document, theSheet, "C" + i); if (!string.IsNullOrEmpty(price) && decimal.TryParse(price, out number)) { product.Price = number; } int number1 = 0; var productTypeId = IOReader.GetCellValue(document, theSheet, "D" + i); if (!string.IsNullOrEmpty(productTypeId) && int.TryParse(productTypeId, out number1)) { product.ProductTypeId = number1; } var item = biz.LoadItems().FirstOrDefault(p => p.Code == product.Code); if (string.IsNullOrEmpty(product.Code)) { break; } if (item != null) { product.Id = item.Id; product.Code = item.Code; product.Name = item.Name; product.ProductTypeId = item.ProductTypeId; product.Created = item.Created; product.CreatedByUserId = item.CreatedByUserId; product.Modified = item.Modified; product.ModifiedByUserId = item.ModifiedByUserId; try { biz.UpdateItem(product); } catch (Exception ex) { logger.LogInfoMessage("Import Update Product"); string log = string.Format("ID: {0}, Code: {1}, Name: {2}, TypeId: {3}", item.Id, item.Code, item.Name, item.ProductTypeId); logger.LogInfoMessage(log); logger.LogException(ex); } } else { product.Id = 0; product.Created = DateTime.Now; product.CreatedByUserId = currentUser.Id; product.Modified = DateTime.Now; product.ModifiedByUserId = currentUser.Id; try { biz.SaveItem(product); } catch (Exception ex) { logger.LogInfoMessage("Import New Product"); string log = string.Format("ID: {0}, Code: {1}, Name: {2}, TypeId: {3}", 0, product.Code, product.Name, product.ProductTypeId); logger.LogInfoMessage(log); logger.LogException(ex); } } } MessageBox.Show("Cập nhật thành công."); } }
private void UnSerialize(Stream input) { m_vtfReader = new IOReader(input); int ident = this.m_vtfReader.ReadInt(); if (ident == "VTF\0".MakeID()) this.m_bIs360 = false; else if (ident == "VTFX".MakeID()) { this.m_bIs360 = true; this.m_vtfReader.ByteOrder = Endian.Big; } else throw new BadImageFormatException(); // rewind stream m_vtfReader.Seek(-4); VTFFileHeader vtfHDR = new VTFFileHeader(); vtfHDR.UnSerialize(this.m_vtfReader); this.m_dwVersionMajor = (int)vtfHDR.VersionMajor; this.m_dwVersionMinor = (int)vtfHDR.VersionMinor; VTFHeader_PC hdr = new VTFHeader_PC(); hdr.UnSerialize(this.m_vtfReader); this.m_dwResourceCount = (int)hdr.NumResources; this.m_dwHeight = hdr.Height; this.m_dwWidth = hdr.Width; this.m_Format = hdr.ImageFormat; this.m_dwFlags = hdr.Flags; this.m_dwFrameCount = hdr.NumFrames; this.m_dwDepth = hdr.Depth; // Envmaps only have 1 face, if its not then it must be a cubemap with 7 sides if (m_dwFlags.IsFlagSet<VTFFlags>(VTFFlags.TEXTUREFLAGS_ENVMAP)) this.m_dwFaceCount = 1; else this.m_dwFaceCount = 7; this.m_vecReflectivity = hdr.Reflectivity; this.m_flBumpScale = hdr.BumpScale; this.m_dwLowResImageWidth = hdr.LowResImgWidth; this.m_dwLowResImageHeight = hdr.LowResImgHeight; this.m_LowResImageFormat = hdr.LowResImgFmt; this.m_dwMipCount = ComputeMipCount(); }
public CentralDirectoryEntry(IOReader reader) { UnSerialize(reader); }
public void UnSerialize(IOReader reader) { this.m_flVecX = reader.ReadFloat(); this.m_flVecY = reader.ReadFloat(); this.m_flVecZ = reader.ReadFloat(); }