Decompiled source of BoneWheel v1.0.2
Mods/BoneWheel.dll
Decompiled 8 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BoneLib; using BoneLib.BoneMenu; using BoneLib.BoneMenu.Elements; using BoneWheel; using HarmonyLib; using MelonLoader; using SLZ.Marrow.Input; using SLZ.Marrow.Utilities; using SLZ.Vehicle; using SharpDX; using SharpDX.DirectInput; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: MelonInfo(typeof(global::BoneWheel.BoneWheel), "BoneWheel", "1.0.0", "Joe Swanson", null)] [assembly: MelonGame("Stress Level Zero", "BONELAB")] [assembly: AssemblyTitle("BoneWheel")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("BoneWheel")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("14e2b85a-240b-47f7-9a10-d150f0f20ada")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace BoneWheel { public static class BuildInfo { public const string Name = "BoneWheel"; public const string Author = "Joe Swanson"; public const string Version = "1.0.0"; } public class BoneWheel : MelonMod { private static DirectInput input = new DirectInput(); public static Joystick wheel = null; internal static MenuCategory category; internal static SubPanelElement settings; internal static Dictionary<string, object> Settings = new Dictionary<string, object> { { "Enabled", true }, { "MaxWheelAngle", 45 } }; private int i = 0; public static void DisposeWheel() { Joystick obj = wheel; if (obj != null) { ((DisposeBase)obj).Dispose(); } } public static void ReloadWheel() { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown DisposeWheel(); foreach (DeviceInstance device in input.GetDevices((DeviceType)22, (DeviceEnumerationFlags)0)) { wheel = new Joystick(input, device.InstanceGuid); ((Device)wheel).Acquire(); ((Device)wheel).Poll(); } } public override void OnInitializeMelon() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) category = MenuManager.CreateCategory("BoneWheel", new Color(0f, 238f, 255f)); settings = category.CreateSubPanel("Settings", new Color(255f, 155f, 0f)); settings.CreateBoolElement("Enabled", Color.white, true, (Action<bool>)delegate(bool value) { Settings["Enabled"] = value; }); IntElement val = settings.CreateIntElement("Max Wheel Angle", Color.white, 45, 5, 0, 900, (Action<int>)delegate(int value) { Settings["MaxWheelAngle"] = value; }); settings.CreateFunctionElement("Wheel Angle +1", Color.white, (Action)delegate { ((GenericElement<int>)(object)val).SetValue(((GenericElement<int>)(object)val).GetValue() + 1); }); settings.CreateFunctionElement("Reload Wheel", Color.yellow, (Action)delegate { ReloadWheel(); }); settings.CreateFunctionElement("(!) Dispose Wheel", Color.red, (Action)delegate { DisposeWheel(); }); settings.CreateFunctionElement("^ Disables Wheel Setup Functionality", Color.red, (Action)delegate { }); } public override void OnUpdate() { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Expected O, but got Unknown if (!(bool)Settings["Enabled"] || wheel != null) { return; } i++; if (i <= 30) { return; } foreach (DeviceInstance device in input.GetDevices((DeviceType)22, (DeviceEnumerationFlags)0)) { wheel = new Joystick(input, device.InstanceGuid); ((Device)wheel).Acquire(); ((Device)wheel).Poll(); } i = 0; } } } namespace BoneWheel.Patches { [HarmonyPatch(typeof(Atv))] internal class AtvPatches { private static XRApi xr = MarrowGame.xr; [HarmonyPatch("Update")] [HarmonyPostfix] public static void Postfix(Atv __instance) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Invalid comparison between Unknown and I4 //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) if ((bool)BoneWheel.Settings["Enabled"]) { if (xr == null && MarrowGame.xr != null) { xr = MarrowGame.xr; } if (BoneWheel.wheel != null && (int)__instance.driverSeat.seatState == 1) { Quaternion localRotation = ((Component)__instance.steeringWheel).gameObject.transform.localRotation; ((Component)__instance.steeringWheel).gameObject.transform.localRotation = Quaternion.Euler(((Quaternion)(ref localRotation)).eulerAngles.x, ((float)((CustomDevice<JoystickState, RawJoystickState, JoystickUpdate>)(object)BoneWheel.wheel).GetCurrentState().X - 32767f) / 32768f * (float)(int)BoneWheel.Settings["MaxWheelAngle"], ((Quaternion)(ref localRotation)).eulerAngles.z); JoystickState currentState = ((CustomDevice<JoystickState, RawJoystickState, JoystickUpdate>)(object)BoneWheel.wheel).GetCurrentState(); xr.RightController.Joystick2DAxis = new Vector2(float.Epsilon, (float)(0.0 - ((double)((float)currentState.Y / 65535f) - Math.Max(0.0, (double)((float)currentState.RotationZ / 65535f) * 2.5 - 1.5)))); } } } } [HarmonyPatch(typeof(XRController))] internal class XRControllerPatches { [HarmonyPatch(/*Could not decode attribute arguments.*/)] [HarmonyPrefix] public static bool Joystick2DAxisSetterPrefix(Vector2 value) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)Player.rigManager.activeSeat)) { if (value.x == float.Epsilon) { return true; } return false; } return true; } } }
UserLibs/SharpDX.DirectInput.dll
Decompiled 8 months ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Threading; using SharpDX.DirectInput; using SharpDX.IO; using SharpDX.Mathematics.Interop; using SharpDX.Multimedia; using SharpDX.Win32; [assembly: AssemblyTitle("SharpDX.DirectInput")] [assembly: AssemblyProduct("SharpDX.DirectInput")] [assembly: AssemblyInformationalVersion("4.2.0+8e5df9f17b1d328c595a9df5851dbb2537b55621")] [assembly: AssemblyFileVersion("4.2.0")] [assembly: AssemblyDescription("Assembly providing DirectX - DirectInput managed API.")] [assembly: AssemblyCopyright("Copyright (c) 2010-2016 Alexandre Mutel")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCompany("Alexandre Mutel")] [assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")] [assembly: ComVisible(false)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: NeutralResourcesLanguage("en-US")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("4.2.0.0")] [module: UnverifiableCode] internal class <Module> { static <Module>() { ModuleInit.Setup(); } } namespace SharpDX { internal class Win32Native { [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct TextMetric { public int tmHeight; public int tmAscent; public int tmDescent; public int tmInternalLeading; public int tmExternalLeading; public int tmAveCharWidth; public int tmMaxCharWidth; public int tmWeight; public int tmOverhang; public int tmDigitizedAspectX; public int tmDigitizedAspectY; public char tmFirstChar; public char tmLastChar; public char tmDefaultChar; public char tmBreakChar; public byte tmItalic; public byte tmUnderlined; public byte tmStruckOut; public byte tmPitchAndFamily; public byte tmCharSet; } public enum WindowLongType { WndProc = -4, HInstance = -6, HwndParent = -8, Style = -16, ExtendedStyle = -20, UserData = -21, Id = -12 } public delegate IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "CreateFile", SetLastError = true)] internal static extern IntPtr Create(string fileName, NativeFileAccess desiredAccess, NativeFileShare shareMode, IntPtr securityAttributes, NativeFileMode mode, NativeFileOptions flagsAndOptions, IntPtr templateFile); [DllImport("user32.dll")] public static extern int PeekMessage(out NativeMessage lpMsg, IntPtr hWnd, int wMsgFilterMin, int wMsgFilterMax, int wRemoveMsg); [DllImport("user32.dll")] public static extern int GetMessage(out NativeMessage lpMsg, IntPtr hWnd, int wMsgFilterMin, int wMsgFilterMax); [DllImport("user32.dll")] public static extern int TranslateMessage(ref NativeMessage lpMsg); [DllImport("user32.dll")] public static extern int DispatchMessage(ref NativeMessage lpMsg); public static IntPtr GetWindowLong(IntPtr hWnd, WindowLongType index) { if (IntPtr.Size == 4) { return GetWindowLong32(hWnd, index); } return GetWindowLong64(hWnd, index); } [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr GetFocus(); [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetWindowLong")] private static extern IntPtr GetWindowLong32(IntPtr hwnd, WindowLongType index); [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetWindowLongPtr")] private static extern IntPtr GetWindowLong64(IntPtr hwnd, WindowLongType index); public static IntPtr SetWindowLong(IntPtr hwnd, WindowLongType index, IntPtr wndProcPtr) { if (IntPtr.Size == 4) { return SetWindowLong32(hwnd, index, wndProcPtr); } return SetWindowLongPtr64(hwnd, index, wndProcPtr); } [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr SetParent(IntPtr hWnd, IntPtr hWndParent); [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "SetWindowLong")] private static extern IntPtr SetWindowLong32(IntPtr hwnd, WindowLongType index, IntPtr wndProc); public static bool ShowWindow(IntPtr hWnd, bool windowVisible) { return ShowWindow(hWnd, windowVisible ? 1 : 0); } [DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern bool ShowWindow(IntPtr hWnd, int mCmdShow); [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "SetWindowLongPtr")] private static extern IntPtr SetWindowLongPtr64(IntPtr hwnd, WindowLongType index, IntPtr wndProc); [DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll")] public static extern bool GetClientRect(IntPtr hWnd, out RawRectangle lpRect); [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr GetModuleHandle(string lpModuleName); } } namespace SharpDX.DirectInput { [CompilerGenerated] internal class AssemblyDoc { } public class Capabilities { internal struct __Native { public int Size; public DeviceFlags Flags; public int RawType; public int AxeCount; public int ButtonCount; public int PovCount; public int ForceFeedbackSamplePeriod; public int ForceFeedbackMinimumTimeResolution; public int FirmwareRevision; public int HardwareRevision; public int DriverVersion; internal void __MarshalFree() { } } internal int Size; public DeviceFlags Flags; internal int RawType; public int AxeCount; public int ButtonCount; public int PovCount; public int ForceFeedbackSamplePeriod; public int ForceFeedbackMinimumTimeResolution; public int FirmwareRevision; public int HardwareRevision; public int DriverVersion; public DeviceType Type => (DeviceType)(RawType & 0xFF); public int Subtype => RawType >> 8; public bool IsHumanInterfaceDevice => (RawType & 0x10000) != 0; public unsafe Capabilities() { Size = sizeof(__Native); } internal unsafe static __Native __NewNative() { __Native result = default(__Native); result.Size = sizeof(__Native); return result; } internal void __MarshalFree(ref __Native @ref) { @ref.__MarshalFree(); } internal void __MarshalFrom(ref __Native @ref) { Size = @ref.Size; Flags = @ref.Flags; RawType = @ref.RawType; AxeCount = @ref.AxeCount; ButtonCount = @ref.ButtonCount; PovCount = @ref.PovCount; ForceFeedbackSamplePeriod = @ref.ForceFeedbackSamplePeriod; ForceFeedbackMinimumTimeResolution = @ref.ForceFeedbackMinimumTimeResolution; FirmwareRevision = @ref.FirmwareRevision; HardwareRevision = @ref.HardwareRevision; DriverVersion = @ref.DriverVersion; } internal void __MarshalTo(ref __Native @ref) { @ref.Size = Size; @ref.Flags = Flags; @ref.RawType = RawType; @ref.AxeCount = AxeCount; @ref.ButtonCount = ButtonCount; @ref.PovCount = PovCount; @ref.ForceFeedbackSamplePeriod = ForceFeedbackSamplePeriod; @ref.ForceFeedbackMinimumTimeResolution = ForceFeedbackMinimumTimeResolution; @ref.FirmwareRevision = FirmwareRevision; @ref.HardwareRevision = HardwareRevision; @ref.DriverVersion = DriverVersion; } } public class ConditionSet : TypeSpecificParameters { public Condition[] Conditions { get; set; } public unsafe override int Size { get { if (Conditions == null) { return 0; } return Conditions.Length * sizeof(Condition); } } protected unsafe override TypeSpecificParameters MarshalFrom(int bufferSize, IntPtr bufferPointer) { if (bufferSize <= 0 || bufferSize % sizeof(Condition) != 0) { return null; } int num = bufferSize / sizeof(Condition); Conditions = new Condition[num]; Utilities.Read<Condition>(bufferPointer, Conditions, 0, Conditions.Length); return this; } internal override IntPtr MarshalTo() { if (Size == 0) { return IntPtr.Zero; } IntPtr intPtr = Marshal.AllocHGlobal(Size); Utilities.Write<Condition>(intPtr, Conditions, 0, Conditions.Length); return intPtr; } } public class ConstantForce : TypeSpecificParameters { public int Magnitude { get; set; } public override int Size => Utilities.SizeOf<RawConstantForce>(); protected unsafe override TypeSpecificParameters MarshalFrom(int bufferSize, IntPtr bufferPointer) { if (bufferSize != sizeof(RawConstantForce)) { return null; } Magnitude = ((RawConstantForce*)(void*)bufferPointer)->Magnitude; return this; } internal unsafe override IntPtr MarshalTo() { IntPtr intPtr = Marshal.AllocHGlobal(Size); ((RawConstantForce*)(void*)intPtr)->Magnitude = Magnitude; return intPtr; } } public abstract class CustomDevice<T, TRaw, TUpdate> : Device where T : class, IDeviceState<TRaw, TUpdate>, new() where TRaw : struct where TUpdate : struct, IStateUpdate { private DataFormat _dataFormat; private readonly Dictionary<string, DataObjectFormat> _mapNameToObjectFormat = new Dictionary<string, DataObjectFormat>(); private static readonly TUpdate[] singletonEmptyArray = new TUpdate[0]; protected CustomDevice(IntPtr nativePtr) : base(nativePtr) { } protected CustomDevice(DirectInput directInput, Guid deviceGuid) : base(directInput, deviceGuid) { DataFormat dataFormat = GetDataFormat(); SetDataFormat(dataFormat); } public unsafe TUpdate[] GetBufferedData() { TUpdate[] result = singletonEmptyArray; int arg = Utilities.SizeOf<ObjectData>(); int arg2 = -1; GetDeviceData(arg, IntPtr.Zero, ref arg2, 1); if (arg2 == 0) { return result; } ObjectData* ptr = stackalloc ObjectData[arg2]; GetDeviceData(arg, (IntPtr)ptr, ref arg2, 0); if (arg2 == 0) { return result; } result = new TUpdate[arg2]; for (int i = 0; i < arg2; i++) { result[i] = new TUpdate { RawOffset = ptr[i].Offset, Value = ptr[i].Data, Timestamp = ptr[i].TimeStamp, Sequence = ptr[i].Sequence }; } return result; } public T GetCurrentState() { T data = new T(); GetCurrentState(ref data); return data; } public unsafe void GetCurrentState(ref T data) { int num = Utilities.SizeOf<TRaw>(); byte* ptr = stackalloc byte[(int)(uint)(num * 2)]; TRaw value = default(TRaw); GetDeviceState(num, (IntPtr)ptr); Utilities.Read<TRaw>((IntPtr)ptr, ref value); data.MarshalFrom(ref value); } public DeviceObjectInstance GetObjectInfoByName(string name) { return GetObjectInfo(GetFromName(name).Offset, PropertyHowType.Byoffset); } public DeviceObjectInstance GetObjectInfoByOffset(int offset) { return GetObjectInfo(offset, PropertyHowType.Byoffset); } public ObjectProperties GetObjectPropertiesByName(string name) { return new ObjectProperties(this, GetFromName(name).Offset, PropertyHowType.Byoffset); } private DataObjectFormat GetFromName(string name) { if (!_mapNameToObjectFormat.TryGetValue(name, out var value)) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid name [{0}]. Must be in [{1}]", new object[2] { name, Utilities.Join(";", (IEnumerable)_mapNameToObjectFormat.Keys) })); } return value; } private DataFormat GetDataFormat() { if (_dataFormat == null) { if (typeof(IDataFormatProvider).GetTypeInfo().IsAssignableFrom(typeof(TRaw).GetTypeInfo())) { IDataFormatProvider dataFormatProvider = (IDataFormatProvider)(object)new TRaw(); _dataFormat = new DataFormat(dataFormatProvider.Flags) { DataSize = Utilities.SizeOf<TRaw>(), ObjectsFormat = dataFormatProvider.ObjectsFormat }; } else { IEnumerable<DataFormatAttribute> customAttributes = typeof(TRaw).GetTypeInfo().GetCustomAttributes<DataFormatAttribute>(inherit: false); if (customAttributes.Count() != 1) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The structure [{0}] must be marked with DataFormatAttribute or provide a IDataFormatProvider", new object[1] { typeof(TRaw).FullName })); } _dataFormat = new DataFormat(customAttributes.First().Flags) { DataSize = Utilities.SizeOf<TRaw>() }; List<DataObjectFormat> list = new List<DataObjectFormat>(); foreach (FieldInfo item in (IEnumerable<FieldInfo>)typeof(TRaw).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { IEnumerable<DataObjectFormatAttribute> customAttributes2 = item.GetCustomAttributes<DataObjectFormatAttribute>(inherit: false); if (customAttributes2.Count() <= 0) { continue; } int num = Marshal.OffsetOf(typeof(TRaw), item.Name).ToInt32(); int num2 = Marshal.SizeOf(item.FieldType); int num3 = num; int num4 = 0; for (int i = 0; i < customAttributes2.Count(); i++) { DataObjectFormatAttribute dataObjectFormatAttribute = customAttributes2.ElementAt(i); num4 += ((dataObjectFormatAttribute.ArrayCount == 0) ? 1 : dataObjectFormatAttribute.ArrayCount); } int num5 = num2 / num4; if (num5 * num4 != num2) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Field [{0}] has incompatible size [{1}] and number of DataObjectAttributes [{2}]", new object[3] { item.Name, (double)num2 / (double)num4, num4 })); } int num6 = 0; for (int j = 0; j < customAttributes2.Count(); j++) { DataObjectFormatAttribute dataObjectFormatAttribute2 = customAttributes2.ElementAt(j); num4 = ((dataObjectFormatAttribute2.ArrayCount == 0) ? 1 : dataObjectFormatAttribute2.ArrayCount); for (int k = 0; k < num4; k++) { DataObjectFormat dataObjectFormat = new DataObjectFormat(string.IsNullOrEmpty(dataObjectFormatAttribute2.Guid) ? Guid.Empty : new Guid(dataObjectFormatAttribute2.Guid), num3, dataObjectFormatAttribute2.TypeFlags, dataObjectFormatAttribute2.Flags, dataObjectFormatAttribute2.InstanceNumber); string text = (string.IsNullOrEmpty(dataObjectFormatAttribute2.Name) ? item.Name : dataObjectFormatAttribute2.Name); text = ((num4 == 1) ? text : (text + num6)); dataObjectFormat.Name = text; list.Add(dataObjectFormat); num3 += num5; num6++; } } } _dataFormat.ObjectsFormat = list.ToArray(); } for (int l = 0; l < _dataFormat.ObjectsFormat.Length; l++) { DataObjectFormat dataObjectFormat2 = _dataFormat.ObjectsFormat[l]; if (_mapNameToObjectFormat.ContainsKey(dataObjectFormat2.Name)) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Incorrect field name [{0}]. Field name must be unique", new object[1] { dataObjectFormat2.Name })); } _mapNameToObjectFormat.Add(dataObjectFormat2.Name, dataObjectFormat2); } } return _dataFormat; } private unsafe void DumpDataFormat(DataFormat format) { DataFormat.__Native @ref = default(DataFormat.__Native); format.__MarshalTo(ref @ref); string name = typeof(TRaw).Name; Console.WriteLine("{0}.dwSize {1}", name, @ref.Size); Console.WriteLine("{0}.dwObjSize {1}", name, @ref.ObjectSize); Console.WriteLine("{0}.dwFlags {1} ({2})", name, (int)@ref.Flags, @ref.Flags); Console.WriteLine("{0}.dwDataSize {1}", name, @ref.DataSize); Console.WriteLine("{0}.dwNumObjs {1}", name, @ref.ObjectArrayCount); Console.WriteLine("{4,32};{0,38};{1,8},{2,8};{3,8}", "Guid", "Offset", "Type", "Flags", "Name"); DataObjectFormat.__Native* ptr = (DataObjectFormat.__Native*)(void*)@ref.ObjectArrayPointer; for (int i = 0; i < @ref.ObjectArrayCount; i++) { DataObjectFormat.__Native _Native = ptr[i]; string text = ((_Native.GuidPointer == IntPtr.Zero) ? "" : ((Guid*)(void*)_Native.GuidPointer)->ToString()); Console.WriteLine("{5,32};{0,38};{1,8},{2:X8};{3:X8} ({4})", text, _Native.Offset, _Native.Type, (int)_Native.Flags, _Native.Flags, format.ObjectsFormat[i].Name); } Console.WriteLine(); } } public class CustomForce : TypeSpecificParameters { public int ChannelCount { get; set; } public int SamplePeriod { get; set; } public int SampleCount { get; set; } public int[] ForceData { get; set; } public override int Size => Utilities.SizeOf<RawCustomForce>(); protected unsafe override TypeSpecificParameters MarshalFrom(int bufferSize, IntPtr bufferPointer) { if (bufferSize != sizeof(RawCustomForce)) { return null; } ChannelCount = ((RawCustomForce*)(void*)bufferPointer)->Channels; SamplePeriod = ((RawCustomForce*)(void*)bufferPointer)->SamplePeriod; SampleCount = ((RawCustomForce*)(void*)bufferPointer)->Samples; ForceData = new int[SampleCount]; Utilities.Read<int>(((RawCustomForce*)(void*)bufferPointer)->ForceDataPointer, ForceData, 0, ForceData.Length); return this; } internal unsafe override IntPtr MarshalTo() { IntPtr intPtr = Marshal.AllocHGlobal(Size); ((RawCustomForce*)(void*)intPtr)->Channels = ChannelCount; ((RawCustomForce*)(void*)intPtr)->SamplePeriod = SamplePeriod; ((RawCustomForce*)(void*)intPtr)->Samples = SampleCount; IntPtr intPtr2 = Marshal.AllocHGlobal(ForceData.Length * 4); ((RawCustomForce*)(void*)intPtr)->ForceDataPointer = intPtr2; Utilities.Write<int>(intPtr2, ForceData, 0, ForceData.Length); return intPtr; } internal unsafe override void MarshalFree(IntPtr bufferPointer) { base.MarshalFree(bufferPointer); if (bufferPointer != IntPtr.Zero) { Marshal.FreeHGlobal(((RawCustomForce*)(void*)bufferPointer)->ForceDataPointer); } } } internal class DataFormat { internal struct __Native { public int Size; public int ObjectSize; public DataFormatFlag Flags; public int DataSize; public int ObjectArrayCount; public IntPtr ObjectArrayPointer; internal void __MarshalFree() { } } internal int Size; internal int ObjectSize; public DataFormatFlag Flags; public int DataSize; internal int ObjectArrayCount; internal IntPtr ObjectArrayPointer; public DataObjectFormat[] ObjectsFormat { get; set; } public DataFormat(DataFormatFlag flags) { Size = Utilities.SizeOf<__Native>(); ObjectSize = Utilities.SizeOf<DataObjectFormat.__Native>(); Flags = flags; } public unsafe DataFormat() { Size = sizeof(__Native); ObjectSize = sizeof(DataObjectFormat.__Native); } internal unsafe static __Native __NewNative() { __Native result = default(__Native); result.Size = sizeof(__Native); result.ObjectSize = sizeof(DataObjectFormat.__Native); return result; } internal void __MarshalFree(ref __Native @ref) { @ref.__MarshalFree(); } internal void __MarshalFrom(ref __Native @ref) { Size = @ref.Size; ObjectSize = @ref.ObjectSize; Flags = @ref.Flags; DataSize = @ref.DataSize; ObjectArrayCount = @ref.ObjectArrayCount; ObjectArrayPointer = @ref.ObjectArrayPointer; } internal void __MarshalTo(ref __Native @ref) { @ref.Size = Size; @ref.ObjectSize = ObjectSize; @ref.Flags = Flags; @ref.DataSize = DataSize; @ref.ObjectArrayCount = 0; @ref.ObjectArrayPointer = IntPtr.Zero; if (ObjectsFormat != null && ObjectsFormat.Length != 0) { @ref.ObjectArrayCount = ObjectsFormat.Length; DataObjectFormat.__Native[] array = new DataObjectFormat.__Native[ObjectsFormat.Length]; for (int i = 0; i < ObjectsFormat.Length; i++) { ObjectsFormat[i].__MarshalTo(ref array[i]); } @ref.ObjectArrayPointer = GCHandle.Alloc(array, GCHandleType.Pinned).AddrOfPinnedObject(); } } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)] public sealed class DataFormatAttribute : Attribute { public DataFormatFlag Flags; public DataFormatAttribute(DataFormatFlag flags) { Flags = flags; } } public class DataObjectFormat { internal struct __Native { public IntPtr GuidPointer; public int Offset; public int Type; public ObjectDataFormatFlags Flags; internal void __MarshalFree() { } } public string Name { get; set; } public Guid Guid { get; set; } public int Offset { get; set; } public DeviceObjectTypeFlags TypeFlags { get; set; } public int InstanceNumber { get; set; } public ObjectDataFormatFlags Flags { get; set; } public DataObjectFormat() { } public DataObjectFormat(Guid guid, int offset, DeviceObjectTypeFlags typeFlags, ObjectDataFormatFlags flags) : this(guid, offset, typeFlags, flags, 0) { } public DataObjectFormat(Guid guid, int offset, DeviceObjectTypeFlags typeFlags, ObjectDataFormatFlags flags, int instanceNumber) { Guid = guid; Offset = offset; TypeFlags = typeFlags; InstanceNumber = instanceNumber; Flags = flags; } internal void __MarshalFree(ref __Native @ref) { @ref.__MarshalFree(); } internal void __MarshalFrom(ref __Native @ref) { Offset = @ref.Offset; TypeFlags = (DeviceObjectTypeFlags)@ref.Type; if ((TypeFlags & DeviceObjectTypeFlags.AnyInstance) != DeviceObjectTypeFlags.AnyInstance) { TypeFlags = (DeviceObjectTypeFlags)(@ref.Type & 0xFF0000FFu); InstanceNumber = (@ref.Type >> 8) & 0xFFFF; } Flags = @ref.Flags; } internal void __MarshalTo(ref __Native @ref) { @ref.Offset = Offset; @ref.Type = (int)TypeFlags | ((((TypeFlags & DeviceObjectTypeFlags.AnyInstance) != DeviceObjectTypeFlags.AnyInstance) ? InstanceNumber : 0) << 8); @ref.Flags = Flags; if (Guid == Guid.Empty) { @ref.GuidPointer = IntPtr.Zero; } else { @ref.GuidPointer = GCHandle.Alloc(Guid, GCHandleType.Pinned).AddrOfPinnedObject(); } } } [AttributeUsage(AttributeTargets.Field)] public sealed class DataObjectFormatAttribute : Attribute { public string Name; public string Guid; public int ArrayCount; public DeviceObjectTypeFlags TypeFlags; public ObjectDataFormatFlags Flags; public int InstanceNumber; public DataObjectFormatAttribute() { Flags = ObjectDataFormatFlags.None; InstanceNumber = 0; Guid = ""; TypeFlags = DeviceObjectTypeFlags.All; } public DataObjectFormatAttribute(string guid, DeviceObjectTypeFlags typeFlags) { Guid = guid; TypeFlags = typeFlags; Flags = ObjectDataFormatFlags.None; InstanceNumber = 0; ArrayCount = 0; } public DataObjectFormatAttribute(string guid, DeviceObjectTypeFlags typeFlags, ObjectDataFormatFlags flags) { Guid = guid; TypeFlags = typeFlags; Flags = flags; } public DataObjectFormatAttribute(string guid, DeviceObjectTypeFlags typeFlags, ObjectDataFormatFlags flags, int instanceNumber) { Guid = guid; TypeFlags = typeFlags; Flags = flags; InstanceNumber = instanceNumber; } public DataObjectFormatAttribute(string guid, int arrayCount, DeviceObjectTypeFlags typeFlags, ObjectDataFormatFlags flags) { Guid = guid; ArrayCount = arrayCount; TypeFlags = typeFlags; Flags = flags; } public DataObjectFormatAttribute(string guid, int arrayCount, DeviceObjectTypeFlags typeFlags) { Guid = guid; ArrayCount = arrayCount; TypeFlags = typeFlags; Flags = ObjectDataFormatFlags.None; } public DataObjectFormatAttribute(DeviceObjectTypeFlags typeFlags) { TypeFlags = typeFlags; Flags = ObjectDataFormatFlags.None; InstanceNumber = 0; ArrayCount = 0; } public DataObjectFormatAttribute(DeviceObjectTypeFlags typeFlags, ObjectDataFormatFlags flags) { TypeFlags = typeFlags; Flags = flags; } public DataObjectFormatAttribute(DeviceObjectTypeFlags typeFlags, ObjectDataFormatFlags flags, int instanceNumber) { TypeFlags = typeFlags; Flags = flags; InstanceNumber = instanceNumber; } public DataObjectFormatAttribute(int arrayCount, DeviceObjectTypeFlags typeFlags) { ArrayCount = arrayCount; TypeFlags = typeFlags; Flags = ObjectDataFormatFlags.None; } public DataObjectFormatAttribute(int arrayCount, DeviceObjectTypeFlags typeFlags, ObjectDataFormatFlags flags) { ArrayCount = arrayCount; TypeFlags = typeFlags; Flags = flags; } public DataObjectFormatAttribute(int arrayCount, DeviceObjectTypeFlags typeFlags, ObjectDataFormatFlags flags, int instanceNumber) { ArrayCount = arrayCount; TypeFlags = typeFlags; Flags = flags; InstanceNumber = instanceNumber; } public DataObjectFormatAttribute(int arrayCount, DeviceObjectTypeFlags typeFlags, int instanceNumber) { ArrayCount = arrayCount; TypeFlags = typeFlags; Flags = ObjectDataFormatFlags.None; InstanceNumber = instanceNumber; } } [Guid("54d41081-dc15-4833-a41b-748f73a38179")] public class Device : ComObject { private DeviceProperties _properties; public DeviceProperties Properties { get { if (_properties == null) { _properties = new DeviceProperties(this); } return _properties; } } public IList<Effect> CreatedEffects { get { EnumCreatedEffectsCallback enumCreatedEffectsCallback = new EnumCreatedEffectsCallback(); EnumCreatedEffectObjects(FunctionCallback.op_Implicit(enumCreatedEffectsCallback.NativePointer), IntPtr.Zero, 0); return enumCreatedEffectsCallback.Effects; } } public Capabilities Capabilities { get { GetCapabilities(out var arg); return arg; } } public DeviceInstance Information { get { GetInformation(out var arg); return arg; } } protected Device(DirectInput directInput, Guid deviceGuid) { directInput.CreateDevice(deviceGuid, out var arg, null); ((CppObject)this).NativePointer = arg; } public unsafe int Escape(int command, byte[] inData, byte[] outData) { EffectEscape arg = default(EffectEscape); fixed (byte* ptr = &inData[0]) { void* ptr2 = ptr; fixed (byte* ptr3 = &outData[0]) { void* ptr4 = ptr3; arg.Size = sizeof(EffectEscape); arg.Command = command; arg.InBufferPointer = (IntPtr)ptr2; arg.InBufferSize = inData.Length; arg.OutBufferPointer = (IntPtr)ptr4; arg.OutBufferSize = outData.Length; Escape(ref arg); return arg.OutBufferSize; } } } public unsafe DeviceImageHeader GetDeviceImages() { DeviceImageHeader deviceImageHeader = new DeviceImageHeader(); GetImageInfo(deviceImageHeader); if (deviceImageHeader.BufferUsed > 0) { deviceImageHeader.BufferSize = deviceImageHeader.BufferUsed; DeviceImage.__Native* ptr = stackalloc DeviceImage.__Native[deviceImageHeader.BufferSize / System.Runtime.CompilerServices.Unsafe.SizeOf<DeviceImage.__Native>()]; deviceImageHeader.ImageInfoArrayPointer = (IntPtr)ptr; GetImageInfo(deviceImageHeader); } return deviceImageHeader; } public IList<EffectInfo> GetEffects() { return GetEffects(EffectType.All); } public IList<EffectInfo> GetEffects(EffectType effectType) { EnumEffectsCallback enumEffectsCallback = new EnumEffectsCallback(); EnumEffects(FunctionCallback.op_Implicit(enumEffectsCallback.NativePointer), IntPtr.Zero, effectType); return enumEffectsCallback.EffectInfos; } public IList<EffectFile> GetEffectsInFile(string fileName) { return GetEffectsInFile(fileName, EffectFileFlags.None); } public IList<EffectFile> GetEffectsInFile(string fileName, EffectFileFlags effectFileFlags) { EnumEffectsInFileCallback enumEffectsInFileCallback = new EnumEffectsInFileCallback(); EnumEffectsInFile(fileName, FunctionCallback.op_Implicit(enumEffectsInFileCallback.NativePointer), IntPtr.Zero, effectFileFlags); return enumEffectsInFileCallback.EffectsInFile; } public DeviceObjectInstance GetObjectInfoById(DeviceObjectId objectId) { return GetObjectInfo((int)objectId, PropertyHowType.Byid); } public DeviceObjectInstance GetObjectInfoByUsage(int usageCode) { return GetObjectInfo(usageCode, PropertyHowType.Byusage); } public ObjectProperties GetObjectPropertiesById(DeviceObjectId objectId) { return new ObjectProperties(this, (int)objectId, PropertyHowType.Byid); } public ObjectProperties GetObjectPropertiesByUsage(int usageCode) { return new ObjectProperties(this, usageCode, PropertyHowType.Byusage); } public IList<DeviceObjectInstance> GetObjects() { return GetObjects(DeviceObjectTypeFlags.All); } public IList<DeviceObjectInstance> GetObjects(DeviceObjectTypeFlags deviceObjectTypeFlag) { EnumObjectsCallback enumObjectsCallback = new EnumObjectsCallback(); EnumObjects(FunctionCallback.op_Implicit(enumObjectsCallback.NativePointer), IntPtr.Zero, (int)deviceObjectTypeFlag); return enumObjectsCallback.Objects; } public void RunControlPanel() { RunControlPanel(IntPtr.Zero, 0); } public void RunControlPanel(IntPtr parentHwnd) { RunControlPanel(parentHwnd, 0); } public void SetNotification(WaitHandle eventHandle) { SetEventNotification((eventHandle?.SafeWaitHandle)?.DangerousGetHandle() ?? IntPtr.Zero); } public void WriteEffectsToFile(string fileName, EffectFile[] effects) { WriteEffectsToFile(fileName, effects, includeNonstandardEffects: false); } public void WriteEffectsToFile(string fileName, EffectFile[] effects, bool includeNonstandardEffects) { WriteEffectToFile(fileName, effects.Length, effects, includeNonstandardEffects ? 1 : 0); } public Device(IntPtr nativePtr) : base(nativePtr) { } public static explicit operator Device(IntPtr nativePointer) { if (!(nativePointer == IntPtr.Zero)) { return new Device(nativePointer); } return null; } internal unsafe void GetCapabilities(out Capabilities arg0) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) Capabilities.__Native @ref = Capabilities.__NewNative(); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)3 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &@ref)); arg0 = new Capabilities(); arg0.__MarshalFrom(ref @ref); ((Result)(ref val)).CheckError(); } internal unsafe void EnumObjects(FunctionCallback arg0, IntPtr arg1, int arg2) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)4 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, FunctionCallback.op_Implicit(arg0), (void*)arg1, arg2)); ((Result)(ref val)).CheckError(); } internal unsafe void GetProperty(IntPtr arg0, IntPtr arg1) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)5 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)arg0, (void*)arg1)); ((Result)(ref val)).CheckError(); } internal unsafe void SetProperty(IntPtr arg0, IntPtr arg1) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)6 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)arg0, (void*)arg1)); ((Result)(ref val)).CheckError(); } public unsafe void Acquire() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)7 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer)); ((Result)(ref val)).CheckError(); } public unsafe void Unacquire() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)8 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer)); ((Result)(ref val)).CheckError(); } internal unsafe void GetDeviceState(int arg0, IntPtr arg1) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)9 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, arg0, (void*)arg1)); ((Result)(ref val)).CheckError(); } internal unsafe void GetDeviceData(int arg0, IntPtr arg1, ref int arg2, int arg3) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) Result val; fixed (int* ptr = &arg2) { void* ptr2 = ptr; val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int, void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)10 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, arg0, (void*)arg1, ptr2, arg3)); } ((Result)(ref val)).CheckError(); } internal unsafe void SetDataFormat(DataFormat arg0) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) DataFormat.__Native @ref = DataFormat.__NewNative(); arg0.__MarshalTo(ref @ref); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)11 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &@ref)); arg0.__MarshalFree(ref @ref); ((Result)(ref val)).CheckError(); } internal unsafe void SetEventNotification(IntPtr arg0) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)12 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)arg0)); ((Result)(ref val)).CheckError(); } public unsafe void SetCooperativeLevel(IntPtr arg0, CooperativeLevel arg1) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)13 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)arg0, (int)arg1)); ((Result)(ref val)).CheckError(); } internal unsafe DeviceObjectInstance GetObjectInfo(int arg1, PropertyHowType arg2) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) DeviceObjectInstance.__Native @ref = DeviceObjectInstance.__NewNative(); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)14 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &@ref, arg1, (int)arg2)); DeviceObjectInstance deviceObjectInstance = new DeviceObjectInstance(); deviceObjectInstance.__MarshalFrom(ref @ref); ((Result)(ref val)).CheckError(); return deviceObjectInstance; } internal unsafe void GetInformation(out DeviceInstance arg0) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) DeviceInstance.__Native @ref = DeviceInstance.__NewNative(); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)15 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &@ref)); arg0 = new DeviceInstance(); arg0.__MarshalFrom(ref @ref); ((Result)(ref val)).CheckError(); } internal unsafe void RunControlPanel(IntPtr arg0, int arg1) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)16 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)arg0, arg1)); ((Result)(ref val)).CheckError(); } internal unsafe void Initialize(IntPtr arg0, int arg1, Guid arg2) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)17 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)arg0, arg1, &arg2)); ((Result)(ref val)).CheckError(); } internal unsafe void CreateEffect(Guid arg0, EffectParameters arg1, Effect arg2, ComObject arg3) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) EffectParameters.__Native @ref = EffectParameters.__NewNative(); arg1.__MarshalTo(ref @ref); IntPtr zero = IntPtr.Zero; void* nativePointer = ((CppObject)this)._nativePointer; Guid* num = &arg0; EffectParameters.__Native* num2 = &@ref; IntPtr* num3 = &zero; IntPtr intPtr = ((arg3 == null) ? IntPtr.Zero : ((CppObject)arg3).NativePointer); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)18 * (nint)sizeof(void*))))(nativePointer, num, num2, num3, (void*)intPtr)); arg1.__MarshalFree(ref @ref); ((CppObject)arg2).NativePointer = zero; ((Result)(ref val)).CheckError(); } internal unsafe void EnumEffects(FunctionCallback arg0, IntPtr arg1, EffectType arg2) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)19 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, FunctionCallback.op_Implicit(arg0), (void*)arg1, (int)arg2)); ((Result)(ref val)).CheckError(); } public unsafe EffectInfo GetEffectInfo(Guid arg1) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) EffectInfo.__Native @ref = EffectInfo.__NewNative(); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)20 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &@ref, &arg1)); EffectInfo effectInfo = new EffectInfo(); effectInfo.__MarshalFrom(ref @ref); ((Result)(ref val)).CheckError(); return effectInfo; } public unsafe ForceFeedbackState GetForceFeedbackState() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) ForceFeedbackState result = default(ForceFeedbackState); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)21 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &result)); ((Result)(ref val)).CheckError(); return result; } public unsafe void SendForceFeedbackCommand(ForceFeedbackCommand arg0) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)22 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (int)arg0)); ((Result)(ref val)).CheckError(); } internal unsafe void EnumCreatedEffectObjects(FunctionCallback arg0, IntPtr arg1, int arg2) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)23 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, FunctionCallback.op_Implicit(arg0), (void*)arg1, arg2)); ((Result)(ref val)).CheckError(); } internal unsafe void Escape(ref EffectEscape arg0) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Result val; fixed (EffectEscape* ptr = &arg0) { void* ptr2 = ptr; val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)24 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, ptr2)); } ((Result)(ref val)).CheckError(); } public unsafe void Poll() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)25 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer)); ((Result)(ref val)).CheckError(); } internal unsafe void SendDeviceData(int arg0, ObjectData[] arg1, ref int arg2, int arg3) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) Result val; fixed (ObjectData* ptr = arg1) { void* ptr2 = ptr; fixed (int* ptr3 = &arg2) { void* ptr4 = ptr3; val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int, void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)26 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, arg0, ptr2, ptr4, arg3)); } } ((Result)(ref val)).CheckError(); } internal unsafe void EnumEffectsInFile(string arg0, FunctionCallback arg1, IntPtr arg2, EffectFileFlags arg3) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) IntPtr intPtr = Utilities.StringToHGlobalUni(arg0); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)27 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)intPtr, FunctionCallback.op_Implicit(arg1), (void*)arg2, (int)arg3)); Marshal.FreeHGlobal(intPtr); ((Result)(ref val)).CheckError(); } public unsafe void WriteEffectToFile(string arg0, int arg1, EffectFile[] arg2, int arg3) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) IntPtr intPtr = Utilities.StringToHGlobalUni(arg0); EffectFile.__Native[] array = new EffectFile.__Native[arg2.Length]; for (int i = 0; i < arg2.Length; i++) { arg2[i].__MarshalTo(ref array[i]); } Result val; fixed (EffectFile.__Native* ptr = array) { void* ptr2 = ptr; val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)28 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)intPtr, arg1, ptr2, arg3)); } Marshal.FreeHGlobal(intPtr); for (int j = 0; j < arg2.Length; j++) { arg2[j].__MarshalFree(ref array[j]); } ((Result)(ref val)).CheckError(); } internal unsafe void BuildActionMap(ref ActionFormat arg0, string arg1, int arg2) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) ActionFormat.__Native @ref = default(ActionFormat.__Native); arg0.__MarshalTo(ref @ref); IntPtr intPtr = Utilities.StringToHGlobalUni(arg1); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)29 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &@ref, (void*)intPtr, arg2)); arg0.__MarshalFree(ref @ref); Marshal.FreeHGlobal(intPtr); ((Result)(ref val)).CheckError(); } internal unsafe void SetActionMap(ref ActionFormat arg0, string arg1, int arg2) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) ActionFormat.__Native @ref = default(ActionFormat.__Native); arg0.__MarshalTo(ref @ref); IntPtr intPtr = Utilities.StringToHGlobalUni(arg1); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)30 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &@ref, (void*)intPtr, arg2)); arg0.__MarshalFree(ref @ref); Marshal.FreeHGlobal(intPtr); ((Result)(ref val)).CheckError(); } internal unsafe void GetImageInfo(DeviceImageHeader arg0) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) DeviceImageHeader.__Native @ref = DeviceImageHeader.__NewNative(); arg0.__MarshalTo(ref @ref); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)31 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &@ref)); arg0.__MarshalFrom(ref @ref); arg0.__MarshalFree(ref @ref); ((Result)(ref val)).CheckError(); } } public enum DeviceDataFormat { Keyboard, Mouse, Joystick } public class DeviceImageHeader { internal struct __Native { public int Size; public int SizeImageInfo; public int ViewCount; public int ButtonCount; public int AxeCount; public int PovCount; public int BufferSize; public int BufferUsed; public IntPtr ImageInfoArrayPointer; } internal int Size; internal int SizeImageInfo; public int ViewCount; public int ButtonCount; public int AxeCount; public int PovCount; internal int BufferSize; internal int BufferUsed; internal IntPtr ImageInfoArrayPointer; public DeviceImage[] Images { get; private set; } public unsafe DeviceImageHeader() { Size = sizeof(__Native); SizeImageInfo = System.Runtime.CompilerServices.Unsafe.SizeOf<DeviceImage.__Native>(); } internal unsafe static __Native __NewNative() { __Native result = default(__Native); result.Size = sizeof(__Native); result.SizeImageInfo = System.Runtime.CompilerServices.Unsafe.SizeOf<DeviceImage.__Native>(); return result; } internal void __MarshalFree(ref __Native @ref) { } internal unsafe void __MarshalFrom(ref __Native @ref) { Size = @ref.Size; SizeImageInfo = @ref.SizeImageInfo; ViewCount = @ref.ViewCount; ButtonCount = @ref.ButtonCount; AxeCount = @ref.AxeCount; PovCount = @ref.PovCount; BufferSize = @ref.BufferSize; BufferUsed = @ref.BufferUsed; ImageInfoArrayPointer = @ref.ImageInfoArrayPointer; if (BufferSize > 0 && ImageInfoArrayPointer != IntPtr.Zero) { int num = BufferSize / System.Runtime.CompilerServices.Unsafe.SizeOf<DeviceImage.__Native>(); Images = new DeviceImage[num]; DeviceImage.__Native* ptr = (DeviceImage.__Native*)(void*)ImageInfoArrayPointer; for (int i = 0; i < Images.Length; i++) { default(DeviceImage).__MarshalFrom(ref *ptr); ptr++; } } } internal void __MarshalTo(ref __Native @ref) { @ref.Size = Size; @ref.SizeImageInfo = SizeImageInfo; @ref.ViewCount = ViewCount; @ref.ButtonCount = ButtonCount; @ref.AxeCount = AxeCount; @ref.PovCount = PovCount; @ref.BufferSize = BufferSize; @ref.BufferUsed = BufferUsed; @ref.ImageInfoArrayPointer = ImageInfoArrayPointer; } } public class DeviceInstance { internal struct __Native { public int Size; public Guid InstanceGuid; public Guid ProductGuid; public int RawType; public char InstanceName; private char __InstanceName1; private char __InstanceName2; private char __InstanceName3; private char __InstanceName4; private char __InstanceName5; private char __InstanceName6; private char __InstanceName7; private char __InstanceName8; private char __InstanceName9; private char __InstanceName10; private char __InstanceName11; private char __InstanceName12; private char __InstanceName13; private char __InstanceName14; private char __InstanceName15; private char __InstanceName16; private char __InstanceName17; private char __InstanceName18; private char __InstanceName19; private char __InstanceName20; private char __InstanceName21; private char __InstanceName22; private char __InstanceName23; private char __InstanceName24; private char __InstanceName25; private char __InstanceName26; private char __InstanceName27; private char __InstanceName28; private char __InstanceName29; private char __InstanceName30; private char __InstanceName31; private char __InstanceName32; private char __InstanceName33; private char __InstanceName34; private char __InstanceName35; private char __InstanceName36; private char __InstanceName37; private char __InstanceName38; private char __InstanceName39; private char __InstanceName40; private char __InstanceName41; private char __InstanceName42; private char __InstanceName43; private char __InstanceName44; private char __InstanceName45; private char __InstanceName46; private char __InstanceName47; private char __InstanceName48; private char __InstanceName49; private char __InstanceName50; private char __InstanceName51; private char __InstanceName52; private char __InstanceName53; private char __InstanceName54; private char __InstanceName55; private char __InstanceName56; private char __InstanceName57; private char __InstanceName58; private char __InstanceName59; private char __InstanceName60; private char __InstanceName61; private char __InstanceName62; private char __InstanceName63; private char __InstanceName64; private char __InstanceName65; private char __InstanceName66; private char __InstanceName67; private char __InstanceName68; private char __InstanceName69; private char __InstanceName70; private char __InstanceName71; private char __InstanceName72; private char __InstanceName73; private char __InstanceName74; private char __InstanceName75; private char __InstanceName76; private char __InstanceName77; private char __InstanceName78; private char __InstanceName79; private char __InstanceName80; private char __InstanceName81; private char __InstanceName82; private char __InstanceName83; private char __InstanceName84; private char __InstanceName85; private char __InstanceName86; private char __InstanceName87; private char __InstanceName88; private char __InstanceName89; private char __InstanceName90; private char __InstanceName91; private char __InstanceName92; private char __InstanceName93; private char __InstanceName94; private char __InstanceName95; private char __InstanceName96; private char __InstanceName97; private char __InstanceName98; private char __InstanceName99; private char __InstanceName100; private char __InstanceName101; private char __InstanceName102; private char __InstanceName103; private char __InstanceName104; private char __InstanceName105; private char __InstanceName106; private char __InstanceName107; private char __InstanceName108; private char __InstanceName109; private char __InstanceName110; private char __InstanceName111; private char __InstanceName112; private char __InstanceName113; private char __InstanceName114; private char __InstanceName115; private char __InstanceName116; private char __InstanceName117; private char __InstanceName118; private char __InstanceName119; private char __InstanceName120; private char __InstanceName121; private char __InstanceName122; private char __InstanceName123; private char __InstanceName124; private char __InstanceName125; private char __InstanceName126; private char __InstanceName127; private char __InstanceName128; private char __InstanceName129; private char __InstanceName130; private char __InstanceName131; private char __InstanceName132; private char __InstanceName133; private char __InstanceName134; private char __InstanceName135; private char __InstanceName136; private char __InstanceName137; private char __InstanceName138; private char __InstanceName139; private char __InstanceName140; private char __InstanceName141; private char __InstanceName142; private char __InstanceName143; private char __InstanceName144; private char __InstanceName145; private char __InstanceName146; private char __InstanceName147; private char __InstanceName148; private char __InstanceName149; private char __InstanceName150; private char __InstanceName151; private char __InstanceName152; private char __InstanceName153; private char __InstanceName154; private char __InstanceName155; private char __InstanceName156; private char __InstanceName157; private char __InstanceName158; private char __InstanceName159; private char __InstanceName160; private char __InstanceName161; private char __InstanceName162; private char __InstanceName163; private char __InstanceName164; private char __InstanceName165; private char __InstanceName166; private char __InstanceName167; private char __InstanceName168; private char __InstanceName169; private char __InstanceName170; private char __InstanceName171; private char __InstanceName172; private char __InstanceName173; private char __InstanceName174; private char __InstanceName175; private char __InstanceName176; private char __InstanceName177; private char __InstanceName178; private char __InstanceName179; private char __InstanceName180; private char __InstanceName181; private char __InstanceName182; private char __InstanceName183; private char __InstanceName184; private char __InstanceName185; private char __InstanceName186; private char __InstanceName187; private char __InstanceName188; private char __InstanceName189; private char __InstanceName190; private char __InstanceName191; private char __InstanceName192; private char __InstanceName193; private char __InstanceName194; private char __InstanceName195; private char __InstanceName196; private char __InstanceName197; private char __InstanceName198; private char __InstanceName199; private char __InstanceName200; private char __InstanceName201; private char __InstanceName202; private char __InstanceName203; private char __InstanceName204; private char __InstanceName205; private char __InstanceName206; private char __InstanceName207; private char __InstanceName208; private char __InstanceName209; private char __InstanceName210; private char __InstanceName211; private char __InstanceName212; private char __InstanceName213; private char __InstanceName214; private char __InstanceName215; private char __InstanceName216; private char __InstanceName217; private char __InstanceName218; private char __InstanceName219; private char __InstanceName220; private char __InstanceName221; private char __InstanceName222; private char __InstanceName223; private char __InstanceName224; private char __InstanceName225; private char __InstanceName226; private char __InstanceName227; private char __InstanceName228; private char __InstanceName229; private char __InstanceName230; private char __InstanceName231; private char __InstanceName232; private char __InstanceName233; private char __InstanceName234; private char __InstanceName235; private char __InstanceName236; private char __InstanceName237; private char __InstanceName238; private char __InstanceName239; private char __InstanceName240; private char __InstanceName241; private char __InstanceName242; private char __InstanceName243; private char __InstanceName244; private char __InstanceName245; private char __InstanceName246; private char __InstanceName247; private char __InstanceName248; private char __InstanceName249; private char __InstanceName250; private char __InstanceName251; private char __InstanceName252; private char __InstanceName253; private char __InstanceName254; private char __InstanceName255; private char __InstanceName256; private char __InstanceName257; private char __InstanceName258; private char __InstanceName259; public char ProductName; private char __ProductName1; private char __ProductName2; private char __ProductName3; private char __ProductName4; private char __ProductName5; private char __ProductName6; private char __ProductName7; private char __ProductName8; private char __ProductName9; private char __ProductName10; private char __ProductName11; private char __ProductName12; private char __ProductName13; private char __ProductName14; private char __ProductName15; private char __ProductName16; private char __ProductName17; private char __ProductName18; private char __ProductName19; private char __ProductName20; private char __ProductName21; private char __ProductName22; private char __ProductName23; private char __ProductName24; private char __ProductName25; private char __ProductName26; private char __ProductName27; private char __ProductName28; private char __ProductName29; private char __ProductName30; private char __ProductName31; private char __ProductName32; private char __ProductName33; private char __ProductName34; private char __ProductName35; private char __ProductName36; private char __ProductName37; private char __ProductName38; private char __ProductName39; private char __ProductName40; private char __ProductName41; private char __ProductName42; private char __ProductName43; private char __ProductName44; private char __ProductName45; private char __ProductName46; private char __ProductName47; private char __ProductName48; private char __ProductName49; private char __ProductName50; private char __ProductName51; private char __ProductName52; private char __ProductName53; private char __ProductName54; private char __ProductName55; private char __ProductName56; private char __ProductName57; private char __ProductName58; private char __ProductName59; private char __ProductName60; private char __ProductName61; private char __ProductName62; private char __ProductName63; private char __ProductName64; private char __ProductName65; private char __ProductName66; private char __ProductName67; private char __ProductName68; private char __ProductName69; private char __ProductName70; private char __ProductName71; private char __ProductName72; private char __ProductName73; private char __ProductName74; private char __ProductName75; private char __ProductName76; private char __ProductName77; private char __ProductName78; private char __ProductName79; private char __ProductName80; private char __ProductName81; private char __ProductName82; private char __ProductName83; private char __ProductName84; private char __ProductName85; private char __ProductName86; private char __ProductName87; private char __ProductName88; private char __ProductName89; private char __ProductName90; private char __ProductName91; private char __ProductName92; private char __ProductName93; private char __ProductName94; private char __ProductName95; private char __ProductName96; private char __ProductName97; private char __ProductName98; private char __ProductName99; private char __ProductName100; private char __ProductName101; private char __ProductName102; private char __ProductName103; private char __ProductName104; private char __ProductName105; private char __ProductName106; private char __ProductName107; private char __ProductName108; private char __ProductName109; private char __ProductName110; private char __ProductName111; private char __ProductName112; private char __ProductName113; private char __ProductName114; private char __ProductName115; private char __ProductName116; private char __ProductName117; private char __ProductName118; private char __ProductName119; private char __ProductName120; private char __ProductName121; private char __ProductName122; private char __ProductName123; private char __ProductName124; private char __ProductName125; private char __ProductName126; private char __ProductName127; private char __ProductName128; private char __ProductName129; private char __ProductName130; private char __ProductName131; private char __ProductName132; private char __ProductName133; private char __ProductName134; private char __ProductName135; private char __ProductName136; private char __ProductName137; private char __ProductName138; private char __ProductName139; private char __ProductName140; private char __ProductName141; private char __ProductName142; private char __ProductName143; private char __ProductName144; private char __ProductName145; private char __ProductName146; private char __ProductName147; private char __ProductName148; private char __ProductName149; private char __ProductName150; private char __ProductName151; private char __ProductName152; private char __ProductName153; private char __ProductName154; private char __ProductName155; private char __ProductName156; private char __ProductName157; private char __ProductName158; private char __ProductName159; private char __ProductName160; private char __ProductName161; private char __ProductName162; private char __ProductName163; private char __ProductName164; private char __ProductName165; private char __ProductName166; private char __ProductName167; private char __ProductName168; private char __ProductName169; private char __ProductName170; private char __ProductName171; private char __ProductName172; private char __ProductName173; private char __ProductName174; private char __ProductName175; private char __ProductName176; private char __ProductName177; private char __ProductName178; private char __ProductName179; private char __ProductName180; private char __ProductName181; private char __ProductName182; private char __ProductName183; private char __ProductName184; private char __ProductName185; private char __ProductName186; private char __ProductName187; private char __ProductName188; private char __ProductName189; private char __ProductName190; private char __ProductName191; private char __ProductName192; private char __ProductName193; private char __ProductName194; private char __ProductName195; private char __ProductName196; private char __ProductName197; private char __ProductName198; private char __ProductName199; private char __ProductName200; private char __ProductName201; private char __ProductName202; private char __ProductName203; private char __ProductName204; private char __ProductName205; private char __ProductName206; private char __ProductName207; private char __ProductName208; private char __ProductName209; private char __ProductName210; private char __ProductName211; private char __ProductName212; private char __ProductName213; private char __ProductName214; private char __ProductName215; private char __ProductName216; private char __ProductName217; private char __ProductName218; private char __ProductName219; private char __ProductName220; private char __ProductName221; private char __ProductName222; private char __ProductName223; private char __ProductName224; private char __ProductName225; private char __ProductName226; private char __ProductName227; private char __ProductName228; private char __ProductName229; private char __ProductName230; private char __ProductName231; private char __ProductName232; private char __ProductName233; private char __ProductName234; private char __ProductName235; private char __ProductName236; private char __ProductName237; private char __ProductName238; private char __ProductName239; private char __ProductName240; private char __ProductName241; private char __ProductName242; private char __ProductName243; private char __ProductName244; private char __ProductName245; private char __ProductName246; private char __ProductName247; private char __ProductName248; private char __ProductName249; private char __ProductName250; private char __ProductName251; private char __ProductName252; private char __ProductName253; private char __ProductName254; private char __ProductName255; private char __ProductName256; private char __ProductName257; private char __ProductName258; private char __ProductName259; public Guid ForceFeedbackDriverGuid; public UsagePage UsagePage; public UsageId Usage; internal void __MarshalFree() { } } internal int Size; public Guid InstanceGuid; public Guid ProductGuid; internal int RawType; public string InstanceName; public string ProductName; public Guid ForceFeedbackDriverGuid; public UsagePage UsagePage; public UsageId Usage; public DeviceType Type => (DeviceType)(RawType & 0xFF); public int Subtype => RawType >> 8; public bool IsHumanInterfaceDevice => (RawType & 0x10000) != 0; public DeviceInstance() { Size = System.Runtime.CompilerServices.Unsafe.SizeOf<__Native>(); } internal static __Native __NewNative() { __Native result = default(__Native); result.Size = System.Runtime.CompilerServices.Unsafe.SizeOf<__Native>(); return result; } internal void __MarshalFree(ref __Native @ref) { @ref.__MarshalFree(); } internal unsafe void __MarshalFrom(ref __Native @ref) { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) Size = @ref.Size; InstanceGuid = @ref.InstanceGuid; ProductGuid = @ref.ProductGuid; RawType = @ref.RawType; fixed (char* ptr = &@ref.InstanceName) { InstanceName = Utilities.PtrToStringUni((IntPtr)ptr, 260); } fixed (char* ptr2 = &@ref.ProductName) { ProductName = Utilities.PtrToStringUni((IntPtr)ptr2, 260); } ForceFeedbackDriverGuid = @ref.ForceFeedbackDriverGuid; UsagePage = @ref.UsagePage; Usage = @ref.Usage; } internal unsafe void __MarshalTo(ref __Native @ref) { //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) @ref.Size = Size; @ref.InstanceGuid = InstanceGuid; @ref.ProductGuid = ProductGuid; @ref.RawType = RawType; fixed (char* ptr2 = InstanceName) { fixed (char* ptr = &@ref.InstanceName) { Utilities.CopyMemory((IntPtr)ptr, (IntPtr)ptr2, InstanceName.Length * 2); } } fixed (char* ptr3 = ProductName) { fixed (char* ptr = &@ref.ProductName) { Utilities.CopyMemory((IntPtr)ptr, (IntPtr)ptr3, ProductName.Length * 2); } } @ref.ForceFeedbackDriverGuid = ForceFeedbackDriverGuid; @ref.UsagePage = UsagePage; @ref.Usage = Usage; } } [StructLayout(LayoutKind.Sequential, Size = 4)] public struct DeviceObjectId { private int _rawType; private const int InstanceNumberMax = 65534; private const int AnyInstanceMask = 16776960; public DeviceObjectTypeFlags Flags => (DeviceObjectTypeFlags)(_rawType & -16776961); public int InstanceNumber => (_rawType >> 8) & 0xFFFF; public DeviceObjectId(DeviceObjectTypeFlags typeFlags, int instanceNumber) { this = default(DeviceObjectId); _rawType = (int)(typeFlags & ~DeviceObjectTypeFlags.AnyInstance) | ((!(instanceNumber < 0 || instanceNumber > 65534)) ? ((instanceNumber & 0xFFFF) << 8) : 0); } public static explicit operator int(DeviceObjectId type) { return type._rawType; } public bool Equals(DeviceObjectId other) { return other._rawType == _rawType; } public override bool Equals(object obj) { if (obj == null) { return false; } if (obj.GetType() != typeof(DeviceObjectId)) { return false; } return Equals((DeviceObjectId)obj); } public override int GetHashCode() { return _rawType; } public override string ToString() { return string.Format(CultureInfo.InvariantCulture, "Flags: {0} InstanceNumber: {1} RawId: 0x{2:X8}", new object[3] { Flags, InstanceNumber, _rawType }); } } public class DeviceObjectInstance { internal struct __Native { public int Size; public Guid ObjectType; public int Offset; public DeviceObjectId ObjectId; public ObjectAspect Aspect; public char Name; private char __Name1; private char __Name2; private char __Name3; private char __Name4; private char __Name5; private char __Name6; private char __Name7; private char __Name8; private char __Name9; private char __Name10; private char __Name11; private char __Name12; private char __Name13; private char __Name14; private char __Name15; private char __Name16; private char __Name17; private char __Name18; private char __Name19; private char __Name20; private char __Name21; private char __Name22; private char __Name23; private char __Name24; private char __Name25; private char __Name26; private char __Name27; private char __Name28; private char __Name29; private char __Name30; private char __Name31; private char __Name32; private char __Name33; private char __Name34; private char __Name35; private char __Name36; private char __Name37; private char __Name38; private char __Name39; private char __Name40; private char __Name41; private char __Name42; private char __Name43; private char __Name44; private char __Name45; private char __Name46; private char __Name47; private char __Name48; private char __Name49; private char __Name50; private char __Name51; private char __Name52; private char __Name53; private char __Name54; private char __Name55; private char __Name56; private char __Name57; private char __Name58; private char __Name59; private char __Name60; private char __Name61; private char __Name62; private char __Name63; private char __Name64; private char __Name65; private char __Name66; private char __Name67; private char __Name68; private char __Name69; private char __Name70; private char __Name71; private char __Name72; private char __Name73; private char __Name74; private char __Name75; private char __Name76; private char __Name77; private char __Name78; private char __Name79; private char __Name80; private char __Name81; private char __Name82; private char __Name83; private char __Name84; private char __Name85; private char __Name86; private char __Name87; private char __Name88; private char __Name89; private char __Name90; private char __Name91; private char __Name92; private char __Name93; private char __Name94; private char __Name95; private char __Name96; private char __Name97; private char __Name98; private char __Name99; private char __Name100; private char __Name101; private char __Name102; private char __Name103; private char __Name104; private char __Name105; private char __Name106; private char __Name107; private char __Name108; private char __Name109; private char __Name110; private char __Name111; private char __Name112; private char __Name113; private char __Name114; private char __Name115; private char __Name116; private char __Name117; private char __Name118; private char __Name119; private char __Name120; private char __Name121; private char __Name122; private char __Name123; private char __Name124; private char __Name125; private char __Name126; private char __Name127; private char __Name128; private char __Name129; private char __Name130; private char __Name131; private char __Name132; private char __Name133; private char __Name134; private char __Name135; private char __Name136; private char __Name137; private char __Name138; private char __Name139; private char __Name140; private char __Name141; private char __Name142; private char __Name143; private char __Name144; private char __Name145; private char __Name146; private char __Name147; private char __Name148; private char __Name149; private char __Name150; private char __Name151; private char __Name152; private char __Name153; private char __Name154; private char __Name155; private char __Name156; private char __Name157; private char __Name158; private char __Name159; private char __Name160; private char __Name161; private char __Name162; private char __Name163; private char __Name164; private char __Name165; private char __Name166; private char __Name167; private char __Name168; private char __Name169; private char __Name170; private char __Name171; private char __Name172; private char __Name173; private char __Name174; private char __Name175; private char __Name176; private char __Name177; private char __Name178; private char __Name179; private char __Name180; private char __Name181; private char __Name182; private char __Name183; private char __Name184; private char __Name185; private char __Name186; private char __Name187; private char __Name188; private char __Name189; private char __Name190; private char __Name191; private char __Name192; private char __Name193; private char __Name194; private char __Name195; private char __Name196; private char __Name197; private char __Name198; private char __Name199; private char __Name200; private char __Name201; private char __Name202; private char __Name203; private char __Name204; private char __Name205; private char __Name206; private char __Name207; private char __Name208; private char __Name209; private char __Name210; private char __Name211; private char __Name212; private char __Name213; private char __Name214; private char __Name215; private char __Name216; private char __Name217; private char __Name218; private char __Name219; private char __Name220; private char __Name221; private char __Name222; private char __Name223; private char __Name224; private char __Name225; private char __Name226; private char __Name227; private char __Name228; private char __Name229; private char __Name230; private char __Name231; private char __Name232; private char __Name233; private char __Name234; private char __Name235; private char __Name236; private char __Name237; private char __Name238; private char __Name239; private char __Name240; private char __Name241; private char __Name242; private char __Name243; private char __Name244; private char __Name245; private char __Name246; private char __Name247; private char __Name248; private char __Name249; private char __Name250; private char __Name251; private char __Name252; private char __Name253; private char __Name254; private char __Name255; private char __Name256; private char __Name257; private char __Name258; private char __Name259; public int MaximumForceFeedback; public int ForceFeedbackResolution; public short CollectionNumber; public short DesignatorIndex; public short UsagePage; public short Usage; public int Dimension; public short Exponent; public short ReportId; internal void __MarshalFree() { } } internal int Size; public Guid ObjectType; public int Offset; public DeviceObjectId ObjectId; public ObjectAspect Aspect; public string Name; public int MaximumForceFeedback; public int ForceFeedbackResolution; public short CollectionNumber; public short DesignatorIndex; public short UsagePage; public short Usage; public int Dimension; public short Exponent; public short ReportId; public unsafe DeviceObjectInstance() { Size = sizeof(__Native); } internal unsafe static __Native __NewNative() { __Native result = default(__Native); result.Size = sizeof(__Native); return result; } internal void __MarshalFree(ref __Native @ref) { @ref.__MarshalFree(); } internal unsafe void __MarshalFrom(ref __Native @ref) { Size = @ref.Size; ObjectType = @ref.ObjectType; Offset = @ref.Offset; ObjectId = @ref.ObjectId; Aspect = @ref.Aspect; fixed (char* ptr = &@ref.Name) { Name = Utilities.PtrToStringUni((IntPtr)ptr, 260); } MaximumForceFeedback = @ref.MaximumForceFeedback; ForceFeedbackResolution = @ref.ForceFeedbackResolution; CollectionNumber = @ref.CollectionNumber; DesignatorIndex = @ref.DesignatorIndex; UsagePage = @ref.UsagePage; Usage = @ref.Usage; Dimension = @ref.Dimension; Exponent = @ref.Exponent; ReportId = @ref.ReportId; } internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Size = Size; @ref.ObjectType = ObjectType; @ref.Offset = Offset; @ref.ObjectId = ObjectId; @ref.Aspect = Aspect; fixed (char* ptr2 = Name) { fixed (char* ptr = &@ref.Name) { Utilities.CopyMemory((IntPtr)ptr, (IntPtr)ptr2, Name.Length * 2); } } @ref.MaximumForceFeedback = MaximumForceFeedback; @ref.ForceFeedbackResolution = ForceFeedbackResolution; @ref.CollectionNumber = CollectionNumber; @ref.DesignatorIndex = DesignatorIndex; @ref.UsagePage = UsagePage; @ref.Usage = Usage; @ref.Dimension = Dimension; @ref.Exponent = Exponent; @ref.ReportId = ReportId; } } public class DeviceProperties : PropertyAccessor { public bool AutoCenter { get { return GetInt(PropertyGuids.Autocenter) != 0; } set { Set(PropertyGuids.Autocenter, value ? 1 : 0); } } public DeviceAxisMode AxisMode { get { return (DeviceAxisMode)GetInt(PropertyGuids.Axismode); } set { Set(PropertyGuids.Axismode, (int)value); } } public int BufferSize { get { return GetInt(PropertyGuids.BufferSize); } set { Set(PropertyGuids.BufferSize, value); } } public Guid ClassGuid => GetGuid(PropertyGuids.Guidandpath); public int DeadZone { get { return GetInt(PropertyGuids.Deadzone); } set { Set(PropertyGuids.Deadzone, value); } } public int ForceFeedbackGain { get { return GetInt(PropertyGuids.Ffgain); } set { Set(PropertyGuids.Ffgain, value); } } public int Granularity => GetInt(PropertyGuids.Granularity); public string InstanceName { get { return GetString(PropertyGuids.InstanceName); } set { Set(PropertyGuids.InstanceName, value); } } public string InterfacePath => GetPath(PropertyGuids.Guidandpath); public int JoystickId => GetInt(PropertyGuids.Joystickid); public int MemoryLoad => GetInt(PropertyGuids.Ffload); public string PortDisplayName => GetPath(PropertyGuids.GetPortdisplayname); public int ProductId => (GetInt(PropertyGuids.Vidpid) >> 16) & 0xFFFF; public string ProductName { get { return GetString(PropertyGuids.Productname); } set { Set(PropertyGuids.Productname, value); } } public InputRange Range { get { return GetRange(PropertyGuids.Range); } set { Set(PropertyGuids.Range, value); } } public int Saturation { get { return GetInt(PropertyGuids.Saturation); } set { Set(PropertyGuids.Saturation, value); } } public string TypeName => GetPath(PropertyGuids.Typename); public string UserName => GetPath(PropertyGuids.Username); public int VendorId => GetInt(PropertyGuids.Vidpid) & 0xFFFF; internal DeviceProperties(Device device) : base(device, 0, PropertyHowType.Device) { } public int GetKeyCode(Key key) { return GetInt(PropertyGuids.Scancode, (int)key); } public string GetKeyName(Key key) { return GetString(PropertyGuids.Keyname, (int)key); } } [Guid("bf798031-483a-4da2-aa99-5d64ed369700")] public class DirectInput : ComObject { public DirectInput() : base(IntPtr.Zero) { DInput.DirectInput8Create(Win32Native.GetModuleHandle(null), 2048, Utilities.GetGuidFromType(typeof(DirectInput)), out var vOutOut, null); ((CppObject)this).NativePointer = vOutOut; } public IList<DeviceInstance> GetDevices() { return GetDevices(DeviceClass.All, DeviceEnumerationFlags.AllDevices); } public IList<DeviceInstance> GetDevices(DeviceClass deviceClass, DeviceEnumerationFlags deviceEnumFlags) { EnumDevicesCallback enumDevicesCallback = new EnumDevicesCallback(); EnumDevices((int)deviceClass, FunctionCallback.op_Implicit(enumDevicesCallback.NativePointer), IntPtr.Zero, deviceEnumFlags); return enumDevicesCallback.DeviceInstances; } public IList<DeviceInstance> GetDevices(DeviceType deviceType, DeviceEnumerationFlags deviceEnumFlags) { EnumDevicesCallback enumDevicesCallback = new EnumDevicesCallback(); EnumDevices((int)deviceType, FunctionCallback.op_Implicit(enumDevicesCallback.NativePointer), IntPtr.Zero, deviceEnumFlags); return enumDevicesCallback.DeviceInstances; } public bool IsDeviceAttached(Guid deviceGuid) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) Result deviceStatus = GetDeviceStatus(deviceGuid); return ((Result)(ref deviceStatus)).Code == 0; } public void RunControlPanel() { RunControlPanel(IntPtr.Zero); } public void RunControlPanel(IntPtr handle) { RunControlPanel(handle, 0); } public DirectInput(IntPtr nativePtr) : base(nativePtr) { } public static explicit operator DirectInput(IntPtr nativePointer) { if (!(nativePointer == IntPtr.Zero)) { return new DirectInput(nativePointer); } return null; } internal unsafe void CreateDevice(Guid arg0, out IntPtr arg1, ComObject arg2) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) Result val; fixed (IntPtr* ptr = &arg1) { void* ptr2 = ptr; void* nativePointer = ((CppObject)this)._nativePointer; Guid* num = &arg0; IntPtr intPtr = ((arg2 == null) ? IntPtr.Zero : ((CppObject)arg2).NativePointer); val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)3 * (nint)sizeof(void*))))(nativePointer, num, ptr2, (void*)intPtr)); } ((Result)(ref val)).CheckError(); } internal unsafe void EnumDevices(int arg0, FunctionCallback arg1, IntPtr arg2, DeviceEnumerationFlags arg3) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int, void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)4 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, arg0, FunctionCallback.op_Implicit(arg1), (void*)arg2, (int)arg3)); ((Result)(ref val)).CheckError(); } internal unsafe Result GetDeviceStatus(Guid arg0) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) return Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)5 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &arg0)); } internal unsafe void RunControlPanel(IntPtr arg0, int arg1) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)6 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)arg0, arg1)); ((Result)(ref val)).CheckError(); } internal unsafe void Initialize(IntPtr arg0, int arg1) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)7 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)arg0, arg1)); ((Result)(ref val)).CheckError(); } public unsafe Guid FindDevice(Guid arg0, string arg1) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) IntPtr intPtr = Utilities.StringToHGlobalUni(arg1); Guid result = default(Guid); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)8 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &arg0, (void*)intPtr, &result)); Marshal.FreeHGlobal(intPtr); ((Result)(ref val)).CheckError(); return result; } internal unsafe void EnumDevicesBySemantics(string arg0, ref ActionFormat arg1, FunctionCallback arg2, IntPtr arg3, int arg4) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) IntPtr intPtr = Utilities.StringToHGlobalUni(arg0); ActionFormat.__Native @ref = default(ActionFormat.__Native); arg1.__MarshalTo(ref @ref); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, void*, void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)9 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)intPtr, &@ref, FunctionCallback.op_Implicit(arg2), (void*)arg3, arg4)); Marshal.FreeHGlobal(intPtr); arg1.__MarshalFree(ref @ref); ((Result)(ref val)).CheckError(); } } [Guid("e7e1f7c0-88d2-11d0-9ad0-00a0c9a06e35")] public class Effect : ComObject { public Guid Guid { get { GetGuid(out var arg); return arg; } } public EffectStatus Status { get { GetStatus(out var arg); return arg; } } public Effect(Device device, Guid guid, EffectParameters parameters) { device.CreateEffect(guid, parameters, this, null); } public unsafe int Escape(int command, byte[] inData, byte[] outData) { EffectEscape arg = default(EffectEscape); fixed (byte* ptr = &inData[0]) { void* ptr2 = ptr; fixed (byte* ptr3 = &outData[0]) { void* ptr4 = ptr3; arg.Size = sizeof(EffectEscape); arg.Command = command; arg.InBufferPointer = (IntPtr)ptr2; arg.InBufferSize = inData.Length; arg.OutBufferPointer = (IntPtr)ptr4; arg.OutBufferSize = outData.Length; Escape(ref arg); return arg.OutBufferSize; } } } public EffectParameters GetParameters() { return GetParameters(EffectParameterFlags.All); } public void SetParameters(EffectParameters parameters) { SetParameters(parameters, EffectParameterFlags.All); } public void Start() { Start(-1); } public void Start(EffectPlayFlags flags) { Start(-1, flags); } public void Start(int iterations) { Start(iterations, EffectPlayFlags.None); } public Effect(IntPtr nativePtr) : base(nativePtr) { } public static explicit operator Effect(IntPtr nativePointer) { if (!(nativePointer == IntPtr.Zero)) { return new Effect(nativePointer); } return null; } internal unsafe void Initialize(IntPtr arg0, int arg1, Guid arg2) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)3 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, (void*)arg0, arg1, &arg2)); ((Result)(ref val)).CheckError(); } internal unsafe void GetGuid(out Guid arg0) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) arg0 = default(Guid); Result val; fixed (Guid* ptr = &arg0) { void* ptr2 = ptr; val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)4 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, ptr2)); } ((Result)(ref val)).CheckError(); } public unsafe EffectParameters GetParameters(EffectParameterFlags arg1) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) EffectParameters.__Native @ref = EffectParameters.__NewNative(); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)5 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &@ref, (int)arg1)); EffectParameters effectParameters = new EffectParameters(); effectParameters.__MarshalFrom(ref @ref); ((Result)(ref val)).CheckError(); return effectParameters; } public unsafe void SetParameters(EffectParameters arg0, EffectParameterFlags arg1) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) EffectParameters.__Native @ref = EffectParameters.__NewNative(); arg0.__MarshalTo(ref @ref); Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)6 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, &@ref, (int)arg1)); arg0.__MarshalFree(ref @ref); ((Result)(ref val)).CheckError(); } public unsafe void Start(int arg0, EffectPlayFlags arg1) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int, int, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)7 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, arg0, (int)arg1)); ((Result)(ref val)).CheckError(); } public unsafe void Stop() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)8 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer)); ((Result)(ref val)).CheckError(); } internal unsafe void GetStatus(out EffectStatus arg0) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Result val; fixed (EffectStatus* ptr = &arg0) { void* ptr2 = ptr; val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)9 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, ptr2)); } ((Result)(ref val)).CheckError(); } public unsafe void Download() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)10 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer)); ((Result)(ref val)).CheckError(); } public unsafe void Unload() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) Result val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)11 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer)); ((Result)(ref val)).CheckError(); } internal unsafe void Escape(ref EffectEscape arg0) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Result val; fixed (EffectEscape* ptr = &arg0) { void* ptr2 = ptr; val = Result.op_Implicit(((delegate* unmanaged[Stdcall]<void*, void*, int>)(*(IntPtr*)((nint)(*(IntPtr*)((CppObject)this)._nativePointer) + (nint)12 * (nint)sizeof(void*))))(((CppObject)this)._nativePointer, ptr2)); } ((Result)(ref val)).CheckError(); } } public class EffectFile { internal struct __Native { public int Size; public Guid Guid; public IntPtr EffectParametersPointer; public byte Name; public byte _Name2; public byte _Name3; public byte _Name4; public byte _Name5; public byte _Name6; public byte _Name7; public byte _Name8; public byte _Name9; public byte _Name10; public byte _Name11; public byte _Name12; public byte _Name13; public byte _Name14; public byte _Name15; public byte _Name16; public byte _Name17; public byte _Name18; public byte _Name19; public byte _Name20; public byte _Name21; public byte _Name22; public byte _Name23; public byte _Name24; public byte _Name25; public byte _Name26; public byte _Name27; public byte _Name28; public byte _Name29; public byte _Name30; public byte _Name31; public byte _Name32; public byte _Name33; public byte _Name34; public byte _Name35; public byte _Name36; public byte _Name37; public byte _Name38; public byte _Name39; public byte _Name40; public byte _Name41; public byte _Name42; public byte _Name43; public byte _Name44; public byte _Name45; public byte _Name46; public byte _Name47; public byte _Name48; public byte _Name49; public byte _Name50; public byte _Name51; public byte _Name52; public byte _Name53; public byte _Name54; public byte _Name55; public byte _Name56; public byte _Name57; public byte _Name58; public byte _Name59; public byte _Name60; public byte _Name61; public byte _Name62; public byte _Name63; public byte _Name64; public byte _Name65; public byte _Name66; public byte _Name67; public byte _Name68; public byte _Name69; public byte _Name70; public byte _Name71; public byte _Name72; public byte _Name73; public byte _Name74; public byte _Name75; public byte _Name76; public byte _Name77; public byte _Name78; public byte _Name79; public byte _Name80; public byte _Name81; public byte _Name82; public byte _Name83; public byte _Name84; public byte _Name85; public byte _Name86; public byte _Name87; public byte _Name88; public byte _Name89; public byte _Name90; public byte _Name91; public byte _Name92; public byte _Name93; public byte _Name94; public byte _Name95; public byte _Name96; public byte _Name97; public byte _Name98; public byte _Name99; public byte _Name100; public byte _Name101; public byte _Name102; public byte _Name103; public byte _Name104; public byte _Name105; public byte _Name106; public byte _Name107; public byte _Name108; public byte _Name109; public byte _Name110; public byte _Name111; public byte _Name112; public byte _Name113; public byte _Name114; public byte _Name115; public byte _Name116; public byte _Name117; public byte _Name118; public byte _Name119; public byte _Name120; public byte _Name121; public byte _Name122; public byte _Name123; public byte _Name124; public byte _Name125; public byte _Name126; public byte _Name127; public byte _Name128; public byte _Name129; public byte _Name130; public byte _Nam
UserLibs/SharpDX.dll
Decompiled 8 months ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq.Expressions; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Threading; using SharpDX; using SharpDX.Collections; using SharpDX.Diagnostics; using SharpDX.Direct3D; using SharpDX.Mathematics.Interop; [assembly: InternalsVisibleTo("SharpDX.DirectSound,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.RawInput,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.DirectInput,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.Direct2D1,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.Direct3D11.Effects,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.Direct3D12,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.XAPO,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.Direct3D11,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.Direct3D9,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.Desktop,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.D3DCompiler,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.DXGI,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.Animation,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: InternalsVisibleTo("SharpDX.Direct3D10,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: InternalsVisibleTo("SharpDX.XAudio2,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.WIC,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: AssemblyTitle("SharpDX")] [assembly: AssemblyProduct("SharpDX")] [assembly: AssemblyInformationalVersion("4.2.0+8e5df9f17b1d328c595a9df5851dbb2537b55621")] [assembly: AssemblyFileVersion("4.2.0")] [assembly: AssemblyDescription("Core assembly for all SharpDX assemblies.")] [assembly: InternalsVisibleTo("SharpDX.XACT3,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: AssemblyCopyright("Copyright (c) 2010-2016 Alexandre Mutel")] [assembly: AssemblyCompany("Alexandre Mutel")] [assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")] [assembly: ComVisible(false)] [assembly: InternalsVisibleTo("SharpDX.DirectManipulation,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.DirectComposition,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: InternalsVisibleTo("SharpDX.MediaFoundation,PublicKey=00240000048000009400000006020000002400005253413100040000010001004543d77b41222cfd48f4e0d8dd9b2f83dc15fbede312a422a7454a0b723e988718ebba619773fc8dfed2bc69c97aec4063f51dc5821f5eaa72f331b2782755754dfd998ade0dcbf92a734e532870f661cbe4388f544befa2f32a8e4568e0be071a90fa546c8b4e6efcea755703ae03f6479e787632688be8f6aaae808f6f43ba")] [assembly: AssemblyConfiguration("Release")] [assembly: NeutralResourcesLanguage("en-US")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("4.2.0.0")] [module: UnverifiableCode] internal class <Module> { static <Module>() { Interop.ModuleInit(); ModuleInit.Setup(); } } namespace SharpDX { [CompilerGenerated] internal class AssemblyDoc { } public abstract class CallbackBase : DisposeBase, ICallbackable, IDisposable { private int refCount = 1; IDisposable ICallbackable.Shadow { get; set; } protected override void Dispose(bool disposing) { if (disposing) { Release(); } } public int AddReference() { int num = refCount; while (true) { if (num == 0) { throw new ObjectDisposedException("Cannot add a reference to a nonreferenced item"); } int num2 = Interlocked.CompareExchange(ref refCount, num + 1, num); if (num2 == num) { break; } num = num2; } return num + 1; } public int Release() { int num = refCount; while (true) { int num2 = Interlocked.CompareExchange(ref refCount, num - 1, num); if (num2 == num) { break; } num = num2; } if (num == 1) { ((ICallbackable)this).Shadow.Dispose(); ((ICallbackable)this).Shadow = null; } return num - 1; } public Result QueryInterface(ref Guid guid, out IntPtr comObject) { ShadowContainer shadowContainer = (ShadowContainer)((ICallbackable)this).Shadow; comObject = shadowContainer.Find(guid); if (comObject == IntPtr.Zero) { return Result.NoInterface; } return Result.Ok; } } public class ComArray : DisposeBase, IEnumerable { protected ComObject[] values; private IntPtr nativeBuffer; public IntPtr NativePointer => nativeBuffer; public int Length { get { if (values != null) { return values.Length; } return 0; } } public ComArray(params ComObject[] array) { values = array; nativeBuffer = IntPtr.Zero; if (values != null) { int num = array.Length; values = new ComObject[num]; nativeBuffer = Utilities.AllocateMemory(num * Utilities.SizeOf<IntPtr>()); for (int i = 0; i < num; i++) { Set(i, array[i]); } } } public ComArray(int size) { values = new ComObject[size]; nativeBuffer = Utilities.AllocateMemory(size * Utilities.SizeOf<IntPtr>()); } public ComObject Get(int index) { return values[index]; } internal unsafe void SetFromNative(int index, ComObject value) { values[index] = value; value.NativePointer = *(IntPtr*)((byte*)(void*)nativeBuffer + (nint)index * (nint)sizeof(IntPtr)); } public unsafe void Set(int index, ComObject value) { values[index] = value; *(IntPtr*)((byte*)(void*)nativeBuffer + (nint)index * (nint)sizeof(IntPtr)) = value.NativePointer; } protected override void Dispose(bool disposing) { if (disposing) { values = null; } Utilities.FreeMemory(nativeBuffer); nativeBuffer = IntPtr.Zero; } public IEnumerator GetEnumerator() { return values.GetEnumerator(); } } public class ComArray<T> : ComArray, IEnumerable<T>, IEnumerable where T : ComObject { private struct ArrayEnumerator<T1> : IEnumerator<T1>, IDisposable, IEnumerator where T1 : ComObject { private readonly IEnumerator enumerator; public T1 Current => (T1)enumerator.Current; object IEnumerator.Current => Current; public ArrayEnumerator(IEnumerator enumerator) { this.enumerator = enumerator; } public void Dispose() { } public bool MoveNext() { return enumerator.MoveNext(); } public void Reset() { enumerator.Reset(); } } public T this[int i] { get { return (T)Get(i); } set { Set(i, value); } } public ComArray(params T[] array) : base(array) { } public ComArray(int size) : base(size) { } public new IEnumerator<T> GetEnumerator() { return new ArrayEnumerator<T>(values.GetEnumerator()); } } [Guid("00000000-0000-0000-C000-000000000046")] public class ComObject : CppObject, IUnknown, ICallbackable, IDisposable { public static Action<string> LogMemoryLeakWarning = delegate { }; public ComObject(object iunknowObject) { base.NativePointer = Marshal.GetIUnknownForObject(iunknowObject); } protected ComObject() { } public virtual void QueryInterface(Guid guid, out IntPtr outPtr) { ((IUnknown)this).QueryInterface(ref guid, out outPtr).CheckError(); } public virtual IntPtr QueryInterfaceOrNull(Guid guid) { IntPtr comObject = IntPtr.Zero; ((IUnknown)this).QueryInterface(ref guid, out comObject); return comObject; } public static bool EqualsComObject<T>(T left, T right) where T : ComObject { if (object.Equals(left, right)) { return true; } if (left == null || right == null) { return false; } return left.NativePointer == right.NativePointer; } public virtual T QueryInterface<T>() where T : ComObject { QueryInterface(Utilities.GetGuidFromType(typeof(T)), out var outPtr); return CppObject.FromPointer<T>(outPtr); } internal virtual T QueryInterfaceUnsafe<T>() { QueryInterface(Utilities.GetGuidFromType(typeof(T)), out var outPtr); return CppObject.FromPointerUnsafe<T>(outPtr); } public static T As<T>(object comObject) where T : ComObject { using ComObject comObject2 = new ComObject(Marshal.GetIUnknownForObject(comObject)); return comObject2.QueryInterface<T>(); } public static T As<T>(IntPtr iunknownPtr) where T : ComObject { using ComObject comObject = new ComObject(iunknownPtr); return comObject.QueryInterface<T>(); } internal static T AsUnsafe<T>(IntPtr iunknownPtr) { using ComObject comObject = new ComObject(iunknownPtr); return comObject.QueryInterfaceUnsafe<T>(); } public static T QueryInterface<T>(object comObject) where T : ComObject { using ComObject comObject2 = new ComObject(Marshal.GetIUnknownForObject(comObject)); return comObject2.QueryInterface<T>(); } public static T QueryInterfaceOrNull<T>(IntPtr comPointer) where T : ComObject { if (comPointer == IntPtr.Zero) { return null; } Guid iid = Utilities.GetGuidFromType(typeof(T)); if (!((Result)Marshal.QueryInterface(comPointer, ref iid, out var ppv)).Failure) { return CppObject.FromPointerUnsafe<T>(ppv); } return null; } public virtual T QueryInterfaceOrNull<T>() where T : ComObject { return CppObject.FromPointer<T>(QueryInterfaceOrNull(Utilities.GetGuidFromType(typeof(T)))); } protected void QueryInterfaceFrom<T>(T fromObject) where T : ComObject { fromObject.QueryInterface(Utilities.GetGuidFromType(GetType()), out var outPtr); base.NativePointer = outPtr; } Result IUnknown.QueryInterface(ref Guid guid, out IntPtr comObject) { return Marshal.QueryInterface(base.NativePointer, ref guid, out comObject); } int IUnknown.AddReference() { if (base.NativePointer == IntPtr.Zero) { throw new InvalidOperationException("COM Object pointer is null"); } return Marshal.AddRef(base.NativePointer); } int IUnknown.Release() { if (base.NativePointer == IntPtr.Zero) { throw new InvalidOperationException("COM Object pointer is null"); } return Marshal.Release(base.NativePointer); } protected unsafe override void Dispose(bool disposing) { if (base.NativePointer != IntPtr.Zero) { if (!disposing && Configuration.EnableTrackingReleaseOnFinalizer && !Configuration.EnableReleaseOnFinalizer) { ObjectReference arg = ObjectTracker.Find(this); LogMemoryLeakWarning?.Invoke($"Warning: Live ComObject [0x{base.NativePointer.ToInt64():X}], potential memory leak: {arg}"); } if (disposing || Configuration.EnableReleaseOnFinalizer) { ((IUnknown)this).Release(); } if (Configuration.EnableObjectTracking) { ObjectTracker.UnTrack(this); } _nativePointer = null; } base.Dispose(disposing); } protected override void NativePointerUpdating() { if (Configuration.EnableObjectTracking) { ObjectTracker.UnTrack(this); } } protected override void NativePointerUpdated(IntPtr oldNativePointer) { if (Configuration.EnableObjectTracking) { ObjectTracker.Track(this); } } public ComObject(IntPtr nativePtr) : base(nativePtr) { } public static explicit operator ComObject(IntPtr nativePtr) { if (!(nativePtr == IntPtr.Zero)) { return new ComObject(nativePtr); } return null; } } internal abstract class ComObjectShadow : CppObjectShadow { internal class ComObjectVtbl : CppObjectVtbl { [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate int QueryInterfaceDelegate(IntPtr thisObject, IntPtr guid, out IntPtr output); [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate int AddRefDelegate(IntPtr thisObject); [UnmanagedFunctionPointer(CallingConvention.StdCall)] public delegate int ReleaseDelegate(IntPtr thisObject); public ComObjectVtbl(int numberOfCallbackMethods) : base(numberOfCallbackMethods + 3) { AddMethod(new QueryInterfaceDelegate(QueryInterfaceImpl)); AddMethod(new AddRefDelegate(AddRefImpl)); AddMethod(new ReleaseDelegate(ReleaseImpl)); } protected unsafe static int QueryInterfaceImpl(IntPtr thisObject, IntPtr guid, out IntPtr output) { ComObjectShadow comObjectShadow = CppObjectShadow.ToShadow<ComObjectShadow>(thisObject); if (comObjectShadow == null) { output = IntPtr.Zero; return Result.NoInterface.Code; } return comObjectShadow.QueryInterfaceImpl(ref *(Guid*)(void*)guid, out output); } protected static int AddRefImpl(IntPtr thisObject) { return CppObjectShadow.ToShadow<ComObjectShadow>(thisObject)?.AddRefImpl() ?? 0; } protected static int ReleaseImpl(IntPtr thisObject) { return CppObjectShadow.ToShadow<ComObjectShadow>(thisObject)?.ReleaseImpl() ?? 0; } } public static Guid IID_IUnknown = new Guid("00000000-0000-0000-C000-000000000046"); protected int QueryInterfaceImpl(ref Guid guid, out IntPtr output) { ComObjectShadow comObjectShadow = (ComObjectShadow)((ShadowContainer)base.Callback.Shadow).FindShadow(guid); if (comObjectShadow != null) { ((IUnknown)base.Callback).AddReference(); output = comObjectShadow.NativePointer; return Result.Ok.Code; } output = IntPtr.Zero; return Result.NoInterface.Code; } protected virtual int AddRefImpl() { return ((IUnknown)base.Callback).AddReference(); } protected virtual int ReleaseImpl() { return ((IUnknown)base.Callback).Release(); } } public static class Configuration { public static bool EnableObjectTracking = false; public static bool EnableReleaseOnFinalizer = false; public static bool EnableTrackingReleaseOnFinalizer = true; public static bool ThrowOnShaderCompileError = true; public static bool UseThreadStaticObjectTracking = false; } public class CppObject : DisposeBase, ICallbackable, IDisposable { protected internal unsafe void* _nativePointer; public object Tag { get; set; } public unsafe IntPtr NativePointer { get { return (IntPtr)_nativePointer; } set { void* ptr = (void*)value; if (_nativePointer != ptr) { NativePointerUpdating(); void* nativePointer = _nativePointer; _nativePointer = ptr; NativePointerUpdated((IntPtr)nativePointer); } } } IDisposable ICallbackable.Shadow { get { throw new InvalidOperationException("Invalid access to Callback. This is used internally."); } set { throw new InvalidOperationException("Invalid access to Callback. This is used internally."); } } public CppObject(IntPtr pointer) { NativePointer = pointer; } protected CppObject() { } public static explicit operator IntPtr(CppObject cppObject) { return cppObject?.NativePointer ?? IntPtr.Zero; } protected void FromTemp(CppObject temp) { NativePointer = temp.NativePointer; temp.NativePointer = IntPtr.Zero; } protected void FromTemp(IntPtr temp) { NativePointer = temp; } protected virtual void NativePointerUpdating() { } protected virtual void NativePointerUpdated(IntPtr oldNativePointer) { } protected override void Dispose(bool disposing) { } public static T FromPointer<T>(IntPtr comObjectPtr) where T : CppObject { if (!(comObjectPtr == IntPtr.Zero)) { return (T)Activator.CreateInstance(typeof(T), comObjectPtr); } return null; } internal static T FromPointerUnsafe<T>(IntPtr comObjectPtr) { if (!(comObjectPtr == IntPtr.Zero)) { return (T)Activator.CreateInstance(typeof(T), comObjectPtr); } return (T)(object)null; } public static IntPtr ToCallbackPtr<TCallback>(ICallbackable callback) where TCallback : ICallbackable { if (callback == null) { return IntPtr.Zero; } if (callback is CppObject) { return ((CppObject)callback).NativePointer; } ShadowContainer shadowContainer = callback.Shadow as ShadowContainer; if (shadowContainer == null) { shadowContainer = new ShadowContainer(); shadowContainer.Initialize(callback); } return shadowContainer.Find(typeof(TCallback)); } } internal abstract class CppObjectShadow : CppObject { public ICallbackable Callback { get; private set; } protected abstract CppObjectVtbl GetVtbl { get; } public unsafe virtual void Initialize(ICallbackable callbackInstance) { Callback = callbackInstance; base.NativePointer = Marshal.AllocHGlobal(IntPtr.Size * 2); GCHandle value = GCHandle.Alloc(this); Marshal.WriteIntPtr(base.NativePointer, GetVtbl.Pointer); *(IntPtr*)((byte*)(void*)base.NativePointer + sizeof(IntPtr)) = GCHandle.ToIntPtr(value); } protected unsafe override void Dispose(bool disposing) { if (base.NativePointer != IntPtr.Zero) { GCHandle.FromIntPtr(*(IntPtr*)((byte*)(void*)base.NativePointer + sizeof(IntPtr))).Free(); Marshal.FreeHGlobal(base.NativePointer); base.NativePointer = IntPtr.Zero; } Callback = null; base.Dispose(disposing); } internal unsafe static T ToShadow<T>(IntPtr thisPtr) where T : CppObjectShadow { return (T)GCHandle.FromIntPtr(*(IntPtr*)((byte*)(void*)thisPtr + sizeof(IntPtr))).Target; } } internal class CppObjectVtbl { private readonly List<Delegate> methods; private readonly IntPtr vtbl; public IntPtr Pointer => vtbl; public CppObjectVtbl(int numberOfCallbackMethods) { vtbl = Marshal.AllocHGlobal(IntPtr.Size * numberOfCallbackMethods); methods = new List<Delegate>(); } public unsafe void AddMethod(Delegate method) { int count = methods.Count; methods.Add(method); *(IntPtr*)((byte*)(void*)vtbl + (nint)count * (nint)sizeof(IntPtr)) = Marshal.GetFunctionPointerForDelegate(method); } } public struct DataBox { public IntPtr DataPointer; public int RowPitch; public int SlicePitch; public bool IsEmpty { get { if (DataPointer == IntPtr.Zero && RowPitch == 0) { return SlicePitch == 0; } return false; } } public DataBox(IntPtr datapointer, int rowPitch, int slicePitch) { DataPointer = datapointer; RowPitch = rowPitch; SlicePitch = slicePitch; } public DataBox(IntPtr dataPointer) { DataPointer = dataPointer; RowPitch = 0; SlicePitch = 0; } } public class DataBuffer : DisposeBase { private unsafe sbyte* _buffer; private GCHandle _gCHandle; private readonly bool _ownsBuffer; private readonly int _size; private Blob _blob; public unsafe IntPtr DataPointer => new IntPtr(_buffer); public int Size => _size; public unsafe static DataBuffer Create<T>(T[] userBuffer, int index = 0, bool pinBuffer = true) where T : struct { if (userBuffer == null) { throw new ArgumentNullException("userBuffer"); } if (index < 0 || index > userBuffer.Length) { throw new ArgumentException("Index is out of range [0, userBuffer.Length-1]", "index"); } int num = Utilities.SizeOf(userBuffer); int num2 = index * Utilities.SizeOf<T>(); if (pinBuffer) { GCHandle handle = GCHandle.Alloc(userBuffer, GCHandleType.Pinned); return new DataBuffer(num2 + (byte*)(void*)handle.AddrOfPinnedObject(), num - num2, handle); } fixed (T* ptr = &userBuffer[0]) { return new DataBuffer(num2 + (byte*)(void*)(IntPtr)ptr, num - num2, makeCopy: true); } } public unsafe DataBuffer(int sizeInBytes) { _buffer = (sbyte*)(void*)Utilities.AllocateMemory(sizeInBytes); _size = sizeInBytes; _ownsBuffer = true; } public DataBuffer(DataPointer dataPointer) : this(dataPointer.Pointer, dataPointer.Size) { } public unsafe DataBuffer(IntPtr userBuffer, int sizeInBytes) : this((void*)userBuffer, sizeInBytes, makeCopy: false) { } internal unsafe DataBuffer(void* buffer, int sizeInBytes, GCHandle handle) { _buffer = (sbyte*)buffer; _size = sizeInBytes; _gCHandle = handle; _ownsBuffer = false; } internal unsafe DataBuffer(void* buffer, int sizeInBytes, bool makeCopy) { if (makeCopy) { _buffer = (sbyte*)(void*)Utilities.AllocateMemory(sizeInBytes); Utilities.CopyMemory((IntPtr)_buffer, (IntPtr)buffer, sizeInBytes); } else { _buffer = (sbyte*)buffer; } _size = sizeInBytes; _ownsBuffer = makeCopy; } internal unsafe DataBuffer(Blob buffer) { _buffer = (sbyte*)(void*)buffer.GetBufferPointer(); _size = buffer.GetBufferSize(); _blob = buffer; } protected unsafe override void Dispose(bool disposing) { if (disposing && _blob != null) { _blob.Dispose(); _blob = null; } if (_gCHandle.IsAllocated) { _gCHandle.Free(); } if (_ownsBuffer && _buffer != null) { Utilities.FreeMemory((IntPtr)_buffer); _buffer = null; } } public unsafe void Clear(byte value = 0) { Utilities.ClearMemory((IntPtr)_buffer, value, Size); } public unsafe T Get<T>(int positionInBytes) where T : struct { T data = default(T); Utilities.Read((IntPtr)(_buffer + positionInBytes), ref data); return data; } public unsafe void Get<T>(int positionInBytes, out T value) where T : struct { Utilities.ReadOut<T>((IntPtr)(_buffer + positionInBytes), out value); } public unsafe T[] GetRange<T>(int positionInBytes, int count) where T : struct { T[] array = new T[count]; Utilities.Read((IntPtr)(_buffer + positionInBytes), array, 0, count); return array; } public unsafe void GetRange<T>(int positionInBytes, T[] buffer, int offset, int count) where T : struct { Utilities.Read((IntPtr)(_buffer + positionInBytes), buffer, offset, count); } public unsafe void Set<T>(int positionInBytes, ref T value) where T : struct { System.Runtime.CompilerServices.Unsafe.Write(_buffer + positionInBytes, value); } public unsafe void Set<T>(int positionInBytes, T value) where T : struct { System.Runtime.CompilerServices.Unsafe.Write(_buffer + positionInBytes, value); } public unsafe void Set(int positionInBytes, bool value) { *(int*)(_buffer + positionInBytes) = (value ? 1 : 0); } public void Set<T>(int positionInBytes, T[] data) where T : struct { Set(positionInBytes, data, 0, data.Length); } public unsafe void Set(int positionInBytes, IntPtr source, long count) { Utilities.CopyMemory((IntPtr)(_buffer + positionInBytes), source, (int)count); } public unsafe void Set<T>(int positionInBytes, T[] data, int offset, int count) where T : struct { Utilities.Write((IntPtr)(_buffer + positionInBytes), data, offset, count); } public static implicit operator DataPointer(DataBuffer from) { return new DataPointer(from.DataPointer, from.Size); } } public struct DataPointer : IEquatable<DataPointer> { public static readonly DataPointer Zero = new DataPointer(IntPtr.Zero, 0); public IntPtr Pointer; public int Size; public bool IsEmpty => Equals(Zero); public DataPointer(IntPtr pointer, int size) { Pointer = pointer; Size = size; } public unsafe DataPointer(void* pointer, int size) { Pointer = (IntPtr)pointer; Size = size; } public bool Equals(DataPointer other) { if (Pointer.Equals((object?)(nint)other.Pointer)) { return Size == other.Size; } return false; } public override bool Equals(object obj) { if (obj == null) { return false; } if (obj is DataPointer) { return Equals((DataPointer)obj); } return false; } public override int GetHashCode() { return (Pointer.GetHashCode() * 397) ^ Size; } public DataStream ToDataStream() { if (Pointer == IntPtr.Zero) { throw new InvalidOperationException("DataPointer is Zero"); } return new DataStream(this); } public DataBuffer ToDataBuffer() { if (Pointer == IntPtr.Zero) { throw new InvalidOperationException("DataPointer is Zero"); } return new DataBuffer(this); } public byte[] ToArray() { if (Pointer == IntPtr.Zero) { throw new InvalidOperationException("DataPointer is Zero"); } if (Size < 0) { throw new InvalidOperationException("Size cannot be < 0"); } byte[] array = new byte[Size]; Utilities.Read(Pointer, array, 0, Size); return array; } public T[] ToArray<T>() where T : struct { if (Pointer == IntPtr.Zero) { throw new InvalidOperationException("DataPointer is Zero"); } T[] array = new T[Size / Utilities.SizeOf<T>()]; CopyTo(array, 0, array.Length); return array; } public void CopyTo<T>(T[] buffer, int offset, int count) where T : struct { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (Pointer == IntPtr.Zero) { throw new InvalidOperationException("DataPointer is Zero"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset", "Must be >= 0"); } if (count <= 0) { throw new ArgumentOutOfRangeException("count", "Must be > 0"); } if (count * Utilities.SizeOf<T>() > Size) { throw new ArgumentOutOfRangeException("buffer", "Total buffer size cannot be larger than size of this data pointer"); } Utilities.Read(Pointer, buffer, offset, count); } public void CopyFrom<T>(T[] buffer) where T : struct { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (Pointer == IntPtr.Zero) { throw new InvalidOperationException("DataPointer is Zero"); } CopyFrom(buffer, 0, buffer.Length); } public void CopyFrom<T>(T[] buffer, int offset, int count) where T : struct { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (Pointer == IntPtr.Zero) { throw new InvalidOperationException("DataPointer is Zero"); } if (offset < 0) { throw new ArgumentOutOfRangeException("offset", "Must be >= 0"); } if (count <= 0) { throw new ArgumentOutOfRangeException("count", "Must be > 0"); } if (count * Utilities.SizeOf<T>() > Size) { throw new ArgumentOutOfRangeException("buffer", "Total buffer size cannot be larger than size of this data pointer"); } Utilities.Write(Pointer, buffer, offset, count); } public static bool operator ==(DataPointer left, DataPointer right) { return left.Equals(right); } public static bool operator !=(DataPointer left, DataPointer right) { return !left.Equals(right); } } public struct DataRectangle { public IntPtr DataPointer; public int Pitch; public DataRectangle(IntPtr dataPointer, int pitch) { DataPointer = dataPointer; Pitch = pitch; } } public class DataStream : Stream { private unsafe byte* _buffer; private readonly bool _canRead; private readonly bool _canWrite; private GCHandle _gCHandle; private Blob _blob; private readonly bool _ownsBuffer; private long _position; private readonly long _size; public override bool CanRead => _canRead; public override bool CanSeek => true; public override bool CanWrite => _canWrite; public unsafe IntPtr DataPointer => new IntPtr(_buffer); public override long Length => _size; public override long Position { get { return _position; } set { Seek(value, SeekOrigin.Begin); } } public unsafe IntPtr PositionPointer => (IntPtr)(_buffer + _position); public long RemainingLength => _size - _position; public unsafe DataStream(Blob buffer) { _buffer = (byte*)(void*)buffer.GetBufferPointer(); _size = buffer.GetBufferSize(); _canRead = true; _canWrite = true; _blob = buffer; } public unsafe static DataStream Create<T>(T[] userBuffer, bool canRead, bool canWrite, int index = 0, bool pinBuffer = true) where T : struct { if (userBuffer == null) { throw new ArgumentNullException("userBuffer"); } if (index < 0 || index > userBuffer.Length) { throw new ArgumentException("Index is out of range [0, userBuffer.Length-1]", "index"); } int num = Utilities.SizeOf(userBuffer); int num2 = index * Utilities.SizeOf<T>(); if (pinBuffer) { GCHandle handle = GCHandle.Alloc(userBuffer, GCHandleType.Pinned); return new DataStream(num2 + (byte*)(void*)handle.AddrOfPinnedObject(), num - num2, canRead, canWrite, handle); } fixed (T* ptr = &userBuffer[0]) { return new DataStream(num2 + (byte*)(void*)(IntPtr)ptr, num - num2, canRead, canWrite, makeCopy: true); } } public unsafe DataStream(int sizeInBytes, bool canRead, bool canWrite) { _buffer = (byte*)(void*)Utilities.AllocateMemory(sizeInBytes); _size = sizeInBytes; _ownsBuffer = true; _canRead = canRead; _canWrite = canWrite; } public DataStream(DataPointer dataPointer) : this(dataPointer.Pointer, dataPointer.Size, canRead: true, canWrite: true) { } public unsafe DataStream(IntPtr userBuffer, long sizeInBytes, bool canRead, bool canWrite) { _buffer = (byte*)userBuffer.ToPointer(); _size = sizeInBytes; _canRead = canRead; _canWrite = canWrite; } internal unsafe DataStream(void* dataPointer, int sizeInBytes, bool canRead, bool canWrite, GCHandle handle) { _gCHandle = handle; _buffer = (byte*)dataPointer; _size = sizeInBytes; _canRead = canRead; _canWrite = canWrite; _ownsBuffer = false; } internal unsafe DataStream(void* buffer, int sizeInBytes, bool canRead, bool canWrite, bool makeCopy) { if (makeCopy) { _buffer = (byte*)(void*)Utilities.AllocateMemory(sizeInBytes); Utilities.CopyMemory((IntPtr)_buffer, (IntPtr)buffer, sizeInBytes); } else { _buffer = (byte*)buffer; } _size = sizeInBytes; _canRead = canRead; _canWrite = canWrite; _ownsBuffer = makeCopy; } ~DataStream() { Dispose(disposing: false); } protected unsafe override void Dispose(bool disposing) { if (disposing && _blob != null) { _blob.Dispose(); _blob = null; } if (_gCHandle.IsAllocated) { _gCHandle.Free(); } if (_ownsBuffer && _buffer != null) { Utilities.FreeMemory((IntPtr)_buffer); _buffer = null; } } public override void Flush() { throw new NotSupportedException("DataStream objects cannot be flushed."); } public unsafe T Read<T>() where T : struct { if (!_canRead) { throw new NotSupportedException(); } byte* ptr = _buffer + _position; T data = default(T); _position = (byte*)(void*)Utilities.ReadAndPosition((IntPtr)ptr, ref data) - _buffer; return data; } public unsafe override int ReadByte() { if (_position >= Length) { return -1; } return _buffer[_position++]; } public override int Read(byte[] buffer, int offset, int count) { int count2 = (int)Math.Min(RemainingLength, count); return ReadRange(buffer, offset, count2); } public unsafe void Read(IntPtr buffer, int offset, int count) { Utilities.CopyMemory(new IntPtr((byte*)(void*)buffer + offset), (IntPtr)(_buffer + _position), count); _position += count; } public unsafe T[] ReadRange<T>(int count) where T : struct { if (!_canRead) { throw new NotSupportedException(); } byte* ptr = _buffer + _position; T[] array = new T[count]; _position = (byte*)(void*)Utilities.Read((IntPtr)ptr, array, 0, count) - _buffer; return array; } public unsafe int ReadRange<T>(T[] buffer, int offset, int count) where T : struct { if (!_canRead) { throw new NotSupportedException(); } long position = _position; _position = (byte*)(void*)Utilities.Read((IntPtr)(_buffer + _position), buffer, offset, count) - _buffer; return (int)(_position - position); } public override long Seek(long offset, SeekOrigin origin) { long num = 0L; switch (origin) { case SeekOrigin.Begin: num = offset; break; case SeekOrigin.Current: num = _position + offset; break; case SeekOrigin.End: num = _size - offset; break; } if (num < 0) { throw new InvalidOperationException("Cannot seek beyond the beginning of the stream."); } if (num > _size) { throw new InvalidOperationException("Cannot seek beyond the end of the stream."); } _position = num; return _position; } public override void SetLength(long value) { throw new NotSupportedException("DataStream objects cannot be resized."); } public unsafe void Write<T>(T value) where T : struct { if (!_canWrite) { throw new NotSupportedException(); } _position = (byte*)(void*)Utilities.WriteAndPosition((IntPtr)(_buffer + _position), ref value) - _buffer; } public override void Write(byte[] buffer, int offset, int count) { WriteRange(buffer, offset, count); } public unsafe void Write(IntPtr buffer, int offset, int count) { Utilities.CopyMemory((IntPtr)(_buffer + _position), new IntPtr((byte*)(void*)buffer + offset), count); _position += count; } public void WriteRange<T>(T[] data) where T : struct { WriteRange(data, 0, data.Length); } public unsafe void WriteRange(IntPtr source, long count) { if (!_canWrite) { throw new NotSupportedException(); } Utilities.CopyMemory((IntPtr)(_buffer + _position), source, (int)count); _position += count; } public unsafe void WriteRange<T>(T[] data, int offset, int count) where T : struct { if (!_canWrite) { throw new NotSupportedException(); } _position = (byte*)(void*)Utilities.Write((IntPtr)(_buffer + _position), data, offset, count) - _buffer; } public static implicit operator DataPointer(DataStream from) { return new DataPointer(from.PositionPointer, (int)from.RemainingLength); } } public class CompilationException : SharpDXException { public CompilationException(string message) : base(message) { } public CompilationException(Result errorCode, string message) : base(errorCode, message) { } } public abstract class CompilationResultBase<T> : DisposeBase where T : class, IDisposable { public T Bytecode { get; private set; } public Result ResultCode { get; private set; } public bool HasErrors => ResultCode.Failure; public string Message { get; private set; } protected CompilationResultBase(T bytecode, Result resultCode, string message = null) { Bytecode = bytecode; ResultCode = resultCode; Message = message; } protected override void Dispose(bool disposing) { if (disposing && Bytecode != null) { Bytecode.Dispose(); Bytecode = null; } } } public abstract class DisposeBase : IDisposable { public bool IsDisposed { get; private set; } public event EventHandler<EventArgs> Disposing; public event EventHandler<EventArgs> Disposed; ~DisposeBase() { CheckAndDispose(disposing: false); } public void Dispose() { CheckAndDispose(disposing: true); } private void CheckAndDispose(bool disposing) { if (!IsDisposed) { this.Disposing?.Invoke(this, DisposeEventArgs.Get(disposing)); Dispose(disposing); GC.SuppressFinalize(this); IsDisposed = true; this.Disposed?.Invoke(this, DisposeEventArgs.Get(disposing)); } } protected abstract void Dispose(bool disposing); } public class DisposeCollector : DisposeBase { private List<object> disposables; public int Count => disposables.Count; public void DisposeAndClear(bool disposeManagedResources = true) { if (disposables == null) { return; } for (int num = disposables.Count - 1; num >= 0; num--) { object obj = disposables[num]; if (obj is IDisposable disposable) { if (disposeManagedResources) { disposable.Dispose(); } } else { Utilities.FreeMemory((IntPtr)obj); } disposables.RemoveAt(num); } disposables.Clear(); } protected override void Dispose(bool disposeManagedResources) { DisposeAndClear(disposeManagedResources); disposables = null; } public T Collect<T>(T toDispose) { if (!(toDispose is IDisposable) && !(toDispose is IntPtr)) { throw new ArgumentException("Argument must be IDisposable or IntPtr"); } if (toDispose is IntPtr && !Utilities.IsMemoryAligned((IntPtr)(object)toDispose)) { throw new ArgumentException("Memory pointer is invalid. Memory must have been allocated with Utilties.AllocateMemory"); } if (!object.Equals(toDispose, default(T))) { if (disposables == null) { disposables = new List<object>(); } if (!disposables.Contains(toDispose)) { disposables.Add(toDispose); } } return toDispose; } public void RemoveAndDispose<T>(ref T objectToDispose) { if (disposables != null) { Remove(objectToDispose); if ((object)objectToDispose is IDisposable disposable) { disposable.Dispose(); } else { Utilities.FreeMemory((IntPtr)(object)objectToDispose); } objectToDispose = default(T); } } public void Remove<T>(T toDisposeArg) { if (disposables != null && disposables.Contains(toDisposeArg)) { disposables.Remove(toDisposeArg); } } } public class DisposeEventArgs : EventArgs { public static readonly DisposeEventArgs DisposingEventArgs = new DisposeEventArgs(disposing: true); public static readonly DisposeEventArgs NotDisposingEventArgs = new DisposeEventArgs(disposing: false); public readonly bool Disposing; private DisposeEventArgs(bool disposing) { Disposing = disposing; } public static DisposeEventArgs Get(bool disposing) { if (!disposing) { return NotDisposingEventArgs; } return DisposingEventArgs; } } [StructLayout(LayoutKind.Sequential)] internal class FunctionCallback { public IntPtr Pointer; public FunctionCallback(IntPtr pointer) { Pointer = pointer; } public unsafe FunctionCallback(void* pointer) { Pointer = new IntPtr(pointer); } public static explicit operator IntPtr(FunctionCallback value) { return value.Pointer; } public static implicit operator FunctionCallback(IntPtr value) { return new FunctionCallback(value); } public unsafe static implicit operator void*(FunctionCallback value) { return (void*)value.Pointer; } public unsafe static explicit operator FunctionCallback(void* value) { return new FunctionCallback(value); } public override string ToString() { return string.Format(CultureInfo.CurrentCulture, "{0}", new object[1] { Pointer }); } public string ToString(string format) { if (format == null) { return ToString(); } return string.Format(CultureInfo.CurrentCulture, "{0}", new object[1] { Pointer.ToString(format) }); } public override int GetHashCode() { return Pointer.ToInt32(); } public bool Equals(FunctionCallback other) { return Pointer == other.Pointer; } public override bool Equals(object value) { if (value == null) { return false; } if ((object)value.GetType() != typeof(FunctionCallback)) { return false; } return Equals((FunctionCallback)value); } } public interface ICallbackable : IDisposable { IDisposable Shadow { get; set; } } [Guid("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90")] [Shadow(typeof(InspectableShadow))] public interface IInspectable : ICallbackable, IDisposable { } internal class InspectableShadow : ComObjectShadow { public class InspectableProviderVtbl : ComObjectVtbl { [UnmanagedFunctionPointer(CallingConvention.StdCall)] private unsafe delegate int GetIidsDelegate(IntPtr thisPtr, int* iidCount, IntPtr* iids); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate int GetRuntimeClassNameDelegate(IntPtr thisPtr, IntPtr className); private enum TrustLevel { BaseTrust, PartialTrust, FullTrust } [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate int GetTrustLevelDelegate(IntPtr thisPtr, IntPtr trustLevel); public InspectableProviderVtbl() : base(3) { AddMethod(new GetIidsDelegate(GetIids)); AddMethod(new GetRuntimeClassNameDelegate(GetRuntimeClassName)); AddMethod(new GetTrustLevelDelegate(GetTrustLevel)); } private unsafe static int GetIids(IntPtr thisPtr, int* iidCount, IntPtr* iids) { try { ShadowContainer shadowContainer = (ShadowContainer)((IInspectable)CppObjectShadow.ToShadow<InspectableShadow>(thisPtr).Callback).Shadow; int num = shadowContainer.Guids.Length; iids = (IntPtr*)(void*)Marshal.AllocCoTaskMem(IntPtr.Size * num); *iidCount = num; for (int i = 0; i < num; i++) { iids[i] = shadowContainer.Guids[i]; } } catch (Exception ex) { return (int)Result.GetResultFromException(ex); } return Result.Ok.Code; } private static int GetRuntimeClassName(IntPtr thisPtr, IntPtr className) { try { _ = (IInspectable)CppObjectShadow.ToShadow<InspectableShadow>(thisPtr).Callback; } catch (Exception ex) { return (int)Result.GetResultFromException(ex); } return Result.Ok.Code; } private static int GetTrustLevel(IntPtr thisPtr, IntPtr trustLevel) { try { _ = (IInspectable)CppObjectShadow.ToShadow<InspectableShadow>(thisPtr).Callback; Marshal.WriteInt32(trustLevel, 2); } catch (Exception ex) { return (int)Result.GetResultFromException(ex); } return Result.Ok.Code; } } private static readonly InspectableProviderVtbl Vtbl = new InspectableProviderVtbl(); protected override CppObjectVtbl GetVtbl => Vtbl; public static IntPtr ToIntPtr(IInspectable callback) { return CppObject.ToCallbackPtr<IInspectable>(callback); } } internal class Interop { public unsafe static void* Fixed<T>(ref T data) { throw new NotImplementedException(); } public unsafe static void* Fixed<T>(T[] data) { throw new NotImplementedException(); } public unsafe static void* Cast<T>(ref T data) where T : struct { return System.Runtime.CompilerServices.Unsafe.AsPointer(ref data); } public unsafe static void* CastOut<T>(out T data) where T : struct { return System.Runtime.CompilerServices.Unsafe.AsPointer(ref data); } public static TCAST[] CastArray<TCAST, T>(T[] arrayData) where TCAST : struct where T : struct { return (TCAST[])(object)arrayData; } public unsafe static void memcpy(void* pDest, void* pSrc, int count) { // IL cpblk instruction System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(pDest, pSrc, count); } public unsafe static void memset(void* pDest, byte value, int count) { // IL initblk instruction System.Runtime.CompilerServices.Unsafe.InitBlockUnaligned(pDest, value, count); } public unsafe static void* Read<T>(void* pSrc, ref T data) where T : struct { fixed (T* ptr = &data) { ref ? reference = ref *(?*)ptr; int num = System.Runtime.CompilerServices.Unsafe.SizeOf<T>(); // IL cpblk instruction System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(ref reference, pSrc, num); return num + (byte*)pSrc; } } public unsafe static T ReadInline<T>(void* pSrc) where T : struct { throw new NotImplementedException(); } public unsafe static void WriteInline<T>(void* pDest, ref T data) where T : struct { throw new NotImplementedException(); } public unsafe static void CopyInline<T>(ref T data, void* pSrc) where T : struct { throw new NotImplementedException(); } public unsafe static void CopyInline<T>(void* pDest, ref T srcData) where T : struct { throw new NotImplementedException(); } public unsafe static void CopyInlineOut<T>(out T data, void* pSrc) where T : struct { throw new NotImplementedException(); } public unsafe static void* ReadOut<T>(void* pSrc, out T data) where T : struct { fixed (T* ptr = &data) { ref ? reference = ref *(?*)ptr; int num = System.Runtime.CompilerServices.Unsafe.SizeOf<T>(); // IL cpblk instruction System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(ref reference, pSrc, num); return num + (byte*)pSrc; } } public unsafe static void* Read<T>(void* pSrc, T[] data, int offset, int count) where T : struct { fixed (T* ptr = &data[offset]) { ref ? reference = ref *(?*)ptr; int num = System.Runtime.CompilerServices.Unsafe.SizeOf<T>() * count; // IL cpblk instruction System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(ref reference, pSrc, num); return num + (byte*)pSrc; } } public unsafe static void* Read2D<T>(void* pSrc, T[,] data, int offset, int count) where T : struct { fixed (T* ptr = &data[offset]) { ref ? reference = ref *(?*)ptr; int num = System.Runtime.CompilerServices.Unsafe.SizeOf<T>() * count; // IL cpblk instruction System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(ref reference, pSrc, num); return num + (byte*)pSrc; } } public static int SizeOf<T>() { throw new NotImplementedException(); } public unsafe static void* Write<T>(void* pDest, ref T data) where T : struct { fixed (T* ptr = &data) { ref ? reference = ref *(?*)ptr; int num = System.Runtime.CompilerServices.Unsafe.SizeOf<T>(); // IL cpblk instruction System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(pDest, ref reference, num); return num + (byte*)pDest; } } public unsafe static void* Write<T>(void* pDest, T[] data, int offset, int count) where T : struct { fixed (T* ptr = &data[offset]) { ref ? reference = ref *(?*)ptr; int num = System.Runtime.CompilerServices.Unsafe.SizeOf<T>() * count; // IL cpblk instruction System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(pDest, ref reference, num); return num + (byte*)pDest; } } public unsafe static void* Write2D<T>(void* pDest, T[,] data, int offset, int count) where T : struct { fixed (T* ptr = &data[offset]) { ref ? reference = ref *(?*)ptr; int num = System.Runtime.CompilerServices.Unsafe.SizeOf<T>() * count; // IL cpblk instruction System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(pDest, ref reference, num); return num + (byte*)pDest; } } [Tag("SharpDX.ModuleInit")] public static void ModuleInit() { } } [Guid("00000000-0000-0000-C000-000000000046")] public interface IUnknown : ICallbackable, IDisposable { Result QueryInterface(ref Guid guid, out IntPtr comObject); int AddReference(); int Release(); } internal class ModuleInit { [Tag("SharpDX.ModuleInit")] internal static void Setup() { ResultDescriptor.RegisterProvider(typeof(Result)); } } [CompilerGenerated] internal class NamespaceDoc { } public struct PointerSize : IEquatable<PointerSize> { private IntPtr _size; public static readonly PointerSize Zero = new PointerSize(0); public PointerSize(IntPtr size) { _size = size; } private unsafe PointerSize(void* size) { _size = new IntPtr(size); } public PointerSize(int size) { _size = new IntPtr(size); } public PointerSize(long size) { _size = new IntPtr(size); } public override string ToString() { return string.Format(CultureInfo.CurrentCulture, "{0}", new object[1] { _size }); } public string ToString(string format) { if (format == null) { return ToString(); } return string.Format(CultureInfo.CurrentCulture, "{0}", new object[1] { _size.ToString(format) }); } public override int GetHashCode() { return _size.GetHashCode(); } public bool Equals(PointerSize other) { return _size.Equals((object?)(nint)other._size); } public override bool Equals(object value) { if (value == null) { return false; } if (value is PointerSize) { return Equals((PointerSize)value); } return false; } public static PointerSize operator +(PointerSize left, PointerSize right) { return new PointerSize(left._size.ToInt64() + right._size.ToInt64()); } public static PointerSize operator +(PointerSize value) { return value; } public static PointerSize operator -(PointerSize left, PointerSize right) { return new PointerSize(left._size.ToInt64() - right._size.ToInt64()); } public static PointerSize operator -(PointerSize value) { return new PointerSize(-value._size.ToInt64()); } public static PointerSize operator *(int scale, PointerSize value) { return new PointerSize(scale * value._size.ToInt64()); } public static PointerSize operator *(PointerSize value, int scale) { return new PointerSize(scale * value._size.ToInt64()); } public static PointerSize operator /(PointerSize value, int scale) { return new PointerSize(value._size.ToInt64() / scale); } public static bool operator ==(PointerSize left, PointerSize right) { return left.Equals(right); } public static bool operator !=(PointerSize left, PointerSize right) { return !left.Equals(right); } public static implicit operator int(PointerSize value) { return value._size.ToInt32(); } public static implicit operator long(PointerSize value) { return value._size.ToInt64(); } public static implicit operator PointerSize(int value) { return new PointerSize(value); } public static implicit operator PointerSize(long value) { return new PointerSize(value); } public static implicit operator PointerSize(IntPtr value) { return new PointerSize(value); } public static implicit operator IntPtr(PointerSize value) { return value._size; } public unsafe static implicit operator PointerSize(void* value) { return new PointerSize(value); } public unsafe static implicit operator void*(PointerSize value) { return (void*)value._size; } } public struct Result : IEquatable<Result> { private int _code; public static readonly Result Ok = new Result(0); public static readonly Result False = new Result(1); public static readonly ResultDescriptor Abort = new ResultDescriptor(-2147467260, "General", "E_ABORT", "Operation aborted"); public static readonly ResultDescriptor AccessDenied = new ResultDescriptor(-2147024891, "General", "E_ACCESSDENIED", "General access denied error"); public static readonly ResultDescriptor Fail = new ResultDescriptor(-2147467259, "General", "E_FAIL", "Unspecified error"); public static readonly ResultDescriptor Handle = new ResultDescriptor(-2147024890, "General", "E_HANDLE", "Invalid handle"); public static readonly ResultDescriptor InvalidArg = new ResultDescriptor(-2147024809, "General", "E_INVALIDARG", "Invalid Arguments"); public static readonly ResultDescriptor NoInterface = new ResultDescriptor(-2147467262, "General", "E_NOINTERFACE", "No such interface supported"); public static readonly ResultDescriptor NotImplemented = new ResultDescriptor(-2147467263, "General", "E_NOTIMPL", "Not implemented"); public static readonly ResultDescriptor OutOfMemory = new ResultDescriptor(-2147024882, "General", "E_OUTOFMEMORY", "Out of memory"); public static readonly ResultDescriptor InvalidPointer = new ResultDescriptor(-2147467261, "General", "E_POINTER", "Invalid pointer"); public static readonly ResultDescriptor UnexpectedFailure = new ResultDescriptor(-2147418113, "General", "E_UNEXPECTED", "Catastrophic failure"); public static readonly ResultDescriptor WaitAbandoned = new ResultDescriptor(128, "General", "WAIT_ABANDONED", "WaitAbandoned"); public static readonly ResultDescriptor WaitTimeout = new ResultDescriptor(258, "General", "WAIT_TIMEOUT", "WaitTimeout"); public static readonly ResultDescriptor Pending = new ResultDescriptor(-2147483638, "General", "E_PENDING", "Pending"); public int Code => _code; public bool Success => Code >= 0; public bool Failure => Code < 0; public Result(int code) { _code = code; } public Result(uint code) { _code = (int)code; } public static explicit operator int(Result result) { return result.Code; } public static explicit operator uint(Result result) { return (uint)result.Code; } public static implicit operator Result(int result) { return new Result(result); } public static implicit operator Result(uint result) { return new Result(result); } public bool Equals(Result other) { return Code == other.Code; } public override bool Equals(object obj) { if (!(obj is Result)) { return false; } return Equals((Result)obj); } public override int GetHashCode() { return Code; } public static bool operator ==(Result left, Result right) { return left.Code == right.Code; } public static bool operator !=(Result left, Result right) { return left.Code != right.Code; } public override string ToString() { return string.Format(CultureInfo.InvariantCulture, "HRESULT = 0x{0:X}", new object[1] { _code }); } public void CheckError() { if (_code < 0) { throw new SharpDXException(this); } } public static Result GetResultFromException(Exception ex) { return new Result(Marshal.GetHRForException(ex)); } public static Result GetResultFromWin32Error(int win32Error) { return (int)((win32Error <= 0) ? win32Error : ((win32Error & 0xFFFF) | 0x70000 | 0x80000000u)); } } public sealed class ResultDescriptor { private static readonly object LockDescriptor = new object(); private static readonly List<Type> RegisteredDescriptorProvider = new List<Type>(); private static readonly Dictionary<Result, ResultDescriptor> Descriptors = new Dictionary<Result, ResultDescriptor>(); private const string UnknownText = "Unknown"; public Result Result { get; private set; } public int Code => Result.Code; public string Module { get; private set; } public string NativeApiCode { get; private set; } public string ApiCode { get; private set; } public string Description { get; set; } public ResultDescriptor(Result code, string module, string nativeApiCode, string apiCode, string description = null) { Result = code; Module = module; NativeApiCode = nativeApiCode; ApiCode = apiCode; Description = description; } public bool Equals(ResultDescriptor other) { if (other == null) { return false; } if ((object)this == other) { return true; } return other.Result.Equals(Result); } public override bool Equals(object obj) { if (obj == null) { return false; } if (this == obj) { return true; } if (obj.GetType() != typeof(ResultDescriptor)) { return false; } return Equals((ResultDescriptor)obj); } public override int GetHashCode() { return Result.GetHashCode(); } public override string ToString() { return $"HRESULT: [0x{Result.Code:X}], Module: [{Module}], ApiCode: [{NativeApiCode}/{ApiCode}], Message: {Description}"; } public static implicit operator Result(ResultDescriptor result) { return result.Result; } public static explicit operator int(ResultDescriptor result) { return result.Result.Code; } public static explicit operator uint(ResultDescriptor result) { return (uint)result.Result.Code; } public static bool operator ==(ResultDescriptor left, Result right) { if (left == null) { return false; } return left.Result.Code == right.Code; } public static bool operator !=(ResultDescriptor left, Result right) { if (left == null) { return false; } return left.Result.Code != right.Code; } public static void RegisterProvider(Type descriptorsProviderType) { lock (LockDescriptor) { if (!RegisteredDescriptorProvider.Contains(descriptorsProviderType)) { RegisteredDescriptorProvider.Add(descriptorsProviderType); } } } public static ResultDescriptor Find(Result result) { ResultDescriptor value; lock (LockDescriptor) { if (RegisteredDescriptorProvider.Count > 0) { foreach (Type item in RegisteredDescriptorProvider) { AddDescriptorsFromType(item); } RegisteredDescriptorProvider.Clear(); } if (!Descriptors.TryGetValue(result, out value)) { value = new ResultDescriptor(result, "Unknown", "Unknown", "Unknown"); } if (value.Description == null) { string descriptionFromResultCode = GetDescriptionFromResultCode(result.Code); value.Description = descriptionFromResultCode ?? "Unknown"; } } return value; } private static void AddDescriptorsFromType(Type type) { foreach (FieldInfo declaredField in type.GetTypeInfo().DeclaredFields) { if (declaredField.FieldType == typeof(ResultDescriptor) && declaredField.IsPublic && declaredField.IsStatic) { ResultDescriptor resultDescriptor = (ResultDescriptor)declaredField.GetValue(null); if (!Descriptors.ContainsKey(resultDescriptor.Result)) { Descriptors.Add(resultDescriptor.Result, resultDescriptor); } } } } private static string GetDescriptionFromResultCode(int resultCode) { IntPtr lpBuffer = IntPtr.Zero; FormatMessageW(4864, IntPtr.Zero, resultCode, 0, ref lpBuffer, 0, IntPtr.Zero); string? result = Marshal.PtrToStringUni(lpBuffer); Marshal.FreeHGlobal(lpBuffer); return result; } [DllImport("kernel32.dll")] private static extern uint FormatMessageW(int dwFlags, IntPtr lpSource, int dwMessageId, int dwLanguageId, ref IntPtr lpBuffer, int nSize, IntPtr Arguments); } public class ServiceEventArgs : EventArgs { public Type ServiceType { get; private set; } public object Instance { get; private set; } public ServiceEventArgs(Type serviceType, object serviceInstance) { ServiceType = serviceType; Instance = serviceInstance; } } [AttributeUsage(AttributeTargets.Interface)] internal class ShadowAttribute : Attribute { private Type type; public Type Type => type; public ShadowAttribute(Type typeOfTheAssociatedShadow) { type = typeOfTheAssociatedShadow; } public static ShadowAttribute Get(Type type) { return type.GetTypeInfo().GetCustomAttribute<ShadowAttribute>(); } } internal class ShadowContainer : DisposeBase { private readonly Dictionary<Guid, CppObjectShadow> guidToShadow = new Dictionary<Guid, CppObjectShadow>(); private static readonly Dictionary<Type, List<Type>> typeToShadowTypes = new Dictionary<Type, List<Type>>(); private IntPtr guidPtr; public IntPtr[] Guids { get; private set; } public unsafe void Initialize(ICallbackable callbackable) { callbackable.Shadow = this; Type type = callbackable.GetType(); List<Type> value; lock (typeToShadowTypes) { if (!typeToShadowTypes.TryGetValue(type, out value)) { IEnumerable<Type> implementedInterfaces = type.GetTypeInfo().ImplementedInterfaces; value = new List<Type>(); value.AddRange(implementedInterfaces); typeToShadowTypes.Add(type, value); foreach (Type item in implementedInterfaces) { if (ShadowAttribute.Get(item) == null) { value.Remove(item); continue; } foreach (Type implementedInterface in item.GetTypeInfo().ImplementedInterfaces) { value.Remove(implementedInterface); } } } } CppObjectShadow cppObjectShadow = null; foreach (Type item2 in value) { CppObjectShadow cppObjectShadow2 = (CppObjectShadow)Activator.CreateInstance(ShadowAttribute.Get(item2).Type); cppObjectShadow2.Initialize(callbackable); if (cppObjectShadow == null) { cppObjectShadow = cppObjectShadow2; guidToShadow.Add(ComObjectShadow.IID_IUnknown, cppObjectShadow); } guidToShadow.Add(Utilities.GetGuidFromType(item2), cppObjectShadow2); foreach (Type implementedInterface2 in item2.GetTypeInfo().ImplementedInterfaces) { if (ShadowAttribute.Get(implementedInterface2) != null) { guidToShadow.Add(Utilities.GetGuidFromType(implementedInterface2), cppObjectShadow2); } } } int num = 0; foreach (Guid key in guidToShadow.Keys) { if (key != Utilities.GetGuidFromType(typeof(IInspectable)) && key != Utilities.GetGuidFromType(typeof(IUnknown))) { num++; } } guidPtr = Marshal.AllocHGlobal(Utilities.SizeOf<Guid>() * num); Guids = new IntPtr[num]; int num2 = 0; Guid* ptr = (Guid*)(void*)guidPtr; foreach (Guid key2 in guidToShadow.Keys) { if (!(key2 == Utilities.GetGuidFromType(typeof(IInspectable))) && !(key2 == Utilities.GetGuidFromType(typeof(IUnknown)))) { ptr[num2] = key2; Guids[num2] = new IntPtr(ptr + num2); num2++; } } } internal IntPtr Find(Type type) { return Find(Utilities.GetGuidFromType(type)); } internal IntPtr Find(Guid guidType) { return FindShadow(guidType)?.NativePointer ?? IntPtr.Zero; } internal CppObjectShadow FindShadow(Guid guidType) { guidToShadow.TryGetValue(guidType, out var value); return value; } protected override void Dispose(bool disposing) { if (!disposing) { return; } foreach (CppObjectShadow value in guidToShadow.Values) { value.Dispose(); } guidToShadow.Clear(); if (guidPtr != IntPtr.Zero) { Marshal.FreeHGlobal(guidPtr); guidPtr = IntPtr.Zero; } } } public class SharpDXException : Exception { private ResultDescriptor descriptor; public Result ResultCode => descriptor.Result; public ResultDescriptor Descriptor => descriptor; public SharpDXException() : base("A SharpDX exception occurred.") { descriptor = ResultDescriptor.Find(Result.Fail); base.HResult = (int)Result.Fail; } public SharpDXException(Result result) : this(ResultDescriptor.Find(result)) { base.HResult = (int)result; } public SharpDXException(ResultDescriptor descriptor) : base(descriptor.ToString()) { this.descriptor = descriptor; base.HResult = (int)descriptor.Result; } public SharpDXException(Result result, string message) : base(message) { descriptor = ResultDescriptor.Find(result); base.HResult = (int)result; } public SharpDXException(Result result, string message, params object[] args) : base(string.Format(CultureInfo.InvariantCulture, message, args)) { descriptor = ResultDescriptor.Find(result); base.HResult = (int)result; } public SharpDXException(string message, params object[] args) : this(Result.Fail, message, args) { } public SharpDXException(string message, Exception innerException, params object[] args) : base(string.Format(CultureInfo.InvariantCulture, message, args), innerException) { descriptor = ResultDescriptor.Find(Result.Fail); base.HResult = (int)Result.Fail; } } public struct Size2 : IEquatable<Size2> { public static readonly Size2 Zero = new Size2(0, 0); public static readonly Size2 Empty = Zero; public int Width; public int Height; public Size2(int width, int height) { Width = width; Height = height; } public bool Equals(Size2 other) { if (other.Width == Width) { return other.Height == Height; } return false; } public override bool Equals(object obj) { if (!(obj is Size2)) { return false; } return Equals((Size2)obj); } public override int GetHashCode() { return (Width * 397) ^ Height; } public static bool operator ==(Size2 left, Size2 right) { return left.Equals(right); } public static bool operator !=(Size2 left, Size2 right) { return !left.Equals(right); } public override string ToString() { return $"({Width},{Height})"; } } public struct Size2F : IEquatable<Size2F> { public static readonly Size2F Zero = new Size2F(0f, 0f); public static readonly Size2F Empty = Zero; public float Width; public float Height; public Size2F(float width, float height) { Width = width; Height = height; } public bool Equals(Size2F other) { if (other.Width == Width) { return other.Height == Height; } return false; } public override bool Equals(object obj) { if (!(obj is Size2F)) { return false; } return Equals((Size2F)obj); } public override int GetHashCode() { return (Width.GetHashCode() * 397) ^ Height.GetHashCode(); } public static bool operator ==(Size2F left, Size2F right) { return left.Equals(right); } public static bool operator !=(Size2F left, Size2F right) { return !left.Equals(right); } public override string ToString() { return $"({Width},{Height})"; } } [AttributeUsage(AttributeTargets.All)] public class TagAttribute : Attribute { public string Value { get; private set; } public TagAttribute(string value) { Value = value; } } public delegate void GetValueFastDelegate<T>(object obj, out T value); public delegate void SetValueFastDelegate<T>(object obj, ref T value); public static class Utilities { [Flags] public enum CLSCTX : uint { ClsctxInprocServer = 1u, ClsctxInprocHandler = 2u, ClsctxLocalServer = 4u, ClsctxInprocServer16 = 8u, ClsctxRemoteServer = 0x10u, ClsctxInprocHandler16 = 0x20u, ClsctxReserved1 = 0x40u, ClsctxReserved2 = 0x80u, ClsctxReserved3 = 0x100u, ClsctxReserved4 = 0x200u, ClsctxNoCodeDownload = 0x400u, ClsctxReserved5 = 0x800u, ClsctxNoCustomMarshal = 0x1000u, ClsctxEnableCodeDownload = 0x2000u, ClsctxNoFailureLog = 0x4000u, ClsctxDisableAaa = 0x8000u, ClsctxEnableAaa = 0x10000u, ClsctxFromDefaultContext = 0x20000u, ClsctxInproc = 3u, ClsctxServer = 0x15u, ClsctxAll = 0x17u } public enum CoInit { MultiThreaded = 0, ApartmentThreaded = 2, DisableOle1Dde = 4, SpeedOverMemory = 8 } internal struct Buffer<TElement> { internal TElement[] items; internal int count; internal Buffer(IEnumerable<TElement> source) { TElement[] array = null; int num = 0; if (source is ICollection<TElement> collection) { num = collection.Count; if (num > 0) { array = new TElement[num]; collection.CopyTo(array, 0); } } else { foreach (TElement item in source) { if (array == null) { array = new TElement[4]; } else if (array.Length == num) { TElement[] array2 = new TElement[checked(num * 2)]; Array.Copy(array, 0, array2, 0, num); array = array2; } array[num] = item; num++; } } items = array; count = num; } internal TElement[] ToArray() { if (count == 0) { return new TElement[0]; } if (items.Length == count) { return items; } TElement[] array = new TElement[count]; Array.Copy(items, 0, array, 0, count); return array; } } public unsafe static void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy) { Interop.memcpy((void*)dest, (void*)src, sizeInBytesToCopy); } public unsafe static bool CompareMemory(IntPtr from, IntPtr against, int sizeToCompare) { byte* ptr = (byte*)(void*)from; byte* ptr2 = (byte*)(void*)against; for (int num = sizeToCompare >> 3; num > 0; num--) { if (*(long*)ptr != *(long*)ptr2) { return false; } ptr += 8; ptr2 += 8; } for (int num = sizeToCompare & 7; num > 0; num--) { if (*ptr != *ptr2) { return false; } ptr++; ptr2++; } return true; } public unsafe static void ClearMemory(IntPtr dest, byte value, int sizeInBytesToClear) { Interop.memset((void*)dest, value, sizeInBytesToClear); } public static int SizeOf<T>() where T : struct { return System.Runtime.CompilerServices.Unsafe.SizeOf<T>(); } public static int SizeOf<T>(T[] array) where T : struct { if (array != null) { return array.Length * System.Runtime.CompilerServices.Unsafe.SizeOf<T>(); } return 0; } public unsafe static void Pin<T>(ref T source, Action<IntPtr> pinAction) where T : struct { fixed (T* ptr = &source) { pinAction((IntPtr)ptr); } } public unsafe static void Pin<T>(T[] source, Action<IntPtr> pinAction) where T : struct { //The blocks IL_0019 are reachable both inside and outside the pinned region starting at IL_000b. ILSpy has duplicated these blocks in order to place them both within and outside the `fixed` statement. IntPtr obj; if (source != null) { fixed (T* ptr = &source[0]) { obj = (IntPtr)ptr; pinAction(obj); return; } } obj = IntPtr.Zero; pinAction(obj); } public unsafe static byte[] ToByteArray<T>(T[] source) where T : struct { if (source == null) { return null; } byte[] array = new byte[SizeOf<T>() * source.Length]; if (source.Length == 0) { return array; } fixed (byte* ptr = array) { void* pDest = ptr; Interop.Write(pDest, source, 0, source.Length); } return array; } public static void Swap<T>(ref T left, ref T right) { T val = left; left = right; right = val; } public unsafe static T Read<T>(IntPtr source) where T : struct { return System.Runtime.CompilerServices.Unsafe.Read<T>((void*)source); } public unsafe static void Read<T>(IntPtr source, ref T data) where T : struct { data = System.Runtime.CompilerServices.Unsafe.Read<T>((void*)source); } public unsafe static void ReadOut<T>(IntPtr source, out T data) where T : struct { data = System.Runtime.CompilerServices.Unsafe.Read<T>((void*)source); } public unsafe static IntPtr ReadAndPosition<T>(IntPtr source, ref T data) where T : struct { return (IntPtr)Interop.Read((void*)source, ref data); } public unsafe static IntPtr Read<T>(IntPtr source, T[] data, int offset, int count) where T : struct { return (IntPtr)Interop.Read((void*)source, data, offset, count); } public unsafe static void Write<T>(IntPtr destination, ref T data) where T : struct { System.Runtime.CompilerServices.Unsafe.Write((void*)destination, data); } public unsafe static IntPtr WriteAndPosition<T>(IntPtr destination, ref T data) where T : struct { return (IntPtr)Interop.Write((void*)destination, ref data); } public unsafe static IntPtr Write<T>(IntPtr destination, T[] data, int offset, int count) where T : struct { return (IntPtr)Interop.Write((void*)destination, data, offset, count); } public unsafe static void ConvertToIntArray(bool[] array, int* dest) { for (int i = 0; i < array.Length; i++) { dest[i] = (array[i] ? 1 : 0); } } public static RawBool[] ConvertToIntArray(bool[] array) { RawBool[] array2 = new RawBool[array.Length]; for (int i = 0; i < array2.Length; i++) { array2[i] = array[i]; } return array2; } public unsafe static bool[] ConvertToBoolArray(int* array, int length) { bool[] array2 = new bool[length]; for (int i = 0; i < array2.Length; i++) { array2[i] = array[i] != 0; } return array2; } public static bool[] ConvertToBoolArray(RawBool[] array) { bool[] array2 = new bool[array.Length]; for (int i = 0; i < array2.Length; i++) { array2[i] = array[i]; } return array2; } public static Guid GetGuidFromType(Type type) { return type.GetTypeInfo().GUID; } public static bool IsAssignableToGenericType(Type givenType, Type genericType) { foreach (Type implementedInterface in givenType.GetTypeInfo().ImplementedInterfaces) { if (implementedInterface.GetTypeInfo().IsGenericType && implementedInterface.GetGenericTypeDefinition() == genericType) { return true; } } if (givenType.GetTypeInfo().IsGenericType && givenType.GetGenericTypeDefinition() == genericType) { return true; } Type baseType = givenType.GetTypeInfo().BaseType; if (baseType == null) { return false; } return IsAssignableToGenericType(baseType, genericType); } public unsafe static IntPtr AllocateMemory(int sizeInBytes, int align = 16) { int num = align - 1; IntPtr intPtr = Marshal.AllocHGlobal(sizeInBytes + num + IntPtr.Size); long num2 = (long)((byte*)(void*)intPtr + sizeof(void*) + num) & (long)(~num); *(IntPtr*)((nint)num2 + (nint)(-1) * (nint)sizeof(IntPtr)) = intPtr; return new IntPtr((void*)num2); } public static IntPtr AllocateClearedMemory(int sizeInBytes, byte clearValue = 0, int align = 16) { IntPtr intPtr = AllocateMemory(sizeInBytes, align); ClearMemory(intPtr, clearValue, sizeInBytes); return intPtr; } public static bool IsMemoryAligned(IntPtr memoryPtr, int align = 16) { return (memoryPtr.ToInt64() & (align - 1)) == 0; } public unsafe static void FreeMemory(IntPtr alignedBuffer) { if (!(alignedBuffer == IntPtr.Zero)) { Marshal.FreeHGlobal(*(IntPtr*)((byte*)(void*)alignedBuffer + (nint)(-1) * (nint)sizeof(IntPtr))); } } public static string PtrToStringAnsi(IntPtr pointer, int maxLength) { string text = Marshal.PtrToStringAnsi(pointer); if (text != null && text.Length > maxLength) { text = text.Substring(0, maxLength); } return text; } public static string PtrToStringUni(IntPtr pointer, int maxLength) { string text = Marshal.PtrToStringUni(pointer); if (text != null && text.Length > maxLength) { text = text.Substring(0, maxLength); } return text; } public static IntPtr StringToHGlobalAnsi(string s) { return Marshal.StringToHGlobalAnsi(s); } public static IntPtr StringToHGlobalUni(string s) { return Marshal.StringToHGlobalUni(s); } public static IntPtr StringToCoTaskMemUni(string s) { if (s == null) { return IntPtr.Zero; } int num = (s.Length + 1) * 2; if (num < s.Length) { throw new ArgumentOutOfRangeException("s"); } IntPtr intPtr = Marshal.AllocCoTaskMem(num); if (intPtr == IntPtr.Zero) { throw new OutOfMemoryException(); } CopyStringToUnmanaged(intPtr, s); return intPtr; } private unsafe static void CopyStringToUnmanaged(IntPtr ptr, string str) { fixed (char* value = str) { CopyMemory(ptr, new IntPtr(value), (str.Length + 1) * 2); } } public static IntPtr GetIUnknownForObject(object obj) { if (obj != null) { return Marshal.GetIUnknownForObject(obj); } return IntPtr.Zero; } public static object GetObjectForIUnknown(IntPtr iunknownPtr) { if (!(iunknownPtr == IntPtr.Zero)) { return Marshal.GetObjectForIUnknown(iunknownPtr); } return null; } public static string Join<T>(string separator, T[] array) { StringBuilder stringBuilder = new StringBuilder(); if (array != null) { for (int i = 0; i < array.Length; i++) { if (i > 0) { stringBuilder.Append(separator); } stringBuilder.Append(array[i]); } } return stringBuilder.ToString(); } public static string Join(string separator, IEnumerable elements) { List<string> list = new List<string>(); foreach (object element in elements) { list.Add(element.ToString()); } StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < list.Count; i++) { string value = list[i]; if (i > 0) { stringBuilder.Append(separator); } stringBuilder.Append(value); } return stringBuilder.ToString(); } public static string Join(string separator, IEnumerator elements) { List<string> list = new List<string>(); while (elements.MoveNext()) { list.Add(elements.Current.ToString()); } StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < list.Count; i++) { string value = list[i]; if (i > 0) { stringBuilder.Append(separator); } stringBuilder.Append(value); } return stringBuilder.ToString(); } public static string BlobToString(Blob blob) { if (blob == null) { return null; } string? result = Marshal.PtrToStringAnsi(blob.BufferPointer); blob.Dispose(); return result; } public unsafe static IntPtr IntPtrAdd(IntPtr ptr, int offset) { return new IntPtr((byte*)(void*)ptr + offset); } public static byte[] ReadStream(Stream stream) { int readLength = 0; return ReadStream(stream, ref readLength); } public static byte[] ReadStream(Stream stream, ref int readLength) { if (readLength == 0) { readLength = (int)(stream.Length - stream.Position); } int num = readLength; if (num == 0) { return new byte[0]; } byte[] array = new byte[num]; int num2 = 0; if (num > 0) { do { num2 += stream.Read(array, num2, readLength - num2); } while (num2 < readLength); } return array; } public static bool Compare(IEnumerable left, IEnumerable right) { if (left == right) { return true; } if (left == null || right == null) { return false; } return Compare(left.GetEnumerator(), right.GetEnumerator()); } public static bool Compare(IEnumerator leftIt, IEnumerator rightIt) { if (leftIt == rightIt) { return true; } if (leftIt == null || rightIt == null) { return false; } bool flag; bool flag2; while (true) { flag = leftIt.MoveNext(); flag2 = rightIt.MoveNext(); if (!flag || !flag2) { break; } if (!object.Equals(leftIt.Current, rightIt.Current)) { return false; } } if (flag != flag2) { return false; } return true; } public static bool Compare(ICollection left, ICollection right) { if (left == right) { return true; } if (left == null || right == null) { return false; } if (left.Count != right.Count) { return false; } int num = 0; IEnumerator enumerator = left.GetEnumerator(); IEnumerator enumerator2 = right.GetEnumerator(); while (enumerator.MoveNext() && enumerator2.MoveNext()) { if (!object.Equals(enumerator.Current, enumerator2.Current)) { return false; } num++; } if (num != left.Count) { return false; } return true; } public static T GetCustomAttribute<T>(MemberInfo memberInfo, bool inherited = false) where T : Attribute { return memberInfo.GetCustomAttribute<T>(inherited); } public static IEnumerable<T> GetCustomAttributes<T>(MemberInfo memberInfo, bool inherited = false) where T : Attribute { return memberInfo.GetCustomAttributes<T>(inherited); } public static bool IsAssignableFrom(Type toType, Type fromType) { return toType.GetTypeInfo().IsAssignableFrom(fromType.GetTypeInfo()); } public static bool IsEnum(Type typeToTest) { return typeToTest.GetTypeInfo().IsEnum; } public static bool IsValueType(Type typeToTest) { return typeToTest.GetTypeInfo().IsValueType; } private static MethodInfo GetMethod(Type type, string name, Type[] typeArgs) { foreach (MethodInfo declaredMethod in type.GetTypeInfo().GetDeclaredMethods(name)) { if (declaredMethod.GetParameters().Length != typeArgs.Length) { continue; } ParameterInfo[] parameters = declaredMethod.GetParameters(); bool flag = true; for (int i = 0; i < typeArgs.Length; i++) { if (parameters[i].ParameterType != typeArgs[i]) { flag = false; break; } } if (flag) { return declaredMethod; } } return null; } public static GetValueFastDelegate<T> BuildPropertyGetter<T>(Type customEffectType, PropertyInfo propertyInfo) { ParameterExpression parameterExpression = Expression.Parameter(typeof(T).MakeByRefType()); ParameterExpression parameterExpression2 = Expression.Parameter(typeof(object)); MemberExpression memberExpression = Expression.Property(Expression.Convert(parameterExpression2, customEffectType), propertyInfo); Expression right = ((!(propertyInfo.PropertyType == typeof(bool))) ? ((Expression)Expression.Convert(memberExpression, typeof(T))) : ((Expression)Expression.Condition(memberExpression, Expression.Constant(1), Expression.Constant(0)))); return Expression.Lambda<GetValueFastDelegate<T>>(Expression.Assign(parameterExpression, right), new ParameterExpression[2] { parameterExpression2, parameterExpression }).Compile(); } public static SetValueFastDelegate<T> BuildPropertySetter<T>(Type customEffectType, PropertyInfo propertyInfo) { ParameterExpression parameterExpression = Expression.Parameter(typeof(T).MakeByRefType()); ParameterExpression parameterExpression2 = Expression.Parameter(typeof(object)); MemberExpression left = Expression.Property(Expression.Convert(parameterExpression2, customEffectType), propertyInfo); Expression right = ((!(propertyInfo.PropertyType == typeof(bool))) ? ((Expression)Expression.Convert(parameterExpression, propertyInfo.PropertyType)) : ((Expression)Expression.NotEqual(parameterExpression, Expression.Constant(0)))); return Expression.Lambda<SetValueFastDelegate<T>>(Expression.Assign(left, right), new ParameterExpression[2] { parameterExpression2, parameterExpression }).Compile(); } private static MethodInfo FindExplicitConverstion(Type sourceType, Type targetType) { if (sourceType == targetType) { return null; } List<MethodInfo> list = new List<MethodInfo>(); Type type = sourceType; while (type != null) { list.AddRange(type.GetTypeInfo().DeclaredMethods); type = type.GetTypeInfo().BaseType; } type = targetType; while (type != null) { list.AddRange(type.GetTypeInfo().DeclaredMethods); type = type.GetTypeInfo().BaseType; } foreach (MethodInfo item in list) { if (item.Name == "op_Explicit" && item.ReturnType == targetType && IsAssignableFrom(item.GetParameters()[0].ParameterType, sourceType)) { return item; } } return null; } [DllImport("ole32.dll", ExactSpelling = true)] private static extern Result CoCreateInstance([In][MarshalAs(UnmanagedType.LPStruct)] Guid rclsid, IntPtr pUnkOuter, CLSCTX dwClsContext, [In][MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IntPtr comObject); internal static void CreateComInstance(Guid clsid, CLSCTX clsctx, Guid riid, ComObject comObject) { CoCreateInstance(clsid, IntPtr.Zero, clsctx, riid, out var comObject2).CheckError(); comObject.NativePointer = comObject2; } internal static bool TryCreateComInstance(Guid clsid, CLSCTX clsctx, Guid riid, ComObject comObject) { IntPtr comObject2; Result result = CoCreateInstance(clsid, IntPtr.Zero, clsctx, riid, out comObject2); comObject.NativePointer = comObject2; return result.Success; } [DllImport("kernel32.dll", SetLastError = true)] internal static extern bool CloseHandle(IntPtr handle); public static IntPtr GetProcAddress(IntPtr handle, string dllFunctionToImport) { IntPtr procAddress_ = GetProcAddress_(handle, dllFunctionToImport); if (procAddress_ == IntPtr.Zero) { throw new SharpDXException(dllFunctionToImport); } return procAddress_; } [DllImport("kernel32", CharSet = CharSet.Ansi, EntryPoint = "GetProcAddress", ExactSpelling = true, SetLastError = true)] private static extern IntPtr GetProcAddress_(IntPtr hModule, string procName); public static int ComputeHashFNVModified(byte[] data) { uint num = 2166136261u; foreach (byte b in data) { num = (num ^ b) * 16777619; } num += num << 13; num ^= num >> 7; num += num << 3; num ^= num >> 17; return (int)(num + (num << 5)); } public static void Dispose<T>(ref T comObject) where T : class, IDisposable { if (comObject != null) { comObject.Dispose(); comObject = null; } } public static T[] ToArray<T>(IEnumerable<T> source) { return new Buffer<T>(source).ToArray(); } public static bool Any<T>(IEnumerable<T> source) { return source.GetEnumerator().MoveNext(); } public static IEnumerable<TResult> SelectMany<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector) { foreach (TSource item in source) { foreach (TResult item2 in selector(item)) { yield return item2; } } } public static IEnumerable<TSource> Distinct<TSource>(IEnumerable<TSource> source, IEqualityComparer<TSource> comparer = null) { if (comparer == null) { comparer = EqualityComparer<TSource>.Default; } Dictionary<TSource, object> values = new Dictionary<TSource, object>(comparer); foreach (TSource item in source) { if (!values.ContainsKey(item)) { values.Add(item, null); yield return item; } } } public static bool IsTypeInheritFrom(Type type, string parentType) { while (type != null) { if (type.FullName == parentType) { return true; } type = type.GetTypeInfo().BaseType; } return false; } } } namespace SharpDX.Win32 { public struct BitmapInfoHeader { public int SizeInBytes; public int Width; public int Height; public short PlaneCount; public short BitCount; public int Compression; public int SizeImage; public int XPixelsPerMeter; public int YPixelsPerMeter; public int ColorUsedCount; public int ColorImportantCount; } public class ComBaseStreamNative { public IDisposable Callback { get; set; } } internal class ComStreamBaseShadow : ComObjectShadow { internal class ComStreamBaseVtbl : ComObjectVtbl { [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate int ReadDelegate(IntPtr thisPtr, IntPtr buffer, int sizeOfBytes, out int bytesRead); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate int WriteDelegate(IntPtr thisPtr, IntPtr buffer, int sizeOfBytes, out int bytesWrite); public ComStreamBaseVtbl(int numberOfMethods) : base(numberOfMethods + 2) { AddMethod(new ReadDelegate(ReadImpl)); AddMethod(new WriteDelegate(WriteImpl)); } private static int ReadImpl(IntPtr thisPtr, IntPtr buffer, int sizeOfBytes, out int bytesRead) { bytesRead = 0; try { IStream stream = (IStream)CppObjectShadow.ToShadow<ComStreamBaseShadow>(thisPtr).Callback; bytesRead = stream.Read(buffer, sizeOfBytes); } catch (Exception ex) { return (int)Result.GetResultFromException(ex); } return Result.Ok.Code; } private static int WriteImpl(IntPtr thisPtr, IntPtr buffer, int sizeOfBytes, out int bytesWrite) { bytesWrite = 0; try { IStream stream = (IStream)CppObjectShadow.ToShadow<ComStreamBaseShadow>(thisPtr).Callback; bytesWrite = stream.Write(buffer, sizeOfBytes); } catch (Exception ex) { return (int)Result.GetResultFromException(ex); } return Result.Ok.Code; } } private static readonly ComStreamBaseVtbl Vtbl = new ComStreamBaseVtbl(0); protected override CppObjectVtbl GetVtbl => Vtbl; } [Guid("0000000c-0000-0000-C000-000000000046")] internal class ComStreamProxy : CallbackBase, IStream, IStreamBase, IUnknown, ICallbackable, IDisposable { private Stream sourceStream; private byte[] tempBuffer = new byte[4096]; public ComStreamProxy(Stream sourceStream) { this.sourceStream = sourceStream; } public unsafe int Read(IntPtr buffer, int numberOfBytesToRead) { int num = 0; while (numberOfBytesToRead > 0) { int count = Math.Min(numberOfBytesToRead, tempBuffer.Length); int num2 = sourceStream.Read(tempBuffer, 0, count); if (num2 == 0) { return num; } Utilities.Write(new IntPtr(num + (byte*)(void*)buffer), tempBuffer, 0, num2); numberOfBytesToRead -= num2; num += num2; } return num; } public unsafe int Write(IntPtr buffer, int numberOfBytesToWrite) { int num = 0; while (numberOfBytesToWrite > 0) { int num2 = Math.Min(numberOfBytesToWrite, tempBuffer.Length); Utilities.Read(new IntPtr(num + (byte*)(void*)buffer), tempBuffer, 0, num2); sourceStream.Write(tempBuffer, 0, num2); numberOfBytesToWrite -= num2; num += num2; } return num; } public long Seek(long offset, SeekOrigin origin) { return sourceStream.Seek(offset, origin); } public void SetSize(long newSize) { } public unsafe long CopyTo(IStream streamDest, long numberOfBytesToCopy, out long bytesWritten) { bytesWritten = 0L; fixed (byte* ptr = tempBuffer) { void* ptr2 = ptr; while (numberOfBytesToCopy > 0) { int count = (int)Math.Min(numberOfBytesToCopy, tempBuffer.Length); int num = sourceStream.Read(tempBuffer, 0, count); if (num == 0) { break; } streamDest.Write((IntPtr)ptr2, num); numberOfBytesToCopy -= num; bytesWritten += num; } } return bytesWritten; } public void Commit(CommitFlags commitFlags) { sourceStream.Flush(); } public void Revert() { throw new NotImplementedException(); } public void LockRegion(long offset, long numberOfBytesToLock, LockType dwLockType) { throw new NotImplementedException(); } public void UnlockRegion(long offset, long numberOfBytesToLock, LockType dwLockType) { throw new NotImplementedException(); } public StorageStatistics GetStatistics(StorageStatisticsFlags storageStatisticsFlags) { long num = sourceStream.Length; if (num == 0L) { num = 2147483647L; } StorageStatistics result = default(StorageStatistics); result.Type = 2; result.CbSize = num; result.GrfLocksSupported = 2; result.GrfMode = 2; return result; } public IStream Clone() { return new ComStreamProxy(sourceStream); } protected override void Dispose(bool disposing) { sourceStream = null; base.Dispose(disposing); } } internal class ComStreamShadow : ComStreamBaseShadow { private class ComStreamVtbl : ComStreamBaseVtbl { [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate int SeekDelegate(IntPtr thisPtr, long offset, SeekOrigin origin, IntPtr newPosition); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate Result SetSizeDelegate(IntPtr thisPtr, long newSize); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate int CopyToDelegate(IntPtr thisPtr, IntPtr streamPointer, long numberOfBytes, out long numberOfBytesRead, out long numberOfBytesWritten); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate Result CommitDelegate(IntPtr thisPtr, CommitFlags flags); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate Result RevertDelegate(IntPtr thisPtr); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate Result LockRegionDelegate(IntPtr thisPtr, long offset, long numberOfBytes, LockType lockType); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate Result UnlockRegionDelegate(IntPtr thisPtr, long offset, long numberOfBytes, LockType lockType); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate Result StatDelegate(IntPtr thisPtr, ref StorageStatistics.__Native statisticsPtr, StorageStatisticsFlags flags); [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate Result CloneDelegate(IntPtr thisPtr, out IntPtr streamPointer); public ComStreamVtbl() : base(9) { AddMethod(new SeekDelegate(SeekImpl)); AddMethod(new SetSizeDelegate(SetSizeImpl)); AddMethod(new CopyToDelegate(CopyToImpl)); AddMethod(new CommitDelegate(CommitImpl)); AddMethod(new RevertDelegate(RevertImpl)); AddMethod(new LockRegionDelegate(LockRegionImpl)); AddMethod(new UnlockRegionDelegate(UnlockRegionImpl)); AddMethod(new StatDelegate(StatImpl)); AddMethod(new CloneDelegate(CloneImpl)); } private unsafe static int SeekImpl(IntPtr thisPtr, long offset, SeekOrigin origin, IntPtr newPosition) { try { long num = ((IStream)CppObjectShadow.ToShadow<ComStreamShadow>(thisPtr).Callback).Seek(offset, origin); if (newPosition != IntPtr.Zero) { *(long*)(void*)newPosition = num; } } catch (Exception ex) { return (int)Result.GetResultFromException(ex); } return Result.Ok.Code; } private static Result SetSizeImpl(IntPtr thisPtr, long newSize) { Result result = Result.Ok; try { ((IStream)CppObjectShadow.ToShadow<ComStreamShadow>(thisPtr).Callback).SetSize(newSize); } catch (SharpDXException ex) { result = ex.ResultCode; } catch (Exception) { result = Result.Fail.Code; } return result; } private static int CopyToImpl(IntPtr thisPtr, IntPtr streamPointer, long numberOfBytes, out long numberOfBytesRead, out long numberOfBytesWritten) { numberOfBytesRead = 0L; numberOfBytesWritten = 0L; try { IStream stream = (IStream)CppObjectShadow.ToShadow<ComStreamShadow>(thisPtr).Callback; numberOfBytesRead = stream.CopyTo(new ComStream(streamPointer), numberOfBytes, out numberOfBytesWritten); } catch (Exception ex) { return (int)Result.GetResultFromException(ex); } return Result.Ok.Code; } private static Result CommitImpl(IntPtr thisPtr, CommitFlags flags) { Result result = Result.Ok; try { ((IStream)CppObjectShadow.ToShadow<ComStreamShadow>(thisPtr).Callback).Commit(flags); } catch (SharpDXException ex) { result = ex.ResultCode; } catch (Exception) { result = Result.Fail.Code; } return result; } private static Result RevertImpl(IntPtr thisPtr) { Result result = Result.Ok; try { ((IStream)CppObjectShadow.ToShadow<ComStreamShadow>(thisPtr).Callback).Revert(); } catch (SharpDXException ex) { result = ex.ResultCode; } catch (Exception) { result = Result.Fail.Code; } return result; } private static Result LockRegionImpl(IntPtr thisPtr, long offset, long numberOfBytes, LockType lockType) { Result result = Result.Ok; try { ((IStream)CppObjectShadow.ToShadow<ComStreamShadow>(thisPtr).Callback).LockRegion(offset, numberOfBytes, lockType); } catch (SharpDXException ex) { result = ex.ResultCode; } catch (Exception) { result = Result.Fail.Code; } return result; } private static Result UnlockRegionImpl(IntPtr thisPtr, long offset, long numberOfBytes, LockType lockType) { Result result = Result.Ok; try { ((IStream)CppObjectShadow.ToShadow<ComStreamShadow>(thisPtr).Callback).UnlockRegion(offset, numberOfBytes, lockType); } catch (SharpDXException ex) { result = ex.ResultCode; } catch (Exception) { result = Result.Fail.Code; } return result; } private static Result StatImpl(IntPtr thisPtr, ref StorageStatistics.__Native statisticsPtr, StorageStatisticsFlags flags) { try { ((IStream)CppObjectShadow.ToShadow<ComStreamShadow>(thisPtr).Callback).GetStatistics(flags).__MarshalTo(ref statisticsPtr); } catch (SharpDXException ex) { return ex.ResultCode; } catch (Exception) { return Result.Fail.Code; } return Result.Ok; } private static Result CloneImpl(IntPtr thisPtr, out IntPtr streamPointer) { streamPointer = IntPtr.Zero; Result result = Result.Ok; try { IStream stream = ((IStream)CppObjectShadow.ToShadow<ComStreamShadow>(thisPtr).Callback).Clone(); streamPointer = ToIntPtr(stream); } catch (SharpDXException ex) { result = ex.ResultCode; } catch (Exception) { result = Result.Fail.Code; } return result; } } private static readonly ComStreamVtbl Vtbl = new ComStreamVtbl(); protected override CppObjectVtbl GetVtbl => Vtbl; public static IntPtr ToIntPtr(IS