public RespawnInfo(BinaryReader reader, int Version, int Customversion) { MonsterIndex = reader.ReadInt32(); Location = new Point(reader.ReadInt32(), reader.ReadInt32()); Count = reader.ReadUInt16(); Spread = reader.ReadUInt16(); Delay = reader.ReadUInt16(); Direction = reader.ReadByte(); if (Envir.LoadVersion >= 36) { RoutePath = reader.ReadString(); } if (Version > 67) { RandomDelay = reader.ReadUInt16(); RespawnIndex = reader.ReadInt32(); SaveRespawnTime = reader.ReadBoolean(); RespawnTicks = reader.ReadUInt16(); } else { RespawnIndex = ++SMain.Envir.RespawnIndex; } }
private static bool ReadInfoHeader(System.IO.BinaryReader aReader, ref BitmapInfoHeader aHeader) { aHeader.size = aReader.ReadUInt32(); if (aHeader.size < 40) { return(false); } aHeader.width = aReader.ReadInt32(); aHeader.height = aReader.ReadInt32(); aHeader.nColorPlanes = aReader.ReadUInt16(); aHeader.nBitsPerPixel = aReader.ReadUInt16(); aHeader.compressionMethod = (BMPComressionMode)aReader.ReadInt32(); aHeader.rawImageSize = aReader.ReadUInt32(); aHeader.xPPM = aReader.ReadInt32(); aHeader.yPPM = aReader.ReadInt32(); aHeader.nPaletteColors = aReader.ReadUInt32(); aHeader.nImportantColors = aReader.ReadUInt32(); int pad = (int)aHeader.size - 40; if (pad > 0) { aReader.ReadBytes(pad); } return(true); }
public Character(System.IO.BinaryReader reader, bool sentFromServer) : base(reader, sentFromServer) { myHitPoints = reader.ReadInt16(); myManaLevel = reader.ReadInt16(); ushort attribCount = reader.ReadUInt16(); for (int i = 0; i < attribCount; ++i) { myBaseAttributes.Add(CharAttribute.GetByID(reader.ReadUInt16()), reader.ReadByte()); } ushort skillCount = reader.ReadUInt16(); for (int i = 0; i < skillCount; ++i) { myBaseSkills.Add(CharSkill.GetByID(reader.ReadUInt16()), reader.ReadByte()); } myCurrentWalkDirection = myFacingDirection = (WalkDirection)reader.ReadByte(); if (!sentFromServer) { Inventory = new Inventory(this, reader); } }
/// <summary> /// Initializes a new instance of the <see cref="NiTriShapeData"/> class. /// </summary> /// <param name="file">The file.</param> /// <param name="reader">The reader.</param> public NiTriShapeData(NiFile file, BinaryReader reader) : base(file, reader) { this.NumTrianglePoints = reader.ReadUInt32(); if (base.Version >= eNifVersion.VER_10_1_0_0) { this.HasTriangles = reader.ReadBoolean(Version); } if (base.Version <= eNifVersion.VER_10_0_1_2 || this.HasTriangles || base.Version >= eNifVersion.VER_10_0_1_3) { this.Triangles = new Triangle[(int)this.NumTriangles]; this.HasTriangles = this.Triangles.Length > 0; for (int i = 0; i < (int)this.NumTriangles; i++) { this.Triangles[i] = new Triangle(reader); } } if (base.Version >= eNifVersion.VER_3_1) { ushort num = reader.ReadUInt16(); this.MatchGroups = new ushort[(int)num][]; for (int j = 0; j < (int)num; j++) { ushort num2 = reader.ReadUInt16(); this.MatchGroups[j] = new ushort[(int)num2]; for (int k = 0; k < (int)num2; k++) { this.MatchGroups[j][k] = reader.ReadUInt16(); } } } }
public static string peType(byte[] data) { ushort architecture = 0; Stream s = new MemoryStream(data); using (System.IO.BinaryReader bReader = new System.IO.BinaryReader(s)) { if (bReader.ReadUInt16() == 23117) //check the MZ signature { s.Seek(0x3A, System.IO.SeekOrigin.Current); // seek to e_lfanew. s.Seek(bReader.ReadUInt32(), System.IO.SeekOrigin.Begin); //Seek to the start of the NT header. if (bReader.ReadUInt32() == 17744) // check the PE\0\0 signature. { s.Seek(20, System.IO.SeekOrigin.Current); // seek past the file header, and architecture = bReader.ReadUInt16(); // read the magic number of the optional header. } } if (architecture == 0x10b) { return("PE32"); } else if (architecture == 0x20b) { return("PE32+"); } } return("Unknown"); }
protected override void check(object sender, EventArgs e) { int read_width = 0; int read_height = 0; int read_cwidth = 0; int read_cheight = 0; int read_quality = 0; int read_samples = 0; using (Stream stream = new FileStream(outPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader reader = new BinaryReader(stream, Encoding.Default)) { read_width = reader.ReadUInt16(); read_height = reader.ReadUInt16(); read_cwidth = reader.ReadUInt16(); read_cheight = reader.ReadUInt16(); read_quality = reader.ReadByte(); read_samples = reader.ReadByte(); } } System.Windows.Forms.MessageBox.Show( "image width: " + inC1.imageWidth + " = " + read_width + "\nimage height: " + inC1.imageHeight + " = " + read_height + "\nchannel width: " + inC1.channelWidth + " = " + read_cwidth + "\nchannel height: " + inC1.channelHeight + " = " + read_cheight + "\nquality: " + inC1.quantizeQuality + " = " + read_quality + "\nsamples: " + inC1.samplingMode + " = " + (DataBlob.Samples)read_samples , "File Information"); }
public void GetDiskInfo(String diskPathname) { base.LoadDisk(diskPathname); System.Text.Encoding enc = System.Text.Encoding.ASCII; // Read the System Sector Byte[] sectorData = base.ReadSector(0, 1); System.IO.MemoryStream stm = new System.IO.MemoryStream(sectorData, 0, sectorData.Length); System.IO.BinaryReader rdr = new System.IO.BinaryReader(stm); stm.Seek(0x10, SeekOrigin.Begin); nextAvailableSector = rdr.ReadByte(); nextAvailableTrack = rdr.ReadByte(); directorySector = rdr.ReadByte(); directoryTrack = rdr.ReadByte(); sectorsFree = rdr.ReadUInt16(); sectorsUsed = rdr.ReadUInt16(); sectors = (UInt16)(sectorsUsed + sectorsFree); Byte[] bByteArray = rdr.ReadBytes(21); diskName = enc.GetString(bByteArray); diskName.Trim(); diskType = OricDisk.DiskTypes.Master; sides = 2; tracksPerSide = 40; sectorsPerTrack = 16; }
bool IsX86Architecture(string filePath) { ushort architecture = 0; try { using (System.IO.FileStream fStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { using (System.IO.BinaryReader bReader = new System.IO.BinaryReader(fStream)) { if (bReader.ReadUInt16() == 23117) { fStream.Seek(0x3A, System.IO.SeekOrigin.Current); fStream.Seek(bReader.ReadUInt32(), System.IO.SeekOrigin.Begin); if (bReader.ReadUInt32() == 17744) { fStream.Seek(20, System.IO.SeekOrigin.Current); architecture = bReader.ReadUInt16(); } } } } } catch { } if (architecture == 0x10b) { return(true); } else { return(false); } }
public override void Read(string file) { BinaryReader br = new BinaryReader(File.OpenRead(file)); uint file_size = (uint)br.BaseStream.Length; // Read header values ushort depth = br.ReadUInt16(); ushort width = br.ReadUInt16(); ushort height = br.ReadUInt16(); ushort unknown = br.ReadUInt16(); ColorFormat format = (depth == 0x01) ? ColorFormat.colors256 : ColorFormat.colors16; // Palette int palette_length = (depth == 0x01) ? 0x200 : 0x20; Color[][] colors = new Color[1][]; colors[0] = Actions.BGR555ToColor(br.ReadBytes(palette_length)); palette = new RawPalette(colors, false, format); // Tiles int tiles_length = width * height; if (depth == 0) tiles_length /= 2; Byte[] tiles = br.ReadBytes(tiles_length); br.Close(); Set_Tiles(tiles, width, height, format, TileForm.Lineal, true); }
// As found in .DAT archives (RESOURCE.DAT, IO.DAT) public void Load(string destinationDirectory, string baseName, BinaryReader binaryReader) { xOffset = binaryReader.ReadInt16(); yOffset = binaryReader.ReadInt16(); binaryReader.BaseStream.Seek(4, SeekOrigin.Current); width = binaryReader.ReadUInt16(); height = binaryReader.ReadUInt16(); binaryReader.BaseStream.Seek(2, SeekOrigin.Current); uint length = binaryReader.ReadUInt32(); var imageOffset = binaryReader.BaseStream.Position; var rowDataOffsets = new ushort[height]; for (int i = 0; i < height; ++i) { rowDataOffsets[i] = binaryReader.ReadUInt16(); } var bmp = new Bmp(width, height); var imageData = binaryReader.ReadBytes((int)length - 2*height); ReadImage(imageData, rowDataOffsets, false, bmp.Data); Debug.Assert(binaryReader.BaseStream.Position - imageOffset == length); bmp.Save(Path.Combine(destinationDirectory, baseName), ImageFormat); Bmp.SaveOffsets(baseName, xOffset, yOffset); }
/// <summary> /// Gets the name of the first model on a CGFX file. /// Returns null if the file doesn't contain any model. /// </summary> /// <param name="data"></param> /// <returns></returns> public static string getName(MemoryStream data) { BinaryReader input = new BinaryReader(data); cgfxHeader header = new cgfxHeader(); header.magic = IOUtils.readString(input, 0, 4); header.endian = input.ReadUInt16(); header.length = input.ReadUInt16(); header.revision = input.ReadUInt32(); header.fileLength = input.ReadUInt32(); header.entries = input.ReadUInt32(); data.Seek(header.length + 8, SeekOrigin.Begin); List<dictEntry> models = getDictionary(input); if (models.Count > 0) { data.Seek(models[0].dataOffset + 0xc, SeekOrigin.Begin); string name = IOUtils.readString(input, getRelativeOffset(input)); data.Close(); return name; } else { data.Close(); return null; } }
public InstallShieldPackage(string filename, int priority) { this.priority = priority; s = FileSystem.Open(filename); // Parse package header BinaryReader reader = new BinaryReader(s); uint signature = reader.ReadUInt32(); if (signature != 0x8C655D13) throw new InvalidDataException("Not an Installshield package"); reader.ReadBytes(8); /*var FileCount = */reader.ReadUInt16(); reader.ReadBytes(4); /*var ArchiveSize = */reader.ReadUInt32(); reader.ReadBytes(19); var TOCAddress = reader.ReadInt32(); reader.ReadBytes(4); var DirCount = reader.ReadUInt16(); // Parse the directory list s.Seek(TOCAddress, SeekOrigin.Begin); BinaryReader TOCreader = new BinaryReader(s); for (var i = 0; i < DirCount; i++) ParseDirectory(TOCreader); }
public async Task<ImageInfo[]> LoadFromDbAsync(string dbFileName) { var file = await FileSystem.Current.GetFileFromPathAsync(dbFileName).ConfigureAwait(false); if (file == null) throw new FileNotFoundException(); using (var fs = await file.OpenAsync(FileAccess.Read).ConfigureAwait(false)) using (var gz = new GZipStream(fs, CompressionMode.Decompress)) using (var br = new BinaryReader(gz)) { long count = br.ReadInt32(); _info = new ImageInfo[count]; for (var i = 0; i < count; i++) { var hash = br.ReadUInt64(); var titleId = br.ReadUInt16(); var episodeId = br.ReadUInt16(); var frame = br.ReadUInt32(); _info[i] = new ImageInfo { Hash = hash, TitleId = titleId, EpisodeId = episodeId, Frame = frame }; } } return _info; }
/// <summary> /// Read the end of the Zip64 central directory /// </summary> /// <returns>Status of the given stream</returns> private ZipReturn ReadZip64EndOfCentralDir() { // Set the type of the archive to Zip64 _zip64 = true; // Open the stream for reading BinaryReader br = new BinaryReader(_zipstream); // If the signature doesn't match, then return uint thisSignature = br.ReadUInt32(); if (thisSignature != Constants.Zip64EndOfCentralDirSignature) { return(ZipReturn.ZipEndOfCentralDirectoryError); } // If the size of the central dir record isn't right, return ulong tulong = br.ReadUInt64(); // Size of zip64 end of central directory record if (tulong != 44) { return(ZipReturn.Zip64EndOfCentralDirError); } br.ReadUInt16(); // version made by // If the version needed to extract isn't correct, return ushort tushort = br.ReadUInt16(); // version needed to extract if (tushort != (ushort)ArchiveVersion.TorrentZip64) { return(ZipReturn.Zip64EndOfCentralDirError); } // If this is part of a spanned archive, return uint tuint = br.ReadUInt32(); // number of this disk if (tuint != 0) { return(ZipReturn.Zip64EndOfCentralDirError); } tuint = br.ReadUInt32(); // number of the disk with the start of the central directory if (tuint != 0) { return(ZipReturn.Zip64EndOfCentralDirError); } // If the number of entries in the current disk doesn't match up with the total entries, return _entriesCount = (uint)br.ReadUInt64(); // total number of entries in the central directory on this disk tulong = br.ReadUInt64(); // total number of entries in the central directory if (tulong != _entriesCount) { return(ZipReturn.Zip64EndOfCentralDirError); } _centerDirSize = br.ReadUInt64(); // size of central directory _centerDirStart = br.ReadUInt64(); // offset of start of central directory with respect to the starting disk number return(ZipReturn.ZipGood); }
public MixFile(string filename, int priority) { this.priority = priority; s = FileSystem.Open(filename); // Detect format type s.Seek(0, SeekOrigin.Begin); var reader = new BinaryReader(s); var isCncMix = reader.ReadUInt16() != 0; // The C&C mix format doesn't contain any flags or encryption var isEncrypted = false; if (!isCncMix) isEncrypted = (reader.ReadUInt16() & 0x2) != 0; List<PackageEntry> entries; if (isEncrypted) { long unused; entries = ParseHeader(DecryptHeader(s, 4, out dataStart), 0, out unused); } else entries = ParseHeader(s, isCncMix ? 0 : 4, out dataStart); index = entries.ToDictionaryWithConflictLog(x => x.Hash, "{0} ({1} format, Encrypted: {2}, DataStart: {3})".F(filename, (isCncMix ? "C&C" : "RA/TS/RA2"), isEncrypted, dataStart), null, x => "(offs={0}, len={1})".F(x.Offset, x.Length) ); }
internal static void ReadCustomData(Player player, BinaryReader reader) { int count = reader.ReadUInt16(); for (int k = 0; k < count; k++) { string modName = reader.ReadString(); string name = reader.ReadString(); byte[] data = reader.ReadBytes(reader.ReadUInt16()); Mod mod = ModLoader.GetMod(modName); ModPlayer modPlayer = mod == null ? null : player.GetModPlayer(mod, name); if (modPlayer != null) { using (MemoryStream stream = new MemoryStream(data)) { using (BinaryReader customReader = new BinaryReader(stream)) { modPlayer.LoadCustomData(customReader); } } if (modName == "ModLoader" && name == "MysteryPlayer") { ((MysteryPlayer)modPlayer).RestoreData(player); } } else { ModPlayer mystery = player.GetModPlayer(ModLoader.GetMod("ModLoader"), "MysteryPlayer"); ((MysteryPlayer)mystery).AddData(modName, name, data); } } }
public void Deserialize(byte[] buffer) { if (buffer.Length == 240) { MemoryStream MS = new MemoryStream(buffer); BinaryReader BR = new BinaryReader(MS); ushort length = BR.ReadUInt16(); if (length == 240) { ushort type = BR.ReadUInt16(); if (type == 1124) { Username = Encoding.ASCII.GetString(BR.ReadBytes(16)); Username = Username.Replace("\0", ""); BR.ReadBytes(112); Password = Encoding.ASCII.GetString(BR.ReadBytes(16)); BR.ReadBytes(112); Server = Encoding.ASCII.GetString(BR.ReadBytes(16)); Server = Server.Replace("\0", ""); } } BR.Close(); MS.Close(); } }
public Metadata(BinaryReader reader) { magic = reader.ReadUInt32(); if (magic != 0x424A5342) return; offset = (uint)reader.BaseStream.Position - 4; majorVersion = reader.ReadUInt16(); minorVersion = reader.ReadUInt16(); reserved = reader.ReadUInt32(); versionString = readString(reader, reader.ReadInt32()); flags = reader.ReadUInt16(); int numStreams = reader.ReadUInt16(); streams = new DotNetStream[numStreams]; uint lastOffset = offset; for (int i = 0; i < numStreams; i++) { uint fileOffset = offset + reader.ReadUInt32(); uint size = reader.ReadUInt32(); string name = readAsciizString(reader); streams[i] = new DotNetStream(name, fileOffset, size); lastOffset = Math.Max(lastOffset, fileOffset + size); } lastOffset = Math.Max(lastOffset, (uint)reader.BaseStream.Position); length = lastOffset - offset; headerLength = (uint)reader.BaseStream.Position - offset; }
protected override void ReadContentFrom(BinaryReader input) { //https://www.microsoft.com/typography/otspec/cmap.htm long beginAt = input.BaseStream.Position; // ushort version = input.ReadUInt16(); // 0 ushort tableCount = input.ReadUInt16(); var entries = new CMapEntry[tableCount]; for (int i = 0; i < tableCount; i++) { ushort platformId = input.ReadUInt16(); ushort encodingId = input.ReadUInt16(); uint offset = input.ReadUInt32(); entries[i] = new CMapEntry(platformId, encodingId, offset); } charMaps = new CharacterMap[tableCount]; for (int i = 0; i < tableCount; i++) { CMapEntry entry = entries[i]; input.BaseStream.Seek(beginAt + entry.Offset, SeekOrigin.Begin); CharacterMap cmap = charMaps[i] = ReadCharacterMap(entry, input); cmap.PlatformId = entry.PlatformId; cmap.EncodingId = entry.EncodingId; } }
internal NameResolutionRecord(BinaryReader reader) { UInt16 type = reader.ReadUInt16(); int valueLength = reader.ReadUInt16(); if (type != EndRecordType) { int entriesLength = valueLength; if (type == Ip6RecordType) { this.IsIpVersion6 = true; this.IpAddress = reader.ReadBytes(Ip6Length); entriesLength -= Ip6Length; } else { this.IsIpVersion6 = false; this.IpAddress = reader.ReadBytes(Ip4Length); entriesLength -= Ip4Length; } this.DnsEntries = this.ReadDnsEntries(reader, entriesLength); int remainderLength = valueLength % ValueAlignmentBoundary; if (remainderLength > 0) { reader.ReadBytes(ValueAlignmentBoundary - remainderLength); // Read fill bytes to boundary. } } }
public static ushort GetPEArchitecture(string pFilePath) { ushort architecture = 0; try { using (System.IO.FileStream fStream = new System.IO.FileStream(pFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { using (System.IO.BinaryReader bReader = new System.IO.BinaryReader(fStream)) { if (bReader.ReadUInt16() == 23117) //check the MZ signature { fStream.Seek(0x3A, System.IO.SeekOrigin.Current); //seek to e_lfanew. fStream.Seek(bReader.ReadUInt32(), System.IO.SeekOrigin.Begin); //seek to the start of the NT header. if (bReader.ReadUInt32() == 17744) //check the PE\0\0 signature. { fStream.Seek(20, System.IO.SeekOrigin.Current); //seek past the file header, architecture = bReader.ReadUInt16(); //read the magic number of the optional header. } } } } } catch (Exception) { return(0); } //if architecture returns 0, there has been an error. return(architecture); }
public static bool Is64BitNativeDll(string filePath) { if (!System.IO.File.Exists(filePath)) { return(false); } ushort architecture = 0; using (System.IO.FileStream fStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { using (System.IO.BinaryReader bReader = new System.IO.BinaryReader(fStream)) { if (bReader.ReadUInt16() == 23117) { fStream.Seek(0x3A, System.IO.SeekOrigin.Current); fStream.Seek(bReader.ReadUInt32(), System.IO.SeekOrigin.Begin); if (bReader.ReadUInt32() == 17744) { fStream.Seek(20, System.IO.SeekOrigin.Current); architecture = bReader.ReadUInt16(); } } } } return(architecture == 0x20b); }
public OBJf(IffChunk Chunk) : base(Chunk) { MemoryStream MemStream = new MemoryStream(Chunk.Data); BinaryReader Reader = new BinaryReader(MemStream); //Unknown + version (always 0) Reader.ReadBytes(8); string Header = Encoding.ASCII.GetString(Reader.ReadBytes(4)); if (Header != "fJBO") return; //Error? This shouldn't occur... m_NumEntries = Reader.ReadInt32(); for (int i = 0; i < m_NumEntries; i++) { IDPair FuncIDs = new IDPair(); FuncIDs.GuardFuncID = Reader.ReadUInt16(); FuncIDs.FunctionID = Reader.ReadUInt16(); m_FuncIDs.Add(FuncIDs); } }
public override void Read(Stream input) { BinaryReader reader = new BinaryReader(input, Encoding.Default, true); uint magicNumber1 = reader.ReadUInt32(); // foxf ushort magicNumber2 = reader.ReadUInt16(); // pk FpkType = (FpkType) reader.ReadByte(); // ' ' or 'd' byte magicNumber3 = reader.ReadByte(); // w ushort magicNumber4 = reader.ReadUInt16(); // in uint fileSize = reader.ReadUInt32(); reader.Skip(18); uint magicNumber5 = reader.ReadUInt32(); // 2 uint fileCount = reader.ReadUInt32(); uint referenceCount = reader.ReadUInt32(); reader.Skip(4); for (int i = 0; i < fileCount; i++) { Entries.Add(FpkEntry.ReadFpkEntry(input)); } for (int i = 0; i < referenceCount; i++) { References.Add(FpkReference.ReadFpkReference(input)); } }
public FaceGroup(BinaryReader reader) { Min = new Vector3(reader); Max = new Vector3(reader); StartFace = reader.ReadUInt16(); EndFace = reader.ReadUInt16(); }
/// <summary> /// Initialize an instance of this structure by reading it from the given <see cref="BinaryReader"/>. /// </summary> /// <param name="reader">The <see cref="BinaryReader"/> to read the structure from.</param> internal RWTriangle(BinaryReader reader) { C = reader.ReadUInt16(); B = reader.ReadUInt16(); MatID = reader.ReadInt16(); A = reader.ReadUInt16(); }
public WowCorePacketReader(string filename) { _reader = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read), Encoding.ASCII); _reader.ReadBytes(3); // PKT Version = _reader.ReadUInt16(); // sniff version (0x0201, 0x0202) ushort build; switch (Version) { case 0x0201: build = _reader.ReadUInt16(); // build _reader.ReadBytes(40); // session key break; case 0x0202: _reader.ReadByte(); // 0x06 build = _reader.ReadUInt16(); // build _reader.ReadBytes(4); // client locale _reader.ReadBytes(20); // packet key _reader.ReadBytes(64); // realm name break; case 0x0300: _reader.ReadByte(); // snifferId build = (ushort)_reader.ReadUInt32();// client build _reader.ReadBytes(4); // client locale _reader.ReadBytes(40); // session key var optionalHeaderLength = _reader.ReadInt32(); _reader.ReadBytes(optionalHeaderLength); break; default: throw new Exception(String.Format("Unknown sniff version {0:X2}", Version)); } UpdateFieldsLoader.LoadUpdateFields(build); }
public void Load(string destinationDirectory, string resourceName, BinaryReader binaryReader) { binaryReader.BaseStream.Seek(2, SeekOrigin.Current); uint length = binaryReader.ReadUInt32(); byte[] imageData = binaryReader.ReadBytes((int)length); short xOffset = binaryReader.ReadInt16(); short yOffset = binaryReader.ReadInt16(); ushort width = binaryReader.ReadUInt16(); ushort height = binaryReader.ReadUInt16(); binaryReader.BaseStream.Seek(8, SeekOrigin.Current); var bmp = new Bmp(width, height); var colorData = bmp.Data; var palette = PaletteLoader.DefaultPalette; int index = 0; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { colorData[y, x] = palette.Colors[imageData[index]]; ++index; } } bmp.Save(Path.Combine(destinationDirectory, resourceName), ImageFormat); Bmp.SaveOffsets(resourceName, xOffset, yOffset); }
/// <summary> /// 获取指定文件的架构位数 523-64位, 267-32位/AnyCpu /// </summary> /// <param name="filePath"></param> /// <returns></returns> private static ushort GetPEArchitecture(string filePath) { ushort architecture = 0; try { using (System.IO.FileStream fStream = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { using (System.IO.BinaryReader bReader = new System.IO.BinaryReader(fStream)) { if (bReader.ReadUInt16() == 23117) //check the MZ signature { //Any CPU PE32 with 32BIT = 0 //x86 PE32 with 32BIT = 1 //x64 / Itanium(IA - 64) PE32 + with 32BIT = 0 fStream.Seek(0x3A, System.IO.SeekOrigin.Current); //seek to e_lfanew. fStream.Seek(bReader.ReadUInt32(), System.IO.SeekOrigin.Begin); //seek to the start of the NT header. if (bReader.ReadUInt32() == 17744) //check the PE\0\0 signature. { fStream.Seek(20, System.IO.SeekOrigin.Current); //seek past the file header, architecture = bReader.ReadUInt16(); //read the magic number of the optional header. } } } } } catch (Exception ex) { /* TODO: Any exception handling you want to do, personally I just take 0 as a sign of failure */ } //if architecture returns 0, there has been an error. return(architecture); }
protected override void ReadContentFrom(BinaryReader reader) { //USHORT version Version number (0 or 1). //USHORT numRecs Number of VDMX groups present //USHORT numRatios Number of aspect ratio groupings //Ratio ratRange[numRatios] Ratio ranges (see below for more info) //USHORT offset[numRatios] Offset from start of this table to the VDMX group for this ratio range. //Vdmx groups The actual VDMX groupings (documented below) //Ratio Record Type Name Description //BYTE bCharSet Character set (see below). //BYTE xRatio Value to use for x-Ratio //BYTE yStartRatio Starting y-Ratio value. //BYTE yEndRatio Ending y-Ratio value. ushort version = reader.ReadUInt16(); ushort numRecs = reader.ReadUInt16(); ushort numRatios = reader.ReadUInt16(); ratios = new Ratio[numRatios]; for (int i = 0; i < numRatios; ++i) { ratios[i] = new Ratio( reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); } short[] offsets = Utils.ReadInt16Array(reader, numRatios); //------ //actual vdmx group //TODO: implement this }
public MapInfo(BinaryReader reader) { Index = reader.ReadInt32(); FileName = reader.ReadString(); Title = reader.ReadString(); MiniMap = reader.ReadUInt16(); Light = (LightSetting) reader.ReadByte(); if (Envir.LoadVersion >= 3) BigMap = reader.ReadUInt16(); if (Envir.LoadVersion >= 10) reader.ReadByte(); int count = reader.ReadInt32(); for (int i = 0; i < count; i++) SafeZones.Add(new SafeZoneInfo(reader) { Info = this }); count = reader.ReadInt32(); for (int i = 0; i < count; i++) Respawns.Add(new RespawnInfo(reader)); count = reader.ReadInt32(); for (int i = 0; i < count; i++) NPCs.Add(new NPCInfo(reader)); count = reader.ReadInt32(); for (int i = 0; i < count; i++) Movements.Add(new MovementInfo(reader)); }
public FaceInfo( BinaryReader reader ) { Vertex1 = reader.ReadUInt16(); Vertex0 = reader.ReadUInt16(); Flags = (GeometryFlag) reader.ReadUInt16(); Vertex2 = reader.ReadUInt16(); }
public IEnumerable<Packet> ReadPackets(string file) { using (var gr = new BinaryReader(new FileStream(file, FileMode.Open, FileAccess.Read), Encoding.ASCII)) { gr.ReadBytes(3); // PKT gr.ReadBytes(2); // 0x02, 0x02 gr.ReadByte(); // 0x06 Build = gr.ReadUInt16(); // build gr.ReadBytes(4); // client locale gr.ReadBytes(20); // packet key gr.ReadBytes(64); // realm name var packets = new List<Packet>(); while (gr.PeekChar() >= 0) { Direction direction = gr.ReadByte() == 0xff ? Direction.Server : Direction.Client; uint unixtime = gr.ReadUInt32(); uint tickcount = gr.ReadUInt32(); uint size = gr.ReadUInt32(); OpCodes opcode = (direction == Direction.Client) ? (OpCodes)gr.ReadUInt32() : (OpCodes)gr.ReadUInt16(); byte[] data = gr.ReadBytes((int)size - ((direction == Direction.Client) ? 4 : 2)); packets.Add(new Packet(direction, opcode, data, unixtime, tickcount)); } return packets; } }
public static CpuArchitectures GetPEArchitecture(string pFilePath) { ushort architecture = 0; ushort[] coffHeader = new ushort[10]; using (FileStream fStream = new FileStream(pFilePath, FileMode.Open, FileAccess.Read)) { using (BinaryReader bReader = new BinaryReader(fStream)) { if (bReader.ReadUInt16() == 23117) //check the MZ signature { fStream.Seek(0x3A, SeekOrigin.Current); // Go to the location of the location of the NT header fStream.Seek(bReader.ReadUInt32(), SeekOrigin.Begin); // seek to the start of the NT header. if (bReader.ReadUInt32() == 17744) //check the PE\0\0 signature. { for (int i = 0; i < 10; i++) // Read COFF Header coffHeader[i] = bReader.ReadUInt16(); if (coffHeader[8] > 0) // Read Optional Header architecture = bReader.ReadUInt16(); } } } } switch (architecture) { case 0x20b: return CpuArchitectures.x64; case 0x10b: return ((coffHeader[9] & 0x100) == 0) ? CpuArchitectures.AnyCpu : CpuArchitectures.x86; default: return CpuArchitectures.Unknown; } }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { var fileStream = new FileStream(bldPath + "\\" + "model" + "\\" + listBox1.SelectedIndex.ToString("D4"), FileMode.Open); file_2 = bldPath + "\\" + "model" + "\\" + listBox1.SelectedIndex.ToString("D4"); _nsbmd = NsbmdLoader.LoadNsbmd(fileStream); if (!checkBox1.Checked) { _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(Form1.workingFolder + @"data\a\1\7\bldtilesets" + "\\" + comboBox1.SelectedIndex.ToString("D4"))), out _nsbmd.Textures, out _nsbmd.Palettes); } else { _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(Form1.workingFolder + @"data\a\1\7\bld2tilesets" + "\\" + comboBox1.SelectedIndex.ToString("D4"))), out _nsbmd.Textures, out _nsbmd.Palettes); } try { _nsbmd.MatchTextures(); } catch { } RenderBuilding(null, null); fileStream.Close(); System.IO.BinaryReader readHeader = new System.IO.BinaryReader(File.OpenRead(bldPath + "\\" + "header" + "\\" + listBox1.SelectedIndex.ToString("D4"))); numericUpDown1.Value = readHeader.ReadUInt16(); // ID readHeader.BaseStream.Position += 2; numericUpDown2.Value = readHeader.ReadUInt16(); // Door ID numericUpDown3.Value = readHeader.ReadInt16(); // X numericUpDown4.Value = readHeader.ReadInt16(); // Y numericUpDown5.Value = readHeader.ReadInt16(); // Z readHeader.Close(); }
/// <summary> /// Constructs a new <see cref="Key"/> instance. /// </summary> /// <param name="encodedText">The encoded Licence text.</param> public Key(String encodedText) { _encodedText = encodedText; try { using (BinaryReader reader = new BinaryReader( new MemoryStream(Base32.Decode(encodedText)))) { // Get the Licence data from the reader. LicenceId = reader.ReadInt32(); _startDateOffset = reader.ReadUInt16(); _endDateOffset = reader.ReadUInt16(); byte productCount = reader.ReadByte(); for (int i = 0; i < productCount; i++) { _products.Add(new Product(reader)); } // Validate the signature that follows the Licence data. _isValid = DSAVerifyHash( new SHA1CryptoServiceProvider().ComputeHash(ToArray()), reader.ReadBytes(reader.ReadByte()), LicenceConstants.PublicKey, "SHA1"); } } catch { _isValid = false; } }
public PosTbl(Stream si) { var binaryReader = new BinaryReader(si); int num = tbloff - 144; si.Position = num + 160; va0 = binaryReader.ReadUInt16(); va2 = binaryReader.ReadUInt16(); si.Position = num + 168; va8 = binaryReader.ReadInt32(); vac = binaryReader.ReadInt32(); si.Position = num + 176; vb0 = binaryReader.ReadInt32(); vb4 = binaryReader.ReadInt32(); vb8 = binaryReader.ReadInt32(); si.Position = num + 192; vc0 = binaryReader.ReadInt32(); vc4 = binaryReader.ReadInt32(); vc8 = binaryReader.ReadInt32(); vcc = binaryReader.ReadInt32(); si.Position = num + 208; vd0 = binaryReader.ReadInt32(); vd4 = binaryReader.ReadInt32(); vd8 = binaryReader.ReadInt32(); vdc = binaryReader.ReadInt32(); si.Position = num + 224; ve0 = binaryReader.ReadInt32(); ve4 = binaryReader.ReadInt32(); ve8 = binaryReader.ReadInt32(); vec = binaryReader.ReadInt32(); si.Position = num + 240; vf0 = binaryReader.ReadInt32(); vf4 = binaryReader.ReadInt32(); vf8 = binaryReader.ReadInt32(); vfc = binaryReader.ReadInt32(); }
/// <summary> Creates a new glyph variant record by reading it from the specified stream. </summary> /// <param name="reader"> The correctly positioned stream to read from. </param> public GlyphVariantRecord(BinaryReader reader) { Contract.Requires(reader != null); Glyph = reader.ReadUInt16(); AdvanceMeasurement = reader.ReadUInt16(); }
/// <summary> /// /// </summary> /// <param name="input"></param> public void Parse(Stream input) { BinaryReader br = new BinaryReader(input); _FrameSize = new Rect(this.Version); _FrameSize.Parse(input); _FrameRateDelay = br.ReadUInt16(); _FrameRate = (_FrameRateDelay >> 8) + ((_FrameRateDelay & 0xFF) / 100); _FrameCount = br.ReadUInt16(); int x = Math.Abs((this._FrameSize.Xmax - this._FrameSize.Xmin) / 12); int y = Math.Abs((this._FrameSize.Ymax - this._FrameSize.Ymin) / 12); if (x > SwfFile.Configuration.MaximumStageSizeX) { Log.Warn(this, "The x value(" + x + ") of the stage exceeds the allowed maximum."); } if (x < SwfFile.Configuration.MinimumStageSizeX) { Log.Warn(this, "The x value(" + x + ") of the stage under-runs the allowed minimum."); } if (y > SwfFile.Configuration.MaximumStageSizeY) { Log.Warn(this, "The y value(" + y + ") of the stage exceeds the allowed maximum."); } if (y < SwfFile.Configuration.MinimumStageSizeY) { Log.Warn(this, "The y value(" + y + ") of the stage under-runs the allowed minimum."); } }
public override void Read(string file) { BinaryReader br = new BinaryReader(File.OpenRead(file)); ushort num_tiles = br.ReadUInt16(); ushort depth = br.ReadUInt16(); ColorFormat format = (depth == 0x01 ? ColorFormat.colors256 : ColorFormat.colors16); if (br.BaseStream.Length - 4 == num_tiles * 0x40) format = ColorFormat.colors256; Byte[] tiles = br.ReadBytes(num_tiles * (0x20 + 0x20 * depth)); int width = 64; if (num_tiles == 0x10) width = 32; int height = tiles.Length / width; if (depth == 0) height *= 2; br.Close(); Set_Tiles(tiles, width, height, format, TileForm.Horizontal, true); pluginHost.Set_Image(this); // If the image is 8bpp, convert to 8bpp the palette (4bpp per default) PaletteBase palette = pluginHost.Get_Palette(); if (palette.Loaded && format == ColorFormat.colors256) { palette.Depth = ColorFormat.colors256; pluginHost.Set_Palette(palette); } }
public override object ReadScalarValue(System.IO.BinaryReader br) { VTPropertyType vType = (VTPropertyType)br.ReadUInt16(); br.ReadUInt16(); // Ushort Padding ITypedPropertyValue p = PropertyFactory.Instance.NewProperty(vType, codePage, true); p.Read(br); return(p); }
public static sSWAV Read(string path) { /***Lectura del archivo SWAV***/ System.IO.FileStream fs = null; System.IO.BinaryReader br = null; sSWAV swav = new sSWAV(); try { fs = new System.IO.FileStream(path, System.IO.FileMode.Open); br = new System.IO.BinaryReader(fs); //Leer Header swav.header.type = Encoding.ASCII.GetChars(br.ReadBytes(4)); swav.header.magic = br.ReadUInt32(); swav.header.nFileSize = br.ReadUInt32(); swav.header.nSize = br.ReadUInt16(); swav.header.nBlock = br.ReadUInt16(); //Leer Data swav.data.type = Encoding.ASCII.GetChars(br.ReadBytes(4)); swav.data.nSize = br.ReadUInt32(); {//Leer Info swav.data.info.nWaveType = br.ReadByte(); swav.data.info.bLoop = br.ReadByte(); swav.data.info.nSampleRate = br.ReadUInt16(); swav.data.info.nTime = br.ReadUInt16(); swav.data.info.nLoopOffset = br.ReadUInt16(); swav.data.info.nNonLoopLen = br.ReadUInt32(); } //Leer resto de Data uint tamañoDatos = (uint)(br.BaseStream.Length - br.BaseStream.Position); swav.data.data = br.ReadBytes((int)tamañoDatos); } catch (Exception ex) { System.Console.WriteLine(ex.Message.ToString()); } finally { if (fs != null) { fs.Close(); } if (br != null) { br.Close(); } } return(swav); }
public void Load(System.IO.BinaryReader reader) { version = reader.ReadByte(); if (version > VERSION) { throw new CacheException("Unknown CacheItem Version.", null, version); } name = reader.ReadString(); if (version >= 2) { objdname = reader.ReadString(); } else { objdname = null; } if (version >= 3) { int ct = reader.ReadUInt16(); valuenames = new string[ct]; for (int i = 0; i < ct; i++) { valuenames[i] = reader.ReadString(); } } else { valuenames = new string[0]; } type = (SimPe.Data.ObjectTypes)reader.ReadUInt16(); pfd = new Packages.PackedFileDescriptor(); pfd.Type = reader.ReadUInt32(); pfd.Group = reader.ReadUInt32(); pfd.LongInstance = reader.ReadUInt64(); guid = reader.ReadUInt32(); int size = reader.ReadInt32(); if (size == 0) { thumb = null; } else { byte[] data = reader.ReadBytes(size); MemoryStream ms = new MemoryStream(data); thumb = Image.FromStream(ms); } }
private static void ReadVarFileInfo(System.IO.BinaryReader reader) { ushort us; string s; us = reader.ReadUInt16(); us = reader.ReadUInt16(); //0 us = reader.ReadUInt16(); //1 s = ReadString(reader); //"Translation" reader.BaseStream.Position = (reader.BaseStream.Position + 3) & ~3; //round up to 32bit boundary us = reader.ReadUInt16(); //langId; MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)) = 0 us = reader.ReadUInt16(); //codepage; 1200 = CP_WINUNICODE }
/// <summary> /// Read the end of the central directory /// </summary> /// <returns>Status of the given stream</returns> private ZipReturn ReadEndOfCentralDir() { // Open the stream for reading BinaryReader br = new BinaryReader(_zipstream); // If the stream doesn't start with the correct signature, return uint thisSignature = br.ReadUInt32(); if (thisSignature != Constants.EndOfCentralDirSignature) { return(ZipReturn.ZipEndOfCentralDirectoryError); } // If this is part of a spanned archive, return ushort tushort = br.ReadUInt16(); // NumberOfThisDisk if (tushort != 0) { return(ZipReturn.ZipEndOfCentralDirectoryError); } tushort = br.ReadUInt16(); // NumberOfThisDiskCenterDir if (tushort != 0) { return(ZipReturn.ZipEndOfCentralDirectoryError); } // If the number of entries in the current disk doesn't match up with the total entries, return _entriesCount = br.ReadUInt16(); // TotalNumberOfEntriesDisk tushort = br.ReadUInt16(); // TotalNumber of entries in the central directory if (tushort != _entriesCount) { return(ZipReturn.ZipEndOfCentralDirectoryError); } _centerDirSize = br.ReadUInt32(); // SizeOfCenteralDir _centerDirStart = br.ReadUInt32(); // Offset // Get the file comment ushort zipFileCommentLength = br.ReadUInt16(); _fileComment = br.ReadBytes(zipFileCommentLength); // If there's extra data past the comment, flag that we have extra data if (_zipstream.Position != _zipstream.Length) { _zipStatus |= ZipStatus.ExtraData; } return(ZipReturn.ZipGood); }
private void ReadBitmap1() { // Read the System sector Byte[] sectorData = base.ReadSector(20, 2); System.IO.MemoryStream stm = new System.IO.MemoryStream(sectorData, 0, sectorData.Length); System.IO.BinaryReader rdr = new System.IO.BinaryReader(stm); Byte[] bByteArray = rdr.ReadBytes(2); sectorsFree = rdr.ReadUInt16(); noOfFiles = rdr.ReadUInt16(); tracksPerSide = rdr.ReadByte(); sectorsPerTrack = rdr.ReadByte(); noOfDirectories = rdr.ReadByte(); bByteArray = rdr.ReadBytes(1); if ((bByteArray[0] & 0x80) == 0x80) { sides = 2; } else { sides = 1; } bByteArray = rdr.ReadBytes(1); if (bByteArray[0] == 0) { diskType = DiskTypes.Master; } else if (bByteArray[0] == 0x01) { diskType = DiskTypes.Slave; } else if (bByteArray[0] == 0x47) { diskType = DiskTypes.Game; } else { diskType = DiskTypes.Unknown; } sectors = (ushort)((sectorsPerTrack * tracksPerSide) * sides); sectorsUsed = (ushort)(sectors - sectorsFree); }
public override Resource Load(System.IO.BinaryReader reader, string name, LoaderFileOpener opener, Resource context) { reader.Require(Magic); var contentSize = reader.ReadInt32(); // total size - header size reader.Require(1); reader.Require(0); reader.Require(0x80); // headerSize if (contentSize + 0x80 != reader.BaseStream.Length) { throw new Exception(); } reader.Require(contentSize); // contentSize2 reader.Require(0x85040201); reader.Require(0xAAE4); int width = reader.ReadUInt16(); int height = reader.ReadUInt16(); reader.Require((ushort)1); reader.RequireZeroes(90); if (width != height) { throw new InvalidDataException("Width and height must be equal for a cube map."); } TextureCube cube = new TextureCube(); //cube.Storage( //cube., width, TextureFormats.Vector4nb); throw new NotImplementedException(); /* * byte[] data = new byte[width * height * 4]; * * foreach (CubeFace face in TextureCube.Faces) { * int lod = 0; * * for (int size = width; size >= 8; size /= 2, lod++) { * reader.Read(data, 0, size * size * 4); * cube.SetData(face, lod, Box2i.CreateSize(size, size), data); * } * * cube.MaxLod = lod - 1; * } * * return new TextureResource(Manager, cube, name);*/ }
//Support to convert RSA key from PEM to XML, currently RSACryptoServiceProvider only support XML format. private static System.Security.Cryptography.RSAParameters ConvertPemToXmlFormat(string privateKey) { var privateKeyBits = System.Convert.FromBase64String(privateKey); var rsaParams = new System.Security.Cryptography.RSAParameters(); using (var binr = new System.IO.BinaryReader(new System.IO.MemoryStream(privateKeyBits))) { byte bt = 0; ushort twobytes = 0; twobytes = binr.ReadUInt16(); if (twobytes == 0x8130) { binr.ReadByte(); } else if (twobytes == 0x8230) { binr.ReadInt16(); } else { throw new Exception("Unexpected value read binr.ReadUInt16()"); } twobytes = binr.ReadUInt16(); if (twobytes != 0x0102) { throw new Exception("Unexpected version"); } bt = binr.ReadByte(); if (bt != 0x00) { throw new Exception("Unexpected value read binr.ReadByte()"); } rsaParams.Modulus = binr.ReadBytes(GetIntegerSize(binr)); rsaParams.Exponent = binr.ReadBytes(GetIntegerSize(binr)); rsaParams.D = binr.ReadBytes(GetIntegerSize(binr)); rsaParams.P = binr.ReadBytes(GetIntegerSize(binr)); rsaParams.Q = binr.ReadBytes(GetIntegerSize(binr)); rsaParams.DP = binr.ReadBytes(GetIntegerSize(binr)); rsaParams.DQ = binr.ReadBytes(GetIntegerSize(binr)); rsaParams.InverseQ = binr.ReadBytes(GetIntegerSize(binr)); } return(rsaParams); }
private WaveFormat GetWaveFormat(System.IO.BinaryReader br) { WaveFormat format = new WaveFormat(); int formatChunkLength = br.ReadInt32(); if (formatChunkLength < 16) { throw new ApplicationException("Invalid WaveFormat Structure"); } format.FormatTag = (WaveFormatTag)br.ReadUInt16(); format.Channels = br.ReadInt16(); format.SamplesPerSecond = br.ReadInt32(); format.AverageBytesPerSecond = br.ReadInt32(); format.BlockAlignment = br.ReadInt16(); format.BitsPerSample = br.ReadInt16(); short extraSize = 0; if (formatChunkLength > 16) { extraSize = br.ReadInt16(); if (extraSize > formatChunkLength - 18) { Console.WriteLine("Format chunk mismatch"); //RRL GSM exhibits this bug. Don't throw an exception //throw new ApplicationException("Format chunk length mismatch"); extraSize = (short)(formatChunkLength - 18); } // read any extra data // br.ReadBytes(extraSize); } return(format); }
private void ParseQuestData(string fileName) { QuestData = new Dictionary <ushort, Quest>(); using (var stream = new MemoryStream(File.ReadAllBytes(fileName))) using (var reader = new System.IO.BinaryReader(stream)) { header = reader.ReadUInt16(); var count = reader.ReadInt16(); for (var i = 0; i < count; i++) { var size = reader.ReadInt32(); var data = reader.ReadBytes(size - 4); var parsed = Quest.Parse(data); if (parsed == null) { MessageBox.Show("Failed to parse QuestData.shn"); return; } QuestData.Add(parsed.ID, parsed); } } }
public static string ReadUTF(System.IO.BinaryReader input) { ushort len = input.ReadUInt16(); byte[] data = input.ReadBytes(len); return(System.Text.Encoding.UTF8.GetString(data)); }
public static void Main(Client client) { //byte property = 2; var property = Enums.ObjectPropertiesFlags.IsTopOrder1; string datPath = client.TibiaProcess.MainModule.FileName; datPath = datPath.Substring(0, datPath.LastIndexOf('\\') + 1) + "Tibia.dat"; if (!File.Exists(datPath)) { return; } ushort count = 0; using (FileStream fstream = File.OpenRead(datPath)) { System.IO.BinaryReader reader = new System.IO.BinaryReader(fstream); reader.ReadUInt32(); // file signature count = (ushort)(reader.ReadUInt16() - 100); // item ids start at 100 } string s = string.Empty; for (int i = 0; i < count; i++) { var flag = client.GetObjectProperty((ushort)(i + 100)); if (!flag.HasFlag(property)) { continue; } s += (i + 100) + "\n"; //Thread.Sleep(2); } File.WriteAllText("items with " + property + ".txt", s); }
internal PdfFont(System.IO.BinaryReader reader) { _fontName = reader.ReadString(); _fullName = reader.ReadString(); _familyName = reader.ReadString(); _weight = reader.ReadString(); _isCIDFont = reader.ReadBoolean(); _italicAngle = reader.ReadDouble(); _isFixedPitch = reader.ReadBoolean(); _characterSet = reader.ReadString(); _fontBBox = new AfmRectangle(reader); _underlinePosition = reader.ReadInt16(); _underlineThickness = reader.ReadInt16(); _capHeight = reader.ReadInt16(); _xheight = reader.ReadInt16(); _ascender = reader.ReadInt16(); _descender = reader.ReadInt16(); _stdHW = reader.ReadInt16(); _stdVW = reader.ReadInt16(); _charMetric = new AfmCharMetric[65536]; UInt16 pos; while ((pos = reader.ReadUInt16()) != 0) { _charMetric[pos] = new AfmCharMetric(reader); } }
static int ReadUInt16(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); System.IO.BinaryReader obj = (System.IO.BinaryReader)LuaScriptMgr.GetNetObjectSelf(L, 1, "System.IO.BinaryReader"); ushort o = obj.ReadUInt16(); LuaScriptMgr.Push(L, o); return(1); }
/// <summary> /// Default Map Constructor /// </summary> /// <param name="Number">Map Number</param> /// <param name="Width">Map Width</param> /// <param name="Height">Map Height</param> public Map(ushort Number, ushort Width, ushort Height) { try { System.IO.FileStream FS = System.IO.File.OpenRead(DAFolder + @"\Maps\lod" + Number.ToString() + ".map"); System.IO.BinaryReader Reader = new System.IO.BinaryReader(FS); BaseMatrix = new byte[Width, Height]; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Reader.ReadUInt16(); BaseMatrix[x, y] = (byte)(CheckSOTP(Reader.ReadUInt16(), Reader.ReadUInt16()) ? 0x00 : 0x01); } } Entities = new Dictionary <uint, MapEntity>(); } catch { } }
private static void loadGk3Bitmap(System.IO.BinaryReader reader, out byte[] pixels, out int width, out int height, out bool containsAlpha) { const string errorMessage = "This is not a valid GK3 bitmap"; containsAlpha = false; uint header = reader.ReadUInt32(); if (header != Gk3BitmapHeader) { throw new Resource.InvalidResourceFileFormat(errorMessage); } height = reader.ReadUInt16(); width = reader.ReadUInt16(); pixels = new byte[width * height * 4]; byte r, g, b; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int currentPixel = (y * width + x) * 4; ushort pixel = reader.ReadUInt16(); convert565(pixel, out r, out g, out b); pixels[currentPixel + 0] = r; pixels[currentPixel + 1] = g; pixels[currentPixel + 2] = b; pixels[currentPixel + 3] = 255; } // do we need to skip a padding pixel? if ((width & 0x00000001) != 0) { reader.ReadUInt16(); } } }
private bool LoadCalabash(System.IO.BinaryReader br) { try { fStream.Seek(PAL_CALABASH_OFFSET, SeekOrigin.Begin); palCalabash = br.ReadUInt16(); return(true); } catch (Exception e) { System.Console.WriteLine("Exception in RPGData.LoadCalabash(): " + e.Message); return(false); } }
private static ushort?ReadUShort(double?value, bool specified, System.IO.BinaryReader binaryReader) { if (specified) { if (value.HasValue) { return((ushort)value.Value); } return(binaryReader.ReadUInt16()); } return(null); }
private void Mod_LoadEdges(SDHeader header, ref CModel.SModel _SModel, ref System.IO.BinaryReader br) { List <CModel.SMEdge> MEdge = new List <CModel.SMEdge>(); br.BaseStream.Seek(header.lumps[LUMP_EDGES].fileofs, System.IO.SeekOrigin.Begin); while (br.BaseStream.Position < (header.lumps[LUMP_EDGES].fileofs + header.lumps[LUMP_EDGES].filelen)) { CModel.SMEdge _MEdge; _MEdge.v = new ushort[2]; _MEdge.v[0] = br.ReadUInt16(); _MEdge.v[1] = br.ReadUInt16(); _MEdge.cachededgeoffset = 0; MEdge.Add(_MEdge); } _SModel.numedges = MEdge.Count; _SModel.edges = MEdge.ToArray(); }
private static bool ReadFileHeader(System.IO.BinaryReader aReader, ref BMPFileHeader aFileHeader) { aFileHeader.magic = aReader.ReadUInt16(); if (aFileHeader.magic != MAGIC) { return(false); } aFileHeader.filesize = aReader.ReadUInt32(); aFileHeader.reserved = aReader.ReadUInt32(); aFileHeader.offset = aReader.ReadUInt32(); return(true); }