Here are the examples of the csharp api System.IO.BinaryReader.ReadInt16() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
759 Examples
19
Source : UESerializer.cs
with MIT License
from 13xforever
with MIT License
from 13xforever
public static Gvas Read(Stream stream)
{
using (var reader = new BinaryReader(stream, Encoding.ASCII, true))
{
var header = reader.ReadBytes(Gvas.Header.Length);
if (!Gvas.Header.SequenceEqual(header))
throw new FormatException($"Invalid header, expected {Gvas.Header.AsHex()}");
var result = new Gvas();
result.SaveGameVersion = reader.ReadInt32();
result.PackageVersion = reader.ReadInt32();
result.EngineVersion.Major = reader.ReadInt16();
result.EngineVersion.Minor = reader.ReadInt16();
result.EngineVersion.Patch = reader.ReadInt16();
result.EngineVersion.Build = reader.ReadInt32();
result.EngineVersion.BuildId = reader.ReadUEString();
result.CustomFormatVersion = reader.ReadInt32();
result.CustomFormatData.Count = reader.ReadInt32();
result.CustomFormatData.Entries = new CustomFormatDataEntry[result.CustomFormatData.Count];
for (var i = 0; i < result.CustomFormatData.Count; i++)
{
var entry = new CustomFormatDataEntry();
entry.Id = new Guid(reader.ReadBytes(16));
entry.Value = reader.ReadInt32();
result.CustomFormatData.Entries[i] = entry;
}
result.SaveGameType = reader.ReadUEString();
while (UEProperty.Read(reader) is UEProperty prop)
result.Properties.Add(prop);
return result;
}
}
19
Source : WaveFormat.cs
with MIT License
from 3wz
with MIT License
from 3wz
private void ReadWaveFormat(BinaryReader br, int formatChunkLength)
{
if (formatChunkLength < 16)
throw new ApplicationException("Invalid WaveFormat Structure");
this.waveFormatTag = (WaveFormatEncoding)br.ReadUInt16();
this.channels = br.ReadInt16();
this.sampleRate = br.ReadInt32();
this.averageBytesPerSecond = br.ReadInt32();
this.blockAlign = br.ReadInt16();
this.bitsPerSample = br.ReadInt16();
if (formatChunkLength > 16)
{
this.extraSize = br.ReadInt16();
if (this.extraSize != formatChunkLength - 18)
{
Debug.WriteLine("Format chunk mismatch");
this.extraSize = (short)(formatChunkLength - 18);
}
}
}
19
Source : EndianBinaryReader.cs
with MIT License
from 91Act
with MIT License
from 91Act
public override short ReadInt16()
{
if (endian == EndianType.BigEndian)
{
a16 = ReadBytes(2);
Array.Reverse(a16);
return BitConverter.ToInt16(a16, 0);
}
return base.ReadInt16();
}
19
Source : PortalPoly.cs
with GNU Affero General Public License v3.0
from ACEmulator
with GNU Affero General Public License v3.0
from ACEmulator
public void Unpack(BinaryReader reader)
{
PortalIndex = reader.ReadInt16();
PolygonId = reader.ReadInt16();
}
19
Source : Texture.cs
with GNU Affero General Public License v3.0
from ACEmulator
with GNU Affero General Public License v3.0
from ACEmulator
private List<int> GetImageColorArray()
{
List<int> colors = new List<int>();
if (Length == 0) return colors;
switch (Format)
{
case SurfacePixelFormat.PFID_R8G8B8: // RGB
using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
{
for (uint i = 0; i < Height; i++)
for (uint j = 0; j < Width; j++)
{
byte b = reader.ReadByte();
byte g = reader.ReadByte();
byte r = reader.ReadByte();
int color = (r << 16) | (g << 8) | b;
colors.Add(color);
}
}
break;
case SurfacePixelFormat.PFID_CUSTOM_LSCAPE_R8G8B8:
using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
{
for (uint i = 0; i < Height; i++)
for (uint j = 0; j < Width; j++)
{
byte r = reader.ReadByte();
byte g = reader.ReadByte();
byte b = reader.ReadByte();
int color = (r << 16) | (g << 8) | b;
colors.Add(color);
}
}
break;
case SurfacePixelFormat.PFID_A8R8G8B8: // ARGB format. Most UI textures fall into this category
using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
{
for (uint i = 0; i < Height; i++)
for (uint j = 0; j < Width; j++)
colors.Add(reader.ReadInt32());
}
break;
case SurfacePixelFormat.PFID_INDEX16: // 16-bit indexed colors. Index references position in a palette;
using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
{
for (uint y = 0; y < Height; y++)
for (uint x = 0; x < Width; x++)
colors.Add(reader.ReadInt16());
}
break;
case SurfacePixelFormat.PFID_A8: // Greyscale, also known as Cairo A8.
case SurfacePixelFormat.PFID_CUSTOM_LSCAPE_ALPHA:
using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
{
for (uint y = 0; y < Height; y++)
for (uint x = 0; x < Width; x++)
colors.Add(reader.ReadByte());
}
break;
case SurfacePixelFormat.PFID_P8: // Indexed
using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
{
for (uint y = 0; y < Height; y++)
for (uint x = 0; x < Width; x++)
colors.Add(reader.ReadByte());
}
break;
case SurfacePixelFormat.PFID_R5G6B5: // 16-bit RGB
using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
{
for (uint y = 0; y < Height; y++)
for (uint x = 0; x < Width; x++)
{
ushort val = reader.ReadUInt16();
List<int> color = get565RGB(val);
colors.Add(color[0]); // Red
colors.Add(color[1]); // Green
colors.Add(color[2]); // Blue
}
}
break;
case SurfacePixelFormat.PFID_A4R4G4B4:
using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
{
for (uint y = 0; y < Height; y++)
for (uint x = 0; x < Width; x++)
{
ushort val = reader.ReadUInt16();
int alpha = (val >> 12) / 0xF * 255;
int red = (val >> 8 & 0xF) / 0xF * 255;
int green = (val >> 4 & 0xF) / 0xF * 255;
int blue = (val & 0xF) / 0xF * 255;
colors.Add(alpha);
colors.Add(red);
colors.Add(green);
colors.Add(blue);
}
}
break;
default:
Console.WriteLine("Unhandled SurfacePixelFormat (" + Format.ToString() + ") in RenderSurface " + Id.ToString("X8"));
break;
}
return colors;
}
19
Source : Texture.cs
with GNU Affero General Public License v3.0
from ACEmulator
with GNU Affero General Public License v3.0
from ACEmulator
private List<int> GetPaletteIndexes()
{
List<int> colors = new List<int>();
using (BinaryReader reader = new BinaryReader(new MemoryStream(SourceData)))
{
for (uint y = 0; y < Height; y++)
for (uint x = 0; x < Width; x++)
colors.Add(reader.ReadInt16());
}
return colors;
}
19
Source : LanguageInfo.cs
with GNU Affero General Public License v3.0
from ACEmulator
with GNU Affero General Public License v3.0
from ACEmulator
public override void Unpack(BinaryReader reader)
{
Version = reader.ReadInt32();
Base = reader.ReadInt16();
NumDecimalDigits = reader.ReadInt16();
LeadingZero = reader.ReadBoolean();
GroupingSize = reader.ReadInt16();
Numerals = UnpackList(reader);
DecimalSeperator = UnpackList(reader);
GroupingSeperator = UnpackList(reader);
NegativeNumberFormat = UnpackList(reader);
IsZeroSingular = reader.ReadBoolean();
IsOneSingular = reader.ReadBoolean();
IsNegativeOneSingular = reader.ReadBoolean();
IsTwoOrMoreSingular = reader.ReadBoolean();
IsNegativeTwoOrLessSingular = reader.ReadBoolean();
reader.AlignBoundary();
TreasurePrefixLetters = UnpackList(reader);
TreasureMiddleLetters = UnpackList(reader);
TreasureSuffixLetters = UnpackList(reader);
MalePlayerLetters = UnpackList(reader);
FemalePlayerLetters = UnpackList(reader);
ImeEnabledSetting = reader.ReadUInt32();
SymbolColor = reader.ReadUInt32();
SymbolColorText = reader.ReadUInt32();
SymbolHeight = reader.ReadUInt32();
SymbolTranslucence = reader.ReadUInt32();
SymbolPlacement = reader.ReadUInt32();
CandColorBase = reader.ReadUInt32();
CandColorBorder = reader.ReadUInt32();
CandColorText = reader.ReadUInt32();
CompColorInput = reader.ReadUInt32();
CompColorTargetConv = reader.ReadUInt32();
CompColorConverted = reader.ReadUInt32();
CompColorTargetNotConv = reader.ReadUInt32();
CompColorInputErr = reader.ReadUInt32();
CompTranslucence = reader.ReadUInt32();
CompColorText = reader.ReadUInt32();
OtherIME = reader.ReadUInt32();
WordWrapOnSpace = reader.ReadInt32();
AdditionalSettings = UnpackList(reader);
AdditionalFlags = reader.ReadUInt32();
}
19
Source : Polygon.cs
with GNU Affero General Public License v3.0
from ACEmulator
with GNU Affero General Public License v3.0
from ACEmulator
public void Unpack(BinaryReader reader)
{
NumPts = reader.ReadByte();
Stippling = (StipplingType)reader.ReadByte();
SidesType = (CullMode)reader.ReadInt32();
PosSurface = reader.ReadInt16();
NegSurface = reader.ReadInt16();
for (short i = 0; i < NumPts; i++)
VertexIds.Add(reader.ReadInt16());
if (!Stippling.HasFlag(StipplingType.NoPos))
{
for (short i = 0; i < NumPts; i++)
PosUVIndices.Add(reader.ReadByte());
}
if (SidesType == CullMode.Clockwise && !Stippling.HasFlag(StipplingType.NoNeg))
{
for (short i = 0; i < NumPts; i++)
NegUVIndices.Add(reader.ReadByte());
}
if (SidesType == CullMode.None)
{
NegSurface = PosSurface;
NegUVIndices = PosUVIndices;
}
}
19
Source : TextureCache.cs
with GNU General Public License v3.0
from ACEmulator
with GNU General Public License v3.0
from ACEmulator
private static List<int> GetColors(ACE.DatLoader.FileTypes.Texture texture)
{
var colors = new List<int>();
using (BinaryReader reader = new BinaryReader(new MemoryStream(texture.SourceData)))
{
for (uint y = 0; y < texture.Height; y++)
for (uint x = 0; x < texture.Width; x++)
colors.Add(reader.ReadInt16());
}
return colors;
}
19
Source : Pack.cs
with Apache License 2.0
from aequabit
with Apache License 2.0
from aequabit
public object[] Deserialize(byte[] data)
{
MemoryStream Stream = new MemoryStream(data);
BinaryReader Reader = new BinaryReader(Stream, Encoding.UTF8);
List<object> Items = new List<object>();
byte Current = 0;
byte Count = Reader.ReadByte();
for (int I = 0; I <= Count - 1; I++)
{
Current = Reader.ReadByte();
switch (Current)
{
case 0:
Items.Add(Reader.ReadBoolean());
break;
case 1:
Items.Add(Reader.ReadByte());
break;
case 2:
Items.Add(Reader.ReadBytes(Reader.ReadInt32()));
break;
case 3:
Items.Add(Reader.ReadChar());
break;
case 4:
Items.Add(Reader.ReadString().ToCharArray());
break;
case 5:
Items.Add(Reader.ReadDecimal());
break;
case 6:
Items.Add(Reader.ReadDouble());
break;
case 7:
Items.Add(Reader.ReadInt32());
break;
case 8:
Items.Add(Reader.ReadInt64());
break;
case 9:
Items.Add(Reader.ReadSByte());
break;
case 10:
Items.Add(Reader.ReadInt16());
break;
case 11:
Items.Add(Reader.ReadSingle());
break;
case 12:
Items.Add(Reader.ReadString());
break;
case 13:
Items.Add(Reader.ReadUInt32());
break;
case 14:
Items.Add(Reader.ReadUInt64());
break;
case 15:
Items.Add(Reader.ReadUInt16());
break;
case 16:
Items.Add(DateTime.FromBinary(Reader.ReadInt64()));
break;
}
}
Reader.Close();
return Items.ToArray();
}
19
Source : AdpcmInfo.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
numSamples16Bit = br.ReadInt32();
unk3 = new short[]
{
br.ReadInt16(),
br.ReadInt16(),
br.ReadInt16(),
br.ReadInt16(),
};
numStates = br.ReadInt32();
if (numStates > 0)
{
states = new DviAdpcmDecoder.AdpcmState[numStates];
for (int i = 0; i < numStates; i++)
{
states[i].valprev = br.ReadInt16();
states[i].index = br.ReadByte();
}
}
}
19
Source : ChannelInfo.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
unk1Reserved = br.ReadInt32();
unk2Reserved = br.ReadInt32();
hash = br.ReadUInt32();
numSamplesInBytes = br.ReadInt32();
numSamples16Bit = br.ReadInt32();
unk4 = br.ReadInt32();
sampleRate = br.ReadUInt16();
unk5 = br.ReadInt16();
unk6 = br.ReadInt16();
unk7Reserved = br.ReadInt16();
offsetAdpcmStateTable = br.ReadInt64();
}
19
Source : WaveHeader.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public virtual void Read(BinaryReader br)
{
RiffChunkID = br.ReadInt32();
RiffChunkSize = br.ReadInt32();
Format = br.ReadInt32();
FmtChunkID = br.ReadInt32();
FmtChunkSize = br.ReadInt32();
AudioFormat = br.ReadUInt16();
NumChannels = br.ReadInt16();
SampleRate = br.ReadInt32();
ByteRate = br.ReadInt32();
BlockAlign = br.ReadInt16();
BitsPerSample = br.ReadInt16();
if (AudioFormat == WaveFormatExtensible)
{
ExtraDataSize = br.ReadInt16();
ValidBitsPerSample = br.ReadInt16();
AvailableChannelMask = (ChannelMask) br.ReadInt32();
FormatGuid[0] = br.ReadUInt32();
FormatGuid[1] = br.ReadUInt32();
FormatGuid[2] = br.ReadUInt32();
FormatGuid[3] = br.ReadUInt32();
}
DataChunkID = br.ReadInt32();
DataChunkSize = br.ReadInt32();
}
19
Source : Header.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
Identifier = br.ReadUInt32();
Version = br.ReadInt32();
EntryCount = br.ReadInt32();
TocSize = br.ReadInt32();
TocEntrySize = br.ReadInt16();
Unknown2 = br.ReadInt16();
}
19
Source : TOCEntry.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
uint temp = br.ReadUInt32();
IsResourceFile = ((temp & 0xc0000000) != 0);
if (!IsResourceFile)
{
Size = (int) temp;
}
else
{
RSCFlags = temp;
}
ResourceType = (ResourceType) br.ReadInt32();
OffsetBlock = br.ReadInt32();
UsedBlocks = br.ReadInt16();
Flags = br.ReadInt16();
if (IsResourceFile)
{
Size = UsedBlocks*0x800 - PaddingCount;
}
// Uses 0x4000 on Flags to determine if its old style resources
// if its not 0, its old style!
// Uses 0x2000 on Flags to determine if its a RSC,
// if its 1, its a RSC!
}
19
Source : Bone.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
Offset = br.BaseStream.Position;
Name = new PtrString(br).Value;
Unknown1 = br.ReadInt16();
Unknown2 = br.ReadInt16();
NextSiblingOffset = ResourceUtil.ReadOffset(br);
FirstChildOffset = ResourceUtil.ReadOffset(br);
ParentOffset = ResourceUtil.ReadOffset(br);
BoneIndex = br.ReadInt16();
BoneID = br.ReadInt16();
BoneIndex2 = br.ReadInt16();
Unknown3 = br.ReadInt16();
//Debug.replacedert(BoneIndex == BoneIndex2);
Unknown4 = br.ReadInt32();
Position = new Vector4(br);
RotationEuler = new Vector4(br);
RotationQuaternion = new Vector4(br);
UnknownZeroVector1 = new Vector4(br);
AbsolutePosition = new Vector4(br);
AbsoluteRotationEuler = new Vector4(br);
UnknownZeroVector2 = new Vector4(br);
UnknownZeroVector3 = new Vector4(br);
UnknownZeroVector4 = new Vector4(br);
MinPI = new Vector4(br); // Minimum euler rotation maybe?
MaxPI = new Vector4(br); // Maximum euler rotation maybe?
UnknownAllZeros = new Vector4(br);
}
19
Source : VertexShader.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
Variables = new Variables(br);
Size = br.ReadInt16();
CompressedSize = br.ReadInt16();
if (Size != CompressedSize)
{
throw new Exception("Encountered a shader file with a compressed VertexShader");
}
ShaderData = br.ReadBytes(Size);
}
19
Source : Header.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
// Full Structure of rage::pgDictionary
// rage::datBase
VTable = br.ReadUInt32();
// rage::pgBase
BlockMapOffset = ResourceUtil.ReadOffset(br);
ParentDictionary = br.ReadUInt32();
UsageCount = br.ReadUInt32();
// CSimpleCollection<DWORD>
HashTableOffset = ResourceUtil.ReadOffset(br);
TextureCount = br.ReadInt16();
br.ReadInt16();
// CPtrCollection<T>
TextureListOffset = ResourceUtil.ReadOffset(br);
br.ReadInt16();
br.ReadInt16();
}
19
Source : BoneIDMapping.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
ID = br.ReadInt16();
Index = br.ReadInt16();
}
19
Source : Skeleton.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
uint bonesOffset = ResourceUtil.ReadOffset(br);
uint unknownIntsOffset = ResourceUtil.ReadOffset(br);
uint transforms1Offset = ResourceUtil.ReadOffset(br);
uint transforms2Offset = ResourceUtil.ReadOffset(br);
uint transforms3Offset = ResourceUtil.ReadOffset(br);
BoneCount = br.ReadUInt16();
Unknown0 = br.ReadInt16();
Unknown1 = br.ReadInt32();
Unknown2 = br.ReadInt32();
BoneIDMappings = new SimpleCollection<BoneIDMapping>(br, r => new BoneIDMapping(r));
Unknown3 = br.ReadInt32();
UnknownHash = br.ReadUInt32();
Unknown4 = br.ReadInt32();
UnknownSubStruct = new SubStruct(br);
// Data:
br.BaseStream.Seek(bonesOffset, SeekOrigin.Begin);
Bones = new SimpleArray<Bone>(br, BoneCount, r => new Bone(r));
br.BaseStream.Seek(unknownIntsOffset, SeekOrigin.Begin);
UnknownInts = new SimpleArray<int>(br, BoneCount, r => r.ReadInt32());
br.BaseStream.Seek(transforms1Offset, SeekOrigin.Begin);
Transforms1 = new SimpleArray<Matrix44>(br, BoneCount, r => new Matrix44(r));
br.BaseStream.Seek(transforms2Offset, SeekOrigin.Begin);
Transforms2 = new SimpleArray<Matrix44>(br, BoneCount, r => new Matrix44(r));
br.BaseStream.Seek(transforms3Offset, SeekOrigin.Begin);
Transforms3 = new SimpleArray<Matrix44>(br, BoneCount, r => new Matrix44(r));
// Fun stuff...
// Build a mapping of Offset -> Bone
var boneOffsetMapping = new Dictionary<uint, Bone>();
boneOffsetMapping.Add(0, null);
foreach (var bone in Bones)
{
boneOffsetMapping.Add((uint)bone.Offset, bone);
}
// Now resolve all the bone offsets to the real bones
foreach (var bone in Bones)
{
bone.Parent = boneOffsetMapping[bone.ParentOffset];
bone.FirstChild = boneOffsetMapping[bone.FirstChildOffset];
bone.NextSibling = boneOffsetMapping[bone.NextSiblingOffset];
}
}
19
Source : PixelShader.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
Variables = new Variables(br);
Size = br.ReadInt16();
CompressedSize = br.ReadInt16();
if (Size != CompressedSize)
{
throw new Exception("Encountered a shader file with a compressed PixelShader");
}
ShaderData = br.ReadBytes(Size);
}
19
Source : WaveInfo.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
offset = br.ReadInt64();
hash = br.ReadUInt32();
numSamplesInBytes = br.ReadInt32();
numSamplesInBytes_computed = SoundBankMono.GetPaddedSize(numSamplesInBytes);
numSamples16Bit = br.ReadInt32();
unk5 = br.ReadInt32();
samplerate = br.ReadUInt16();
unk6 = br.ReadUInt16();
if (Header.size > 32)
{
unk7 = br.ReadInt32();
offsetToStates = br.ReadInt64();
numSamples16Bit2 = br.ReadUInt32();
unk11 = br.ReadUInt32();
unk12 = br.ReadUInt32();
numStates = br.ReadInt32();
if (numStates > 0)
{
is_compressed = true;
states = new DviAdpcmDecoder.AdpcmState[numStates];
for (int j = 0; j < numStates; j++)
{
DviAdpcmDecoder.AdpcmState state = new DviAdpcmDecoder.AdpcmState();
state.valprev = br.ReadInt16();
state.index = br.ReadByte();
states[j] = state;
}
}
}
}
19
Source : VariableDefinition.cs
with GNU General Public License v3.0
from ahmed605
with GNU General Public License v3.0
from ahmed605
public void Read(BinaryReader br)
{
Unknown1 = br.ReadByte();
Unknown2 = br.ReadByte();
Unknown3 = br.ReadInt16();
byte nameLength = br.ReadByte();
byte[] nameBytes = br.ReadBytes(nameLength);
VariableName = Encoding.ASCII.GetString(nameBytes, 0, nameLength - 1);
}
19
Source : Int16Data.cs
with GNU Affero General Public License v3.0
from aianlinb
with GNU Affero General Public License v3.0
from aianlinb
public override void Read(BinaryReader reader) {
Value = reader.ReadInt16();
}
19
Source : ValueStringData.cs
with GNU Affero General Public License v3.0
from aianlinb
with GNU Affero General Public License v3.0
from aianlinb
public override unsafe void Read(BinaryReader reader) {
if (reader.BaseStream.Position == reader.BaseStream.Length) {
Value = null;
return;
}
var sb = new StringBuilder();
if (Dat.UTF32) {
int ch;
while ((ch = reader.ReadInt32()) != 0)
sb.Append(char.ConvertFromUtf32(ch));
} else {
short ch;
while ((ch = reader.ReadInt16()) != 0)
sb.Append((char)ch);
if (Dat.Name != "Languages" && reader.ReadInt16() != 0) // string should end with 4 bytes of zero
throw new("Not found \\0 at the end of the string");
}
Value = sb.ToString();
}
19
Source : RawEvent.cs
with GNU General Public License v3.0
from aiportal
with GNU General Public License v3.0
from aiportal
public static IEnumerable<RawInputEvent> FromBinary(byte[] bs)
{
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bs))
using (System.IO.BinaryReader br = new System.IO.BinaryReader(ms))
{
RawInputEvent e = new RawInputEvent();
while(br.PeekChar() != -1)
{
e._time = DateTime.FromBinary(br.ReadInt64());
e._evt = (RawEventType)br.ReadInt16();
e._reserved = br.ReadInt16();
e._data = br.ReadUInt32();
yield return e;
}
}
}
19
Source : RawInputEvent.cs
with GNU General Public License v3.0
from aiportal
with GNU General Public License v3.0
from aiportal
public static IEnumerable<IRawEvent> FromBinary(byte[] bs)
{
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(bs))
using (System.IO.BinaryReader br = new System.IO.BinaryReader(ms))
{
RawInputEvent e = new RawInputEvent();
while(br.PeekChar() != -1)
{
e._time = DateTime.FromBinary(br.ReadInt64());
e._evt = (RawEventType)br.ReadInt16();
e._reserved = br.ReadInt16();
e._data = br.ReadUInt32();
yield return e;
}
}
}
19
Source : RSAEncryptor.cs
with Apache License 2.0
from alipay
with Apache License 2.0
from alipay
private static RSACryptoServiceProvider BuildRSAServiceProvider(byte[] privateKey)
{
byte[] MODULUS, E, D, P, Q, DP, DQ, IQ;
byte bt = 0;
ushort twobytes = 0;
int elems = 0;
//set up stream to decode the asn.1 encoded RSA private key
//wrap Memory Stream with BinaryReader for easy reading
using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(privateKey)))
{
twobytes = binaryReader.ReadUInt16();
//data read as little endian order (actual data order for Sequence is 30 81)
if (twobytes == 0x8130)
{
//advance 1 byte
binaryReader.ReadByte();
}
else if (twobytes == 0x8230)
{
//advance 2 bytes
binaryReader.ReadInt16();
}
else
{
return null;
}
twobytes = binaryReader.ReadUInt16();
//version number
if (twobytes != 0x0102)
{
return null;
}
bt = binaryReader.ReadByte();
if (bt != 0x00)
{
return null;
}
//all private key components are Integer sequences
elems = GetIntegerSize(binaryReader);
MODULUS = binaryReader.ReadBytes(elems);
elems = GetIntegerSize(binaryReader);
E = binaryReader.ReadBytes(elems);
elems = GetIntegerSize(binaryReader);
D = binaryReader.ReadBytes(elems);
elems = GetIntegerSize(binaryReader);
P = binaryReader.ReadBytes(elems);
elems = GetIntegerSize(binaryReader);
Q = binaryReader.ReadBytes(elems);
elems = GetIntegerSize(binaryReader);
DP = binaryReader.ReadBytes(elems);
elems = GetIntegerSize(binaryReader);
DQ = binaryReader.ReadBytes(elems);
elems = GetIntegerSize(binaryReader);
IQ = binaryReader.ReadBytes(elems);
//create RSACryptoServiceProvider instance and initialize with public key
RSACryptoServiceProvider rsaService = new RSACryptoServiceProvider();
RSAParameters rsaParams = new RSAParameters
{
Modulus = MODULUS,
Exponent = E,
D = D,
P = P,
Q = Q,
DP = DP,
DQ = DQ,
InverseQ = IQ
};
rsaService.ImportParameters(rsaParams);
return rsaService;
}
}
19
Source : WaveFormat.cs
with MIT License
from amerkoleci
with MIT License
from amerkoleci
private void ReadWaveFormat(BinaryReader br, int formatChunkLength)
{
if (formatChunkLength < 16)
throw new InvalidDataException("Invalid WaveFormat Structure");
waveFormatTag = (WaveFormatEncoding)br.ReadUInt16();
channels = br.ReadInt16();
sampleRate = br.ReadInt32();
averageBytesPerSecond = br.ReadInt32();
blockAlign = br.ReadInt16();
bitsPerSample = br.ReadInt16();
if (formatChunkLength > 16)
{
extraSize = br.ReadInt16();
if (extraSize != formatChunkLength - 18)
{
Debug.WriteLine("Format chunk mismatch");
extraSize = (short)(formatChunkLength - 18);
}
}
}
19
Source : RSAHelper.cs
with Apache License 2.0
from anjoy8
with Apache License 2.0
from anjoy8
private RSA CreateRsaProviderFromPrivateKey(string privateKey)
{
var privateKeyBits = Convert.FromBase64String(privateKey);
var rsa = RSA.Create();
var rsaParameters = new RSAParameters();
using (BinaryReader binr = new BinaryReader(new 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()");
rsaParameters.Modulus = binr.ReadBytes(GetIntegerSize(binr));
rsaParameters.Exponent = binr.ReadBytes(GetIntegerSize(binr));
rsaParameters.D = binr.ReadBytes(GetIntegerSize(binr));
rsaParameters.P = binr.ReadBytes(GetIntegerSize(binr));
rsaParameters.Q = binr.ReadBytes(GetIntegerSize(binr));
rsaParameters.DP = binr.ReadBytes(GetIntegerSize(binr));
rsaParameters.DQ = binr.ReadBytes(GetIntegerSize(binr));
rsaParameters.InverseQ = binr.ReadBytes(GetIntegerSize(binr));
}
rsa.ImportParameters(rsaParameters);
return rsa;
}
19
Source : RSAHelper.cs
with Apache License 2.0
from anjoy8
with Apache License 2.0
from anjoy8
public RSA CreateRsaProviderFromPublicKey(string publicKeyString)
{
// encoded OID sequence for PKCS #1 rsaEncryption szOID_RSA_RSA = "1.2.840.113549.1.1.1"
byte[] seqOid = { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00 };
byte[] seq = new byte[15];
var x509Key = Convert.FromBase64String(publicKeyString);
// --------- Set up stream to read the asn.1 encoded SubjectPublicKeyInfo blob ------
using (MemoryStream mem = new MemoryStream(x509Key))
{
using (BinaryReader binr = new BinaryReader(mem)) //wrap Memory Stream with BinaryReader for easy reading
{
byte bt = 0;
ushort twobytes = 0;
twobytes = binr.ReadUInt16();
if (twobytes == 0x8130) //data read as little endian order (actual data order for Sequence is 30 81)
binr.ReadByte(); //advance 1 byte
else if (twobytes == 0x8230)
binr.ReadInt16(); //advance 2 bytes
else
return null;
seq = binr.ReadBytes(15); //read the Sequence OID
if (!CompareBytearrays(seq, seqOid)) //make sure Sequence for OID is correct
return null;
twobytes = binr.ReadUInt16();
if (twobytes == 0x8103) //data read as little endian order (actual data order for Bit String is 03 81)
binr.ReadByte(); //advance 1 byte
else if (twobytes == 0x8203)
binr.ReadInt16(); //advance 2 bytes
else
return null;
bt = binr.ReadByte();
if (bt != 0x00) //expect null byte next
return null;
twobytes = binr.ReadUInt16();
if (twobytes == 0x8130) //data read as little endian order (actual data order for Sequence is 30 81)
binr.ReadByte(); //advance 1 byte
else if (twobytes == 0x8230)
binr.ReadInt16(); //advance 2 bytes
else
return null;
twobytes = binr.ReadUInt16();
byte lowbyte = 0x00;
byte highbyte = 0x00;
if (twobytes == 0x8102) //data read as little endian order (actual data order for Integer is 02 81)
lowbyte = binr.ReadByte(); // read next bytes which is bytes in modulus
else if (twobytes == 0x8202)
{
highbyte = binr.ReadByte(); //advance 2 bytes
lowbyte = binr.ReadByte();
}
else
return null;
byte[] modint = { lowbyte, highbyte, 0x00, 0x00 }; //reverse byte order since asn.1 key uses big endian order
int modsize = BitConverter.ToInt32(modint, 0);
int firstbyte = binr.PeekChar();
if (firstbyte == 0x00)
{ //if first byte (highest order) of modulus is zero, don't include it
binr.ReadByte(); //skip this null byte
modsize -= 1; //reduce modulus buffer size by 1
}
byte[] modulus = binr.ReadBytes(modsize); //read the modulus bytes
if (binr.ReadByte() != 0x02) //expect an Integer for the exponent data
return null;
int expbytes = (int)binr.ReadByte(); // should only need one byte for actual exponent data (for all useful values)
byte[] exponent = binr.ReadBytes(expbytes);
// ------- create RSACryptoServiceProvider instance and initialize with public key -----
var rsa = RSA.Create();
RSAParameters rsaKeyInfo = new RSAParameters
{
Modulus = modulus,
Exponent = exponent
};
rsa.ImportParameters(rsaKeyInfo);
return rsa;
}
}
}
19
Source : WADReader.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
public static void LoadTextureSet(string sourcename, Stream texturedata, ref List<ImageData> images, PatchNames pnames)
{
BinaryReader reader = new BinaryReader(texturedata);
int flags, width, height, patches, px, py, pi;
uint numtextures;
byte scalebytex, scalebytey;
float scalex, scaley, defaultscale;
byte[] namebytes;
TextureImage image = null;
bool strifedata;
if(texturedata.Length == 0)
return;
// Determine default scale
defaultscale = General.Map.Config.DefaultTextureScale;
// Get number of textures
texturedata.Seek(0, SeekOrigin.Begin);
numtextures = reader.ReadUInt32();
// Skip offset bytes (we will read all textures sequentially)
texturedata.Seek(4 * numtextures, SeekOrigin.Current);
// Go for all textures defined in this lump
for(uint i = 0; i < numtextures; i++)
{
// Read texture properties
namebytes = reader.ReadBytes(8);
flags = reader.ReadUInt16();
scalebytex = reader.ReadByte();
scalebytey = reader.ReadByte();
width = reader.ReadInt16();
height = reader.ReadInt16();
patches = reader.ReadInt16();
// Check for doom or strife data format
if(patches == 0)
{
// Ignore 2 bytes and then read number of patches
texturedata.Seek(2, SeekOrigin.Current);
patches = reader.ReadInt16();
strifedata = false;
}
else
{
// Texture data is in strife format
strifedata = true;
}
// Determine actual scales
if(scalebytex == 0) scalex = defaultscale; else scalex = 1f / ((float)scalebytex / 8f);
if(scalebytey == 0) scaley = defaultscale; else scaley = 1f / ((float)scalebytey / 8f);
// Validate data
if((width > 0) && (height > 0) && (patches > 0) &&
(scalex != 0) || (scaley != 0))
{
string texname = Lump.MakeNormalName(namebytes, WAD.ENCODING);
if(texname.Length > 0)
{
// Make the image object
image = new TextureImage(Lump.MakeNormalName(namebytes, WAD.ENCODING),
width, height, scalex, scaley);
}
else
{
// Can't load image without name
General.ErrorLogger.Add(ErrorType.Error, "Can't load an unnamed texture from \"" + sourcename + "\". Please consider giving names to your resources.");
}
// Go for all patches in texture
for(int p = 0; p < patches; p++)
{
// Read patch properties
px = reader.ReadInt16();
py = reader.ReadInt16();
pi = reader.ReadUInt16();
if(!strifedata) texturedata.Seek(4, SeekOrigin.Current);
// Validate data
if((pi >= 0) && (pi < pnames.Length))
{
if(pnames[pi].Length > 0)
{
// Create patch on image
if(image != null) image.AddPatch(new TexturePatch(pnames[pi], px, py));
}
else
{
// Can't load image without name
General.ErrorLogger.Add(ErrorType.Error, "Can't use an unnamed patch referenced in \"" + sourcename + "\". Please consider giving names to your resources.");
}
}
}
// Add image to collection
images.Add(image);
}
else
{
// Skip patches data
texturedata.Seek(6 * patches, SeekOrigin.Current);
if(!strifedata) texturedata.Seek(4 * patches, SeekOrigin.Current);
}
}
}
19
Source : DeserializerStream.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
public void rShort(out short v) { v = reader.ReadInt16(); }
19
Source : DoomMapSetIO.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
private void ReadThings(MapSet map, int firstindex)
{
MemoryStream mem;
BinaryReader reader;
int num, i, x, y, type, flags, angle;
Dictionary<string, bool> stringflags;
Thing t;
// Get the lump from wad file
Lump lump = wad.FindLump("THINGS", firstindex);
if(lump == null) throw new Exception("Could not find required lump THINGS!");
// Prepare to read the items
mem = new MemoryStream(lump.Stream.ReadAllBytes());
num = (int)lump.Stream.Length / 10;
reader = new BinaryReader(mem);
// Read items from the lump
map.SetCapacity(0, 0, 0, 0, map.Things.Count + num);
for(i = 0; i < num; i++)
{
// Read properties from stream
x = reader.ReadInt16();
y = reader.ReadInt16();
angle = reader.ReadInt16();
type = reader.ReadUInt16();
flags = reader.ReadUInt16();
// Make string flags
stringflags = new Dictionary<string, bool>();
foreach(KeyValuePair<string, string> f in manager.Config.ThingFlags)
{
int fnum;
if(int.TryParse(f.Key, out fnum)) stringflags[f.Key] = ((flags & fnum) == fnum);
}
// Create new item
t = map.CreateThing();
t.Update(type, x, y, 0, angle, stringflags, 0, 0, new int[Thing.NUM_ARGS]);
}
// Done
mem.Dispose();
}
19
Source : DoomPictureReader.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
public bool Validate(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
int width, height;
int dataoffset;
int datalength;
int columnaddr;
// Initialize
dataoffset = (int)stream.Position;
datalength = (int)stream.Length - (int)stream.Position;
// Need at least 4 bytes
if(datalength < 4) return false;
// Read size and offset
width = reader.ReadInt16();
height = reader.ReadInt16();
reader.ReadInt16();
reader.ReadInt16();
// Valid width and height?
if((width <= 0) || (height <= 0)) return false;
// Go for all columns
for(int x = 0; x < width; x++)
{
// Get column address
columnaddr = reader.ReadInt32();
// Check if address is outside valid range
if((columnaddr < (8 + width * 4)) || (columnaddr >= datalength)) return false;
}
// Return success
return true;
}
19
Source : DoomPictureReader.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
private PixelColorBlock ReadAsPixelData(Stream stream, out int width, out int height, out int offsetx, out int offsety)
{
BinaryReader reader = new BinaryReader(stream);
PixelColorBlock pixeldata = null;
int y, read_y, count, p;
int[] columns;
int dataoffset;
// Initialize
width = 0;
height = 0;
offsetx = 0;
offsety = 0;
dataoffset = (int)stream.Position;
// Need at least 4 bytes
if((stream.Length - stream.Position) < 4) return null;
#if !DEBUG
try
{
#endif
// Read size and offset
width = reader.ReadInt16();
height = reader.ReadInt16();
offsetx = reader.ReadInt16();
offsety = reader.ReadInt16();
// Valid width and height?
if((width <= 0) || (height <= 0)) return null;
// Read the column addresses
columns = new int[width];
for(int x = 0; x < width; x++) columns[x] = reader.ReadInt32();
// Allocate memory
pixeldata = new PixelColorBlock(width, height);
pixeldata.Clear();
int numpixels = width * height;
// Go for all columns
for(int x = 0; x < width; x++)
{
// Seek to column start
stream.Seek(dataoffset + columns[x], SeekOrigin.Begin);
// Read first post start
y = reader.ReadByte();
read_y = y;
// Continue while not end of column reached
while(read_y < 255)
{
// Read number of pixels in post
count = reader.ReadByte();
// Skip unused pixel
stream.Seek(1, SeekOrigin.Current);
if ((y + count - 1) * width + x >= numpixels)
{
// ano - cut early in case of problems
return null;
}
// Draw post
for(int yo = 0; yo < count; yo++)
{
// Read pixel color index
p = reader.ReadByte();
// Draw pixel
pixeldata.Pointer[(y + yo) * width + x] = palette[p];
}
// Skip unused pixel
stream.Seek(1, SeekOrigin.Current);
// Read next post start
read_y = reader.ReadByte();
if(read_y < y) y += read_y; else y = read_y;
}
}
// Return pointer
return pixeldata;
#if !DEBUG
}
catch(Exception)
{
// Return nothing
return null;
}
#endif
}
19
Source : HexenMapSetIO.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
private void ReadThings(MapSet map, int firstindex)
{
MemoryStream mem;
BinaryReader reader;
int num, i, tag, z, action, x, y, type, flags, angle;
int[] args = new int[Thing.NUM_ARGS];
Dictionary<string, bool> stringflags;
Thing t;
// Get the lump from wad file
Lump lump = wad.FindLump("THINGS", firstindex);
if(lump == null) throw new Exception("Could not find required lump THINGS!");
// Prepare to read the items
mem = new MemoryStream(lump.Stream.ReadAllBytes());
num = (int)lump.Stream.Length / 20;
reader = new BinaryReader(mem);
// Read items from the lump
map.SetCapacity(0, 0, 0, 0, map.Things.Count + num);
for(i = 0; i < num; i++)
{
// Read properties from stream
tag = reader.ReadUInt16();
x = reader.ReadInt16();
y = reader.ReadInt16();
z = reader.ReadInt16();
angle = reader.ReadInt16();
type = reader.ReadUInt16();
flags = reader.ReadUInt16();
action = reader.ReadByte();
args[0] = reader.ReadByte();
args[1] = reader.ReadByte();
args[2] = reader.ReadByte();
args[3] = reader.ReadByte();
args[4] = reader.ReadByte();
// Make string flags
stringflags = new Dictionary<string, bool>();
foreach(KeyValuePair<string, string> f in manager.Config.ThingFlags)
{
int fnum;
if(int.TryParse(f.Key, out fnum)) stringflags[f.Key] = ((flags & fnum) == fnum);
}
// Create new item
t = map.CreateThing();
t.Update(type, x, y, z, angle, stringflags, tag, action, args);
}
// Done
mem.Dispose();
}
19
Source : HexenMapSetIO.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
private Dictionary<int, Vertex> ReadVertices(MapSet map, int firstindex)
{
MemoryStream mem;
Dictionary<int, Vertex> link;
BinaryReader reader;
int num, i, x, y;
Vertex v;
// Get the lump from wad file
Lump lump = wad.FindLump("VERTEXES", firstindex);
if(lump == null) throw new Exception("Could not find required lump VERTEXES!");
// Prepare to read the items
mem = new MemoryStream(lump.Stream.ReadAllBytes());
num = (int)lump.Stream.Length / 4;
reader = new BinaryReader(mem);
// Create lookup table
link = new Dictionary<int, Vertex>(num);
// Read items from the lump
map.SetCapacity(map.Vertices.Count + num, 0, 0, 0, 0);
for(i = 0; i < num; i++)
{
// Read properties from stream
x = reader.ReadInt16();
y = reader.ReadInt16();
// Create new item
v = map.CreateVertex(new Vector2D((float)x, (float)y));
// Add it to the lookup table
link.Add(i, v);
}
// Done
mem.Dispose();
// Return lookup table
return link;
}
19
Source : HexenMapSetIO.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
private Dictionary<int, Sector> ReadSectors(MapSet map, int firstindex)
{
MemoryStream mem;
Dictionary<int, Sector> link;
BinaryReader reader;
int num, i, hfloor, hceil, bright, special, tag;
string tfloor, tceil;
Sector s;
// Get the lump from wad file
Lump lump = wad.FindLump("SECTORS", firstindex);
if(lump == null) throw new Exception("Could not find required lump SECTORS!");
// Prepare to read the items
mem = new MemoryStream(lump.Stream.ReadAllBytes());
num = (int)lump.Stream.Length / 26;
reader = new BinaryReader(mem);
// Create lookup table
link = new Dictionary<int, Sector>(num);
// Read items from the lump
map.SetCapacity(0, 0, 0, map.Sectors.Count + num, 0);
for(i = 0; i < num; i++)
{
// Read properties from stream
hfloor = reader.ReadInt16();
hceil = reader.ReadInt16();
tfloor = Lump.MakeNormalName(reader.ReadBytes(8), WAD.ENCODING);
tceil = Lump.MakeNormalName(reader.ReadBytes(8), WAD.ENCODING);
bright = reader.ReadInt16();
special = reader.ReadUInt16();
tag = reader.ReadUInt16();
// Create new item
s = map.CreateSector();
s.Update(hfloor, hceil, tfloor, tceil, special, tag, bright);
// Add it to the lookup table
link.Add(i, s);
}
// Done
mem.Dispose();
// Return lookup table
return link;
}
19
Source : DeserializerStream.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
public void rwShort(ref short v) { v = reader.ReadInt16(); }
19
Source : DoomMapSetIO.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
private void ReadLinedefs(MapSet map, int firstindex,
Dictionary<int, Vertex> vertexlink, Dictionary<int, Sector> sectorlink)
{
MemoryStream linedefsmem, sidedefsmem;
BinaryReader readline, readside;
Lump linedefslump, sidedefslump;
int num, numsides, i, offsetx, offsety, v1, v2;
int s1, s2, flags, action, tag, sc;
Dictionary<string, bool> stringflags;
string thigh, tmid, tlow;
Linedef l;
Sidedef s;
// Get the linedefs lump from wad file
linedefslump = wad.FindLump("LINEDEFS", firstindex);
if(linedefslump == null) throw new Exception("Could not find required lump LINEDEFS!");
// Get the sidedefs lump from wad file
sidedefslump = wad.FindLump("SIDEDEFS", firstindex);
if(sidedefslump == null) throw new Exception("Could not find required lump SIDEDEFS!");
// Prepare to read the items
linedefsmem = new MemoryStream(linedefslump.Stream.ReadAllBytes());
sidedefsmem = new MemoryStream(sidedefslump.Stream.ReadAllBytes());
num = (int)linedefslump.Stream.Length / 14;
numsides = (int)sidedefslump.Stream.Length / 30;
readline = new BinaryReader(linedefsmem);
readside = new BinaryReader(sidedefsmem);
// Read items from the lump
// ano - heuristic to detect sidedef compression
if (num > numsides)
{
// ano - set sidedefs to some larger amount than
// numsides before resizing back down
// because in the case of sidedef compression the
// array will have to be resized a lot
map.SetCapacity(0, map.Linedefs.Count + num, map.Sidedefs.Count + (num * 2), 0, 0);
}
else
{
// ano - + 32 as extra leniency for some amount of sidedef
// compression that goes undetected by the prev check
// note this wont be resized back down but 32 is a neglible amount
map.SetCapacity(0, map.Linedefs.Count + num, map.Sidedefs.Count + num + 32, 0, 0);
}
for(i = 0; i < num; i++)
{
// Read properties from stream
v1 = readline.ReadUInt16();
v2 = readline.ReadUInt16();
flags = readline.ReadUInt16();
action = readline.ReadUInt16();
tag = readline.ReadUInt16();
s1 = readline.ReadUInt16();
s2 = readline.ReadUInt16();
// Make string flags
stringflags = new Dictionary<string, bool>();
foreach(string f in manager.Config.SortedLinedefFlags)
{
int fnum;
if(int.TryParse(f, out fnum)) stringflags[f] = ((flags & fnum) == fnum);
}
// Create new linedef
if(vertexlink.ContainsKey(v1) && vertexlink.ContainsKey(v2))
{
// Check if not zero-length
if(Vector2D.ManhattanDistance(vertexlink[v1].Position, vertexlink[v2].Position) > 0.0001f)
{
l = map.CreateLinedef(vertexlink[v1], vertexlink[v2]);
l.Update(stringflags, 0, tag, action, new int[Linedef.NUM_ARGS]);
l.UpdateCache();
// Line has a front side?
if(s1 != ushort.MaxValue)
{
// Read front sidedef
if((s1 * 30L) <= (sidedefsmem.Length - 30L))
{
sidedefsmem.Seek(s1 * 30, SeekOrigin.Begin);
offsetx = readside.ReadInt16();
offsety = readside.ReadInt16();
thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
sc = readside.ReadUInt16();
// Create front sidedef
if(sectorlink.ContainsKey(sc))
{
s = map.CreateSidedef(l, true, sectorlink[sc]);
s.Update(offsetx, offsety, thigh, tmid, tlow);
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Sidedef " + s1 + " references invalid sector " + sc + ". Sidedef has been removed.");
}
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Linedef references invalid sidedef " + s1 + ". Sidedef has been removed.");
}
}
// Line has a back side?
if(s2 != ushort.MaxValue)
{
// Read back sidedef
if((s2 * 30L) <= (sidedefsmem.Length - 30L))
{
sidedefsmem.Seek(s2 * 30, SeekOrigin.Begin);
offsetx = readside.ReadInt16();
offsety = readside.ReadInt16();
thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
sc = readside.ReadUInt16();
// Create back sidedef
if(sectorlink.ContainsKey(sc))
{
s = map.CreateSidedef(l, false, sectorlink[sc]);
s.Update(offsetx, offsety, thigh, tmid, tlow);
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Sidedef " + s2 + " references invalid sector " + sc + ". Sidedef has been removed.");
}
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references invalid sidedef " + s2 + ". Sidedef has been removed.");
}
}
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " is zero-length. Linedef has been removed.");
}
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references one or more invalid vertices. Linedef has been removed.");
}
}
if (num > numsides)
{
// ano - resize the arrays back down
map.SetCapacity(0, map.Linedefs.Count, map.Sidedefs.Count, 0, 0);
}
// Done
linedefsmem.Dispose();
sidedefsmem.Dispose();
}
19
Source : HexenMapSetIO.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
private void ReadLinedefs(MapSet map, int firstindex,
Dictionary<int, Vertex> vertexlink, Dictionary<int, Sector> sectorlink)
{
MemoryStream linedefsmem, sidedefsmem;
BinaryReader readline, readside;
Lump linedefslump, sidedefslump;
int num, numsides, i, offsetx, offsety, v1, v2;
int s1, s2, flags, action, sc;
int[] args = new int[Linedef.NUM_ARGS];
Dictionary<string, bool> stringflags;
string thigh, tmid, tlow;
Linedef l;
Sidedef s;
// Get the linedefs lump from wad file
linedefslump = wad.FindLump("LINEDEFS", firstindex);
if(linedefslump == null) throw new Exception("Could not find required lump LINEDEFS!");
// Get the sidedefs lump from wad file
sidedefslump = wad.FindLump("SIDEDEFS", firstindex);
if(sidedefslump == null) throw new Exception("Could not find required lump SIDEDEFS!");
// Prepare to read the items
linedefsmem = new MemoryStream(linedefslump.Stream.ReadAllBytes());
sidedefsmem = new MemoryStream(sidedefslump.Stream.ReadAllBytes());
num = (int)linedefslump.Stream.Length / 16;
numsides = (int)sidedefslump.Stream.Length / 30;
readline = new BinaryReader(linedefsmem);
readside = new BinaryReader(sidedefsmem);
// Read items from the lump
map.SetCapacity(0, map.Linedefs.Count + num, map.Sidedefs.Count + numsides, 0, 0);
for(i = 0; i < num; i++)
{
// Read properties from stream
v1 = readline.ReadUInt16();
v2 = readline.ReadUInt16();
flags = readline.ReadUInt16();
action = readline.ReadByte();
args[0] = readline.ReadByte();
args[1] = readline.ReadByte();
args[2] = readline.ReadByte();
args[3] = readline.ReadByte();
args[4] = readline.ReadByte();
s1 = readline.ReadUInt16();
s2 = readline.ReadUInt16();
// Make string flags
stringflags = new Dictionary<string, bool>();
foreach(string f in manager.Config.SortedLinedefFlags)
{
int fnum;
if(int.TryParse(f, out fnum)) stringflags[f] = ((flags & fnum) == fnum);
}
// Create new linedef
if(vertexlink.ContainsKey(v1) && vertexlink.ContainsKey(v2))
{
// Check if not zero-length
if(Vector2D.ManhattanDistance(vertexlink[v1].Position, vertexlink[v2].Position) > 0.0001f)
{
l = map.CreateLinedef(vertexlink[v1], vertexlink[v2]);
l.Update(stringflags, (flags & manager.Config.LinedefActivationsFilter), 0, action, args);
l.UpdateCache();
// Line has a front side?
if(s1 != ushort.MaxValue)
{
// Read front sidedef
sidedefsmem.Seek(s1 * 30, SeekOrigin.Begin);
if((s1 * 30L) <= (sidedefsmem.Length - 30L))
{
offsetx = readside.ReadInt16();
offsety = readside.ReadInt16();
thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
sc = readside.ReadUInt16();
// Create front sidedef
if(sectorlink.ContainsKey(sc))
{
s = map.CreateSidedef(l, true, sectorlink[sc]);
s.Update(offsetx, offsety, thigh, tmid, tlow);
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Sidedef " + s1 + " references invalid sector " + sc + ". Sidedef has been removed.");
}
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references invalid sidedef " + s1 + ". Sidedef has been removed.");
}
}
// Line has a back side?
if(s2 != ushort.MaxValue)
{
// Read back sidedef
sidedefsmem.Seek(s2 * 30, SeekOrigin.Begin);
if((s2 * 30L) <= (sidedefsmem.Length - 30L))
{
offsetx = readside.ReadInt16();
offsety = readside.ReadInt16();
thigh = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
tlow = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
tmid = Lump.MakeNormalName(readside.ReadBytes(8), WAD.ENCODING);
sc = readside.ReadUInt16();
// Create back sidedef
if(sectorlink.ContainsKey(sc))
{
s = map.CreateSidedef(l, false, sectorlink[sc]);
s.Update(offsetx, offsety, thigh, tmid, tlow);
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Sidedef " + s2 + " references invalid sector " + sc + ". Sidedef has been removed.");
}
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references invalid sidedef " + s2 + ". Sidedef has been removed.");
}
}
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " is zero-length. Linedef has been removed.");
}
}
else
{
General.ErrorLogger.Add(ErrorType.Warning, "Linedef " + i + " references one or more invalid vertices. Linedef has been removed.");
}
}
// Done
linedefsmem.Dispose();
sidedefsmem.Dispose();
}
19
Source : NodesViewerMode.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
private void LoadStructures()
{
// Load the nodes structure
MemoryStream nodesstream = General.Map.GetLumpData("NODES");
BinaryReader nodesreader = new BinaryReader(nodesstream);
int numnodes = (int)nodesstream.Length / 28;
nodes = new Node[numnodes];
for(int i = 0; i < nodes.Length; i++)
{
nodes[i].linestart.x = nodesreader.ReadInt16();
nodes[i].linestart.y = nodesreader.ReadInt16();
nodes[i].linedelta.x = nodesreader.ReadInt16();
nodes[i].linedelta.y = nodesreader.ReadInt16();
float top = nodesreader.ReadInt16();
float bot = nodesreader.ReadInt16();
float left = nodesreader.ReadInt16();
float right = nodesreader.ReadInt16();
nodes[i].rightbox = new RectangleF(left, top, (right - left), (bot - top));
top = nodesreader.ReadInt16();
bot = nodesreader.ReadInt16();
left = nodesreader.ReadInt16();
right = nodesreader.ReadInt16();
nodes[i].leftbox = new RectangleF(left, top, (right - left), (bot - top));
int rightindex = nodesreader.ReadInt16();
int leftindex = nodesreader.ReadInt16();
nodes[i].rightchild = rightindex & 0x7FFF;
nodes[i].leftchild = leftindex & 0x7FFF;
nodes[i].rightsubsector = (rightindex & 0x8000) != 0;
nodes[i].leftsubsector = (leftindex & 0x8000) != 0;
}
nodesreader.Close();
nodesstream.Close();
nodesstream.Dispose();
// Add additional properties to nodes
nodes[nodes.Length - 1].parent = -1;
RecursiveSetupNodes(nodes.Length - 1);
// Load the segs structure
MemoryStream segsstream = General.Map.GetLumpData("SEGS");
BinaryReader segsreader = new BinaryReader(segsstream);
int numsegs = (int)segsstream.Length / 12;
segs = new Seg[numsegs];
for(int i = 0; i < segs.Length; i++)
{
segs[i].startvertex = segsreader.ReadInt16();
segs[i].endvertex = segsreader.ReadInt16();
segs[i].angle = Angle2D.DoomToReal(segsreader.ReadInt16());
segs[i].lineindex = segsreader.ReadInt16();
segs[i].leftside = segsreader.ReadInt16() != 0;
segs[i].offset = segsreader.ReadInt16();
}
segsreader.Close();
segsstream.Close();
segsstream.Dispose();
// Load the vertexes structure
MemoryStream vertsstream = General.Map.GetLumpData("VERTEXES");
BinaryReader vertsreader = new BinaryReader(vertsstream);
int numverts = (int)vertsstream.Length / 4;
verts = new Vector2D[numverts];
for(int i = 0; i < verts.Length; i++)
{
verts[i].x = vertsreader.ReadInt16();
verts[i].y = vertsreader.ReadInt16();
}
vertsreader.Close();
vertsstream.Close();
vertsstream.Dispose();
// Load the subsectors structure
MemoryStream ssecstream = General.Map.GetLumpData("SSECTORS");
BinaryReader ssecreader = new BinaryReader(ssecstream);
int numssec = (int)ssecstream.Length / 4;
ssectors = new Subsector[numssec];
for(int i = 0; i < ssectors.Length; i++)
{
ssectors[i].numsegs = ssecreader.ReadInt16();
ssectors[i].firstseg = ssecreader.ReadInt16();
}
ssecreader.Close();
ssecstream.Close();
ssecstream.Dispose();
// Link all segs to their subsectors
for(int i = 0; i < ssectors.Length; i++)
{
int lastseg = ssectors[i].firstseg + ssectors[i].numsegs - 1;
for(int sg = ssectors[i].firstseg; sg <= lastseg; sg++)
{
segs[sg].ssector = i;
}
}
}
19
Source : BoyomiTcpServer.cs
with BSD 3-Clause "New" or "Revised" License
from anoyetta
with BSD 3-Clause "New" or "Revised" License
from anoyetta
private void ProcessMessage(
NetworkStream stream)
{
if (stream == null)
{
return;
}
using (var reader = new BinaryReader(stream))
{
var speed = default(short);
var tone = default(short);
var volume = default(short);
var type = default(short);
var textEncoding = default(byte);
var textSize = default(int);
var textChars = default(byte[]);
var command = reader.ReadInt16();
switch (command)
{
case 0:
speed = reader.ReadInt16();
tone = -1;
volume = reader.ReadInt16();
type = reader.ReadInt16();
textEncoding = reader.ReadByte();
textSize = reader.ReadInt32();
textChars = reader.ReadBytes(textSize);
break;
case 1:
speed = reader.ReadInt16();
tone = reader.ReadInt16();
volume = reader.ReadInt16();
type = reader.ReadInt16();
textEncoding = reader.ReadByte();
textSize = reader.ReadInt32();
textChars = reader.ReadBytes(textSize);
break;
case 48:
this.Logger.Info($"[{command}] skip talk queues, but no process on this server.");
return;
case 64:
while (this.SpeakQueue.TryDequeue(out SpeakTask t)) ;
this.Logger.Info($"[{command}] clear talk queues.");
return;
default:
this.Logger.Error($"Boyomi TCP server error. invalid command [{command}].");
return;
}
var text = textEncoding switch
{
0 => Encoding.UTF8.GetString(textChars),
1 => Encoding.Unicode.GetString(textChars),
2 => Encoding.GetEncoding("Shift_JIS").GetString(textChars),
_ => string.Empty,
};
if (string.IsNullOrWhiteSpace(text))
{
return;
}
if (speed == -1)
{
speed = 50;
}
if (volume == -1)
{
volume = 50;
}
// 99文字ずつで分割する
var texts = text.Trim().Split(99);
foreach (var t in texts)
{
var tts = t.Trim();
tts = tts.Replace(" ", " ");
tts = WhitespacesRegex.Replace(tts, " ");
this.SpeakQueue.Enqueue(new SpeakTask()
{
Speed = (uint)speed,
Volume = (uint)volume,
CastNo = type,
Text = tts,
});
}
}
19
Source : NmsBytesMessage.cs
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public short ReadInt16()
{
InitializeReading();
try
{
return dataIn.ReadInt16();
}
catch (EndOfStreamException e)
{
throw NMSExceptionSupport.CreateMessageEOFException(e);
}
catch (IOException e)
{
throw NMSExceptionSupport.CreateMessageFormatException(e);
}
}
19
Source : EndianBinaryReader.cs
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public override short ReadInt16()
{
return EndianSupport.SwitchEndian(base.ReadInt16());
}
19
Source : PrimitiveMap.cs
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public static Object UnmarshalPrimitive(BinaryReader dataIn)
{
Object value = null;
byte type = dataIn.ReadByte();
switch (type)
{
case NULL:
value = null;
break;
case BYTE_TYPE:
value = dataIn.ReadByte();
break;
case BOOLEAN_TYPE:
value = dataIn.ReadBoolean();
break;
case CHAR_TYPE:
value = dataIn.ReadChar();
break;
case SHORT_TYPE:
value = dataIn.ReadInt16();
break;
case INTEGER_TYPE:
value = dataIn.ReadInt32();
break;
case LONG_TYPE:
value = dataIn.ReadInt64();
break;
case FLOAT_TYPE:
value = dataIn.ReadSingle();
break;
case DOUBLE_TYPE:
value = dataIn.ReadDouble();
break;
case BYTE_ARRAY_TYPE:
int size = dataIn.ReadInt32();
byte[] data = new byte[size];
dataIn.Read(data, 0, size);
value = data;
break;
case STRING_TYPE:
value = ((EndianBinaryReader) dataIn).ReadString16();
break;
case BIG_STRING_TYPE:
value = ((EndianBinaryReader) dataIn).ReadString32();
break;
case MAP_TYPE:
value = UnmarshalPrimitiveMap(dataIn);
break;
case LIST_TYPE:
value = UnmarshalPrimitiveList(dataIn);
break;
default:
throw new Exception("Unsupported data type: " + type);
}
return value;
}
19
Source : ExtendedBinaryReader.cs
with GNU Lesser General Public License v3.0
from Apollo3zehn
with GNU Lesser General Public License v3.0
from Apollo3zehn
public short ReadInt16Reverse()
{
return this.ReadReverse<short>(BitConverter.GetBytes(this.ReadInt16()));
}
19
Source : CompoundDocumentFile.cs
with Apache License 2.0
from Appdynamics
with Apache License 2.0
from Appdynamics
internal void Read(BinaryReader br)
{
br.ReadBytes(8); //Read header
br.ReadBytes(16); //Header CLSID (16 bytes): Reserved and unused clreplaced ID that MUST be set to all zeroes (CLSID_NULL).
minorVersion = br.ReadInt16();
majorVersion = br.ReadInt16();
br.ReadInt16(); //Byte order
sectorShif = br.ReadInt16();
minSectorShift = br.ReadInt16();
_sectorSize = 1 << sectorShif;
_miniSectorSize = 1 << minSectorShift;
_sectorSizeInt = _sectorSize / 4;
br.ReadBytes(6); //Reserved
numberOfDirectorySector = br.ReadInt32();
_numberOfFATSectors = br.ReadInt32();
_firstDirectorySectorLocation = br.ReadInt32();
_transactionSignatureNumber = br.ReadInt32();
_miniStreamCutoffSize = br.ReadInt32();
_firstMiniFATSectorLocation = br.ReadInt32();
_numberofMiniFATSectors = br.ReadInt32();
_firstDIFATSectorLocation = br.ReadInt32();
_numberofDIFATSectors = br.ReadInt32();
var dwi = new DocWriteInfo() { DIFAT = new List<int>(), FAT = new List<int>(), miniFAT = new List<int>() };
for (int i = 0; i < 109; i++)
{
var d = br.ReadInt32();
if (d >= 0)
{
dwi.DIFAT.Add(d);
}
}
LoadSectors(br);
if (_firstDIFATSectorLocation > 0)
{
LoadDIFATSectors(dwi);
}
dwi.FAT = ReadFAT(_sectors, dwi);
var dir = ReadDirectories(_sectors, dwi);
LoadMinSectors(ref dwi, dir);
foreach (var d in dir)
{
if (d.Stream == null && d.StreamSize > 0)
{
if (d.StreamSize < _miniStreamCutoffSize)
{
d.Stream = GetStream(d.StartingSectorLocation, d.StreamSize, dwi.miniFAT, _miniSectors);
}
else
{
d.Stream = GetStream(d.StartingSectorLocation, d.StreamSize, dwi.FAT, _sectors);
}
}
}
AddChildTree(dir[0], dir);
}
19
Source : CoumpundDocumentItem.cs
with Apache License 2.0
from Appdynamics
with Apache License 2.0
from Appdynamics
internal void Read(BinaryReader br)
{
var s = br.ReadBytes(0x40);
var sz = br.ReadInt16();
if (sz > 0)
{
Name = UTF8Encoding.Unicode.GetString(s, 0, sz - 2);
}
ObjectType = br.ReadByte();
ColorFlag = br.ReadByte();
LeftSibling = br.ReadInt32();
RightSibling = br.ReadInt32();
ChildID = br.ReadInt32();
//Clsid;
ClsID = new Guid(br.ReadBytes(16));
StatBits = br.ReadInt32();
CreationTime = br.ReadInt64();
ModifiedTime = br.ReadInt64();
StartingSectorLocation = br.ReadInt32();
StreamSize = br.ReadInt64();
}
See More Examples