Here are the examples of the csharp api System.IO.BinaryReader.ReadInt32() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2902 Examples
19
Source : XnaToFnaUtil.cs
with zlib License
from 0x0ade
with zlib License
from 0x0ade
public void ScanPath(string path) {
if (Directory.Exists(path)) {
// Use the directory as "dependency directory" and scan in it.
if (Directories.Contains(path))
// No need to scan the dir if the dir is scanned...
return;
RestoreBackup(path);
Log($"[ScanPath] Scanning directory {path}");
Directories.Add(path);
replacedemblyResolver.AddSearchDirectory(path); // Needs to be added manually as DependencyDirs was already added
// Most probably the actual game directory - let's just copy XnaToFna.exe to there to be referenced properly.
string xtfPath = Path.Combine(path, Path.GetFileName(Thisreplacedembly.Location));
if (Path.GetDirectoryName(Thisreplacedembly.Location) != path) {
Log($"[ScanPath] Found separate game directory - copying XnaToFna.exe and FNA.dll");
File.Copy(Thisreplacedembly.Location, xtfPath, true);
string dbExt = null;
if (File.Exists(Path.ChangeExtension(Thisreplacedembly.Location, "pdb")))
dbExt = "pdb";
if (File.Exists(Path.ChangeExtension(Thisreplacedembly.Location, "mdb")))
dbExt = "mdb";
if (dbExt != null)
File.Copy(Path.ChangeExtension(Thisreplacedembly.Location, dbExt), Path.ChangeExtension(xtfPath, dbExt), true);
if (File.Exists(Path.Combine(Path.GetDirectoryName(Thisreplacedembly.Location), "FNA.dll")))
File.Copy(Path.Combine(Path.GetDirectoryName(Thisreplacedembly.Location), "FNA.dll"), Path.Combine(path, "FNA.dll"), true);
else if (File.Exists(Path.Combine(Path.GetDirectoryName(Thisreplacedembly.Location), "FNA.dll.tmp")))
File.Copy(Path.Combine(Path.GetDirectoryName(Thisreplacedembly.Location), "FNA.dll.tmp"), Path.Combine(path, "FNA.dll"), true);
}
ScanPaths(Directory.GetFiles(path));
return;
}
if (File.Exists(path + ".xex")) {
if (!ExtractedXEX.Contains(path)) {
// Remove the original file - let XnaToFna unpack and handle it later.
File.Delete(path);
} else {
// XnaToFna will handle the .xex instead.
}
return;
}
if (path.EndsWith(".xex")) {
string pathTarget = path.Substring(0, path.Length - 4);
if (string.IsNullOrEmpty(Path.GetExtension(pathTarget)))
return;
using (Stream streamXEX = File.OpenRead(path))
using (BinaryReader reader = new BinaryReader(streamXEX))
using (Stream streamRAW = File.OpenWrite(pathTarget)) {
XEXImageData data = new XEXImageData(reader);
int offset = 0;
int size = data.m_memorySize;
// Check if this file is a PE containing an embedded PE.
if (data.m_memorySize > 0x10000) { // One default segment alignment.
using (MemoryStream streamMEM = new MemoryStream(data.m_memoryData))
using (BinaryReader mem = new BinaryReader(streamMEM)) {
if (mem.ReadUInt32() != 0x00905A4D) // MZ
goto WriteRaw;
// This is horrible.
streamMEM.Seek(0x00000280, SeekOrigin.Begin);
if (mem.ReadUInt64() != 0x000061746164692E) // ".idata\0\0"
goto WriteRaw;
streamMEM.Seek(0x00000288, SeekOrigin.Begin);
mem.ReadInt32(); // Virtual size; It's somewhat incorrect?
offset = mem.ReadInt32(); // Virtual offset.
// mem.ReadInt32(); // Raw size; Still incorrect.
// Let's just write everything...
size = data.m_memorySize - offset;
}
}
WriteRaw:
streamRAW.Write(data.m_memoryData, offset, size);
}
path = pathTarget;
ExtractedXEX.Add(pathTarget);
} else if (!path.EndsWith(".dll") && !path.EndsWith(".exe"))
return;
// Check if .dll is CLR replacedembly
replacedemblyName name;
try {
name = replacedemblyName.GetreplacedemblyName(path);
} catch {
return;
}
ReaderParameters modReaderParams = Modder.GenReaderParameters(false);
// Don't ReadWrite if the module being read is XnaToFna or a relink target.
bool isReadWrite =
#if !CECIL0_9
modReaderParams.ReadWrite =
#endif
path != Thisreplacedembly.Location &&
!Mappings.Exists(mappings => name.Name == mappings.Target);
// Only read debug info if it exists
if (!File.Exists(path + ".mdb") && !File.Exists(Path.ChangeExtension(path, "pdb")))
modReaderParams.ReadSymbols = false;
Log($"[ScanPath] Checking replacedembly {name.Name} ({(isReadWrite ? "rw" : "r-")})");
ModuleDefinition mod;
try {
mod = MonoModExt.ReadModule(path, modReaderParams);
} catch (Exception e) {
Log($"[ScanPath] WARNING: Cannot load replacedembly: {e}");
return;
}
bool add = !isReadWrite || name.Name == ThisreplacedemblyName;
if ((mod.Attributes & ModuleAttributes.ILOnly) != ModuleAttributes.ILOnly) {
// Mono.Cecil can't handle mixed mode replacedemblies.
Log($"[ScanPath] WARNING: Cannot handle mixed mode replacedembly {name.Name}");
if (MixedDeps == MixedDepAction.Stub) {
ModulesToStub.Add(mod);
add = true;
} else {
if (MixedDeps == MixedDepAction.Remove) {
RemoveDeps.Add(name.Name);
}
#if !CECIL0_9
mod.Dispose();
#endif
return;
}
}
if (add && !isReadWrite) { // XNA replacement
foreach (XnaToFnaMapping mapping in Mappings)
if (name.Name == mapping.Target) {
mapping.IsActive = true;
mapping.Module = mod;
foreach (string from in mapping.Sources) {
Log($"[ScanPath] Mapping {from} -> {name.Name}");
Modder.RelinkModuleMap[from] = mod;
}
}
} else if (!add) {
foreach (XnaToFnaMapping mapping in Mappings)
if (mod.replacedemblyReferences.Any(dep => mapping.Sources.Contains(dep.Name))) {
add = true;
Log($"[ScanPath] XnaToFna-ing {name.Name}");
goto BreakMappings;
}
}
BreakMappings:
if (add) {
Modules.Add(mod);
ModulePaths[mod] = path;
} else {
#if !CECIL0_9
mod.Dispose();
#endif
}
}
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 : IrdParser.cs
with MIT License
from 13xforever
with MIT License
from 13xforever
public static Ird Parse(byte[] content)
{
if (content == null)
throw new ArgumentNullException(nameof(content));
if (content.Length < 200)
throw new ArgumentException("Data is too small to be a valid IRD structure", nameof(content));
if (BitConverter.ToInt32(content, 0) != Ird.Magic)
using (var compressedStream = new MemoryStream(content, false))
using (var gzip = new GZipStream(compressedStream, CompressionMode.Decompress))
using (var decompressedStream = new MemoryStream())
{
gzip.CopyTo(decompressedStream);
content = decompressedStream.ToArray();
}
if (BitConverter.ToInt32(content, 0) != Ird.Magic)
throw new FormatException("Not a valid IRD file");
var result = new Ird();
using (var stream = new MemoryStream(content, false))
using (var reader = new BinaryReader(stream, Encoding.UTF8))
{
reader.ReadInt32(); // magic
result.Version = reader.ReadByte();
result.ProductCode = Encoding.ASCII.GetString(reader.ReadBytes(9));
result.replacedleLength = reader.ReadByte();
result.replacedle = Encoding.UTF8.GetString(reader.ReadBytes(result.replacedleLength));
result.UpdateVersion = Encoding.ASCII.GetString(reader.ReadBytes(4)).Trim();
result.GameVersion = Encoding.ASCII.GetString(reader.ReadBytes(5)).Trim();
result.AppVersion = Encoding.ASCII.GetString(reader.ReadBytes(5)).Trim();
if (result.Version == 7)
result.Id = reader.ReadInt32();
result.HeaderLength = reader.ReadInt32();
result.Header = reader.ReadBytes(result.HeaderLength);
result.FooterLength = reader.ReadInt32();
result.Footer = reader.ReadBytes(result.FooterLength);
result.RegionCount = reader.ReadByte();
result.RegionMd5Checksums = new List<byte[]>(result.RegionCount);
for (var i = 0; i < result.RegionCount; i++)
result.RegionMd5Checksums.Add(reader.ReadBytes(16));
result.FileCount = reader.ReadInt32();
result.Files = new List<IrdFile>(result.FileCount);
for (var i = 0; i < result.FileCount; i++)
{
var file = new IrdFile();
file.Offset = reader.ReadInt64();
file.Md5Checksum = reader.ReadBytes(16);
result.Files.Add(file);
}
result.Unknown = reader.ReadInt32();
if (result.Version == 9)
result.Pic = reader.ReadBytes(115);
result.Data1 = reader.ReadBytes(16);
result.Data2 = reader.ReadBytes(16);
if (result.Version < 9)
result.Pic = reader.ReadBytes(115);
result.Uid = reader.ReadInt32();
var dataLength = reader.BaseStream.Position;
result.Crc32 = reader.ReadUInt32();
var crc32 = Crc32Algorithm.Compute(content, 0, (int)dataLength);
if (result.Crc32 != crc32)
throw new InvalidDataException($"Corrupted IRD data, expected {result.Crc32:x8}, but was {crc32:x8}");
}
return result;
}
19
Source : ParamSfoEntry.cs
with MIT License
from 13xforever
with MIT License
from 13xforever
public static ParamSfoEntry Read(BinaryReader reader, ParamSfo paramSfo, int itemNumber)
{
const int indexOffset = 0x14;
const int indexEntryLength = 0x10;
reader.BaseStream.Seek(indexOffset + indexEntryLength * itemNumber, SeekOrigin.Begin);
var result = new ParamSfoEntry();
result.KeyOffset = reader.ReadUInt16();
result.ValueFormat = (EntryFormat)reader.ReadUInt16();
result.ValueLength = reader.ReadInt32();
result.ValueMaxLength = reader.ReadInt32();
result.ValueOffset = reader.ReadInt32();
reader.BaseStream.Seek(paramSfo.KeysOffset + result.KeyOffset, SeekOrigin.Begin);
byte tmp;
var sb = new StringBuilder(32);
while ((tmp = reader.ReadByte()) != 0)
sb.Append((char)tmp);
result.Key = sb.ToString();
reader.BaseStream.Seek(paramSfo.ValuesOffset + result.ValueOffset, SeekOrigin.Begin);
result.BinaryValue = reader.ReadBytes(result.ValueMaxLength);
return result;
}
19
Source : UEByteProperty.cs
with MIT License
from 13xforever
with MIT License
from 13xforever
public static UEByteProperty Read(BinaryReader reader, long valueLength)
{
var terminator = reader.ReadByte();
if (terminator != 0)
throw new FormatException($"Offset: 0x{reader.BaseStream.Position - 1:x8}. Expected terminator (0x00), but was (0x{terminator:x2})");
// valueLength starts here
var arrayLength = reader.ReadInt32();
var bytes = reader.ReadBytes(arrayLength);
return new UEByteProperty {Value = bytes.AsHex()};
}
19
Source : BinaryReaderEx.cs
with MIT License
from 13xforever
with MIT License
from 13xforever
public static string ReadUEString(this BinaryReader reader)
{
if (reader.PeekChar() < 0)
return null;
var length = reader.ReadInt32();
if (length == 0)
return null;
if (length == 1)
return "";
var valueBytes = reader.ReadBytes(length);
return Utf8.GetString(valueBytes, 0, valueBytes.Length - 1);
}
19
Source : WaveFileReader.cs
with MIT License
from 3wz
with MIT License
from 3wz
public static void ReadWaveHeader(Stream stream, out WaveFormat format, out long dataChunkPosition, out int dataChunkLength, List<RiffChunk> chunks)
{
dataChunkPosition = -1;
format = null;
BinaryReader br = new BinaryReader(stream);
if (Encoding.ASCII.GetString(br.ReadBytes(4)) != "RIFF")//WaveInterop.mmioStringToFOURCC("RIFF", 0)
{
throw new FormatException("Not a WAVE file - no RIFF header");
}
uint fileSize = br.ReadUInt32(); // read the file size (minus 8 bytes)
if (Encoding.ASCII.GetString(br.ReadBytes(4)) != "WAVE")//WaveInterop.mmioStringToFOURCC("WAVE", 0)
{
throw new FormatException("Not a WAVE file - no WAVE header");
}
int dataChunkID = BitConverter.ToInt32(Encoding.UTF8.GetBytes("data"), 0); ;//WaveInterop.mmioStringToFOURCC("data", 0)
int formatChunkId = BitConverter.ToInt32(Encoding.UTF8.GetBytes("fmt "), 0); ;//WaveInterop.mmioStringToFOURCC("fmt ", 0)
dataChunkLength = 0;
// sometimes a file has more data than is specified after the RIFF header
long stopPosition = Math.Min(fileSize + 8, stream.Length);
// this -8 is so we can be sure that there are at least 8 bytes for a chunk id and length
while (stream.Position <= stopPosition - 8)
{
Int32 chunkIdentifier = br.ReadInt32();
Int32 chunkLength = br.ReadInt32();
if (chunkIdentifier == dataChunkID)
{
dataChunkPosition = stream.Position;
dataChunkLength = chunkLength;
stream.Position += chunkLength;
}
else if (chunkIdentifier == formatChunkId)
{
format = WaveFormat.FromFormatChunk(br, chunkLength);
}
else
{
// check for invalid chunk length
if (chunkLength < 0 || chunkLength > stream.Length - stream.Position)
{
Debug.replacedert(false, String.Format("Invalid chunk length {0}, pos: {1}. length: {2}",
chunkLength, stream.Position, stream.Length));
// an exception will be thrown further down if we haven't got a format and data chunk yet,
// otherwise we will tolerate this file despite it having corrupt data at the end
break;
}
if (chunks != null)
{
chunks.Add(new RiffChunk(chunkIdentifier, chunkLength, stream.Position));
}
stream.Position += chunkLength;
}
}
if (format == null)
{
throw new FormatException("Invalid WAV file - No fmt chunk found");
}
if (dataChunkPosition == -1)
{
throw new FormatException("Invalid WAV file - No data chunk found");
}
}
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 : EncodingUtil.cs
with MIT License
from 404Lcc
with MIT License
from 404Lcc
public static byte[] LengthDecode(ref List<byte> cacheList)
{
byte[] bytes;
using (MemoryStream stream = new MemoryStream(cacheList.ToArray()))
{
using (BinaryReader reader = new BinaryReader(stream))
{
int length = reader.ReadInt32();
if (length > stream.Length - stream.Position)
{
return null;
}
bytes = reader.ReadBytes(length);
cacheList.Clear();
cacheList.AddRange(reader.ReadBytes((int)(stream.Length - stream.Position)));
}
}
return bytes;
}
19
Source : EncodingUtil.cs
with MIT License
from 404Lcc
with MIT License
from 404Lcc
public static SocketModel SocketModelDncode(byte[] bytes)
{
SocketModel model = new SocketModel();
using (MemoryStream stream = new MemoryStream(bytes))
{
using (BinaryReader reader = new BinaryReader(stream))
{
model.type = reader.ReadByte();
model.area = reader.ReadInt32();
model.command = reader.ReadInt32();
if (stream.Length > stream.Position)
{
model.message = DeserializationDecode(reader.ReadBytes((int)(stream.Length - stream.Position)));
}
}
}
return model;
}
19
Source : SimpleJSON.cs
with MIT License
from 734843327
with MIT License
from 734843327
public static JSONNode Deserialize(System.IO.BinaryReader aReader)
{
JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte();
switch(type)
{
case JSONBinaryTag.Array:
{
int count = aReader.ReadInt32();
JSONArray tmp = new JSONArray();
for(int i = 0; i < count; i++)
tmp.Add(Deserialize(aReader));
return tmp;
}
case JSONBinaryTag.Clreplaced:
{
int count = aReader.ReadInt32();
JSONClreplaced tmp = new JSONClreplaced();
for(int i = 0; i < count; i++)
{
string key = aReader.ReadString();
var val = Deserialize(aReader);
tmp.Add(key, val);
}
return tmp;
}
case JSONBinaryTag.Value:
{
return new JSONData(aReader.ReadString());
}
case JSONBinaryTag.IntValue:
{
return new JSONData(aReader.ReadInt32());
}
case JSONBinaryTag.DoubleValue:
{
return new JSONData(aReader.ReadDouble());
}
case JSONBinaryTag.BoolValue:
{
return new JSONData(aReader.ReadBoolean());
}
case JSONBinaryTag.FloatValue:
{
return new JSONData(aReader.ReadSingle());
}
default:
{
throw new Exception("Error deserializing JSON. Unknown tag: " + type);
}
}
}
19
Source : IPCSupport.cs
with GNU General Public License v3.0
from 9E4ECDDE
with GNU General Public License v3.0
from 9E4ECDDE
public static AvatarBones FromByteArray(byte[] array)
{
using (MemoryStream memoryStream = new MemoryStream(array))
{
using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8))
{
AvatarBones boneList = new AvatarBones();
boneList.name = binaryReader.ReadString();
boneList.boneCount = binaryReader.ReadInt32();
boneList.bones = new SerializedBoneData[boneList.boneCount];
for (int i = 0; i < boneList.boneCount; i++)
{
boneList.bones[i] = SerializedBoneData.FromByteArray(binaryReader.ReadBytes(binaryReader.ReadInt32()));
}
return boneList;
}
}
}
19
Source : IPCSupport.cs
with GNU General Public License v3.0
from 9E4ECDDE
with GNU General Public License v3.0
from 9E4ECDDE
public Message Receive(out byte[] data)
{
if (!IsConnected) throw new InvalidOperationException("Tried to receive a message but the pipe is disconnected.");
Message message = (Message)pipeReader.ReadInt32();
data = pipeReader.ReadBytes(pipeReader.ReadInt32());
return message;
}
19
Source : EndianBinaryReader.cs
with MIT License
from 91Act
with MIT License
from 91Act
public override int ReadInt32()
{
if (endian == EndianType.BigEndian)
{
a32 = ReadBytes(4);
Array.Reverse(a32);
return BitConverter.ToInt32(a32, 0);
}
return base.ReadInt32();
}
19
Source : UmaTPose.cs
with Apache License 2.0
from A7ocin
with Apache License 2.0
from A7ocin
public void DeSerialize()
{
if (boneInfo == null)
{
var ms = new MemoryStream(serializedChunk);
var br = new BinaryReader(ms);
int count = br.ReadInt32();
boneInfo = new SkeletonBone[count];
for (int i = 0; i < count; i++)
{
boneInfo[i] = DeSerializeSkeletonBone(br);
}
count = br.ReadInt32();
humanInfo = new HumanBone[count];
for (int i = 0; i < count; i++)
{
humanInfo[i] = DeSerializeHumanBone(br);
}
if (br.PeekChar() >= 0)
{
extendedInfo = true;
armStretch = br.ReadSingle();
feetSpacing = br.ReadSingle();
legStretch = br.ReadSingle();
lowerArmTwist = br.ReadSingle();
lowerLegTwist = br.ReadSingle();
upperArmTwist = br.ReadSingle();
upperLegTwist = br.ReadSingle();
}
}
}
19
Source : UmaTPose.cs
with Apache License 2.0
from A7ocin
with Apache License 2.0
from A7ocin
private SkeletonBone DeSerializeSkeletonBone(BinaryReader br)
{
var res = new SkeletonBone();
res.name = br.ReadString();
res.position = DeserializeVector3(br);
res.rotation = DeSerializeQuaternion(br);
res.scale = DeserializeVector3(br);
br.ReadInt32();
return res;
}
19
Source : RoomFileSerializer.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from abist-co-ltd
private static void ReadFileHeader(BinaryReader reader, out int vertexCount, out int triangleIndexCount)
{
vertexCount = reader.ReadInt32();
triangleIndexCount = reader.ReadInt32();
}
19
Source : RoomFileSerializer.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from abist-co-ltd
private static int[] ReadTriangleIndicies(BinaryReader reader, int triangleIndexCount)
{
int[] triangleIndices = new int[triangleIndexCount];
for (int i = 0; i < triangleIndices.Length; i++)
{
triangleIndices[i] = reader.ReadInt32();
}
return triangleIndices;
}
19
Source : InputAnimationSerializationUtils.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from abist-co-ltd
public static void ReadHeader(BinaryReader reader, out int fileVersionMajor, out int fileVersionMinor)
{
long fileMagic = reader.ReadInt64();
if (fileMagic != Magic)
{
throw new Exception("File is not an input animation file");
}
fileVersionMajor = reader.ReadInt32();
fileVersionMinor = reader.ReadInt32();
}
19
Source : InputAnimationSerializationUtils.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from abist-co-ltd
public static void ReadFloatCurve(BinaryReader reader, AnimationCurve curve)
{
curve.preWrapMode = (WrapMode)reader.ReadInt32();
curve.postWrapMode = (WrapMode)reader.ReadInt32();
int keyframeCount = reader.ReadInt32();
Keyframe[] keys = new Keyframe[keyframeCount];
for (int i = 0; i < keyframeCount; ++i)
{
keys[i].time = reader.ReadSingle();
keys[i].value = reader.ReadSingle();
keys[i].inTangent = reader.ReadSingle();
keys[i].outTangent = reader.ReadSingle();
keys[i].inWeight = reader.ReadSingle();
keys[i].outWeight = reader.ReadSingle();
keys[i].weightedMode = (WeightedMode)reader.ReadInt32();
}
curve.keys = keys;
}
19
Source : InputAnimationSerializationUtils.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from abist-co-ltd
public static void ReadBoolCurve(BinaryReader reader, AnimationCurve curve)
{
curve.preWrapMode = (WrapMode)reader.ReadInt32();
curve.postWrapMode = (WrapMode)reader.ReadInt32();
int keyframeCount = reader.ReadInt32();
Keyframe[] keys = new Keyframe[keyframeCount];
for (int i = 0; i < keyframeCount; ++i)
{
keys[i].time = reader.ReadSingle();
keys[i].value = reader.ReadSingle();
keys[i].inTangent = 0.0f;
keys[i].outTangent = 0.0f;
keys[i].inWeight = 0.0f;
keys[i].outWeight = 1.0e6f;
keys[i].weightedMode = WeightedMode.Both;
}
curve.keys = keys;
}
19
Source : InputAnimationSerializationUtils.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from abist-co-ltd
public static void ReadMarkerList(BinaryReader reader, List<InputAnimationMarker> markers)
{
markers.Clear();
int count = reader.ReadInt32();
markers.Capacity = count;
for (int i = 0; i < count; ++i)
{
var marker = new InputAnimationMarker();
marker.time = reader.ReadSingle();
marker.name = reader.ReadString();
markers.Add(marker);
}
}
19
Source : OvrAvatarPacket.cs
with MIT License
from absurd-joy
with MIT License
from absurd-joy
public static OvrAvatarPacket Read(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
// Todo: bounds check frame count
int frameCount = reader.ReadInt32();
List<float> frameTimes = new List<float>(frameCount);
for (int i = 0; i < frameCount; ++i)
{
frameTimes.Add(reader.ReadSingle());
}
List<OvrAvatarDriver.PoseFrame> frames = new List<OvrAvatarDriver.PoseFrame>(frameCount);
for (int i = 0; i < frameCount; ++i)
{
frames.Add(reader.ReadPoseFrame());
}
// Todo: bounds check audio packet count
int audioPacketCount = reader.ReadInt32();
List<byte[]> audioPackets = new List<byte[]>(audioPacketCount);
for (int i = 0; i < audioPacketCount; ++i)
{
int audioPacketSize = reader.ReadInt32();
byte[] audioPacket = reader.ReadBytes(audioPacketSize);
audioPackets.Add(audioPacket);
}
return new OvrAvatarPacket(frameTimes, frames, audioPackets);
}
19
Source : RemoteLoopbackManager.cs
with MIT License
from absurd-joy
with MIT License
from absurd-joy
void ReceivePacketData(byte[] data)
{
using (MemoryStream inputStream = new MemoryStream(data))
{
BinaryReader reader = new BinaryReader(inputStream);
int sequence = reader.ReadInt32();
OvrAvatarPacket avatarPacket;
if (LoopbackAvatar.UseSDKPackets)
{
int size = reader.ReadInt32();
byte[] sdkData = reader.ReadBytes(size);
IntPtr packet = CAPI.ovrAvatarPacket_Read((UInt32)data.Length, sdkData);
avatarPacket = new OvrAvatarPacket { ovrNativePacket = packet };
}
else
{
avatarPacket = OvrAvatarPacket.Read(inputStream);
}
LoopbackAvatar.GetComponent<OvrAvatarRemoteDriver>().QueuePacket(sequence, avatarPacket);
}
}
19
Source : DataEntry.cs
with MIT License
from absurd-joy
with MIT License
from absurd-joy
public static chatPacket Deserialize(byte[] data)
{
chatPacket result = new chatPacket();
using (MemoryStream m = new MemoryStream(data))
{
using (BinaryReader reader = new BinaryReader(m))
{
result.packetID = reader.ReadInt32();
result.textString = System.Text.Encoding.Default.GetString(reader.ReadBytes(Constants.BUFFER_SIZE));
}
}
return result;
}
19
Source : EtherealHook.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)
{
base.Unpack(reader);
Ethereal = reader.ReadInt32();
}
19
Source : SetLightHook.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)
{
base.Unpack(reader);
LightsOn = reader.ReadInt32();
}
19
Source : BSPLeaf.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, BSPType treeType)
{
Type = Encoding.ASCII.GetString(reader.ReadBytes(4)).Reverse();
LeafIndex = reader.ReadInt32();
if (treeType == BSPType.Physics)
{
Solid = reader.ReadInt32();
// Note that if Solid is equal to 0, these values will basically be null. Still read them, but they don't mean anything.
Sphere = new Sphere();
Sphere.Unpack(reader);
InPolys = new List<ushort>();
uint numPolys = reader.ReadUInt32();
for (uint i = 0; i < numPolys; i++)
InPolys.Add(reader.ReadUInt16());
}
}
19
Source : CVertexArray.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)
{
VertexType = reader.ReadInt32();
var numVertices = reader.ReadUInt32();
if (VertexType == 1)
Vertices.Unpack(reader, numVertices);
else
throw new NotImplementedException();
}
19
Source : Iteration.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)
{
Ints = new List<int>();
Ints.Add(reader.ReadInt32());
Ints.Add(reader.ReadInt32());
Sorted = reader.ReadBoolean();
reader.AlignBoundary();
}
19
Source : SurfaceTexture.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)
{
Id = reader.ReadUInt32();
Unknown = reader.ReadInt32();
UnknownByte = reader.ReadByte();
Textures.Unpack(reader);
}
19
Source : Texture.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)
{
Id = reader.ReadUInt32();
Unknown = reader.ReadInt32();
Width = reader.ReadInt32();
Height = reader.ReadInt32();
Format = (SurfacePixelFormat)reader.ReadUInt32();
Length = reader.ReadInt32();
SourceData = reader.ReadBytes(Length);
switch (Format)
{
case SurfacePixelFormat.PFID_INDEX16:
case SurfacePixelFormat.PFID_P8:
DefaultPaletteId = reader.ReadUInt32();
break;
default:
DefaultPaletteId = null;
break;
}
}
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 : Wave.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)
{
int objectId = reader.ReadInt32();
int headerSize = reader.ReadInt32();
int dataSize = reader.ReadInt32();
Header = reader.ReadBytes(headerSize);
Data = reader.ReadBytes(dataSize);
}
19
Source : UnpackableExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator
with GNU Affero General Public License v3.0
from ACEmulator
public static void UnpackSmartArray<T>(this Dictionary<int, T> value, BinaryReader reader) where T : IUnpackable, new()
{
var totalObjects = reader.ReadCompressedUInt32();
for (int i = 0; i < totalObjects; i++)
{
var key = reader.ReadInt32();
var item = new T();
item.Unpack(reader);
value.Add(key, item);
}
}
19
Source : UnpackableExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator
with GNU Affero General Public License v3.0
from ACEmulator
public static void Unpack(this List<uint> value, BinaryReader reader)
{
var totalObjects = reader.ReadInt32();
for (int i = 0; i < totalObjects; i++)
{
var item = reader.ReadUInt32();
value.Add(item);
}
}
19
Source : AnimationHook.cs
with GNU Affero General Public License v3.0
from ACEmulator
with GNU Affero General Public License v3.0
from ACEmulator
public virtual void Unpack(BinaryReader reader)
{
HookType = (AnimationHookType)reader.ReadUInt32();
Direction = (AnimationHookDir)reader.ReadInt32();
}
19
Source : AnimData.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)
{
AnimId = reader.ReadUInt32();
LowFrame = reader.ReadInt32();
HighFrame = reader.ReadInt32();
Framerate = reader.ReadSingle();
}
19
Source : LandDefs.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)
{
NumBlockLength = reader.ReadInt32();
NumBlockWidth = reader.ReadInt32();
SquareLength = reader.ReadSingle();
LBlockLength = reader.ReadInt32();
VertexPerCell = reader.ReadInt32();
MaxObjHeight = reader.ReadSingle();
SkyHeight = reader.ReadSingle();
RoadWidth = reader.ReadSingle();
for (int i = 0; i < 256; i++)
LandHeightTable.Add(reader.ReadSingle());
}
19
Source : LocationType.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)
{
PartId = reader.ReadInt32();
Frame.Unpack(reader);
}
19
Source : SkillBase.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)
{
Description = reader.ReadPString(); reader.AlignBoundary();
Name = reader.ReadPString(); reader.AlignBoundary();
IconId = reader.ReadUInt32();
TrainedCost = reader.ReadInt32();
SpecializedCost = reader.ReadInt32();
Category = reader.ReadUInt32();
ChargenUse = reader.ReadUInt32();
MinLevel = reader.ReadUInt32();
Formula.Unpack(reader);
UpperBound = reader.ReadDouble();
LowerBound = reader.ReadDouble();
LearnMod = reader.ReadDouble();
}
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 : SkillCG.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)
{
SkillNum = reader.ReadUInt32();
NormalCost = reader.ReadInt32();
PrimaryCost = reader.ReadInt32();
}
19
Source : XpTable.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)
{
Id = reader.ReadUInt32();
// The counts for each "Table" are at the top of the file.
int attributeCount = reader.ReadInt32();
int vitalCount = reader.ReadInt32();
int trainedSkillCount = reader.ReadInt32();
int specializedSkillCount = reader.ReadInt32();
uint levelCount = reader.ReadUInt32();
for (int i = 0; i <= attributeCount; i++)
AttributeXpList.Add(reader.ReadUInt32());
for (int i = 0; i <= vitalCount; i++)
VitalXpList.Add(reader.ReadUInt32());
for (int i = 0; i <= trainedSkillCount; i++)
TrainedSkillXpList.Add(reader.ReadUInt32());
for (int i = 0; i <= specializedSkillCount; i++)
SpecializedSkillXpList.Add(reader.ReadUInt32());
for (int i = 0; i <= levelCount; i++)
CharacterLevelXPList.Add(reader.ReadUInt64());
for (int i = 0; i <= levelCount; i++)
CharacterLevelSkillCreditList.Add(reader.ReadUInt32());
}
19
Source : UnpackableExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator
with GNU Affero General Public License v3.0
from ACEmulator
public static void UnpackSmartArray(this List<int> value, BinaryReader reader)
{
var totalObjects = reader.ReadCompressedUInt32();
for (int i = 0; i < totalObjects; i++)
{
var item = reader.ReadInt32();
value.Add(item);
}
}
19
Source : UnpackableExtensions.cs
with GNU Affero General Public License v3.0
from ACEmulator
with GNU Affero General Public License v3.0
from ACEmulator
public static void Unpack<T>(this Dictionary<int, T> value, BinaryReader reader) where T : IUnpackable, new()
{
var totalObjects = reader.ReadInt32();
for (int i = 0; i < totalObjects; i++)
{
var key = reader.ReadInt32();
var item = new T();
item.Unpack(reader);
value.Add(key, item);
}
}
19
Source : ParticleEmitterInfo.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)
{
Id = reader.ReadUInt32();
/*uint unknown = */reader.ReadUInt32();
EmitterType = (EmitterType)reader.ReadInt32();
ParticleType = (ParticleType)reader.ReadInt32();
GfxObjId = reader.ReadUInt32();
HwGfxObjId = reader.ReadUInt32();
Birthrate = reader.ReadDouble();
MaxParticles = reader.ReadInt32();
InitialParticles = reader.ReadInt32();
TotalParticles = reader.ReadInt32();
TotalSeconds = reader.ReadDouble();
Lifespan = reader.ReadDouble();
LifespanRand = reader.ReadDouble();
OffsetDir = reader.ReadVector3();
MinOffset = reader.ReadSingle();
MaxOffset = reader.ReadSingle();
A = reader.ReadVector3();
MinA = reader.ReadSingle();
MaxA = reader.ReadSingle();
B = reader.ReadVector3();
MinB = reader.ReadSingle();
MaxB = reader.ReadSingle();
C = reader.ReadVector3();
MinC = reader.ReadSingle();
MaxC = reader.ReadSingle();
StartScale = reader.ReadSingle();
FinalScale = reader.ReadSingle();
ScaleRand = reader.ReadSingle();
StartTrans = reader.ReadSingle();
FinalTrans = reader.ReadSingle();
TransRand = reader.ReadSingle();
IsParentLocal = reader.ReadInt32();
}
19
Source : SetupModel.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)
{
Id = reader.ReadUInt32();
Flags = (SetupFlags)reader.ReadUInt32();
AllowFreeHeading = (Flags & SetupFlags.AllowFreeHeading) != 0;
HasPhysicsBSP = (Flags & SetupFlags.HasPhysicsBSP) != 0;
// Get all the GraphicsObjects in this SetupModel. These are all the 01-types.
uint numParts = reader.ReadUInt32();
for (int i = 0; i < numParts; i++)
Parts.Add(reader.ReadUInt32());
if ((Flags & SetupFlags.HasParent) != 0)
{
for (int i = 0; i < numParts; i++)
ParentIndex.Add(reader.ReadUInt32());
}
if ((Flags & SetupFlags.HasDefaultScale) != 0)
{
for (int i = 0; i < numParts; i++)
DefaultScale.Add(reader.ReadVector3());
}
HoldingLocations.Unpack(reader);
ConnectionPoints.Unpack(reader);
int placementsCount = reader.ReadInt32();
for (int i = 0; i < placementsCount; i++)
{
int key = reader.ReadInt32();
// there is a frame for each Part
var placementType = new PlacementType();
placementType.Unpack(reader, (uint)Parts.Count);
PlacementFrames.Add(key, placementType);
}
CylSpheres.Unpack(reader);
Spheres.Unpack(reader);
Height = reader.ReadSingle();
Radius = reader.ReadSingle();
StepUpHeight = reader.ReadSingle();
StepDownHeight = reader.ReadSingle();
SortingSphere.Unpack(reader);
SelectionSphere.Unpack(reader);
Lights.Unpack(reader);
DefaultAnimation = reader.ReadUInt32();
DefaultScript = reader.ReadUInt32();
DefaultMotionTable = reader.ReadUInt32();
DefaultSoundTable = reader.ReadUInt32();
DefaultScriptTable = reader.ReadUInt32();
}
19
Source : CharacterCreateInfo.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)
{
reader.BaseStream.Position += 4; /* Unknown constant (1) */
Heritage = (HeritageGroup)reader.ReadUInt32();
Gender = reader.ReadUInt32();
Appearance.Unpack(reader);
TemplateOption = reader.ReadInt32();
StrengthAbility = reader.ReadUInt32();
EnduranceAbility = reader.ReadUInt32();
CoordinationAbility = reader.ReadUInt32();
QuicknessAbility = reader.ReadUInt32();
FocusAbility = reader.ReadUInt32();
SelfAbility = reader.ReadUInt32();
CharacterSlot = reader.ReadUInt32();
ClreplacedId = reader.ReadUInt32();
uint numOfSkills = reader.ReadUInt32();
for (uint i = 0; i < numOfSkills; i++)
SkillAdvancementClreplacedes.Add((SkillAdvancementClreplaced)reader.ReadUInt32());
Name = reader.ReadString16L();
StartArea = reader.ReadUInt32();
IsAdmin = (reader.ReadUInt32() == 1);
IsSentinel = (reader.ReadUInt32() == 1);
}
See More Examples