public bool IsHdrTexture(ShaderResourceView view, Size size) { using (var maxColor = GetLimits(view, size, ((Texture2D)view.Resource).Description.Format)) { var texture = maxColor.Texture; using (var copy = new Texture2D(Device, new Texture2DDescription { SampleDescription = new SampleDescription(1, 0), Width = texture.Description.Width, Height = texture.Description.Height, ArraySize = texture.Description.ArraySize, MipLevels = texture.Description.MipLevels, Format = texture.Description.Format, Usage = ResourceUsage.Staging, BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read })) { Device.ImmediateContext.CopyResource(texture, copy); var rect = Device.ImmediateContext.MapSubresource(copy, 0, MapMode.Read, SlimDX.Direct3D11.MapFlags.None); try { using (var b = new ReadAheadBinaryReader(rect.Data)) { var c = b.ReadVec4(); return(c.X < 0f || c.Y < 0f || c.Z < 0f || c.W < 0f || c.X > 1f || c.Y > 1f || c.Z > 1f || c.W > 1f); } } finally { Device.ImmediateContext.UnmapSubresource(texture, 0); } } } }
public bool IsHdrTexture(ShaderResourceView view, Size size) { using (var maxColor = GetLimits(view, size, ((Texture2D)view.Resource).Description.Format)) { var texture = maxColor.Texture; using (var copy = new Texture2D(Device, new Texture2DDescription { SampleDescription = new SampleDescription(1, 0), Width = texture.Description.Width, Height = texture.Description.Height, ArraySize = texture.Description.ArraySize, MipLevels = texture.Description.MipLevels, Format = texture.Description.Format, Usage = ResourceUsage.Staging, BindFlags = BindFlags.None, CpuAccessFlags = CpuAccessFlags.Read })) { Device.ImmediateContext.CopyResource(texture, copy); var rect = Device.ImmediateContext.MapSubresource(copy, 0, MapMode.Read, SlimDX.Direct3D11.MapFlags.None); try { using (var b = new ReadAheadBinaryReader(rect.Data)) { var c = b.ReadSingle4D(); AcToolsLogging.Write("Values: " + c.JoinToString("; ") + "; format: " + texture.Description.Format); return(c.Any(x => x < 0f || x > 1f)); } } finally { Device.ImmediateContext.UnmapSubresource(texture, 0); } } } }
private AiSpline([NotNull] string filename) { using (var reader = new ReadAheadBinaryReader(filename)) { Version = reader.ReadInt32(); if (Version != 7) { throw new Exception($"Version {Version} not supported"); } var points = new AiPoint[reader.ReadInt32()]; LapTime = reader.ReadInt32(); SampleCount = reader.ReadInt32(); for (int i = 0, c = points.Length; i < c; i++) { points[i].LoadFrom(reader); } var pointsExtra = new AiPointExtra[reader.ReadInt32()]; for (int i = 0, c = pointsExtra.Length; i < c; i++) { pointsExtra[i].LoadFrom(reader); } Points = points; PointsExtra = pointsExtra; HasGrid = reader.ReadInt32() != 0; if (HasGrid) { Grid = new AiSplineGrid(reader); } } }
public virtual IEnumerable <LapTimeEntry> Import(string sourceName) { var directory = new DirectoryInfo(Path.Combine(_sidekickDirectory, "personal_best")); if (!directory.Exists) { yield break; } foreach (var file in directory.GetFiles("*_pb.ini")) { long time; try { using (var stream = File.Open(file.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var reader = new ReadAheadBinaryReader(stream)) { if (!ReadPickle(reader, out time) || time == 0) { continue; } } } catch (Exception e) { AcToolsLogging.Write($"Can’t read {file.Name}: {e}"); continue; } string carId, trackLayoutId; if (TryToGuessCarAndTrack(file.FullName, out carId, out trackLayoutId)) { yield return(new LapTimeEntry(sourceName, carId, trackLayoutId, file.LastWriteTime, TimeSpan.FromMilliseconds(time))); } } }
public byte[] LoadTexture(string textureName, ReadAheadBinaryReader reader, int textureSize) { var result = MemoryChunk.Bytes(textureSize).Execute(() => new byte[textureSize]); reader.ReadBytesTo(result, 0, textureSize); return(result); }
public byte[] LoadTexture(string textureName, ReadAheadBinaryReader reader, int textureSize) { if (textureSize > 4e6) { AcToolsLogging.Write($"{textureName}: {(double)textureSize / 1024 / 1024:F1} MB"); } MemoryChunk.Bytes(textureSize).Execute(() => { var bytes = reader.ReadBytes(textureSize); // FromStream simply reads Stream to byte[] underneath, so we could just do it here in // a more controlled manner try { lock (_device) { if (OptionLoadView) { var view = ShaderResourceView.FromMemory(_device, bytes); // new ShaderResourceView(_device, texture); _ready[textureName] = new Tuple <Texture2D, ShaderResourceView>(null, view); } else { var texture = Texture2D.FromMemory(_device, bytes); var view = new ShaderResourceView(_device, texture); _ready[textureName] = new Tuple <Texture2D, ShaderResourceView>(texture, view); } } } catch (SEHException e) { AcToolsLogging.NonFatalErrorNotify("Can’t load texture", "Try again?", e); } }); return(null); }
public void LoadFrom(ReadAheadBinaryReader reader) { Items = new ItemSub[reader.ReadInt32()]; for (int i = 0, c = Items.Length; i < c; i++) { Items[i].LoadFrom(reader); } }
public void LoadFrom(ReadAheadBinaryReader reader) { Values = new int[reader.ReadInt32()]; for (int i = 0, c = Values.Length; i < c; i++) { Values[i] = reader.ReadInt32(); } }
public byte[] LoadTexture(string textureName, ReadAheadBinaryReader reader, int textureSize) { if (textureName == _textureName) { Result = reader.ReadBytes(textureSize); } else { reader.Skip(textureSize); } return(null); }
public AiSplineGrid(ReadAheadBinaryReader reader) { MaxExtreme = reader.ReadVec3(); MinExtreme = reader.ReadVec3(); NeighborsConsideredNumber = reader.ReadInt32(); SamplingDensity = reader.ReadSingle(); Items = new Item[reader.ReadInt32()]; for (int i = 0, c = Items.Length; i < c; i++) { Items[i].LoadFrom(reader); } }
byte[] IKn5TextureLoader.LoadTexture(string textureName, ReadAheadBinaryReader reader, int textureSize) { if (textureName == _textureName) { var s = _fn?.Invoke(textureSize); if (s != null) { reader.CopyTo(s, textureSize); } } return(null); }
private HashStorage([NotNull] string[] keys, [NotNull] string filename) : this(keys) { using (var reader = new ReadAheadBinaryReader(filename)) { if (reader.ReadByte() != 0x8a || reader.ReadByte() != 0x56) { throw new Exception("Invalid format"); } if (reader.ReadInt32() != Version) { throw new Exception("Invalid version"); } ParamsHashCode = reader.ReadInt32(); var keysAmount = reader.ReadInt32(); if (keysAmount != _setsKeys.Length) { throw new HashStorageObsoleteException("Incompatible keys"); } var sizePerSet = new int[keysAmount]; for (var i = 0; i < keysAmount; i++) { if (reader.ReadInt32() != _setsKeys[i].GetHashCode()) { throw new HashStorageObsoleteException("Incompatible keys"); } sizePerSet[i] = reader.ReadInt32(); } var amount = reader.ReadInt32(); for (var i = 0; i < amount; i++) { var carId = reader.ReadString(); var data = new byte[keysAmount][]; for (var j = 0; j < keysAmount; j++) { data[j] = reader.ReadBytes(sizePerSet[j]); } _dictionary[carId] = data; } } }
public void LoadFrom(ReadAheadBinaryReader reader) { Speed = reader.ReadSingle(); Gas = reader.ReadSingle(); Brake = reader.ReadSingle(); ObsoleteLatG = reader.ReadSingle(); Radius = reader.ReadSingle(); SideLeft = reader.ReadSingle(); SideRight = reader.ReadSingle(); Camber = reader.ReadSingle(); Direction = reader.ReadSingle(); Normal = reader.ReadSingle3D(); Length = reader.ReadSingle(); ForwardVector = reader.ReadSingle3D(); Tag = reader.ReadSingle(); Grade = reader.ReadSingle(); }
private AiLane([NotNull] string filename) { using (var reader = new ReadAheadBinaryReader(filename)) { Version = reader.ReadInt32(); if (Version != 7) { throw new Exception($"Version {Version} not supported"); } Size = reader.ReadInt64(); Points = new AiPoint[Size]; for (var i = 0; i < Size; i++) { Points[i].Id = reader.ReadInt32(); Points[i].Position = reader.ReadSingle3D(); Points[i].Length = reader.ReadSingle(); } SizeA = reader.ReadInt32(); SizeB = reader.ReadInt32(); if (SizeA != Size - 1) { throw new Exception($"Unexpected SizeA value ({Size - 1} expected, {SizeA} found)"); } if (SizeB != Size) { AcToolsLogging.Write($"Unexpected SizeB value ({Size} expected, {SizeB} found)"); } for (var i = 0; i < Size; i++) { var e = new float[18]; for (var j = 0; j < 18; j++) { e[j] = reader.ReadSingle(); } Points[i].Extra = e; } // there are some more bytes, but I have no idea what are they for } }
// http://svn.python.org/projects/python/tags/r32/Lib/pickle.py private static bool ReadPickle(ReadAheadBinaryReader reader, out long result) { if (reader.Length < 2) { result = 0; return(false); } if (reader.ReadByte() != 128 || reader.ReadByte() != 3) { result = 0; return(false); } switch (reader.ReadByte()) { case (byte)'F': result = (long)reader.ReadSingle(); return(true); case (byte)'N': result = 0; return(true); case (byte)'I': case (byte)'J': result = reader.ReadInt32(); return(true); case (byte)'L': result = reader.ReadInt64(); return(true); case (byte)'M': result = reader.ReadUInt16(); return(true); case (byte)'K': result = reader.ReadByte(); return(true); } result = 0; return(false); }
public async Task CopyToTest() { var f = @"D:\Games\Assetto Corsa\content\cars\ks_porsche_911_carrera_rsr\porsche_911_carrera_rsr.kn5"; var target = File.ReadAllBytes(f); using (var r = new ReadAheadBinaryReader(f)) using (var m = new MemoryStream()){ Assert.AreEqual('s', r.ReadByte()); m.WriteByte((byte)'s'); r.CopyTo(m); /*File.WriteAllBytes($"{TestDir}/rabr_got.kn5", m.ToArray()); * File.WriteAllBytes($"{TestDir}/rabr_expected.kn5", File.ReadAllBytes(f));*/ Assert.IsTrue(target.SequenceEqual(m.ToArray())); } using (var r = new ReadAheadBinaryReader(f)) using (var m = new MemoryStream()){ Assert.AreEqual('s', r.ReadByte()); m.WriteByte((byte)'s'); await r.CopyToAsync(m); Assert.IsTrue(target.SequenceEqual(m.ToArray())); } using (var r = new ReadAheadBinaryReader(f)) using (var m = new MemoryStream()){ Assert.AreEqual('s', r.ReadByte()); m.WriteByte((byte)'s'); r.CopyTo(m, 19270); Assert.IsTrue(target.Take(19271).SequenceEqual(m.ToArray())); } using (var r = new ReadAheadBinaryReader(f)) using (var m = new MemoryStream()){ Assert.AreEqual('s', r.ReadByte()); m.WriteByte((byte)'s'); await r.CopyToAsync(m, 19270); Assert.IsTrue(target.Take(19271).SequenceEqual(m.ToArray())); } }
public void Load(byte[] data) { DisposeHelper.Dispose(ref _list); var list = new List <T>(); using (var stream = new MemoryStream(data)) using (var reader = new ReadAheadBinaryReader(stream)) { _outputSize = reader.ReadInt32(); while (reader.Position < reader.Length) { var created = new T(); var piece = reader.ReadBytes(reader.ReadInt32()); created.Load(piece); list.Add(created); } } _list = list; _list.ForEach(x => x.SetOptions(_options)); }
public void LoadFrom(ReadAheadBinaryReader reader) { Position = reader.ReadVec3(); Length = reader.ReadSingle(); Id = reader.ReadInt32(); }
public InnerStream(ReadAheadBinaryReader parent) { _parent = parent; }
public Kn5Node LoadNode(ReadAheadBinaryReader reader) { return(LoadHierarchy((Kn5Reader)reader)); }
public Kn5Material LoadMaterial(ReadAheadBinaryReader reader) { return(((IKn5Reader)reader).ReadMaterial()); }
public Kn5Material LoadMaterial(ReadAheadBinaryReader reader) { ((IKn5Reader)reader).SkipMaterial(); return(null); }
public Kn5Node LoadNode(ReadAheadBinaryReader reader) { SkipNode((IKn5Reader)reader); return(null); }
public byte[] LoadTexture(string textureName, ReadAheadBinaryReader reader, int textureSize) { reader.Skip(textureSize); return(null); }
public Kn5Node LoadNode(ReadAheadBinaryReader reader) { return(LoadNode((IKn5Reader)reader)); }