public StructUnpacker(MemoryAccessor vmm, ulong position) { _vmm = vmm; _position = position; _buffPos = 64; }
public static MemoryAccessor[] CreateVertexMemoryAccessors <TVertex>(this IReadOnlyList <TVertex> vertices, PackedEncoding vertexEncoding) where TVertex : IVertexBuilder { if (vertices == null || vertices.Count == 0) { return(null); } vertexEncoding.AdjustJointEncoding(vertices); // determine the vertex attributes from the first vertex. var attributes = GetVertexAttributes(vertices[0], vertices.Count, vertexEncoding); // create a buffer int byteStride = attributes[0].ByteStride; var vbuffer = new ArraySegment <byte>(new Byte[byteStride * vertices.Count]); // fill the buffer with the vertex attributes. var accessors = MemoryAccessInfo .Slice(attributes, 0, vertices.Count) .Select(item => new MemoryAccessor(vbuffer, item)) .ToArray(); foreach (var accessor in accessors) { accessor.FillAccessor(vertices); } MemoryAccessor.SanitizeVertexAttributes(accessors); return(accessors); }
public long HandleOperand(MemoryAccessor buf, long operand, int mod) { return(mod switch { 1 => operand, 2 => buf[BaseAddress + operand], _ => buf[operand] });
private ushort[] GetLocalUshortsForProp() { var newUshorts = MemoryAccessor.GetUshortsFromMemory(_deviceContext.DeviceMemory, (ushort)(_property.Address + _offset), _property.NumberOfPoints, true); if (_property.IsFromBits) { var boolArray = newUshorts.GetBoolArrayFromUshortArray(); bool[] subPropertyBools = new bool[16]; int counter = 0; for (ushort i = 0; i < 16; i++) { if (_property.BitNumbers.Contains(i)) { subPropertyBools[counter] = boolArray[i]; counter++; } } var subPropertyUshort = subPropertyBools.BoolArrayToUshort(); return(new[] { subPropertyUshort }); } else { return(newUshorts); } }
public async Task <Result <ushort[]> > GetUshortsOfProperty(object propertyMaybe, DeviceContext deviceContext, bool cacheAllowed, bool isLocal) { IProperty property = propertyMaybe as IProperty; if (property == null || !deviceContext.DataProviderContainer.DataProvider.IsSuccess) { return(Result <ushort[]> .Create(false)); } if (cacheAllowed && deviceContext.DeviceMemory != null && MemoryAccessor.IsMemoryContainsAddresses( deviceContext.DeviceMemory, property.Address, property.NumberOfPoints, isLocal)) { return(MemoryAccessor.GetUshortsFromMemory(deviceContext.DeviceMemory, property.Address, property.NumberOfPoints, isLocal)); } var ushorts = await deviceContext.DataProviderContainer.DataProvider.Item.ReadHoldingResgistersAsync(property.Address, property.NumberOfPoints, "Read property"); if (ushorts.IsSuccessful) { MemoryAccessor.SetUshortsInMemory(deviceContext.DeviceMemory, property.Address, ushorts.Result, isLocal); return(ushorts.Result); } return(Result <ushort[]> .Create(false)); }
public static MemoryAccessor CreateVertexMemoryAccessor <TVertex>(this IReadOnlyList <TVertex> vertices, string attributeName, Schema2.EncodingType jointEncoding) where TVertex : IVertexBuilder { if (vertices == null || vertices.Count == 0) { return(null); } // determine the vertex attributes from the first vertex. var attributes = GetVertexAttributes(vertices[0], vertices.Count, jointEncoding); var attribute = attributes.FirstOrDefault(item => item.Name == attributeName); if (attribute.Name == null) { return(null); } attribute.ByteOffset = 0; attribute.ByteStride = 0; // create a buffer var vbuffer = new ArraySegment <byte>(new Byte[attribute.PaddedByteLength * vertices.Count]); // fill the buffer with the vertex attributes. var accessor = new MemoryAccessor(vbuffer, attribute); accessor.FillAccessor(vertices); return(accessor); }
public void SetIndexData(MemoryAccessor src) { Guard.NotNull(src, nameof(src)); var bv = this.LogicalParent.UseBufferView(src.Data, src.Attribute.ByteStride, BufferMode.ELEMENT_ARRAY_BUFFER); SetIndexData(bv, src.Attribute.ByteOffset, src.Attribute.ItemsCount, src.Attribute.Encoding.ToIndex()); }
public void SetVertexData(MemoryAccessor src) { Guard.NotNull(src, nameof(src)); var bv = this.LogicalParent.UseBufferView(src.Data, src.Attribute.PaddedByteLength, BufferMode.ARRAY_BUFFER); SetVertexData(bv, src.Attribute.ByteOffset, src.Attribute.ItemsCount, src.Attribute.Dimensions, src.Attribute.Encoding, src.Attribute.Normalized); }
private Array GetKeyArray(MemoryAccessor ma, long index, int count, Type elType) { var arr = Array.CreateInstance(elType, count); Unsafe.CopyBlock(Unsafe.AsPointer(ref arr), ma.GetPtr(GetAbsoluteOffset(index) + keyOffset), (uint)(count * Marshal.SizeOf(elType))); return(arr); }
public void AdjustAddressTest() { //Base address is 0x8000F800; var testPtr = 0x801A1119; var expectedPtr = 0x191919; Assert.AreEqual(expectedPtr, MemoryAccessor.AdjustAddress(testPtr)); }
public Memory.IEncodedArray <Vector4> AsVector4Array() { if (!_Sparse.HasValue) { return(_MemoryAccessor.AsVector4Array()); } return(MemoryAccessor.CreateVector4SparseArray(_MemoryAccessor, _Sparse.Value.Key, _Sparse.Value.Value)); }
public Memory.IEncodedArray <Single> AsScalarArray() { if (!_Sparse.HasValue) { return(_MemoryAccessor.AsScalarArray()); } return(MemoryAccessor.CreateScalarSparseArray(_MemoryAccessor, _Sparse.Value.Key, _Sparse.Value.Value)); }
private static void _ValidateWeights(VALIDATIONCTX result, Accessor weights0, Accessor weights1) { weights0?._ValidateWeights(result); weights1?._ValidateWeights(result); var memory0 = weights0?._GetMemoryAccessor("WEIGHTS_0"); var memory1 = weights1?._GetMemoryAccessor("WEIGHTS_1"); MemoryAccessor.ValidateWeightsSum(result, memory0, memory1); }
private static void _ValidateWeights(VALIDATIONCTX validate, Accessor weights0, Accessor weights1) { weights0?._ValidateWeights(validate); weights1?._ValidateWeights(validate); var memory0 = weights0?._GetMemoryAccessor("WEIGHTS_0"); var memory1 = weights1?._GetMemoryAccessor("WEIGHTS_1"); validate.That(() => MemoryAccessor.VerifyWeightsSum(memory0, memory1)); }
public void ReadMemory() { using (var memory = new MemoryAccessor(Pid.Value)) { Remaining = memory.I4(AddrRemaining); Width = memory.I4(AddrWidth); Height = memory.I4(AddrHeight); Time = memory.I4(AddrTime); Mines = memory.Buffer(AddrMine, Mines.Length); } }
public static MeshPrimitive WithVertexAccessor(this MeshPrimitive primitive, MemoryAccessor memAccessor) { Guard.NotNull(primitive, nameof(primitive)); Guard.NotNull(memAccessor, nameof(memAccessor)); var root = primitive.LogicalParent.LogicalParent; primitive.SetVertexAccessor(memAccessor.Attribute.Name, root.CreateVertexAccessor(memAccessor)); return(primitive); }
internal void ValidateIndices(VALIDATIONCTX validate, uint vertexCount, PrimitiveType drawingType) { validate = validate.GetContext(this); SourceBufferView.ValidateBufferUsageGPU(validate, BufferMode.ELEMENT_ARRAY_BUFFER); validate.IsAnyOf("Format", Format, (DimensionType.SCALAR, EncodingType.UNSIGNED_BYTE), (DimensionType.SCALAR, EncodingType.UNSIGNED_SHORT), (DimensionType.SCALAR, EncodingType.UNSIGNED_INT)); validate.AreEqual(nameof(SourceBufferView.ByteStride), SourceBufferView.ByteStride, 0); // "bufferView.byteStride must not be defined for indices accessor."; validate.That(() => MemoryAccessor.VerifyVertexIndices(_GetMemoryAccessor(), vertexCount)); }
protected override void OnValidateContent(VALIDATIONCTX validate) { base.OnValidateContent(validate); BufferView.VerifyAccess(validate, this.SourceBufferView, this.ByteOffset, this.Format, this.Count); validate.That(() => MemoryAccessor.VerifyAccessorBounds(_GetMemoryAccessor(), _min, _max)); // at this point we don't know which kind of data we're accessing, so it's up to the components // using this accessor to validate the data. }
private T ReadStruct <T>(MemoryAccessor accessor, ulong address) where T : struct { byte[] data = accessor.ReadBytes(address, Marshal.SizeOf <T>()); unsafe { fixed(byte *ptr = data) { return(Marshal.PtrToStructure <T>((IntPtr)ptr)); } } }
public IEncodedArray <Vector4> AsVector4Array() { var memory = _GetMemoryAccessor(); if (this._sparse == null) { return(memory.AsVector4Array()); } var sparseKV = this._sparse._CreateMemoryAccessors(this); return(MemoryAccessor.CreateVector4SparseArray(memory, sparseKV.Key, sparseKV.Value)); }
public IList <Vector4> AsColorArray() { var memory = _GetMemoryAccessor(); if (this._sparse == null) { return(memory.AsColorArray()); } var sparseKV = this._sparse._CreateMemoryAccessors(this); return(MemoryAccessor.CreateColorSparseArray(memory, sparseKV.Key, sparseKV.Value)); }
public IList <Single> AsScalarArray() { var memory = _GetMemoryAccessor(); if (this._sparse == null) { return(memory.AsScalarArray()); } var sparseKV = this._sparse._CreateMemoryAccessors(this); return(MemoryAccessor.CreateScalarSparseArray(memory, sparseKV.Key, sparseKV.Value)); }
public static MemoryAccessor CreateVertexMemoryAccessors <TVertex>(this IReadOnlyList <TVertex> vertices, string attributeName) where TVertex : IVertexBuilder { if (vertices == null || vertices.Count == 0) { return(null); } // determine the vertex attributes from the first vertex. var attributes = GetVertexAttributes(vertices[0], vertices.Count); var isMorphTangent = attributeName == "MORPHTANGENT"; if (isMorphTangent) { attributeName = "TANGENT"; } var attribute = attributes.FirstOrDefault(item => item.Name == attributeName); if (attribute.Name == null) { return(null); } attribute.ByteOffset = 0; attribute.ByteStride = 0; if (isMorphTangent) { attribute.Dimensions = Schema2.DimensionType.VEC3; } // create a buffer var vbuffer = new ArraySegment <byte>(new Byte[attribute.PaddedByteLength * vertices.Count]); // fill the buffer with the vertex attributes. var accessor = new MemoryAccessor(vbuffer, attribute); if (isMorphTangent) { var columnFunc = _GetVertexBuilderAttributeFunc("MORPHTANGENT"); accessor.AsVector3Array().Fill(vertices._GetColumn <TVertex, Vector3>(columnFunc)); } else { accessor.FillAccessor(vertices); } return(accessor); }
static void Main(string[] args) { string FileTitle = System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location); if (args.Length == 0) { Console.WriteLine(FileTitle + ": no input files"); return; } Console.WriteLine("PMAX Patcher v0.1a - patches PMD to PMA model file format"); string InputFileName = args[0]; string OutputFileName = System.IO.Path.ChangeExtension(InputFileName, ".pma"); PMAXPatchObjectModel patches = new PMAXPatchObjectModel(); Document.Load(patches, new PMAXPatchXMLDataFormat(), new FileAccessor(InputFileName), true); string basePath = System.IO.Path.GetDirectoryName(InputFileName); if (String.IsNullOrEmpty(basePath)) { basePath = Environment.CurrentDirectory; } foreach (PMAXPatch patch in patches.Patches) { PMAXPatchObjectModel patches2 = new PMAXPatchObjectModel(); patches2.Patches.Add(patch); MemoryAccessor mem = new MemoryAccessor(); Document.Save(patches2, new PMAXPatchBinaryDataFormat(), mem, true); byte[] patchBytes = mem.ToArray(); byte[] originalFileBytes = System.IO.File.ReadAllBytes(basePath + System.IO.Path.DirectorySeparatorChar.ToString() + patch.InputFileName); byte[] modifiedFileBytes = new byte[originalFileBytes.Length + patchBytes.Length]; Array.Copy(originalFileBytes, 0, modifiedFileBytes, 0, originalFileBytes.Length); Array.Copy(patchBytes, 0, modifiedFileBytes, originalFileBytes.Length, patchBytes.Length); System.IO.File.WriteAllBytes(basePath + System.IO.Path.DirectorySeparatorChar.ToString() + patch.OutputFileName, modifiedFileBytes); } }
protected override void OnValidateContent(VALIDATIONCTX validate) { base.OnValidateContent(validate); // if Accessor.Type uses a custom dimension, // we cannot check the rest of the accessor. if (this.Dimensions == DimensionType.CUSTOM) { return; } BufferView.VerifyAccess(validate, this.SourceBufferView, this.ByteOffset, this.Format, this.Count); validate.That(() => MemoryAccessor.VerifyAccessorBounds(_GetMemoryAccessor(), _min, _max)); // at this point we don't know which kind of data we're accessing, so it's up to the components // using this accessor to validate the data. }
/// <summary> /// Creates a new instance of the GPU emulation context. /// </summary> /// <param name="renderer">Host renderer</param> public GpuContext(IRenderer renderer) { Renderer = renderer; MemoryManager = new MemoryManager(); MemoryAccessor = new MemoryAccessor(this); Methods = new Methods(this); Fifo = new NvGpuFifo(this); DmaPusher = new DmaPusher(this); Window = new Window(this); _caps = new Lazy <Capabilities>(Renderer.GetCapabilities); }
public static IEnumerable <Formula> ReadAchemistRecipes() { if (_baseAddress == 0) { throw new InvalidOperationException("Connect to Darkland process first!"); } using (var accessor = new MemoryAccessor("dosbox")) { var bytes = new byte[FormulaeSize * CharacterCount]; if (accessor.ReadMemory(_baseAddress + FormulaeMonitorOffset, bytes)) { return(ToFormulaeList(bytes)); } } return(Enumerable.Empty <Formula>()); }
public void updateFrameInfo() { do { currFrame = MemoryAccessor.FrameCount(); }while (currFrame == prevFrame); _player1.characterIndex = MemoryAccessor.ReadStaticInt(_player1._playerNumber); _player2.characterIndex = MemoryAccessor.ReadStaticInt(_player2._playerNumber); _player1.assignPlayerPtr("Player1Ptr"); _player2.assignPlayerPtr("Player2Ptr"); _player1._isBlocking = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._BlockstunOffset) != 0; _player2._isBlocking = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._BlockstunOffset) != 0; _player1._isHit = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._HitstunOffset) != 0; _player2._isHit = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._HitstunOffset) != 0; _player1._currentAnim = MemoryAccessor.ReadAnimationString(ref _player1); _player2._currentAnim = MemoryAccessor.ReadAnimationString(ref _player2); frameAdvantage(f, ref _player1, ref _player2); gap(g1, ref _player2); gap(g2, ref _player1); _player1._HP = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._HPOffset); _player2._HP = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._HPOffset); _player1._meter = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._MeterOffset); _player2._meter = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._MeterOffset); _player1._RISC = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._RISCOffset); _player2._RISC = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._RISCOffset); _player1._stun = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._DizzyOffset); _player2._stun = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._DizzyOffset); _player1._pos.x = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._PositionXOffset); _player1._pos.y = MemoryAccessor.ReadInfoInt(ref _player1, MemoryAccessor._PositionYOffset); _player2._pos.x = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._PositionXOffset); _player2._pos.y = MemoryAccessor.ReadInfoInt(ref _player2, MemoryAccessor._PositionYOffset); if (MemoryAccessor.FrameCount() - currFrame != 0) { Console.WriteLine("frame skipped"); } prevFrame = currFrame; }
public void ReadMemory() { using var memory = new MemoryAccessor(Pid.Value); Remaining = memory.I4(AddrRemaining); Width = memory.I4(AddrWidth); Height = memory.I4(AddrHeight); Time = memory.I4(AddrTime); if ((Width * Height).For(n => 0 < n && n <= Mines.Length)) { Mines = memory.Buffer(AddrMine, Mines.Length); Valid = true; } else { Valid = false; } }
static void Main(string[] args) { string FileTitle = System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location); if (args.Length == 0) { Console.WriteLine(FileTitle + ": no input files"); return; } Console.WriteLine("PMAX Patcher v0.1a - patches PMD to PMA model file format"); string InputFileName = args[0]; string OutputFileName = System.IO.Path.ChangeExtension(InputFileName, ".pma"); PMAXPatchObjectModel patches = new PMAXPatchObjectModel(); Document.Load(patches, new PMAXPatchXMLDataFormat(), new FileAccessor(InputFileName), true); string basePath = System.IO.Path.GetDirectoryName(InputFileName); if (String.IsNullOrEmpty(basePath)) { basePath = Environment.CurrentDirectory; } foreach (PMAXPatch patch in patches.Patches) { PMAXPatchObjectModel patches2 = new PMAXPatchObjectModel(); patches2.Patches.Add(patch); MemoryAccessor mem = new MemoryAccessor(); Document.Save(patches2, new PMAXPatchBinaryDataFormat(), mem, true); byte[] patchBytes = mem.ToArray(); byte[] originalFileBytes = System.IO.File.ReadAllBytes(basePath + System.IO.Path.DirectorySeparatorChar.ToString() + patch.InputFileName); byte[] modifiedFileBytes = new byte[originalFileBytes.Length + patchBytes.Length]; Array.Copy(originalFileBytes, 0, modifiedFileBytes, 0, originalFileBytes.Length); Array.Copy(patchBytes, 0, modifiedFileBytes, originalFileBytes.Length, patchBytes.Length); System.IO.File.WriteAllBytes(basePath + System.IO.Path.DirectorySeparatorChar.ToString() + patch.OutputFileName, modifiedFileBytes); } }
public static MemoryAccessor CreateIndexMemoryAccessor(this IReadOnlyList <Int32> indices, Schema2.EncodingType encoding) { if (indices == null || indices.Count == 0) { return(null); } var attribute = new MemoryAccessInfo("INDEX", 0, indices.Count, 0, Schema2.DimensionType.SCALAR, encoding); // create buffer var ibytes = new Byte[encoding.ByteLength() * indices.Count]; var ibuffer = new ArraySegment <byte>(ibytes); // fill the buffer with indices. var accessor = new MemoryAccessor(ibuffer, attribute.Slice(0, indices.Count)); accessor.AsIntegerArray().Fill(indices); return(accessor); }