Guest User

Untitled

a guest
Apr 8th, 2024
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 45.58 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3.  
  4. namespace HandheldCompanion.IGCL
  5. {
  6.     // Define the wrapper class for IGCL
  7.     public class IGCLBackend
  8.     {
  9.         // Define the types used by the C++ functions
  10.         [StructLayout(LayoutKind.Sequential)]
  11.         struct ctl_init_args_t
  12.         {
  13.             public int AppVersion;
  14.             public int flags;
  15.             public int Size;
  16.             public int Version;
  17.         }
  18.  
  19.         [StructLayout(LayoutKind.Sequential)]
  20.         public struct ctl_device_adapter_handle_t
  21.         {
  22.             public IntPtr handle;
  23.         }
  24.  
  25.         public enum ctl_result_t
  26.         {
  27.             CTL_RESULT_SUCCESS = 0x00000000,                ///< success
  28.             CTL_RESULT_SUCCESS_STILL_OPEN_BY_ANOTHER_CALLER = 0x00000001,   ///< success but still open by another caller
  29.             CTL_RESULT_ERROR_SUCCESS_END = 0x0000FFFF,      ///< "Success group error code end value, not to be used
  30.                                                             ///< "
  31.             CTL_RESULT_ERROR_GENERIC_START = 0x40000000,    ///< Generic error code starting value, not to be used
  32.             CTL_RESULT_ERROR_NOT_INITIALIZED = 0x40000001,  ///< Result not initialized
  33.             CTL_RESULT_ERROR_ALREADY_INITIALIZED = 0x40000002,  ///< Already initialized
  34.             CTL_RESULT_ERROR_DEVICE_LOST = 0x40000003,      ///< Device hung, reset, was removed, or driver update occurred
  35.             CTL_RESULT_ERROR_OUT_OF_HOST_MEMORY = 0x40000004,   ///< Insufficient host memory to satisfy call
  36.             CTL_RESULT_ERROR_OUT_OF_DEVICE_MEMORY = 0x40000005, ///< Insufficient device memory to satisfy call
  37.             CTL_RESULT_ERROR_INSUFFICIENT_PERMISSIONS = 0x40000006, ///< Access denied due to permission level
  38.             CTL_RESULT_ERROR_NOT_AVAILABLE = 0x40000007,    ///< Resource was removed
  39.             CTL_RESULT_ERROR_UNINITIALIZED = 0x40000008,    ///< Library not initialized
  40.             CTL_RESULT_ERROR_UNSUPPORTED_VERSION = 0x40000009,  ///< Generic error code for unsupported versions
  41.             CTL_RESULT_ERROR_UNSUPPORTED_FEATURE = 0x4000000a,  ///< Generic error code for unsupported features
  42.             CTL_RESULT_ERROR_INVALID_ARGUMENT = 0x4000000b, ///< Generic error code for invalid arguments
  43.             CTL_RESULT_ERROR_INVALID_API_HANDLE = 0x4000000c,   ///< API handle in invalid
  44.             CTL_RESULT_ERROR_INVALID_NULL_HANDLE = 0x4000000d,  ///< Handle argument is not valid
  45.             CTL_RESULT_ERROR_INVALID_NULL_POINTER = 0x4000000e, ///< Pointer argument may not be nullptr
  46.             CTL_RESULT_ERROR_INVALID_SIZE = 0x4000000f,     ///< Size argument is invalid (e.g., must not be zero)
  47.             CTL_RESULT_ERROR_UNSUPPORTED_SIZE = 0x40000010, ///< Size argument is not supported by the device (e.g., too large)
  48.             CTL_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT = 0x40000011, ///< Image format is not supported by the device
  49.             CTL_RESULT_ERROR_DATA_READ = 0x40000012,        ///< Data read error
  50.             CTL_RESULT_ERROR_DATA_WRITE = 0x40000013,       ///< Data write error
  51.             CTL_RESULT_ERROR_DATA_NOT_FOUND = 0x40000014,   ///< Data not found error
  52.             CTL_RESULT_ERROR_NOT_IMPLEMENTED = 0x40000015,  ///< Function not implemented
  53.             CTL_RESULT_ERROR_OS_CALL = 0x40000016,          ///< Operating system call failure
  54.             CTL_RESULT_ERROR_KMD_CALL = 0x40000017,         ///< Kernel mode driver call failure
  55.             CTL_RESULT_ERROR_UNLOAD = 0x40000018,           ///< Library unload failure
  56.             CTL_RESULT_ERROR_ZE_LOADER = 0x40000019,        ///< Level0 loader not found
  57.             CTL_RESULT_ERROR_INVALID_OPERATION_TYPE = 0x4000001a,   ///< Invalid operation type
  58.             CTL_RESULT_ERROR_NULL_OS_INTERFACE = 0x4000001b,///< Null OS interface
  59.             CTL_RESULT_ERROR_NULL_OS_ADAPATER_HANDLE = 0x4000001c,  ///< Null OS adapter handle
  60.             CTL_RESULT_ERROR_NULL_OS_DISPLAY_OUTPUT_HANDLE = 0x4000001d,///< Null display output handle
  61.             CTL_RESULT_ERROR_WAIT_TIMEOUT = 0x4000001e,     ///< Timeout in Wait function
  62.             CTL_RESULT_ERROR_PERSISTANCE_NOT_SUPPORTED = 0x4000001f,///< Persistance not supported
  63.             CTL_RESULT_ERROR_PLATFORM_NOT_SUPPORTED = 0x40000020,   ///< Platform not supported
  64.             CTL_RESULT_ERROR_UNKNOWN_APPLICATION_UID = 0x40000021,  ///< Unknown Appplicaion UID in Initialization call
  65.             CTL_RESULT_ERROR_INVALID_ENUMERATION = 0x40000022,  ///< The enum is not valid
  66.             CTL_RESULT_ERROR_FILE_DELETE = 0x40000023,      ///< Error in file delete operation
  67.             CTL_RESULT_ERROR_RESET_DEVICE_REQUIRED = 0x40000024,///< The device requires a reset.
  68.             CTL_RESULT_ERROR_FULL_REBOOT_REQUIRED = 0x40000025, ///< The device requires a full reboot.
  69.             CTL_RESULT_ERROR_LOAD = 0x40000026,             ///< Library load failure
  70.             CTL_RESULT_ERROR_UNKNOWN = 0x4000FFFF,          ///< Unknown or internal error
  71.             CTL_RESULT_ERROR_RETRY_OPERATION = 0x40010000,  ///< Operation failed, retry previous operation again
  72.             CTL_RESULT_ERROR_GENERIC_END = 0x4000FFFF,      ///< "Generic error code end value, not to be used
  73.                                                             ///< "
  74.             CTL_RESULT_ERROR_CORE_START = 0x44000000,       ///< Core error code starting value, not to be used
  75.             CTL_RESULT_ERROR_CORE_OVERCLOCK_NOT_SUPPORTED = 0x44000001, ///< The Overclock is not supported.
  76.             CTL_RESULT_ERROR_CORE_OVERCLOCK_VOLTAGE_OUTSIDE_RANGE = 0x44000002, ///< The Voltage exceeds the acceptable min/max.
  77.             CTL_RESULT_ERROR_CORE_OVERCLOCK_FREQUENCY_OUTSIDE_RANGE = 0x44000003,   ///< The Frequency exceeds the acceptable min/max.
  78.             CTL_RESULT_ERROR_CORE_OVERCLOCK_POWER_OUTSIDE_RANGE = 0x44000004,   ///< The Power exceeds the acceptable min/max.
  79.             CTL_RESULT_ERROR_CORE_OVERCLOCK_TEMPERATURE_OUTSIDE_RANGE = 0x44000005, ///< The Power exceeds the acceptable min/max.
  80.             CTL_RESULT_ERROR_CORE_OVERCLOCK_IN_VOLTAGE_LOCKED_MODE = 0x44000006,///< The Overclock is in voltage locked mode.
  81.             CTL_RESULT_ERROR_CORE_OVERCLOCK_RESET_REQUIRED = 0x44000007,///< It indicates that the requested change will not be applied until the
  82.                                                                         ///< device is reset.
  83.             CTL_RESULT_ERROR_CORE_OVERCLOCK_WAIVER_NOT_SET = 0x44000008,///< The $OverclockWaiverSet function has not been called.
  84.             CTL_RESULT_ERROR_CORE_END = 0x0440FFFF,         ///< "Core error code end value, not to be used
  85.                                                             ///< "
  86.             CTL_RESULT_ERROR_3D_START = 0x60000000,         ///< 3D error code starting value, not to be used
  87.             CTL_RESULT_ERROR_3D_END = 0x6000FFFF,           ///< "3D error code end value, not to be used
  88.                                                             ///< "
  89.             CTL_RESULT_ERROR_MEDIA_START = 0x50000000,      ///< Media error code starting value, not to be used
  90.             CTL_RESULT_ERROR_MEDIA_END = 0x5000FFFF,        ///< "Media error code end value, not to be used
  91.                                                             ///< "
  92.             CTL_RESULT_ERROR_DISPLAY_START = 0x48000000,    ///< Display error code starting value, not to be used
  93.             CTL_RESULT_ERROR_INVALID_AUX_ACCESS_FLAG = 0x48000001,  ///< Invalid flag for Aux access
  94.             CTL_RESULT_ERROR_INVALID_SHARPNESS_FILTER_FLAG = 0x48000002,///< Invalid flag for Sharpness
  95.             CTL_RESULT_ERROR_DISPLAY_NOT_ATTACHED = 0x48000003, ///< Error for Display not attached
  96.             CTL_RESULT_ERROR_DISPLAY_NOT_ACTIVE = 0x48000004,   ///< Error for display attached but not active
  97.             CTL_RESULT_ERROR_INVALID_POWERFEATURE_OPTIMIZATION_FLAG = 0x48000005,   ///< Error for invalid power optimization flag
  98.             CTL_RESULT_ERROR_INVALID_POWERSOURCE_TYPE_FOR_DPST = 0x48000006,///< DPST is supported only in DC Mode
  99.             CTL_RESULT_ERROR_INVALID_PIXTX_GET_CONFIG_QUERY_TYPE = 0x48000007,  ///< Invalid query type for pixel transformation get configuration
  100.             CTL_RESULT_ERROR_INVALID_PIXTX_SET_CONFIG_OPERATION_TYPE = 0x48000008,  ///< Invalid operation type for pixel transformation set configuration
  101.             CTL_RESULT_ERROR_INVALID_SET_CONFIG_NUMBER_OF_SAMPLES = 0x48000009, ///< Invalid number of samples for pixel transformation set configuration
  102.             CTL_RESULT_ERROR_INVALID_PIXTX_BLOCK_ID = 0x4800000a,   ///< Invalid block id for pixel transformation
  103.             CTL_RESULT_ERROR_INVALID_PIXTX_BLOCK_TYPE = 0x4800000b, ///< Invalid block type for pixel transformation
  104.             CTL_RESULT_ERROR_INVALID_PIXTX_BLOCK_NUMBER = 0x4800000c,   ///< Invalid block number for pixel transformation
  105.             CTL_RESULT_ERROR_INSUFFICIENT_PIXTX_BLOCK_CONFIG_MEMORY = 0x4800000d,   ///< Insufficient memery allocated for BlockConfigs
  106.             CTL_RESULT_ERROR_3DLUT_INVALID_PIPE = 0x4800000e,   ///< Invalid pipe for 3dlut
  107.             CTL_RESULT_ERROR_3DLUT_INVALID_DATA = 0x4800000f,   ///< Invalid 3dlut data
  108.             CTL_RESULT_ERROR_3DLUT_NOT_SUPPORTED_IN_HDR = 0x48000010,   ///< 3dlut not supported in HDR
  109.             CTL_RESULT_ERROR_3DLUT_INVALID_OPERATION = 0x48000011,  ///< Invalid 3dlut operation
  110.             CTL_RESULT_ERROR_3DLUT_UNSUCCESSFUL = 0x48000012,   ///< 3dlut call unsuccessful
  111.             CTL_RESULT_ERROR_AUX_DEFER = 0x48000013,        ///< AUX defer failure
  112.             CTL_RESULT_ERROR_AUX_TIMEOUT = 0x48000014,      ///< AUX timeout failure
  113.             CTL_RESULT_ERROR_AUX_INCOMPLETE_WRITE = 0x48000015, ///< AUX incomplete write failure
  114.             CTL_RESULT_ERROR_I2C_AUX_STATUS_UNKNOWN = 0x48000016,   ///< I2C/AUX unkonown failure
  115.             CTL_RESULT_ERROR_I2C_AUX_UNSUCCESSFUL = 0x48000017, ///< I2C/AUX unsuccessful
  116.             CTL_RESULT_ERROR_LACE_INVALID_DATA_ARGUMENT_PASSED = 0x48000018,///< Lace Incorrrect AggressivePercent data or LuxVsAggressive Map data
  117.                                                                             ///< passed by user
  118.             CTL_RESULT_ERROR_EXTERNAL_DISPLAY_ATTACHED = 0x48000019,///< External Display is Attached hence fail the Display Switch
  119.             CTL_RESULT_ERROR_CUSTOM_MODE_STANDARD_CUSTOM_MODE_EXISTS = 0x4800001a,  ///< Standard custom mode exists
  120.             CTL_RESULT_ERROR_CUSTOM_MODE_NON_CUSTOM_MATCHING_MODE_EXISTS = 0x4800001b,  ///< Non custom matching mode exists
  121.             CTL_RESULT_ERROR_CUSTOM_MODE_INSUFFICIENT_MEMORY = 0x4800001c,  ///< Custom mode insufficent memory
  122.             CTL_RESULT_ERROR_ADAPTER_ALREADY_LINKED = 0x4800001d,   ///< Adapter is already linked
  123.             CTL_RESULT_ERROR_ADAPTER_NOT_IDENTICAL = 0x4800001e,///< Adapter is not identical for linking
  124.             CTL_RESULT_ERROR_ADAPTER_NOT_SUPPORTED_ON_LDA_SECONDARY = 0x4800001f,   ///< Adapter is LDA Secondary, so not supporting requested operation
  125.             CTL_RESULT_ERROR_SET_FBC_FEATURE_NOT_SUPPORTED = 0x48000020,///< Set FBC Feature not supported
  126.             CTL_RESULT_ERROR_DISPLAY_END = 0x4800FFFF,      ///< "Display error code end value, not to be used
  127.                                                             ///< "
  128.             CTL_RESULT_MAX
  129.         }
  130.  
  131.         // Define a handle type for the ctl_api_handle_t
  132.         [StructLayout(LayoutKind.Sequential)]
  133.         public struct ctl_api_handle_t
  134.         {
  135.             public IntPtr handle;
  136.         }
  137.  
  138.         [StructLayout(LayoutKind.Sequential)]
  139.         public struct ctl_retro_scaling_caps_t
  140.         {
  141.             public uint Size;
  142.             public byte Version;
  143.             public ctl_retro_scaling_type_flags_t SupportedRetroScaling;
  144.         }
  145.  
  146.         [StructLayout(LayoutKind.Sequential)]
  147.         public struct ctl_retro_scaling_settings_t
  148.         {
  149.             public uint Size;
  150.             public byte Version;
  151.             [MarshalAs(UnmanagedType.U1)]
  152.             public bool Get;
  153.             [MarshalAs(UnmanagedType.U1)]
  154.             public bool Enable;
  155.             public ctl_retro_scaling_type_flags_t RetroScalingType;
  156.         }
  157.  
  158.         public enum ctl_retro_scaling_type_flags_t : uint
  159.         {
  160.             CTL_RETRO_SCALING_TYPE_FLAG_INTEGER = 1,
  161.             CTL_RETRO_SCALING_TYPE_FLAG_NEAREST_NEIGHBOUR = 2,
  162.             CTL_RETRO_SCALING_TYPE_FLAG_MAX = 0x80000000
  163.         }
  164.  
  165.         // Define the scaling type flags as an enum
  166.         public enum ctl_scaling_type_flag_t : uint
  167.         {
  168.             CTL_SCALING_TYPE_FLAG_IDENTITY = 1,                    // No scaling is applied and display manages scaling itself when possible
  169.             CTL_SCALING_TYPE_FLAG_CENTERED = 2,                    // Source is not scaled but place in the center of the target display
  170.             CTL_SCALING_TYPE_FLAG_STRETCHED = 4,                   // Source is stretched to fit the target size
  171.             CTL_SCALING_TYPE_FLAG_ASPECT_RATIO_CENTERED_MAX = 8,   // The aspect ratio is maintained with the source centered
  172.             CTL_SCALING_TYPE_FLAG_CUSTOM = 16,                      // None of the standard types match this .Additional parameters are required which should be set via a private driver interface
  173.             CTL_SCALING_TYPE_FLAG_MAX = 0x80000000
  174.         }
  175.  
  176.         // Define the scaling caps struct
  177.         [StructLayout(LayoutKind.Sequential)]
  178.         public struct ctl_scaling_caps_t
  179.         {
  180.             public uint Size;                                  // [in] size of this structure
  181.             public byte Version;                               // [in] version of this structure
  182.             public ctl_scaling_type_flag_t SupportedScaling;   // [out] Supported scaling types. Refer ::ctl_scaling_type_flag_t
  183.         }
  184.  
  185.         // Define the delegate type for the done function pointer
  186.         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  187.         public delegate void doneDelegate(IntPtr thisobj);
  188.  
  189.         // Define the scaling settings struct
  190.         [StructLayout(LayoutKind.Sequential)]
  191.         public struct ctl_scaling_settings_t
  192.         {
  193.             public uint Size;                               // [in] size of this structure
  194.             public byte Version;                            // [in] version of this structure
  195.             [MarshalAs(UnmanagedType.U1)]
  196.             public bool Enable;                             // [in,out] State of the scaler
  197.             public ctl_scaling_type_flag_t ScalingType;    // [in,out] Requested scaling types
  198.             public uint CustomScalingX;                     // [in,out] Custom Scaling X resolution
  199.             public uint CustomScalingY;                     // [in,out] Custom Scaling Y resolution
  200.             [MarshalAs(UnmanagedType.U1)]
  201.             public bool HardwareModeSet;                    // [in] Flag to indicate hardware modeset should be done
  202.         }
  203.  
  204.         [Flags]
  205.         public enum ctl_sharpness_filter_type_flag_t : uint
  206.         {
  207.             CTL_SHARPNESS_FILTER_TYPE_FLAG_NON_ADAPTIVE = 1,   // Non-adaptive sharpness
  208.             CTL_SHARPNESS_FILTER_TYPE_FLAG_ADAPTIVE = 2,   // Adaptive sharpness
  209.             CTL_SHARPNESS_FILTER_TYPE_FLAG_MAX = 0x80000000
  210.         }
  211.  
  212.         // Property range details, a generic struct to hold min/max/step size
  213.         // information of various feature properties
  214.         [StructLayout(LayoutKind.Sequential)]
  215.         public struct ctl_property_range_info_t
  216.         {
  217.             public float min_possible_value;                       // [out] Minimum possible value
  218.             public float max_possible_value;                       // [out] Maximum possible value
  219.             public float step_size;                                // [out] Step size possible
  220.             public float default_value;                            // [out] Default value
  221.         }
  222.  
  223.         // Sharpness filter properties
  224.         [StructLayout(LayoutKind.Sequential)]
  225.         public struct ctl_sharpness_filter_properties_t
  226.         {
  227.             public ctl_sharpness_filter_type_flag_t FilterType;   // [out] Filter type. Refer ctl_sharpness_filter_type_flag_t
  228.             public ctl_property_range_info_t FilterDetails;        // [out] Min, max & step size information
  229.         }
  230.  
  231.         // Various sharpness filter types
  232.         [StructLayout(LayoutKind.Sequential)]
  233.         public struct ctl_sharpness_caps_t
  234.         {
  235.             public uint Size;                                  // [in] size of this structure
  236.             public byte Version;                                // [in] version of this structure
  237.             public ctl_sharpness_filter_type_flag_t SupportedFilterFlags; // [out] Supported sharpness filters for a given display output. Refer
  238.                                                                           // ctl_sharpness_filter_type_flag_t
  239.             public byte NumFilterTypes;                         // [out] Number of elements in filter properties array
  240.             public IntPtr pFilterProperty; // [in,out] Array of filter properties structure describing supported
  241.                                            // filter capabilities. Caller should provide a pre-allocated memory for
  242.                                            // this.
  243.         }
  244.  
  245.         // Current sharpness setting
  246.         [StructLayout(LayoutKind.Sequential)]
  247.         public struct ctl_sharpness_settings_t
  248.         {
  249.             public uint Size;                                  // [in] size of this structure
  250.             public byte Version;                                // [in] version of this structure
  251.             [MarshalAs(UnmanagedType.U1)]
  252.             public bool Enable;                                    // [in,out] Current or new state of sharpness setting
  253.             public ctl_sharpness_filter_type_flag_t FilterType;   // [in,out] Current or new filter to be set. Refer
  254.                                                                   // ctl_sharpness_filter_type_flag_t
  255.             public float Intensity;                                // [in,out] Setting intensity to be applied
  256.         }
  257.  
  258.         [Flags]
  259.         public enum ctl_device_type_t : uint
  260.         {
  261.             CTL_DEVICE_TYPE_GRAPHICS = 1,                   // Graphics Device type
  262.             CTL_DEVICE_TYPE_SYSTEM = 2,                     // System Device type
  263.             CTL_DEVICE_TYPE_MAX = 0
  264.         }
  265.  
  266.         [Flags]
  267.         public enum ctl_supported_functions_flag_t : uint
  268.         {
  269.             CTL_SUPPORTED_FUNCTIONS_FLAG_DISPLAY = (1 << 0),  // [out] Is Display supported
  270.             CTL_SUPPORTED_FUNCTIONS_FLAG_3D = (1 << 1),       // [out] Is 3D supported
  271.             CTL_SUPPORTED_FUNCTIONS_FLAG_MEDIA = (1 << 2),    // [out] Is Media supported
  272.             CTL_SUPPORTED_FUNCTIONS_FLAG_MAX = 0x80000000
  273.         }
  274.  
  275.         public struct ctl_firmware_version_t
  276.         {
  277.             public ulong major_version;                         // [out] Major version
  278.             public ulong minor_version;                         // [out] Minor version
  279.             public ulong build_number;                          // [out] Build number
  280.         }
  281.  
  282.         [Flags]
  283.         public enum ctl_adapter_properties_flag_t : uint
  284.         {
  285.             CTL_ADAPTER_PROPERTIES_FLAG_INTEGRATED = (1 << 0),    // [out] Is Integrated Graphics adapter
  286.             CTL_ADAPTER_PROPERTIES_FLAG_LDA_PRIMARY = (1 << 1),   // [out] Is Primary (Lead) adapter in a Linked Display Adapter (LDA) chain
  287.             CTL_ADAPTER_PROPERTIES_FLAG_LDA_SECONDARY = (1 << 2), // [out] Is Secondary (Linked) adapter in a Linked Display Adapter (LDA) chain
  288.             CTL_ADAPTER_PROPERTIES_FLAG_MAX = 0x80000000
  289.         }
  290.  
  291.         [StructLayout(LayoutKind.Sequential)]
  292.         public struct ctl_adapter_bdf_t
  293.         {
  294.             public byte bus;                                    // [out] PCI Bus Number
  295.             public byte device;                                 // [out] PCI device number
  296.             public byte function;                               // [out] PCI function
  297.         }
  298.  
  299.         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
  300.         public struct ctl_device_adapter_properties_t
  301.         {
  302.             public uint Size;                                  // [in] size of this structure
  303.             public byte Version;                                // [in] version of this structure
  304.             public IntPtr pDeviceID;                                // [in,out] OS specific Device ID
  305.             public uint device_id_size;                        // [in] size of the device ID
  306.             public ctl_device_type_t device_type;                  // [out] Device Type
  307.             public ctl_supported_functions_flag_t supported_subfunction_flags; // [out] Supported functions
  308.             public ulong driver_version;                        // [out] Driver version
  309.             public ctl_firmware_version_t firmware_version;        // [out] Firmware version
  310.             public uint pci_vendor_id;                         // [out] PCI Vendor ID
  311.             public uint pci_device_id;                         // [out] PCI Device ID
  312.             public uint rev_id;                                // [out] PCI Revision ID
  313.             public uint num_eus_per_sub_slice;                 // [out] Number of EUs per sub-slice
  314.             public uint num_sub_slices_per_slice;              // [out] Number of sub-slices per slice
  315.             public uint num_slices;                            // [out] Number of slices
  316.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
  317.             public string name;             // [out] Device name
  318.             public ctl_adapter_properties_flag_t graphics_adapter_properties; // [out] Graphics Adapter Properties
  319.             public uint Frequency;                             // [out] Clock frequency for this device. Supported only for Version > 0
  320.             public ushort pci_subsys_id;                         // [out] PCI SubSys ID, Supported only for Version > 1
  321.             public ushort pci_subsys_vendor_id;                  // [out] PCI SubSys Vendor ID, Supported only for Version > 1
  322.             public ctl_adapter_bdf_t adapter_bdf;                  // [out] Pci Bus, Device, Function. Supported only for Version > 1
  323.             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 112)]
  324.             public string reserved;           // [out] Reserved
  325.         }
  326.  
  327.         [StructLayout(LayoutKind.Sequential)]
  328.         public struct ctl_telemetry_data
  329.         {
  330.             // GPU TDP
  331.             public bool GpuEnergySupported;
  332.             public double GpuEnergyValue;
  333.  
  334.             // GPU Voltage
  335.             public bool GpuVoltageSupported;
  336.             public double GpuVoltagValue; // Note: Typo in the original C++ code, should be "GpuVoltageValue" instead of "GpuVoltagValue"
  337.  
  338.             // GPU Core Frequency
  339.             public bool GpuCurrentClockFrequencySupported;
  340.             public double GpuCurrentClockFrequencyValue;
  341.  
  342.             // GPU Core Temperature
  343.             public bool GpuCurrentTemperatureSupported;
  344.             public double GpuCurrentTemperatureValue;
  345.  
  346.             // GPU Usage
  347.             public bool GlobalActivitySupported;
  348.             public double GlobalActivityValue;
  349.  
  350.             // Render Engine Usage
  351.             public bool RenderComputeActivitySupported;
  352.             public double RenderComputeActivityValue;
  353.  
  354.             // Media Engine Usage
  355.             public bool MediaActivitySupported;
  356.             public double MediaActivityValue;
  357.  
  358.             // VRAM Power Consumption
  359.             public bool VramEnergySupported;
  360.             public double VramEnergyValue;
  361.  
  362.             // VRAM Voltage
  363.             public bool VramVoltageSupported;
  364.             public double VramVoltageValue;
  365.  
  366.             // VRAM Frequency
  367.             public bool VramCurrentClockFrequencySupported;
  368.             public double VramCurrentClockFrequencyValue;
  369.  
  370.             // VRAM Read Bandwidth
  371.             public bool VramReadBandwidthSupported;
  372.             public double VramReadBandwidthValue;
  373.  
  374.             // VRAM Write Bandwidth
  375.             public bool VramWriteBandwidthSupported;
  376.             public double VramWriteBandwidthValue;
  377.  
  378.             // VRAM Temperature
  379.             public bool VramCurrentTemperatureSupported;
  380.             public double VramCurrentTemperatureValue;
  381.  
  382.             // Fanspeed (n Fans)
  383.             public bool FanSpeedSupported;
  384.             public double FanSpeedValue;
  385.         }
  386.  
  387.         [DllImport("kernel32")]
  388.         public static extern IntPtr LoadLibrary(string lpFileName);
  389.  
  390.         [DllImport("kernel32", SetLastError = true)]
  391.         private static extern bool FreeLibrary(IntPtr hModule);
  392.  
  393.         [DllImport("kernel32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = false)]
  394.         private static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string lpProcName);
  395.  
  396.         // Define the function delegates with the same signatures as the functions in the DLL
  397.         private delegate ctl_result_t InitializeIgclDelegate();
  398.         private delegate void CloseIgclDelegate();
  399.         private delegate IntPtr EnumerateDevicesDelegate(ref uint pAdapterCount);
  400.         private delegate ctl_result_t GetDevicePropertiesDelegate(ctl_device_adapter_handle_t hDevice, ref ctl_device_adapter_properties_t StDeviceAdapterProperties);
  401.         private delegate ctl_result_t GetRetroScalingCapsDelegate(ctl_device_adapter_handle_t hDevice, ref ctl_retro_scaling_caps_t RetroScalingCaps);
  402.         private delegate ctl_result_t GetRetroScalingSettingsDelegate(ctl_device_adapter_handle_t hDevice, ref ctl_retro_scaling_settings_t RetroScalingSettings);
  403.         private delegate ctl_result_t SetRetroScalingSettingsDelegate(ctl_device_adapter_handle_t hDevice, ctl_retro_scaling_settings_t retroScalingSettings);
  404.         private delegate ctl_result_t GetScalingCapsDelegate(ctl_device_adapter_handle_t hDevice, uint idx, ref ctl_scaling_caps_t ScalingCaps);
  405.         private delegate ctl_result_t GetScalingSettingsDelegate(ctl_device_adapter_handle_t hDevice, uint idx, ref ctl_scaling_settings_t ScalingSetting);
  406.         private delegate ctl_result_t SetScalingSettingsDelegate(ctl_device_adapter_handle_t hDevice, uint idx, ctl_scaling_settings_t scalingSettings);
  407.         private delegate ctl_result_t GetSharpnessCapsDelegate(ctl_device_adapter_handle_t hDevice, uint idx, ref ctl_sharpness_caps_t SharpnessCaps);
  408.         private delegate ctl_result_t GetSharpnessSettingsDelegate(ctl_device_adapter_handle_t hDevice, uint idx, ref ctl_sharpness_settings_t GetSharpness);
  409.         private delegate ctl_result_t SetSharpnessSettingsDelegate(ctl_device_adapter_handle_t hDevice, uint idx, ctl_sharpness_settings_t SetSharpness);
  410.         private delegate ctl_result_t GetTelemetryDataDelegate(ctl_device_adapter_handle_t hDevice, ref ctl_telemetry_data TelemetryData);
  411.  
  412.         // Define the function pointers
  413.         private static InitializeIgclDelegate InitializeIgcl;
  414.         private static CloseIgclDelegate CloseIgcl;
  415.         private static EnumerateDevicesDelegate EnumerateDevices;
  416.         private static GetDevicePropertiesDelegate GetDeviceProperties;
  417.         private static GetRetroScalingCapsDelegate GetRetroScalingCaps;
  418.         private static GetRetroScalingSettingsDelegate GetRetroScalingSettings;
  419.         private static SetRetroScalingSettingsDelegate SetRetroScalingSettings;
  420.         private static GetScalingCapsDelegate GetScalingCaps;
  421.         private static GetScalingSettingsDelegate GetScalingSettings;
  422.         private static SetScalingSettingsDelegate SetScalingSettings;
  423.         private static GetSharpnessCapsDelegate GetSharpnessCaps;
  424.         private static GetSharpnessSettingsDelegate GetSharpnessSettings;
  425.         private static SetSharpnessSettingsDelegate SetSharpnessSettings;
  426.         private static GetTelemetryDataDelegate GetTelemetryData;
  427.  
  428.         public static IntPtr[] devices = new IntPtr[1] { IntPtr.Zero };
  429.         private static IntPtr pDll = IntPtr.Zero;
  430.  
  431.         // for this support library
  432.         public enum IGCLStatus
  433.         {
  434.             NO_ERROR = 0,
  435.             DLL_NOT_FOUND = 1,
  436.             DLL_INCORRECT_VERSION = 2,
  437.             DLL_INITIALIZE_ERROR = 3
  438.         }
  439.  
  440.         private const string dllName = "IGCL_Wrapper.dll";
  441.         private static IGCLStatus status = IGCLStatus.NO_ERROR;
  442.  
  443.         private static Delegate GetDelegate(string procName, Type delegateType)
  444.         {
  445.             IntPtr ptr = GetProcAddress(pDll, procName);
  446.             if (ptr != IntPtr.Zero)
  447.             {
  448.                 var d = Marshal.GetDelegateForFunctionPointer(ptr, delegateType);
  449.                 return d;
  450.             }
  451.  
  452.             var result = Marshal.GetHRForLastWin32Error();
  453.             throw Marshal.GetExceptionForHR(result);
  454.         }
  455.  
  456.         public static bool Initialize()
  457.         {
  458.             pDll = LoadLibrary(dllName);
  459.             if (pDll == IntPtr.Zero)
  460.             {
  461.                 status = IGCLStatus.DLL_NOT_FOUND;
  462.             }
  463.             else
  464.             {
  465.                 try
  466.                 {
  467.                     // Get the function pointers
  468.                     InitializeIgcl = (InitializeIgclDelegate)GetDelegate("IntializeIgcl", typeof(InitializeIgclDelegate));
  469.                     CloseIgcl = (CloseIgclDelegate)GetDelegate("CloseIgcl", typeof(CloseIgclDelegate));
  470.                     EnumerateDevices = (EnumerateDevicesDelegate)GetDelegate("EnumerateDevices", typeof(EnumerateDevicesDelegate));
  471.                     GetDeviceProperties = (GetDevicePropertiesDelegate)GetDelegate("GetDeviceProperties", typeof(GetDevicePropertiesDelegate));
  472.                     GetRetroScalingCaps = (GetRetroScalingCapsDelegate)GetDelegate("GetRetroScalingCaps", typeof(GetRetroScalingCapsDelegate));
  473.                     GetRetroScalingSettings = (GetRetroScalingSettingsDelegate)GetDelegate("GetRetroScalingSettings", typeof(GetRetroScalingSettingsDelegate));
  474.                     SetRetroScalingSettings = (SetRetroScalingSettingsDelegate)GetDelegate("SetRetroScalingSettings", typeof(SetRetroScalingSettingsDelegate));
  475.                     GetScalingCaps = (GetScalingCapsDelegate)GetDelegate("GetScalingCaps", typeof(GetScalingCapsDelegate));
  476.                     GetScalingSettings = (GetScalingSettingsDelegate)GetDelegate("GetScalingSettings", typeof(GetScalingSettingsDelegate));
  477.                     SetScalingSettings = (SetScalingSettingsDelegate)GetDelegate("SetScalingSettings", typeof(SetScalingSettingsDelegate));
  478.                     GetSharpnessCaps = (GetSharpnessCapsDelegate)GetDelegate("GetSharpnessCaps", typeof(GetSharpnessCapsDelegate));
  479.                     GetSharpnessSettings = (GetSharpnessSettingsDelegate)GetDelegate("GetSharpnessSettings", typeof(GetSharpnessSettingsDelegate));
  480.                     SetSharpnessSettings = (SetSharpnessSettingsDelegate)GetDelegate("SetSharpnessSettings", typeof(SetSharpnessSettingsDelegate));
  481.                     GetTelemetryData = (GetTelemetryDataDelegate)GetDelegate("GetTelemetryData", typeof(GetTelemetryDataDelegate));
  482.                 }
  483.                 catch
  484.                 {
  485.                     status = IGCLStatus.DLL_INITIALIZE_ERROR;
  486.                 }
  487.             }
  488.  
  489.             if (status != IGCLStatus.NO_ERROR)
  490.                 return false;
  491.  
  492.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  493.  
  494.             // Call Init and check the result
  495.             Result = InitializeIgcl();
  496.             return Result == ctl_result_t.CTL_RESULT_SUCCESS;
  497.         }
  498.  
  499.         public static int GetDeviceIdx(string deviceName)
  500.         {
  501.             // test
  502.             Terminate();
  503.             Initialize();
  504.  
  505.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  506.             uint adapterCount = 0;
  507.  
  508.             // Get the number of Intel devices
  509.             IntPtr hDevices = EnumerateDevices(ref adapterCount);
  510.             if (hDevices == IntPtr.Zero)
  511.                 return -1;
  512.  
  513.             // Convert the device handles to an array of IntPtr
  514.             devices = new IntPtr[adapterCount];
  515.             Marshal.Copy(hDevices, devices, 0, (int)adapterCount);
  516.             if (devices.Length == 0)
  517.                 return -1;
  518.  
  519.             for (int idx = 0; idx < devices.Length; idx++)
  520.             {
  521.                 ctl_device_adapter_properties_t StDeviceAdapterProperties = new();
  522.                 ctl_device_adapter_handle_t hDevice = new()
  523.                 {
  524.                     handle = devices[idx]
  525.                 };
  526.  
  527.                 Result = GetDeviceProperties(hDevice, ref StDeviceAdapterProperties);
  528.                 if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  529.                     continue;
  530.  
  531.                 if (deviceName.Equals(StDeviceAdapterProperties.name))
  532.                     return idx;
  533.             }
  534.  
  535.             return -1;
  536.         }
  537.  
  538.         public static void Terminate()
  539.         {
  540.             if (pDll != IntPtr.Zero)
  541.             {
  542.                 CloseIgcl();
  543.                 FreeLibrary(pDll);
  544.                 pDll = IntPtr.Zero;
  545.             }
  546.         }
  547.  
  548.         internal static bool HasGPUScalingSupport(nint deviceIdx, uint displayIdx)
  549.         {
  550.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  551.             ctl_scaling_caps_t ScalingCaps = new();
  552.  
  553.             IntPtr device = devices[deviceIdx];
  554.             if (device == IntPtr.Zero)
  555.                 return false;
  556.  
  557.             ctl_device_adapter_handle_t hDevice = new()
  558.             {
  559.                 handle = device
  560.             };
  561.  
  562.             Result = GetScalingCaps(hDevice, displayIdx, ref ScalingCaps);
  563.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  564.                 return false;
  565.  
  566.             return ScalingCaps.SupportedScaling >= 0;
  567.         }
  568.  
  569.         internal static bool GetGPUScaling(nint deviceIdx, uint displayIdx)
  570.         {
  571.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  572.             ctl_scaling_settings_t ScalingSettings = new();
  573.  
  574.             IntPtr device = devices[deviceIdx];
  575.             if (device == IntPtr.Zero)
  576.                 return false;
  577.  
  578.             ctl_device_adapter_handle_t hDevice = new()
  579.             {
  580.                 handle = device
  581.             };
  582.            
  583.             Result = GetScalingSettings(hDevice, displayIdx, ref ScalingSettings);
  584.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  585.                 return false;
  586.  
  587.             return ScalingSettings.Enable;
  588.         }
  589.  
  590.         internal static bool SetGPUScaling(nint deviceIdx, uint displayIdx, bool enabled = true)
  591.         {
  592.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  593.             ctl_scaling_settings_t ScalingSettings = new();
  594.  
  595.             IntPtr device = devices[deviceIdx];
  596.             if (device == IntPtr.Zero)
  597.                 return false;
  598.  
  599.             ctl_device_adapter_handle_t hDevice = new()
  600.             {
  601.                 handle = device
  602.             };
  603.            
  604.             Result = GetScalingSettings(hDevice, displayIdx, ref ScalingSettings);
  605.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  606.                 return false;
  607.  
  608.             // skip if not needeed
  609.             if (ScalingSettings.Enable == enabled)
  610.                 return true;
  611.  
  612.             // fill custom scaling details
  613.             ScalingSettings.Enable = enabled;
  614.  
  615.             Result = SetScalingSettings(hDevice, displayIdx, ScalingSettings);
  616.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  617.                 return false;
  618.  
  619.             // check if value was properly applied
  620.             Result = GetScalingSettings(hDevice, displayIdx, ref ScalingSettings);
  621.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  622.                 return false;
  623.  
  624.             return ScalingSettings.Enable == enabled;
  625.         }
  626.  
  627.         internal static bool SetImageSharpening(nint deviceIdx, uint displayIdx, bool enable)
  628.         {
  629.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  630.             ctl_sharpness_settings_t GetSharpness = new();
  631.  
  632.             IntPtr device = devices[deviceIdx];
  633.             if (device == IntPtr.Zero)
  634.                 return false;
  635.  
  636.             ctl_device_adapter_handle_t hDevice = new()
  637.             {
  638.                 handle = device
  639.             };
  640.  
  641.             Result = GetSharpnessSettings(hDevice, displayIdx, ref GetSharpness);
  642.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  643.                 return false;
  644.  
  645.             // skip if not needeed
  646.             if (GetSharpness.Enable == enable)
  647.                 return true;
  648.  
  649.             // if disabled, we need to set intensity to 0 first (while enabled)
  650.             switch (enable)
  651.             {
  652.                 default:
  653.                 case false:
  654.                     GetSharpness.Intensity = 0;
  655.                     Result = SetSharpnessSettings(hDevice, displayIdx, GetSharpness);
  656.                     if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  657.                         return false;
  658.                     break;
  659.             }
  660.  
  661.             // fill custom scaling details
  662.             GetSharpness.Enable = enable;
  663.  
  664.             Result = SetSharpnessSettings(hDevice, displayIdx, GetSharpness);
  665.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  666.                 return false;
  667.  
  668.             // check if value was properly applied
  669.             Result = GetSharpnessSettings(hDevice, displayIdx, ref GetSharpness);
  670.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  671.                 return false;
  672.  
  673.             return GetSharpness.Enable == enable;
  674.         }
  675.  
  676.         internal static bool SetScalingMode(nint deviceIdx, uint displayIdx, int mode)
  677.         {
  678.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  679.             ctl_scaling_settings_t ScalingSettings = new();
  680.  
  681.             IntPtr device = devices[deviceIdx];
  682.             if (device == IntPtr.Zero)
  683.                 return false;
  684.  
  685.             ctl_device_adapter_handle_t hDevice = new()
  686.             {
  687.                 handle = device
  688.             };
  689.            
  690.             Result = GetScalingSettings(hDevice, displayIdx, ref ScalingSettings);
  691.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  692.                 return false;
  693.  
  694.             // 0: aspect
  695.             // 1: full
  696.             // 2: center
  697.             ctl_scaling_type_flag_t ScalingType = ctl_scaling_type_flag_t.CTL_SCALING_TYPE_FLAG_IDENTITY;
  698.             switch (mode)
  699.             {
  700.                 case 0:
  701.                     ScalingType = ctl_scaling_type_flag_t.CTL_SCALING_TYPE_FLAG_ASPECT_RATIO_CENTERED_MAX;
  702.                     break;
  703.                 case 1:
  704.                     ScalingType = ctl_scaling_type_flag_t.CTL_SCALING_TYPE_FLAG_STRETCHED;
  705.                     break;
  706.                 case 2:
  707.                     ScalingType = ctl_scaling_type_flag_t.CTL_SCALING_TYPE_FLAG_CENTERED;
  708.                     break;
  709.             }
  710.  
  711.             // skip if not needeed
  712.             if (ScalingSettings.ScalingType == ScalingType)
  713.                 return true;
  714.  
  715.             // fill custom scaling details
  716.             ScalingSettings.ScalingType = ScalingType;
  717.  
  718.             Result = SetScalingSettings(hDevice, displayIdx, ScalingSettings);
  719.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  720.                 return false;
  721.  
  722.             // check if value was properly applied
  723.             Result = GetScalingSettings(hDevice, displayIdx, ref ScalingSettings);
  724.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  725.                 return false;
  726.  
  727.             return ScalingSettings.ScalingType == ScalingType;
  728.         }
  729.  
  730.         internal static bool GetImageSharpening(nint deviceIdx, uint displayIdx)
  731.         {
  732.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  733.             ctl_sharpness_settings_t GetSharpness = new();
  734.  
  735.             IntPtr device = devices[deviceIdx];
  736.             if (device == IntPtr.Zero)
  737.                 return false;
  738.  
  739.             ctl_device_adapter_handle_t hDevice = new()
  740.             {
  741.                 handle = device
  742.             };
  743.  
  744.             Result = GetSharpnessSettings(hDevice, displayIdx, ref GetSharpness);
  745.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  746.                 return false;
  747.  
  748.             return GetSharpness.Enable;
  749.         }
  750.  
  751.         internal static int GetImageSharpeningSharpness(nint deviceIdx, uint displayIdx)
  752.         {
  753.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  754.  
  755.             IntPtr device = devices[deviceIdx];
  756.             if (device == IntPtr.Zero)
  757.                 return 0;
  758.  
  759.             ctl_device_adapter_handle_t hDevice = new()
  760.             {
  761.                 handle = device
  762.             };
  763.  
  764.             ctl_sharpness_settings_t GetSharpness = new();
  765.  
  766.             Result = GetSharpnessSettings(hDevice, displayIdx, ref GetSharpness);
  767.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  768.                 return 0;
  769.  
  770.             return (int)GetSharpness.Intensity;
  771.         }
  772.  
  773.         internal static bool SetImageSharpeningSharpness(nint deviceIdx, uint displayIdx, int sharpness)
  774.         {
  775.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  776.             ctl_sharpness_settings_t GetSharpness = new();
  777.  
  778.             IntPtr device = devices[deviceIdx];
  779.             if (device == IntPtr.Zero)
  780.                 return false;
  781.  
  782.             ctl_device_adapter_handle_t hDevice = new()
  783.             {
  784.                 handle = device
  785.             };
  786.  
  787.             Result = GetSharpnessSettings(hDevice, displayIdx, ref GetSharpness);
  788.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  789.                 return false;
  790.  
  791.             // skip if not needeed
  792.             if (GetSharpness.Intensity == sharpness)
  793.                 return true;
  794.  
  795.             // fill custom scaling details
  796.             GetSharpness.Intensity = sharpness;
  797.  
  798.             Result = SetSharpnessSettings(hDevice, displayIdx, GetSharpness);
  799.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  800.                 return false;
  801.  
  802.             // check if value was properly applied
  803.             Result = GetSharpnessSettings(hDevice, displayIdx, ref GetSharpness);
  804.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  805.                 return false;
  806.  
  807.             return GetSharpness.Intensity == sharpness;
  808.         }
  809.  
  810.         internal static bool HasIntegerScalingSupport(nint deviceIdx, uint displayIdx)
  811.         {
  812.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  813.             ctl_retro_scaling_caps_t RetroScalingCaps = new();
  814.  
  815.             IntPtr device = devices[deviceIdx];
  816.             if (device == IntPtr.Zero)
  817.                 return false;
  818.  
  819.             ctl_device_adapter_handle_t hDevice = new()
  820.             {
  821.                 handle = device
  822.             };
  823.  
  824.             Result = GetRetroScalingCaps(hDevice, ref RetroScalingCaps);
  825.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  826.                 return false;
  827.  
  828.             return RetroScalingCaps.SupportedRetroScaling >= 0;
  829.         }
  830.  
  831.         internal static bool GetIntegerScaling(nint deviceIdx)
  832.         {
  833.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  834.             ctl_retro_scaling_settings_t RetroScalingSettings = new();
  835.  
  836.             IntPtr device = devices[deviceIdx];
  837.             if (device == IntPtr.Zero)
  838.                 return false;
  839.  
  840.             ctl_device_adapter_handle_t hDevice = new()
  841.             {
  842.                 handle = device
  843.             };
  844.  
  845.             Result = GetRetroScalingSettings(hDevice, ref RetroScalingSettings);
  846.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  847.                 return false;
  848.  
  849.             return RetroScalingSettings.Enable;
  850.         }
  851.  
  852.         internal static bool SetIntegerScaling(nint deviceIdx, bool enabled, byte type)
  853.         {
  854.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  855.             ctl_retro_scaling_settings_t RetroScalingSettings = new();
  856.             ctl_retro_scaling_type_flags_t RetroScalingType = (ctl_retro_scaling_type_flags_t)(type + 1);
  857.  
  858.             IntPtr device = devices[deviceIdx];
  859.             if (device == IntPtr.Zero)
  860.                 return false;
  861.  
  862.             ctl_device_adapter_handle_t hDevice = new()
  863.             {
  864.                 handle = device
  865.             };
  866.  
  867.             Result = GetRetroScalingSettings(hDevice, ref RetroScalingSettings);
  868.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  869.                 return false;
  870.  
  871.             // skip if not needeed
  872.             if (RetroScalingSettings.Enable == enabled && RetroScalingSettings.RetroScalingType == RetroScalingType)
  873.                 return true;
  874.  
  875.             // fill custom scaling details
  876.             RetroScalingSettings.Enable = enabled;
  877.             RetroScalingSettings.RetroScalingType = RetroScalingType;
  878.            
  879.             Result = SetRetroScalingSettings(hDevice, RetroScalingSettings);
  880.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  881.                 return false;
  882.  
  883.             // check if value was properly applied
  884.             Result = GetRetroScalingSettings(hDevice, ref RetroScalingSettings);
  885.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  886.                 return false;
  887.  
  888.             return RetroScalingSettings.Enable == enabled;
  889.         }
  890.  
  891.         public static ctl_telemetry_data GetTelemetry(nint deviceIdx)
  892.         {
  893.             ctl_result_t Result = ctl_result_t.CTL_RESULT_SUCCESS;
  894.             ctl_telemetry_data TelemetryData = new();
  895.  
  896.             IntPtr device = devices[deviceIdx];
  897.             if (device == IntPtr.Zero)
  898.                 return TelemetryData;
  899.  
  900.             ctl_device_adapter_handle_t hDevice = new()
  901.             {
  902.                 handle = device
  903.             };
  904.  
  905.             Result = GetTelemetryData(hDevice, ref TelemetryData);
  906.             if (Result != ctl_result_t.CTL_RESULT_SUCCESS)
  907.                 return TelemetryData;
  908.  
  909.             return TelemetryData;
  910.         }
  911.     }
  912. }
Advertisement
Add Comment
Please, Sign In to add comment