diff --git a/CMakeLists.txt b/CMakeLists.txt index c0713fe8..da40378d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,10 +165,14 @@ function(configure_target TARGET_NAME) target_link_libraries( ${TARGET_NAME} PUBLIC + advapi32.lib + bcrypt.lib + dbghelp.lib + dxgi.lib + ole32.lib spdlog::spdlog - Version.lib - Dbghelp.lib - Ws2_32.lib + version.lib + ws2_32.lib ) if(SFSE_SUPPORT_XBYAK) @@ -233,6 +237,7 @@ install( DIRECTORY include/RE include/REL + include/REX include/SFSE DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) diff --git a/include/RE/B/BGSAtmosphere.h b/include/RE/B/BGSAtmosphere.h index e984bd15..4e2f42e4 100644 --- a/include/RE/B/BGSAtmosphere.h +++ b/include/RE/B/BGSAtmosphere.h @@ -3,6 +3,8 @@ #include "RE/B/BGSReflectedForm.h" #include "RE/B/BSTArray.h" +#include "REX/W32/D3D.h" + namespace RE { class BGSResource; @@ -36,20 +38,20 @@ namespace RE public: struct alignas(4) RayleighSettings { - float moleculesPerUnitVolume; // 00 - float refractiveIndexOfAir; // 04 - float depolarizationFactor; // 08 - bool useOzoneAbsorptionApproximation; // 0C - DirectX::XMFLOAT4 ozoneAbsorptionCoef; // 10 - DirectX::XMFLOAT4 rayleighCoef; // 20 + float moleculesPerUnitVolume; // 00 + float refractiveIndexOfAir; // 04 + float depolarizationFactor; // 08 + bool useOzoneAbsorptionApproximation; // 0C + REX::W32::XMFLOAT4 ozoneAbsorptionCoef; // 10 + REX::W32::XMFLOAT4 rayleighCoef; // 20 }; static_assert(sizeof(RayleighSettings) == 0x30); struct alignas(4) MieSettings { - float aerosolDensity; // 00 - float aerosolAbsorbtion; // 04 - DirectX::XMFLOAT4 mieCoef; // 08 + float aerosolDensity; // 00 + float aerosolAbsorbtion; // 04 + REX::W32::XMFLOAT4 mieCoef; // 08 }; static_assert(sizeof(MieSettings) == 0x18); diff --git a/include/RE/B/BGSCloudForm.h b/include/RE/B/BGSCloudForm.h index 9ab1765d..8c05cba0 100644 --- a/include/RE/B/BGSCloudForm.h +++ b/include/RE/B/BGSCloudForm.h @@ -2,6 +2,8 @@ #include "RE/B/BGSReflectedForm.h" +#include "REX/W32/D3D.h" + namespace RE { class BGSEffectSequenceForm; @@ -29,31 +31,31 @@ namespace RE { public: // members - BSFixedString name; // 00 - BSFixedString colorTexture; // 08 - BSFixedString thicknessTexture; // 10 - BSFixedString normalTexture; // 18 - BSFixedString opacityTexture; // 20 - float elevationKm; // 28 - float heightKm; // 2C - float distanceKm; // 30 - float thickness; // 34 - float textureShadowOffset; // 38 - float textureShadowStrength; // 3C - float normalShadowStrength; // 40 - std::uint32_t tiling; // 44 - std::uint32_t verticalTiling; // 48 - float topBlendDistanceKm; // 4C - float topBlendStartKm; // 50 - float bottomBlendDistanceKm; // 54 - float bottomBlendStartKm; // 58 - float windScale; // 5C - float density; // 60 - float coverage; // 64 - float alphaAdd; // 68 - float alphaMultiply; // 6C - DirectX::XMCOLOR tint; // 70 - bool enableEditorRendering; // 74 + BSFixedString name; // 00 + BSFixedString colorTexture; // 08 + BSFixedString thicknessTexture; // 10 + BSFixedString normalTexture; // 18 + BSFixedString opacityTexture; // 20 + float elevationKm; // 28 + float heightKm; // 2C + float distanceKm; // 30 + float thickness; // 34 + float textureShadowOffset; // 38 + float textureShadowStrength; // 3C + float normalShadowStrength; // 40 + std::uint32_t tiling; // 44 + std::uint32_t verticalTiling; // 48 + float topBlendDistanceKm; // 4C + float topBlendStartKm; // 50 + float bottomBlendDistanceKm; // 54 + float bottomBlendStartKm; // 58 + float windScale; // 5C + float density; // 60 + float coverage; // 64 + float alphaAdd; // 68 + float alphaMultiply; // 6C + REX::W32::XMCOLOR tint; // 70 + bool enableEditorRendering; // 74 }; static_assert(sizeof(CloudLayer) == 0x78); @@ -61,26 +63,26 @@ namespace RE { public: // members - BSFixedString name; // 00 - BSFixedString colorTexture; // 08 - BSFixedString thicknessTexture; // 10 - BSFixedString normalTexture; // 18 - BSFixedString opacityTexture; // 20 - float elevationKm; // 28 - float fadeStartKm; // 2C - float fadeDistanceKm; // 30 - float thickness; // 34 - float textureShadowOffset; // 38 - float textureShadowStrength; // 3C - float normalShadowStrength; // 40 - float tilingPerKm; // 44 - float windScale; // 48 - float density; // 4C - float coverage; // 50 - float alphaAdd; // 54 - float alphaMultiply; // 58 - DirectX::XMCOLOR tint; // 5C - bool enableEditorRendering; // 60 + BSFixedString name; // 00 + BSFixedString colorTexture; // 08 + BSFixedString thicknessTexture; // 10 + BSFixedString normalTexture; // 18 + BSFixedString opacityTexture; // 20 + float elevationKm; // 28 + float fadeStartKm; // 2C + float fadeDistanceKm; // 30 + float thickness; // 34 + float textureShadowOffset; // 38 + float textureShadowStrength; // 3C + float normalShadowStrength; // 40 + float tilingPerKm; // 44 + float windScale; // 48 + float density; // 4C + float coverage; // 50 + float alphaAdd; // 54 + float alphaMultiply; // 58 + REX::W32::XMCOLOR tint; // 5C + bool enableEditorRendering; // 60 }; static_assert(sizeof(CloudPlane) == 0x68); diff --git a/include/RE/B/BGSFogVolumeForm.h b/include/RE/B/BGSFogVolumeForm.h index 5da5b512..56a382db 100644 --- a/include/RE/B/BGSFogVolumeForm.h +++ b/include/RE/B/BGSFogVolumeForm.h @@ -2,6 +2,8 @@ #include "RE/B/BGSReflectedForm.h" +#include "REX/W32/D3D.h" + namespace RE { class BGSFogVolumeForm : public BGSReflectedForm @@ -13,17 +15,17 @@ namespace RE ~BGSFogVolumeForm() override; // 00 // members - DirectX::XMCOLOR albedo; // 30 - float meanFreePath; // 34 - how far light can travel freely in meters [1, infinite] - float anisotropy; // 38 - DirectX::XMFLOAT3 emittance; // 3C - float edgeFalloffStart; // 48 - float edgeFalloffEnd; // 4C - float noiseContribution; // 50 - float noiseScale; // 54 - float noiseBias; // 58 - DirectX::XMFLOAT3 noiseScrollingVelocity; // 5C - std::uint32_t pad68; // 68 + REX::W32::XMCOLOR albedo; // 30 + float meanFreePath; // 34 - how far light can travel freely in meters [1, infinite] + float anisotropy; // 38 + REX::W32::XMFLOAT3 emittance; // 3C + float edgeFalloffStart; // 48 + float edgeFalloffEnd; // 4C + float noiseContribution; // 50 + float noiseScale; // 54 + float noiseBias; // 58 + REX::W32::XMFLOAT3 noiseScrollingVelocity; // 5C + std::uint32_t pad68; // 68 }; static_assert(sizeof(BGSFogVolumeForm) == 0x70); } diff --git a/include/RE/B/BGSForceData.h b/include/RE/B/BGSForceData.h index b3a7b046..5d7f5413 100644 --- a/include/RE/B/BGSForceData.h +++ b/include/RE/B/BGSForceData.h @@ -2,6 +2,8 @@ #include "RE/B/BGSReflectedForm.h" +#include "REX/W32/D3D.h" + namespace RE { class BGSCurveForm; @@ -36,7 +38,7 @@ namespace RE float verticalAngle; // 3C float speed; // 40 float strength; // 44 - DirectX::XMFLOAT3 vector; // 48 + REX::W32::XMFLOAT3 vector; // 48 BGSCurveForm* falloffCurve; // 58 float turbulenceSpeedAmplitude; // 60 float turbulenceSpeedFrequency; // 64 diff --git a/include/RE/B/BGSSunPresetForm.h b/include/RE/B/BGSSunPresetForm.h index 89926b4e..b8a18e76 100644 --- a/include/RE/B/BGSSunPresetForm.h +++ b/include/RE/B/BGSSunPresetForm.h @@ -2,6 +2,8 @@ #include "RE/B/BGSReflectedForm.h" +#include "REX/W32/D3D.h" + namespace RE::BSGalaxy { class BGSSunPresetForm : public BGSReflectedForm @@ -12,30 +14,30 @@ namespace RE::BSGalaxy struct alignas(4) DawnDuskSettings { - DirectX::XMFLOAT4 directionalColor; // 00 - float transitionStartAngle; // 10 - float transitionEndAngle; // 14 + REX::W32::XMFLOAT4 directionalColor; // 00 + float transitionStartAngle; // 10 + float transitionEndAngle; // 14 }; static_assert(sizeof(DawnDuskSettings) == 0x18); struct alignas(4) NightSettings { - DirectX::XMFLOAT4 directionalColor; // 00 - float directionalIlluminance; // 10 - DirectX::XMFLOAT4 glareColor; // 14 + REX::W32::XMFLOAT4 directionalColor; // 00 + float directionalIlluminance; // 10 + REX::W32::XMFLOAT4 glareColor; // 14 }; static_assert(sizeof(NightSettings) == 0x24); ~BGSSunPresetForm() override; // 00 // members - BGSSunPresetForm* parent; // 30 - DirectX::XMFLOAT4 sunColor; // 38 - float sunIlluminance; // 48 - DirectX::XMFLOAT4 sunGlareColor; // 4C - DawnDuskSettings dawnDuskPreset; // 5C - NightSettings nightPreset; // 74 - std::uint64_t unk98; // 98 + BGSSunPresetForm* parent; // 30 + REX::W32::XMFLOAT4 sunColor; // 38 + float sunIlluminance; // 48 + REX::W32::XMFLOAT4 sunGlareColor; // 4C + DawnDuskSettings dawnDuskPreset; // 5C + NightSettings nightPreset; // 74 + std::uint64_t unk98; // 98 }; static_assert(sizeof(BGSSunPresetForm) == 0xA0); } diff --git a/include/RE/B/BSBlendable.h b/include/RE/B/BSBlendable.h index 697df4fe..69302b87 100644 --- a/include/RE/B/BSBlendable.h +++ b/include/RE/B/BSBlendable.h @@ -1,5 +1,7 @@ #pragma once +#include "REX/W32/D3D.h" + namespace RE::BSBlendable { enum class BlendOp @@ -15,7 +17,7 @@ namespace RE::BSBlendable public: // members stl::enumeration op; // 00 - DirectX::XMFLOAT4 value; // 04 + REX::W32::XMFLOAT4 value; // 04 float blendAmount; // 14 }; static_assert(sizeof(ColorValue) == 0x18); diff --git a/include/RE/B/BSResourceEnums.h b/include/RE/B/BSResourceEnums.h index 68c04086..fdee0c8d 100644 --- a/include/RE/B/BSResourceEnums.h +++ b/include/RE/B/BSResourceEnums.h @@ -1,5 +1,7 @@ #pragma once +#include "REX/W32/BASE.h" + namespace RE::BSResource { enum class ErrorCode : std::uint32_t @@ -48,9 +50,9 @@ namespace RE::BSResource { public: // members - WinAPI::FILETIME modifyTime; // 00 - WinAPI::FILETIME createTime; // 08 - std::uint64_t fileSize; // 10 + REX::W32::FILETIME modifyTime; // 00 + REX::W32::FILETIME createTime; // 08 + std::uint64_t fileSize; // 10 }; static_assert(sizeof(Info) == 0x18); } diff --git a/include/RE/I/idLogging.h b/include/RE/I/idLogging.h index 7fb34427..1b999e6f 100644 --- a/include/RE/I/idLogging.h +++ b/include/RE/I/idLogging.h @@ -1,5 +1,7 @@ #pragma once +#include "REX/W32/KERNEL32.h" + namespace RE { namespace idLogging @@ -77,7 +79,7 @@ namespace RE break; } snprintf(outputString, 1024, "%s: %s - [%s (%d)]\n", severitystr, msg, a_fileName, a_line_number); - WinAPI::OutputDebugString(outputString); + REX::W32::OutputDebugStringA(outputString); } }; } diff --git a/include/RE/I/idTCP.h b/include/RE/I/idTCP.h index 0b273182..f303ad62 100644 --- a/include/RE/I/idTCP.h +++ b/include/RE/I/idTCP.h @@ -1,5 +1,7 @@ #pragma once +#include "REX/W32/WS2_32.h" + namespace RE { enum class netadrtype_t @@ -19,8 +21,8 @@ namespace RE static_assert(sizeof(netadr_t) == 0xC); const char* NET_ErrorString(void); - void Net_SockadrToNetadr(WinAPI::sockaddr* s, netadr_t* a); // They violated the naming convention here :( - bool NET_WaitForData(std::uintptr_t socket, std::uint32_t timeoutMs); + void Net_SockadrToNetadr(REX::W32::sockaddr* a_socket, netadr_t* a_addr); // They violated the naming convention here :( + bool NET_WaitForData(std::uintptr_t a_socket, std::uint32_t a_timeoutMs); void Sys_InitNetworking(); class idTCP @@ -30,11 +32,11 @@ namespace RE virtual ~idTCP(); // 00 - bool Listen(std::uint16_t port, bool blocking); // 'blocking' is ignored - bool Accept(const idTCP& listener); + bool Listen(std::uint16_t a_port, bool a_blocking); // 'blocking' is ignored + bool Accept(const idTCP& a_listener); std::int32_t Close(); - std::int32_t Read(void* buffer, std::uint32_t size); - std::int32_t Write(const void* buffer, std::uint32_t size, std::uint32_t timeoutMs); + std::int32_t Read(void* a_buffer, std::uint32_t a_size); + std::int32_t Write(const void* a_buffer, std::uint32_t a_size, std::uint32_t a_timeoutMs); // members netadr_t address; // 08 diff --git a/include/REL/Module.h b/include/REL/Module.h index 156a1048..08561721 100644 --- a/include/REL/Module.h +++ b/include/REL/Module.h @@ -2,6 +2,8 @@ #include "REL/Version.h" +#include "REX/W32/KERNEL32.h" + namespace REL { class Segment @@ -60,9 +62,9 @@ namespace REL _base = a_base; - const auto dosHeader = reinterpret_cast(_base); - const auto ntHeader = stl::adjust_pointer(dosHeader, dosHeader->lfanew); - const auto sections = WinAPI::IMAGE_FIRST_SECTION(ntHeader); + const auto dosHeader = reinterpret_cast(_base); + const auto ntHeader = stl::adjust_pointer(dosHeader, dosHeader->lfanew); + const auto sections = REX::W32::IMAGE_FIRST_SECTION(ntHeader); const auto size = std::min(ntHeader->fileHeader.sectionCount, _segments.size()); for (std::size_t i = 0; i < size; ++i) { @@ -78,13 +80,13 @@ namespace REL } } - _file = stl::utf8_to_utf16(WinAPI::GetProcPath(nullptr)).value(); + _file = stl::utf8_to_utf16(REX::W32::GetProcPath(nullptr)).value(); _version = get_file_version(_file).value(); } explicit constexpr Module(std::string_view a_filePath) { - const auto base = AsAddress(WinAPI::GetModuleHandle(a_filePath.data())) & ~3; + const auto base = AsAddress(REX::W32::GetModuleHandleA(a_filePath.data())) & ~3; stl_assert(base, "failed to initializing module info with file {}", a_filePath); @@ -118,19 +120,19 @@ namespace REL [[nodiscard]] static Module& get(const std::string_view a_filePath = {}) noexcept { - const auto base = AsAddress(WinAPI::GetModuleHandle(a_filePath.empty() ? WinAPI::GetProcPath(nullptr).data() : a_filePath.data())); + const auto base = AsAddress(REX::W32::GetModuleHandleA(a_filePath.empty() ? REX::W32::GetProcPath(nullptr).data() : a_filePath.data())); return get(base); } private: static constexpr std::array SEGMENTS{ - std::make_pair(".text"sv, WinAPI::IMAGE_SCN_MEM_EXECUTE), + std::make_pair(".text"sv, REX::W32::IMAGE_SCN_MEM_EXECUTE), std::make_pair(".idata"sv, static_cast(0)), std::make_pair(".rdata"sv, static_cast(0)), std::make_pair(".data"sv, static_cast(0)), std::make_pair(".pdata"sv, static_cast(0)), std::make_pair(".tls"sv, static_cast(0)), - std::make_pair(".text"sv, WinAPI::IMAGE_SCN_MEM_WRITE), + std::make_pair(".text"sv, REX::W32::IMAGE_SCN_MEM_WRITE), std::make_pair(".gfids"sv, static_cast(0)) }; diff --git a/include/REL/Relocation.h b/include/REL/Relocation.h index 90330866..bcbc8725 100644 --- a/include/REL/Relocation.h +++ b/include/REL/Relocation.h @@ -153,10 +153,10 @@ namespace REL inline void safe_write(const std::uintptr_t a_dst, const void* a_src, const std::size_t a_count) { std::uint32_t old{}; - auto success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, WinAPI::PAGE_EXECUTE_READWRITE, std::addressof(old)); + auto success = REX::W32::VirtualProtect(reinterpret_cast(a_dst), a_count, REX::W32::PAGE_EXECUTE_READWRITE, std::addressof(old)); if (success) { std::memcpy(reinterpret_cast(a_dst), a_src, a_count); - success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, old, std::addressof(old)); + success = REX::W32::VirtualProtect(reinterpret_cast(a_dst), a_count, old, std::addressof(old)); } assert(success); @@ -177,10 +177,10 @@ namespace REL inline void safe_fill(const std::uintptr_t a_dst, const std::uint8_t a_value, const std::size_t a_count) { std::uint32_t old{}; - auto success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, WinAPI::PAGE_EXECUTE_READWRITE, std::addressof(old)); + auto success = REX::W32::VirtualProtect(reinterpret_cast(a_dst), a_count, REX::W32::PAGE_EXECUTE_READWRITE, std::addressof(old)); if (success) { std::fill_n(reinterpret_cast(a_dst), a_count, a_value); - success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, old, std::addressof(old)); + success = REX::W32::VirtualProtect(reinterpret_cast(a_dst), a_count, old, std::addressof(old)); } assert(success); diff --git a/include/REL/Version.h b/include/REL/Version.h index c6fb8de9..ed12a035 100644 --- a/include/REL/Version.h +++ b/include/REL/Version.h @@ -1,5 +1,7 @@ #pragma once +#include "REX/W32/VERSION.h" + namespace REL { class Version @@ -177,18 +179,18 @@ namespace REL [[nodiscard]] inline std::optional get_file_version(const stl::zwstring a_filename) { std::uint32_t dummy{}; - std::vector buf(WinAPI::GetFileVersionInfoSize(a_filename.data(), std::addressof(dummy))); + std::vector buf(REX::W32::GetFileVersionInfoSizeW(a_filename.data(), std::addressof(dummy))); if (buf.empty()) { return std::nullopt; } - if (!WinAPI::GetFileVersionInfo(a_filename.data(), 0, buf.size(), buf.data())) { + if (!REX::W32::GetFileVersionInfoW(a_filename.data(), 0, buf.size(), buf.data())) { return std::nullopt; } void* verBuf{}; std::uint32_t verLen{}; - if (!WinAPI::VerQueryValue(buf.data(), L"\\StringFileInfo\\040904B0\\ProductVersion", std::addressof(verBuf), std::addressof(verLen))) { + if (!REX::W32::VerQueryValueW(buf.data(), L"\\StringFileInfo\\040904B0\\ProductVersion", std::addressof(verBuf), std::addressof(verLen))) { return std::nullopt; } diff --git a/include/REX/PS4.h b/include/REX/PS4.h new file mode 100644 index 00000000..8d7b0f3f --- /dev/null +++ b/include/REX/PS4.h @@ -0,0 +1,3 @@ +#pragma once + +#include "REX/PS4/SCEPAD.h" diff --git a/include/REX/PS4/SCEPAD.h b/include/REX/PS4/SCEPAD.h new file mode 100644 index 00000000..fa88dfc2 --- /dev/null +++ b/include/REX/PS4/SCEPAD.h @@ -0,0 +1,27 @@ +#pragma once + +namespace REX::PS4 +{ + enum SCE_PAD_BUTTON : std::uint32_t + { + SCE_PAD_BUTTON_SHARE = 0x00000001, + SCE_PAD_BUTTON_L3 = 0x00000002, + SCE_PAD_BUTTON_R3 = 0x00000004, + SCE_PAD_BUTTON_OPTIONS = 0x00000008, + SCE_PAD_BUTTON_UP = 0x00000010, + SCE_PAD_BUTTON_RIGHT = 0x00000020, + SCE_PAD_BUTTON_DOWN = 0x00000040, + SCE_PAD_BUTTON_LEFT = 0x00000080, + SCE_PAD_BUTTON_L2 = 0x00000100, + SCE_PAD_BUTTON_R2 = 0x00000200, + SCE_PAD_BUTTON_L1 = 0x00000400, + SCE_PAD_BUTTON_R1 = 0x00000800, + SCE_PAD_BUTTON_TRIANGLE = 0x00001000, + SCE_PAD_BUTTON_CIRCLE = 0x00002000, + SCE_PAD_BUTTON_CROSS = 0x00004000, + SCE_PAD_BUTTON_SQUARE = 0x00008000, + SCE_PAD_BUTTON_PLAYSTATION = 0x00010000, + SCE_PAD_BUTTON_TOUCH_PAD = 0x00100000, + SCE_PAD_BUTTON_INTERCEPTED = 0x80000000, + }; +} diff --git a/include/REX/REX.h b/include/REX/REX.h new file mode 100644 index 00000000..b7b8aa04 --- /dev/null +++ b/include/REX/REX.h @@ -0,0 +1,193 @@ +#pragma once + +namespace REX +{ + template < + class E, + class U = std::underlying_type_t> + class EnumSet + { + public: + using enum_type = E; + using underlying_type = U; + + static_assert(std::is_enum_v, "EnumSet must be an enum"); + static_assert(std::is_integral_v, "EnumSet<..., U> must be an integral"); + + constexpr EnumSet() noexcept = default; + constexpr EnumSet(const EnumSet&) noexcept = default; + constexpr EnumSet(EnumSet&&) noexcept = default; + + template // NOLINTNEXTLINE(google-explicit-constructor) + constexpr EnumSet(EnumSet a_rhs) noexcept : + _impl(static_cast(a_rhs.get())) + {} + + template + constexpr EnumSet(Args... a_values) noexcept + requires(std::same_as&&...) : + _impl((static_cast(a_values) | ...)) + {} + + ~EnumSet() noexcept = default; + + constexpr EnumSet& operator=(const EnumSet&) noexcept = default; + constexpr EnumSet& operator=(EnumSet&&) noexcept = default; + + template + constexpr EnumSet& operator=(EnumSet a_rhs) noexcept + { + _impl = static_cast(a_rhs.get()); + } + + constexpr EnumSet& operator=(E a_value) noexcept + { + _impl = static_cast(a_value); + return *this; + } + + public: + [[nodiscard]] explicit constexpr operator bool() const noexcept { return _impl != static_cast(0); } + + [[nodiscard]] constexpr E operator*() const noexcept { return get(); } + [[nodiscard]] constexpr E get() const noexcept { return static_cast(_impl); } + [[nodiscard]] constexpr U underlying() const noexcept { return _impl; } + + public: + template + constexpr EnumSet& set(Args... a_args) noexcept + requires(std::same_as&&...) + { + _impl |= (static_cast(a_args) | ...); + return *this; + } + + template + constexpr EnumSet& reset(Args... a_args) noexcept + requires(std::same_as&&...) + { + _impl &= ~(static_cast(a_args) | ...); + return *this; + } + + constexpr EnumSet& reset() noexcept + { + _impl = 0; + return *this; + } + + template + [[nodiscard]] constexpr bool any(Args... a_args) const noexcept + requires(std::same_as&&...) + { + return (_impl & (static_cast(a_args) | ...)) != static_cast(0); + } + + template + [[nodiscard]] constexpr bool all(Args... a_args) const noexcept + requires(std::same_as&&...) + { + return (_impl & (static_cast(a_args) | ...)) == (static_cast(a_args) | ...); + } + + template + [[nodiscard]] constexpr bool none(Args... a_args) const noexcept + requires(std::same_as&&...) + { + return (_impl & (static_cast(a_args) | ...)) == static_cast(0); + } + + public: + friend constexpr bool operator==(EnumSet a_lhs, EnumSet a_rhs) noexcept { return a_lhs.underlying() == a_rhs.underlying(); } + friend constexpr bool operator==(EnumSet a_lhs, E a_rhs) noexcept { return a_lhs.underlying() == static_cast(a_rhs); } + friend constexpr bool operator==(E a_lhs, EnumSet a_rhs) noexcept { return static_cast(a_lhs) == a_rhs.underlying(); } + + friend constexpr std::strong_ordering operator<=>(EnumSet a_lhs, EnumSet a_rhs) noexcept { return a_lhs.underlying() <=> a_rhs.underlying(); } + friend constexpr std::strong_ordering operator<=>(EnumSet a_lhs, E a_rhs) noexcept { return a_lhs.underlying() <=> static_cast(a_rhs); } + friend constexpr std::strong_ordering operator<=>(E a_lhs, EnumSet a_rhs) noexcept { return static_cast(a_lhs) <=> a_rhs.underlying(); } + + friend constexpr EnumSet operator&(EnumSet a_lhs, EnumSet a_rhs) noexcept { return static_cast(a_lhs.underlying() & a_rhs.underlying()); } + friend constexpr EnumSet operator&(EnumSet a_lhs, E a_rhs) noexcept { return static_cast(a_lhs.underlying() & static_cast(a_rhs)); } + friend constexpr EnumSet operator&(E a_lhs, EnumSet a_rhs) noexcept { return static_cast(static_cast(a_lhs) & a_rhs.underlying()); } + + friend constexpr EnumSet& operator&=(EnumSet& a_lhs, EnumSet a_rhs) noexcept { return a_lhs = a_lhs & a_rhs; } + friend constexpr EnumSet& operator&=(EnumSet& a_lhs, E a_rhs) noexcept { return a_lhs = a_lhs & a_rhs; } + + friend constexpr EnumSet operator|(EnumSet a_lhs, EnumSet a_rhs) noexcept { return static_cast(a_lhs.underlying() | a_rhs.underlying()); } + friend constexpr EnumSet operator|(EnumSet a_lhs, E a_rhs) noexcept { return static_cast(a_lhs.underlying() | static_cast(a_rhs)); } + friend constexpr EnumSet operator|(E a_lhs, EnumSet a_rhs) noexcept { return static_cast(static_cast(a_lhs) | a_rhs.underlying()); } + + friend constexpr EnumSet& operator|=(EnumSet& a_lhs, EnumSet a_rhs) noexcept { return a_lhs = a_lhs | a_rhs; } + friend constexpr EnumSet& operator|=(EnumSet& a_lhs, E a_rhs) noexcept { return a_lhs = a_lhs | a_rhs; } + + friend constexpr EnumSet operator^(EnumSet a_lhs, EnumSet a_rhs) noexcept { return static_cast(a_lhs.underlying() ^ a_rhs.underlying()); } + friend constexpr EnumSet operator^(EnumSet a_lhs, E a_rhs) noexcept { return static_cast(a_lhs.underlying() ^ static_cast(a_rhs)); } + friend constexpr EnumSet operator^(E a_lhs, EnumSet a_rhs) noexcept { return static_cast(static_cast(a_lhs) ^ a_rhs.underlying()); } + + friend constexpr EnumSet& operator^=(EnumSet& a_lhs, EnumSet a_rhs) noexcept { return a_lhs = a_lhs ^ a_rhs; } + friend constexpr EnumSet& operator^=(EnumSet& a_lhs, E a_rhs) noexcept { return a_lhs = a_lhs ^ a_rhs; } + + friend constexpr EnumSet operator+(EnumSet a_lhs, EnumSet a_rhs) noexcept { return static_cast(a_lhs.underlying() + a_rhs.underlying()); } + friend constexpr EnumSet operator+(EnumSet a_lhs, E a_rhs) noexcept { return static_cast(a_lhs.underlying() + static_cast(a_rhs)); } + friend constexpr EnumSet operator+(E a_lhs, EnumSet a_rhs) noexcept { return static_cast(static_cast(a_lhs) + a_rhs.underlying()); } + + friend constexpr EnumSet& operator+=(EnumSet& a_lhs, EnumSet a_rhs) noexcept { return a_lhs = a_lhs + a_rhs; } + friend constexpr EnumSet& operator+=(EnumSet& a_lhs, E a_rhs) noexcept { return a_lhs = a_lhs + a_rhs; } + + friend constexpr EnumSet operator-(EnumSet a_lhs, EnumSet a_rhs) noexcept { return static_cast(a_lhs.underlying() - a_rhs.underlying()); } + friend constexpr EnumSet operator-(EnumSet a_lhs, E a_rhs) noexcept { return static_cast(a_lhs.underlying() - static_cast(a_rhs)); } + friend constexpr EnumSet operator-(E a_lhs, EnumSet a_rhs) noexcept { return static_cast(static_cast(a_lhs) - a_rhs.underlying()); } + + friend constexpr EnumSet& operator-=(EnumSet& a_lhs, EnumSet a_rhs) noexcept { return a_lhs = a_lhs - a_rhs; } + friend constexpr EnumSet& operator-=(EnumSet& a_lhs, E a_rhs) noexcept { return a_lhs = a_lhs - a_rhs; } + + friend constexpr EnumSet operator<<(EnumSet a_lhs, EnumSet a_rhs) noexcept { return static_cast(a_lhs.underlying() << a_rhs.underlying()); } + friend constexpr EnumSet operator<<(EnumSet a_lhs, E a_rhs) noexcept { return static_cast(a_lhs.underlying() << static_cast(a_rhs)); } + friend constexpr EnumSet operator<<(E a_lhs, EnumSet a_rhs) noexcept { return static_cast(static_cast(a_lhs) << a_rhs.underlying()); } + + friend constexpr EnumSet& operator<<=(EnumSet& a_lhs, EnumSet a_rhs) noexcept { return a_lhs = a_lhs << a_rhs; } + friend constexpr EnumSet& operator<<=(EnumSet& a_lhs, E a_rhs) noexcept { return a_lhs = a_lhs << a_rhs; } + + friend constexpr EnumSet operator>>(EnumSet a_lhs, EnumSet a_rhs) noexcept { return static_cast(a_lhs.underlying() >> a_rhs.underlying()); } + friend constexpr EnumSet operator>>(EnumSet a_lhs, E a_rhs) noexcept { return static_cast(a_lhs.underlying() >> static_cast(a_rhs)); } + friend constexpr EnumSet operator>>(E a_lhs, EnumSet a_rhs) noexcept { return static_cast(static_cast(a_lhs) >> a_rhs.underlying()); } + + friend constexpr EnumSet& operator>>=(EnumSet& a_lhs, EnumSet a_rhs) noexcept { return a_lhs = a_lhs >> a_rhs; } + friend constexpr EnumSet& operator>>=(EnumSet& a_lhs, E a_rhs) noexcept { return a_lhs = a_lhs >> a_rhs; } + + friend constexpr EnumSet& operator~(EnumSet& a_lhs) noexcept { return a_lhs = ~a_lhs.underlying(); } + + private: + U _impl{ 0 }; + }; + + template + EnumSet(Args...) -> EnumSet< + std::common_type_t, + std::underlying_type_t< + std::common_type_t>>; +} + +namespace REX +{ + template + class Singleton + { + public: + static T* GetSingleton() + { + static T singleton; + return std::addressof(singleton); + } + + protected: + Singleton() = default; + ~Singleton() = default; + + Singleton(const Singleton&) = delete; + Singleton(Singleton&&) = delete; + + Singleton& operator=(const Singleton&) = delete; + Singleton& operator=(Singleton&&) = delete; + }; +} diff --git a/include/REX/W32.h b/include/REX/W32.h new file mode 100644 index 00000000..eecc379b --- /dev/null +++ b/include/REX/W32.h @@ -0,0 +1,22 @@ +#pragma once + +#include "REX/W32/BASE.h" + +#include "REX/W32/ADVAPI32.h" +#include "REX/W32/COM.h" +#include "REX/W32/COMPTR.h" +#include "REX/W32/D3D.h" +#include "REX/W32/DBGHELP.h" +#include "REX/W32/DINPUT.h" +#include "REX/W32/DXGI.h" +#include "REX/W32/DXGI_2.h" +#include "REX/W32/DXGI_3.h" +#include "REX/W32/DXGI_4.h" +#include "REX/W32/DXGI_5.h" +#include "REX/W32/DXGI_6.h" +#include "REX/W32/KERNEL32.h" +#include "REX/W32/OLE32.h" +#include "REX/W32/USER32.h" +#include "REX/W32/VERSION.h" +#include "REX/W32/WS2_32.h" +#include "REX/W32/XINPUT.h" diff --git a/include/REX/W32/ADVAPI32.h b/include/REX/W32/ADVAPI32.h new file mode 100644 index 00000000..cde43224 --- /dev/null +++ b/include/REX/W32/ADVAPI32.h @@ -0,0 +1,16 @@ +#pragma once + +#include "REX/W32/BASE.h" + +namespace REX::W32 +{ + inline auto HKEY_CLASSES_ROOT{ reinterpret_cast(0x80000000ull) }; + inline auto HKEY_CURRENT_USER{ reinterpret_cast(0x80000001ull) }; + inline auto HKEY_LOCAL_MACHINE{ reinterpret_cast(0x80000002ull) }; +} + +namespace REX::W32 +{ + std::int32_t RegGetValueA(HKEY a_key, const char* a_subKey, const char* a_value, std::uint32_t a_flags, std::uint32_t* a_type, void* a_data, std::uint32_t* a_dataLen); + std::int32_t RegGetValueW(HKEY a_key, const wchar_t* a_subKey, const wchar_t* a_value, std::uint32_t a_flags, std::uint32_t* a_type, void* a_data, std::uint32_t* a_dataLen); +} diff --git a/include/REX/W32/BASE.h b/include/REX/W32/BASE.h new file mode 100644 index 00000000..13cce382 --- /dev/null +++ b/include/REX/W32/BASE.h @@ -0,0 +1,188 @@ +#pragma once + +#ifdef _INC_WINAPIFAMILY +# error Windows API detected. Please move any Windows API includes after CommonLib, or remove them. +#endif + +#define REX_W32_IMPORT(a_ret, a_name, ...) \ + extern "C" __declspec(dllimport) a_ret __stdcall W32_IMPL_##a_name(...) noexcept; \ + __pragma(comment(linker, "/alternatename:__imp_W32_IMPL_" #a_name "=__imp_" #a_name)) + +namespace REX::W32 +{ + using BOOL = std::int32_t; + using HANDLE = void*; + using HBITMAP = struct HBITMAP__*; + using HBRUSH = struct HBRUSH__*; + using HCURSOR = struct HCURSOR__*; + using HDC = struct HDC__*; + using HFONT = struct HFONT__*; + using HICON = struct HICON__*; + using HINSTANCE = struct HINSTANCE__*; + using HKEY = struct HKEY__*; + using HMENU = struct HMENU__*; + using HMODULE = HINSTANCE; + using HMONITOR = struct HMONITOR__*; + using HPALETTE = struct HPALETTE__*; + using HPEN = struct HPEN__*; + using HRESULT = std::int32_t; + using HSTRING = struct HSTRING__*; + using HWND = struct HWND__*; + using NTSTATUS = std::int32_t; + + // general constants + inline const auto INVALID_HANDLE_VALUE{ reinterpret_cast(static_cast(-1)) }; + inline constexpr auto MAX_PATH{ 260u }; +} + +namespace REX::W32 +{ + struct FILETIME + { + constexpr FILETIME() noexcept = default; + + constexpr FILETIME(std::uint64_t a_value) noexcept + { + *this = std::bit_cast(a_value); + } + + constexpr operator std::uint64_t() const noexcept + { + return std::bit_cast(*this); + } + + std::uint32_t lo{}; // 00 + std::uint32_t hi{}; // 04 + }; + static_assert(sizeof(FILETIME) == 0x8); +} + +namespace REX::W32 +{ + struct GUID + { + constexpr GUID() noexcept = default; + + constexpr GUID(const std::uint32_t a_data1, const std::uint16_t a_data2, const std::uint16_t a_data3, const std::array& a_data4) noexcept : + data1(a_data1), data2(a_data2), data3(a_data3), data4{ a_data4[0], a_data4[1], a_data4[2], a_data4[3], a_data4[4], a_data4[5], a_data4[6], a_data4[7] } + {} + + friend bool operator==(const GUID& a_lhs, const GUID& a_rhs) noexcept + { + return std::memcmp(&a_lhs, &a_rhs, sizeof(a_lhs)) == 0; + } + + friend bool operator!=(const GUID& a_lhs, const GUID& a_rhs) noexcept + { + return !(a_lhs == a_rhs); + } + + std::uint32_t data1{}; // 00 + std::uint16_t data2{}; // 04 + std::uint16_t data3{}; // 08 + std::uint8_t data4[8]{}; // 10 + }; + static_assert(sizeof(GUID) == 0x10); + + using UUID = GUID; + using IID = GUID; +} + +namespace REX::W32 +{ + struct POINT + { + constexpr POINT() noexcept = default; + + constexpr POINT(std::int32_t a_x, std::int32_t a_y) noexcept : + x(a_x), y(a_y) + {} + + std::int32_t x{}; // 00 + std::int32_t y{}; // 04 + }; + static_assert(sizeof(POINT) == 0x8); +} + +namespace REX::W32 +{ + struct RECT + { + constexpr RECT() noexcept = default; + + constexpr RECT(const std::int32_t a_x1, const std::int32_t a_y1, const std::int32_t a_x2, const std::int32_t a_y2) noexcept : + x1(a_x1), y1(a_y1), x2(a_x2), y2(a_y2) + {} + + std::int32_t x1{}; // 00 + std::int32_t y1{}; // 04 + std::int32_t x2{}; // 08 + std::int32_t y2{}; // 10 + }; + static_assert(sizeof(RECT) == 0x10); +} + +namespace REX::W32 +{ + struct SIZE + { + std::int32_t x; // 00 + std::int32_t y; // 04 + }; + static_assert(sizeof(SIZE) == 0x8); +} + +namespace REX::W32 +{ + struct CRITICAL_SECTION + { + void* debugInfo; // 00 + std::int32_t lockCount; // 08 + std::int32_t recursionCount; // 0C + HANDLE owningThread; // 10 + HANDLE lockSemaphore; // 18 + std::uintptr_t spinCount; // 20 + }; + static_assert(sizeof(CRITICAL_SECTION) == 0x28); + + struct SECURITY_ATTRIBUTES + { + std::uint32_t length; // 00 + void* securityDescriptor; // 04 + BOOL inheritHandle; // 0C + }; + static_assert(sizeof(SECURITY_ATTRIBUTES) == 0x18); + + union LARGE_INTEGER + { + struct + { + std::uint32_t lo; + std::int32_t hi; + }; + std::int64_t value; + }; + + union ULARGE_INTEGER + { + struct + { + std::uint32_t lo; + std::uint32_t hi; + }; + std::uint64_t value; + }; +} + +namespace REX::W32 +{ + constexpr bool SUCCESS(const HRESULT a_result) + { + return a_result >= 0; + } + + constexpr bool NT_SUCCESS(const NTSTATUS a_status) + { + return a_status >= 0; + } +} diff --git a/include/REX/W32/BCRYPT.h b/include/REX/W32/BCRYPT.h new file mode 100644 index 00000000..7cb3d933 --- /dev/null +++ b/include/REX/W32/BCRYPT.h @@ -0,0 +1,73 @@ +#pragma once + +#include "REX/W32/BASE.h" + +namespace REX::W32 +{ + using BCRYPT_HANDLE = void*; + using BCRYPT_ALG_HANDLE = void*; + using BCRYPT_KEY_HANDLE = void*; + using BCRYPT_HASH_HANDLE = void*; + using BCRYPT_SECRET_HANDLE = void*; + + // algorithms + inline constexpr auto BCRYPT_RSA_ALGORITHM{ L"RSA" }; + inline constexpr auto BCRYPT_RSA_SIGN_ALGORITHM{ L"RSA_SIGN" }; + inline constexpr auto BCRYPT_DH_ALGORITHM{ L"DH" }; + inline constexpr auto BCRYPT_DSA_ALGORITHM{ L"DSA" }; + inline constexpr auto BCRYPT_RC2_ALGORITHM{ L"RC2" }; + inline constexpr auto BCRYPT_RC4_ALGORITHM{ L"RC4" }; + inline constexpr auto BCRYPT_AES_ALGORITHM{ L"AES" }; + inline constexpr auto BCRYPT_DES_ALGORITHM{ L"DES" }; + inline constexpr auto BCRYPT_DESX_ALGORITHM{ L"DESX" }; + inline constexpr auto BCRYPT_3DES_ALGORITHM{ L"3DES" }; + inline constexpr auto BCRYPT_3DES_112_ALGORITHM{ L"3DES_112" }; + inline constexpr auto BCRYPT_MD2_ALGORITHM{ L"MD2" }; + inline constexpr auto BCRYPT_MD4_ALGORITHM{ L"MD4" }; + inline constexpr auto BCRYPT_MD5_ALGORITHM{ L"MD5" }; + inline constexpr auto BCRYPT_SHA1_ALGORITHM{ L"SHA1" }; + inline constexpr auto BCRYPT_SHA256_ALGORITHM{ L"SHA256" }; + inline constexpr auto BCRYPT_SHA384_ALGORITHM{ L"SHA384" }; + inline constexpr auto BCRYPT_SHA512_ALGORITHM{ L"SHA512" }; + inline constexpr auto BCRYPT_AES_GMAC_ALGORITHM{ L"AES-GMAC" }; + inline constexpr auto BCRYPT_AES_CMAC_ALGORITHM{ L"AES-CMAC" }; + inline constexpr auto BCRYPT_ECDSA_P256_ALGORITHM{ L"ECDSA_P256" }; + inline constexpr auto BCRYPT_ECDSA_P384_ALGORITHM{ L"ECDSA_P384" }; + inline constexpr auto BCRYPT_ECDSA_P521_ALGORITHM{ L"ECDSA_P521" }; + inline constexpr auto BCRYPT_ECDH_P256_ALGORITHM{ L"ECDH_P256" }; + inline constexpr auto BCRYPT_ECDH_P384_ALGORITHM{ L"ECDH_P384" }; + inline constexpr auto BCRYPT_ECDH_P521_ALGORITHM{ L"ECDH_P521" }; + inline constexpr auto BCRYPT_RNG_ALGORITHM{ L"RNG" }; + inline constexpr auto BCRYPT_RNG_FIPS186_DSA_ALGORITHM{ L"FIPS186DSARNG" }; + inline constexpr auto BCRYPT_RNG_DUAL_EC_ALGORITHM{ L"DUALECRNG" }; + + // properties + inline constexpr auto BCRYPT_OBJECT_LENGTH{ L"ObjectLength" }; + inline constexpr auto BCRYPT_ALGORITHM_NAME{ L"AlgorithmName" }; + inline constexpr auto BCRYPT_PROVIDER_HANDLE{ L"ProviderHandle" }; + inline constexpr auto BCRYPT_CHAINING_MODE{ L"ChainingMode" }; + inline constexpr auto BCRYPT_BLOCK_LENGTH{ L"BlockLength" }; + inline constexpr auto BCRYPT_KEY_LENGTH{ L"KeyLength" }; + inline constexpr auto BCRYPT_KEY_OBJECT_LENGTH{ L"KeyObjectLength" }; + inline constexpr auto BCRYPT_KEY_STRENGTH{ L"KeyStrength" }; + inline constexpr auto BCRYPT_KEY_LENGTHS{ L"KeyLengths" }; + inline constexpr auto BCRYPT_BLOCK_SIZE_LIST{ L"BlockSizeList" }; + inline constexpr auto BCRYPT_EFFECTIVE_KEY_LENGTH{ L"EffectiveKeyLength" }; + inline constexpr auto BCRYPT_HASH_LENGTH{ L"HashDigestLength" }; + inline constexpr auto BCRYPT_HASH_OID_LIST{ L"HashOIDList" }; + inline constexpr auto BCRYPT_PADDING_SCHEMES{ L"PaddingSchemes" }; + inline constexpr auto BCRYPT_SIGNATURE_LENGTH{ L"SignatureLength" }; + inline constexpr auto BCRYPT_HASH_BLOCK_LENGTH{ L"HashBlockLength" }; + inline constexpr auto BCRYPT_AUTH_TAG_LENGTH{ L"AuthTagLength" }; +} + +namespace REX::W32 +{ + NTSTATUS BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE* a_algorithm, const wchar_t* a_id, const wchar_t* a_impl = nullptr, std::uint32_t a_flags = 0); + NTSTATUS BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE a_algorithm, std::uint32_t a_flags = 0); + NTSTATUS BCryptCreateHash(BCRYPT_ALG_HANDLE a_algorithm, BCRYPT_HASH_HANDLE* a_hash, std::uint8_t* a_hashObject = nullptr, std::uint32_t a_hashObjectSize = 0, std::uint8_t* a_secret = nullptr, std::uint32_t a_secretSize = 0, std::uint32_t a_flags = 0); + NTSTATUS BCryptDestroyHash(BCRYPT_HASH_HANDLE a_hash); + NTSTATUS BCryptFinishHash(BCRYPT_HASH_HANDLE a_hash, std::uint8_t* a_output, std::uint32_t a_outputSize, std::uint32_t a_flags = 0); + NTSTATUS BCryptGetProperty(BCRYPT_HANDLE a_object, const wchar_t* a_property, std::uint8_t* a_output, std::uint32_t a_outputSize, std::uint32_t* a_result, std::uint32_t a_flags = 0); + NTSTATUS BCryptHashData(BCRYPT_HASH_HANDLE a_hash, std::uint8_t* a_input, std::uint32_t a_inputSize, std::uint32_t a_flags = 0); +} diff --git a/include/REX/W32/COM.h b/include/REX/W32/COM.h new file mode 100644 index 00000000..e5a74c47 --- /dev/null +++ b/include/REX/W32/COM.h @@ -0,0 +1,25 @@ +#pragma once + +#include "REX/W32/BASE.h" + +namespace REX::W32 +{ + struct __declspec(novtable, uuid("00000000-0000-0000-c000-000000000046")) + IUnknown + { + virtual HRESULT QueryInterface(const IID& a_iid, void** a_object) = 0; + virtual std::uint32_t AddRef() = 0; + virtual std::uint32_t Release() = 0; + + template + HRESULT QueryInterface(T** a_object) + { + return QueryInterface(*reinterpret_cast(&__uuidof(T)), static_cast(a_object)); + } + }; +} + +namespace REX::W32 +{ + inline constexpr IID IID_IUnknown{ 0x00000000, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }; +} diff --git a/include/REX/W32/COMPTR.h b/include/REX/W32/COMPTR.h new file mode 100644 index 00000000..6453de44 --- /dev/null +++ b/include/REX/W32/COMPTR.h @@ -0,0 +1,196 @@ +#pragma once + +#include "REX/W32/BASE.h" + +namespace REX::W32 +{ + // based on Microsoft::WRL::ComPtr + template + struct ComPtr + { + constexpr ComPtr() noexcept = default; + constexpr ComPtr(std::nullptr_t) noexcept {} + + ComPtr(const ComPtr& a_other) noexcept : + _ptr(a_other._ptr) + { + TryAddRef(); + } + + template + ComPtr(U* a_other) noexcept : + _ptr(a_other) + { + TryAddRef(); + } + + ~ComPtr() noexcept + { + TryRelease(); + } + + ComPtr& operator=(std::nullptr_t) noexcept + { + TryRelease(); + return *this; + } + + ComPtr& operator=(T* a_other) noexcept + { + if (_ptr != a_other) + ComPtr(a_other).Swap(*this); + + return *this; + } + + template + ComPtr& operator=(U* a_other) noexcept + { + ComPtr(a_other).Swap(*this); + return *this; + } + + ComPtr& operator=(const ComPtr& a_other) noexcept + { + if (_ptr != a_other._ptr) + ComPtr(a_other).Swap(*this); + + return *this; + } + + template + ComPtr& operator=(const ComPtr& a_other) noexcept + { + ComPtr(a_other).Swap(*this); + return *this; + } + + ComPtr& operator=(ComPtr&& a_other) noexcept + { + ComPtr(static_cast(a_other)).Swap(*this); + return *this; + } + + template + ComPtr& operator=(ComPtr&& a_other) noexcept + { + ComPtr(static_cast&&>(a_other)).Swap(*this); + return *this; + } + + T* operator->() const noexcept + { + return _ptr; + } + + void Attach(T* a_other) noexcept + { + if (_ptr != nullptr) { + [[maybe_unused]] auto ref = _ptr->Release(); + assert((ref != 0) || (_ptr != a_other)); + } + + _ptr = a_other; + } + + T* Detach() noexcept + { + T* ptr = _ptr; + _ptr = nullptr; + return ptr; + } + + T* Get() const noexcept + { + return _ptr; + } + + T** GetAddressOf() noexcept + { + return &_ptr; + } + + T* const* GetAddressOf() const noexcept + { + return &_ptr; + } + + T** ReleaseAndGetAddressOf() noexcept + { + TryRelease(); + return &_ptr; + } + + std::uint32_t Reset() noexcept + { + return TryRelease(); + } + + void Swap(ComPtr& a_other) noexcept + { + T* ptr = _ptr; + _ptr = a_other._ptr; + a_other._ptr = ptr; + } + + void Swap(ComPtr&& a_other) noexcept + { + T* ptr = _ptr; + _ptr = a_other._ptr; + a_other._ptr = ptr; + } + + template + HRESULT As(ComPtr* a_ptr) const noexcept + { + return _ptr->QueryInterface(__uuidof(U), reinterpret_cast(a_ptr->ReleaseAndGetAddressOf())); + } + + template + HRESULT AsIID(const IID& a_iid, ComPtr* a_ptr) const noexcept + { + return _ptr->QueryInterface(a_iid, reinterpret_cast(a_ptr->ReleaseAndGetAddressOf())); + } + + HRESULT CopyTo(const IID& a_iid, void** a_ptr) const noexcept + { + return _ptr->QueryInterface(a_iid, a_ptr); + } + + HRESULT CopyTo(T** a_ptr) const noexcept + { + TryAddRef(); + *a_ptr = _ptr; + return 0; + } + + template + HRESULT CopyTo(U** a_ptr) const noexcept + { + return _ptr->QueryInterface(__uuidof(U), reinterpret_cast(a_ptr)); + } + + protected: + template + friend struct ComPtr; + + void TryAddRef() const noexcept + { + if (_ptr) + _ptr->AddRef(); + } + + std::uint32_t TryRelease() noexcept + { + T* ptr = _ptr; + if (ptr) { + _ptr = nullptr; + return ptr->Release(); + } + + return 0; + } + + T* _ptr{ nullptr }; + }; +} diff --git a/include/REX/W32/D3D.h b/include/REX/W32/D3D.h new file mode 100644 index 00000000..fe66c814 --- /dev/null +++ b/include/REX/W32/D3D.h @@ -0,0 +1,772 @@ +#pragma once + +#include "REX/W32/DXGI.h" + +namespace REX::W32 +{ + struct ID3DBlob; + struct ID3DDestructionNotifier; + struct ID3DInclude; +} + +namespace REX::W32 +{ + enum D3D_CBUFFER_TYPE + { + D3D_CT_CBUFFER = 0, + D3D_CT_TBUFFER = (D3D_CT_CBUFFER + 1), + D3D_CT_INTERFACE_POINTERS = (D3D_CT_TBUFFER + 1), + D3D_CT_RESOURCE_BIND_INFO = (D3D_CT_INTERFACE_POINTERS + 1), + D3D10_CT_CBUFFER = D3D_CT_CBUFFER, + D3D10_CT_TBUFFER = D3D_CT_TBUFFER, + D3D11_CT_CBUFFER = D3D_CT_CBUFFER, + D3D11_CT_TBUFFER = D3D_CT_TBUFFER, + D3D11_CT_INTERFACE_POINTERS = D3D_CT_INTERFACE_POINTERS, + D3D11_CT_RESOURCE_BIND_INFO = D3D_CT_RESOURCE_BIND_INFO, + }; + + enum D3D_DRIVER_TYPE + { + D3D_DRIVER_TYPE_UNKNOWN = 0, + D3D_DRIVER_TYPE_HARDWARE = (D3D_DRIVER_TYPE_UNKNOWN + 1), + D3D_DRIVER_TYPE_REFERENCE = (D3D_DRIVER_TYPE_HARDWARE + 1), + D3D_DRIVER_TYPE_NULL = (D3D_DRIVER_TYPE_REFERENCE + 1), + D3D_DRIVER_TYPE_SOFTWARE = (D3D_DRIVER_TYPE_NULL + 1), + D3D_DRIVER_TYPE_WARP = (D3D_DRIVER_TYPE_SOFTWARE + 1), + }; + + enum D3D_FEATURE_LEVEL + { + D3D_FEATURE_LEVEL_1_0_CORE = 0x1000, + D3D_FEATURE_LEVEL_9_1 = 0x9100, + D3D_FEATURE_LEVEL_9_2 = 0x9200, + D3D_FEATURE_LEVEL_9_3 = 0x9300, + D3D_FEATURE_LEVEL_10_0 = 0xA000, + D3D_FEATURE_LEVEL_10_1 = 0xA100, + D3D_FEATURE_LEVEL_11_0 = 0xB000, + D3D_FEATURE_LEVEL_11_1 = 0xB100, + D3D_FEATURE_LEVEL_12_0 = 0xC000, + D3D_FEATURE_LEVEL_12_1 = 0xC100, + D3D_FEATURE_LEVEL_12_2 = 0xC200, + }; + + enum D3D_INCLUDE_TYPE + { + D3D_INCLUDE_LOCAL = 0, + D3D_INCLUDE_SYSTEM = (D3D_INCLUDE_LOCAL + 1), + D3D10_INCLUDE_LOCAL = D3D_INCLUDE_LOCAL, + D3D10_INCLUDE_SYSTEM = D3D_INCLUDE_SYSTEM, + D3D_INCLUDE_FORCE_DWORD = 0x7FFFFFFF, + }; + + enum D3D_INTERPOLATION_MODE + { + D3D_INTERPOLATION_UNDEFINED = 0, + D3D_INTERPOLATION_CONSTANT = 1, + D3D_INTERPOLATION_LINEAR = 2, + D3D_INTERPOLATION_LINEAR_CENTROID = 3, + D3D_INTERPOLATION_LINEAR_NOPERSPECTIVE = 4, + D3D_INTERPOLATION_LINEAR_NOPERSPECTIVE_CENTROID = 5, + D3D_INTERPOLATION_LINEAR_SAMPLE = 6, + D3D_INTERPOLATION_LINEAR_NOPERSPECTIVE_SAMPLE = 7, + }; + + enum D3D_MIN_PRECISION + { + D3D_MIN_PRECISION_DEFAULT = 0, + D3D_MIN_PRECISION_FLOAT_16 = 1, + D3D_MIN_PRECISION_FLOAT_2_8 = 2, + D3D_MIN_PRECISION_RESERVED = 3, + D3D_MIN_PRECISION_SINT_16 = 4, + D3D_MIN_PRECISION_UINT_16 = 5, + D3D_MIN_PRECISION_ANY_16 = 0xF0, + D3D_MIN_PRECISION_ANY_10 = 0xF1, + }; + + enum D3D_NAME + { + D3D_NAME_UNDEFINED = 0, + D3D_NAME_POSITION = 1, + D3D_NAME_CLIP_DISTANCE = 2, + D3D_NAME_CULL_DISTANCE = 3, + D3D_NAME_RENDER_TARGET_ARRAY_INDEX = 4, + D3D_NAME_VIEWPORT_ARRAY_INDEX = 5, + D3D_NAME_VERTEX_ID = 6, + D3D_NAME_PRIMITIVE_ID = 7, + D3D_NAME_INSTANCE_ID = 8, + D3D_NAME_IS_FRONT_FACE = 9, + D3D_NAME_SAMPLE_INDEX = 10, + D3D_NAME_FINAL_QUAD_EDGE_TESSFACTOR = 11, + D3D_NAME_FINAL_QUAD_INSIDE_TESSFACTOR = 12, + D3D_NAME_FINAL_TRI_EDGE_TESSFACTOR = 13, + D3D_NAME_FINAL_TRI_INSIDE_TESSFACTOR = 14, + D3D_NAME_FINAL_LINE_DETAIL_TESSFACTOR = 15, + D3D_NAME_FINAL_LINE_DENSITY_TESSFACTOR = 16, + D3D_NAME_BARYCENTRICS = 23, + D3D_NAME_SHADINGRATE = 24, + D3D_NAME_CULLPRIMITIVE = 25, + D3D_NAME_TARGET = 64, + D3D_NAME_DEPTH = 65, + D3D_NAME_COVERAGE = 66, + D3D_NAME_DEPTH_GREATER_EQUAL = 67, + D3D_NAME_DEPTH_LESS_EQUAL = 68, + D3D_NAME_STENCIL_REF = 69, + D3D_NAME_INNER_COVERAGE = 70, + D3D10_NAME_UNDEFINED = D3D_NAME_UNDEFINED, + D3D10_NAME_POSITION = D3D_NAME_POSITION, + D3D10_NAME_CLIP_DISTANCE = D3D_NAME_CLIP_DISTANCE, + D3D10_NAME_CULL_DISTANCE = D3D_NAME_CULL_DISTANCE, + D3D10_NAME_RENDER_TARGET_ARRAY_INDEX = D3D_NAME_RENDER_TARGET_ARRAY_INDEX, + D3D10_NAME_VIEWPORT_ARRAY_INDEX = D3D_NAME_VIEWPORT_ARRAY_INDEX, + D3D10_NAME_VERTEX_ID = D3D_NAME_VERTEX_ID, + D3D10_NAME_PRIMITIVE_ID = D3D_NAME_PRIMITIVE_ID, + D3D10_NAME_INSTANCE_ID = D3D_NAME_INSTANCE_ID, + D3D10_NAME_IS_FRONT_FACE = D3D_NAME_IS_FRONT_FACE, + D3D10_NAME_SAMPLE_INDEX = D3D_NAME_SAMPLE_INDEX, + D3D10_NAME_TARGET = D3D_NAME_TARGET, + D3D10_NAME_DEPTH = D3D_NAME_DEPTH, + D3D10_NAME_COVERAGE = D3D_NAME_COVERAGE, + D3D11_NAME_FINAL_QUAD_EDGE_TESSFACTOR = D3D_NAME_FINAL_QUAD_EDGE_TESSFACTOR, + D3D11_NAME_FINAL_QUAD_INSIDE_TESSFACTOR = D3D_NAME_FINAL_QUAD_INSIDE_TESSFACTOR, + D3D11_NAME_FINAL_TRI_EDGE_TESSFACTOR = D3D_NAME_FINAL_TRI_EDGE_TESSFACTOR, + D3D11_NAME_FINAL_TRI_INSIDE_TESSFACTOR = D3D_NAME_FINAL_TRI_INSIDE_TESSFACTOR, + D3D11_NAME_FINAL_LINE_DETAIL_TESSFACTOR = D3D_NAME_FINAL_LINE_DETAIL_TESSFACTOR, + D3D11_NAME_FINAL_LINE_DENSITY_TESSFACTOR = D3D_NAME_FINAL_LINE_DENSITY_TESSFACTOR, + D3D11_NAME_DEPTH_GREATER_EQUAL = D3D_NAME_DEPTH_GREATER_EQUAL, + D3D11_NAME_DEPTH_LESS_EQUAL = D3D_NAME_DEPTH_LESS_EQUAL, + D3D11_NAME_STENCIL_REF = D3D_NAME_STENCIL_REF, + D3D11_NAME_INNER_COVERAGE = D3D_NAME_INNER_COVERAGE, + D3D12_NAME_BARYCENTRICS = D3D_NAME_BARYCENTRICS, + D3D12_NAME_SHADINGRATE = D3D_NAME_SHADINGRATE, + D3D12_NAME_CULLPRIMITIVE = D3D_NAME_CULLPRIMITIVE, + }; + + enum D3D_PARAMETER_FLAGS + { + D3D_PF_NONE = 0, + D3D_PF_IN = 0x1, + D3D_PF_OUT = 0x2, + D3D_PF_FORCE_DWORD = 0x7FFFFFFF, + }; + + enum D3D_PRIMITIVE + { + D3D_PRIMITIVE_UNDEFINED = 0, + D3D_PRIMITIVE_POINT = 1, + D3D_PRIMITIVE_LINE = 2, + D3D_PRIMITIVE_TRIANGLE = 3, + D3D_PRIMITIVE_LINE_ADJ = 6, + D3D_PRIMITIVE_TRIANGLE_ADJ = 7, + D3D_PRIMITIVE_1_CONTROL_POINT_PATCH = 8, + D3D_PRIMITIVE_2_CONTROL_POINT_PATCH = 9, + D3D_PRIMITIVE_3_CONTROL_POINT_PATCH = 10, + D3D_PRIMITIVE_4_CONTROL_POINT_PATCH = 11, + D3D_PRIMITIVE_5_CONTROL_POINT_PATCH = 12, + D3D_PRIMITIVE_6_CONTROL_POINT_PATCH = 13, + D3D_PRIMITIVE_7_CONTROL_POINT_PATCH = 14, + D3D_PRIMITIVE_8_CONTROL_POINT_PATCH = 15, + D3D_PRIMITIVE_9_CONTROL_POINT_PATCH = 16, + D3D_PRIMITIVE_10_CONTROL_POINT_PATCH = 17, + D3D_PRIMITIVE_11_CONTROL_POINT_PATCH = 18, + D3D_PRIMITIVE_12_CONTROL_POINT_PATCH = 19, + D3D_PRIMITIVE_13_CONTROL_POINT_PATCH = 20, + D3D_PRIMITIVE_14_CONTROL_POINT_PATCH = 21, + D3D_PRIMITIVE_15_CONTROL_POINT_PATCH = 22, + D3D_PRIMITIVE_16_CONTROL_POINT_PATCH = 23, + D3D_PRIMITIVE_17_CONTROL_POINT_PATCH = 24, + D3D_PRIMITIVE_18_CONTROL_POINT_PATCH = 25, + D3D_PRIMITIVE_19_CONTROL_POINT_PATCH = 26, + D3D_PRIMITIVE_20_CONTROL_POINT_PATCH = 27, + D3D_PRIMITIVE_21_CONTROL_POINT_PATCH = 28, + D3D_PRIMITIVE_22_CONTROL_POINT_PATCH = 29, + D3D_PRIMITIVE_23_CONTROL_POINT_PATCH = 30, + D3D_PRIMITIVE_24_CONTROL_POINT_PATCH = 31, + D3D_PRIMITIVE_25_CONTROL_POINT_PATCH = 32, + D3D_PRIMITIVE_26_CONTROL_POINT_PATCH = 33, + D3D_PRIMITIVE_27_CONTROL_POINT_PATCH = 34, + D3D_PRIMITIVE_28_CONTROL_POINT_PATCH = 35, + D3D_PRIMITIVE_29_CONTROL_POINT_PATCH = 36, + D3D_PRIMITIVE_30_CONTROL_POINT_PATCH = 37, + D3D_PRIMITIVE_31_CONTROL_POINT_PATCH = 38, + D3D_PRIMITIVE_32_CONTROL_POINT_PATCH = 39, + D3D10_PRIMITIVE_UNDEFINED = D3D_PRIMITIVE_UNDEFINED, + D3D10_PRIMITIVE_POINT = D3D_PRIMITIVE_POINT, + D3D10_PRIMITIVE_LINE = D3D_PRIMITIVE_LINE, + D3D10_PRIMITIVE_TRIANGLE = D3D_PRIMITIVE_TRIANGLE, + D3D10_PRIMITIVE_LINE_ADJ = D3D_PRIMITIVE_LINE_ADJ, + D3D10_PRIMITIVE_TRIANGLE_ADJ = D3D_PRIMITIVE_TRIANGLE_ADJ, + D3D11_PRIMITIVE_UNDEFINED = D3D_PRIMITIVE_UNDEFINED, + D3D11_PRIMITIVE_POINT = D3D_PRIMITIVE_POINT, + D3D11_PRIMITIVE_LINE = D3D_PRIMITIVE_LINE, + D3D11_PRIMITIVE_TRIANGLE = D3D_PRIMITIVE_TRIANGLE, + D3D11_PRIMITIVE_LINE_ADJ = D3D_PRIMITIVE_LINE_ADJ, + D3D11_PRIMITIVE_TRIANGLE_ADJ = D3D_PRIMITIVE_TRIANGLE_ADJ, + D3D11_PRIMITIVE_1_CONTROL_POINT_PATCH = D3D_PRIMITIVE_1_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_2_CONTROL_POINT_PATCH = D3D_PRIMITIVE_2_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_3_CONTROL_POINT_PATCH = D3D_PRIMITIVE_3_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_4_CONTROL_POINT_PATCH = D3D_PRIMITIVE_4_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_5_CONTROL_POINT_PATCH = D3D_PRIMITIVE_5_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_6_CONTROL_POINT_PATCH = D3D_PRIMITIVE_6_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_7_CONTROL_POINT_PATCH = D3D_PRIMITIVE_7_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_8_CONTROL_POINT_PATCH = D3D_PRIMITIVE_8_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_9_CONTROL_POINT_PATCH = D3D_PRIMITIVE_9_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_10_CONTROL_POINT_PATCH = D3D_PRIMITIVE_10_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_11_CONTROL_POINT_PATCH = D3D_PRIMITIVE_11_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_12_CONTROL_POINT_PATCH = D3D_PRIMITIVE_12_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_13_CONTROL_POINT_PATCH = D3D_PRIMITIVE_13_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_14_CONTROL_POINT_PATCH = D3D_PRIMITIVE_14_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_15_CONTROL_POINT_PATCH = D3D_PRIMITIVE_15_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_16_CONTROL_POINT_PATCH = D3D_PRIMITIVE_16_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_17_CONTROL_POINT_PATCH = D3D_PRIMITIVE_17_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_18_CONTROL_POINT_PATCH = D3D_PRIMITIVE_18_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_19_CONTROL_POINT_PATCH = D3D_PRIMITIVE_19_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_20_CONTROL_POINT_PATCH = D3D_PRIMITIVE_20_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_21_CONTROL_POINT_PATCH = D3D_PRIMITIVE_21_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_22_CONTROL_POINT_PATCH = D3D_PRIMITIVE_22_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_23_CONTROL_POINT_PATCH = D3D_PRIMITIVE_23_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_24_CONTROL_POINT_PATCH = D3D_PRIMITIVE_24_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_25_CONTROL_POINT_PATCH = D3D_PRIMITIVE_25_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_26_CONTROL_POINT_PATCH = D3D_PRIMITIVE_26_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_27_CONTROL_POINT_PATCH = D3D_PRIMITIVE_27_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_28_CONTROL_POINT_PATCH = D3D_PRIMITIVE_28_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_29_CONTROL_POINT_PATCH = D3D_PRIMITIVE_29_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_30_CONTROL_POINT_PATCH = D3D_PRIMITIVE_30_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_31_CONTROL_POINT_PATCH = D3D_PRIMITIVE_31_CONTROL_POINT_PATCH, + D3D11_PRIMITIVE_32_CONTROL_POINT_PATCH = D3D_PRIMITIVE_32_CONTROL_POINT_PATCH, + }; + + enum D3D_PRIMITIVE_TOPOLOGY + { + D3D_PRIMITIVE_TOPOLOGY_UNDEFINED = 0, + D3D_PRIMITIVE_TOPOLOGY_POINTLIST = 1, + D3D_PRIMITIVE_TOPOLOGY_LINELIST = 2, + D3D_PRIMITIVE_TOPOLOGY_LINESTRIP = 3, + D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST = 4, + D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP = 5, + D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = 10, + D3D_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ = 11, + D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ = 12, + D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ = 13, + D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST = 33, + D3D_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST = 34, + D3D_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST = 35, + D3D_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST = 36, + D3D_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST = 37, + D3D_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST = 38, + D3D_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST = 39, + D3D_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST = 40, + D3D_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST = 41, + D3D_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST = 42, + D3D_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST = 43, + D3D_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST = 44, + D3D_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST = 45, + D3D_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST = 46, + D3D_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST = 47, + D3D_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST = 48, + D3D_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST = 49, + D3D_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST = 50, + D3D_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST = 51, + D3D_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST = 52, + D3D_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST = 53, + D3D_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST = 54, + D3D_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST = 55, + D3D_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST = 56, + D3D_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST = 57, + D3D_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST = 58, + D3D_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST = 59, + D3D_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST = 60, + D3D_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST = 61, + D3D_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST = 62, + D3D_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST = 63, + D3D_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST = 64, + D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED, + D3D10_PRIMITIVE_TOPOLOGY_POINTLIST = D3D_PRIMITIVE_TOPOLOGY_POINTLIST, + D3D10_PRIMITIVE_TOPOLOGY_LINELIST = D3D_PRIMITIVE_TOPOLOGY_LINELIST, + D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP, + D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST, + D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, + D3D10_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ, + D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ, + D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ, + D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ, + D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED, + D3D11_PRIMITIVE_TOPOLOGY_POINTLIST = D3D_PRIMITIVE_TOPOLOGY_POINTLIST, + D3D11_PRIMITIVE_TOPOLOGY_LINELIST = D3D_PRIMITIVE_TOPOLOGY_LINELIST, + D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP, + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST, + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, + D3D11_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ, + D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ, + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ, + D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ, + D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST, + D3D11_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST = D3D_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST, + }; + + enum D3D_REGISTER_COMPONENT_TYPE + { + D3D_REGISTER_COMPONENT_UNKNOWN = 0, + D3D_REGISTER_COMPONENT_UINT32 = 1, + D3D_REGISTER_COMPONENT_SINT32 = 2, + D3D_REGISTER_COMPONENT_FLOAT32 = 3, + D3D10_REGISTER_COMPONENT_UNKNOWN = D3D_REGISTER_COMPONENT_UNKNOWN, + D3D10_REGISTER_COMPONENT_UINT32 = D3D_REGISTER_COMPONENT_UINT32, + D3D10_REGISTER_COMPONENT_SINT32 = D3D_REGISTER_COMPONENT_SINT32, + D3D10_REGISTER_COMPONENT_FLOAT32 = D3D_REGISTER_COMPONENT_FLOAT32, + }; + + enum D3D_RESOURCE_RETURN_TYPE + { + D3D_RETURN_TYPE_UNORM = 1, + D3D_RETURN_TYPE_SNORM = 2, + D3D_RETURN_TYPE_SINT = 3, + D3D_RETURN_TYPE_UINT = 4, + D3D_RETURN_TYPE_FLOAT = 5, + D3D_RETURN_TYPE_MIXED = 6, + D3D_RETURN_TYPE_DOUBLE = 7, + D3D_RETURN_TYPE_CONTINUED = 8, + D3D10_RETURN_TYPE_UNORM = D3D_RETURN_TYPE_UNORM, + D3D10_RETURN_TYPE_SNORM = D3D_RETURN_TYPE_SNORM, + D3D10_RETURN_TYPE_SINT = D3D_RETURN_TYPE_SINT, + D3D10_RETURN_TYPE_UINT = D3D_RETURN_TYPE_UINT, + D3D10_RETURN_TYPE_FLOAT = D3D_RETURN_TYPE_FLOAT, + D3D10_RETURN_TYPE_MIXED = D3D_RETURN_TYPE_MIXED, + D3D11_RETURN_TYPE_UNORM = D3D_RETURN_TYPE_UNORM, + D3D11_RETURN_TYPE_SNORM = D3D_RETURN_TYPE_SNORM, + D3D11_RETURN_TYPE_SINT = D3D_RETURN_TYPE_SINT, + D3D11_RETURN_TYPE_UINT = D3D_RETURN_TYPE_UINT, + D3D11_RETURN_TYPE_FLOAT = D3D_RETURN_TYPE_FLOAT, + D3D11_RETURN_TYPE_MIXED = D3D_RETURN_TYPE_MIXED, + D3D11_RETURN_TYPE_DOUBLE = D3D_RETURN_TYPE_DOUBLE, + D3D11_RETURN_TYPE_CONTINUED = D3D_RETURN_TYPE_CONTINUED, + }; + + enum D3D_SHADER_CBUFFER_FLAGS + { + D3D_CBF_USERPACKED = 1, + D3D10_CBF_USERPACKED = D3D_CBF_USERPACKED, + D3D_CBF_FORCE_DWORD = 0x7FFFFFFF, + }; + + enum D3D_SHADER_INPUT_FLAGS + { + D3D_SIF_USERPACKED = 0x1, + D3D_SIF_COMPARISON_SAMPLER = 0x2, + D3D_SIF_TEXTURE_COMPONENT_0 = 0x4, + D3D_SIF_TEXTURE_COMPONENT_1 = 0x8, + D3D_SIF_TEXTURE_COMPONENTS = 0xc, + D3D_SIF_UNUSED = 0x10, + D3D10_SIF_USERPACKED = D3D_SIF_USERPACKED, + D3D10_SIF_COMPARISON_SAMPLER = D3D_SIF_COMPARISON_SAMPLER, + D3D10_SIF_TEXTURE_COMPONENT_0 = D3D_SIF_TEXTURE_COMPONENT_0, + D3D10_SIF_TEXTURE_COMPONENT_1 = D3D_SIF_TEXTURE_COMPONENT_1, + D3D10_SIF_TEXTURE_COMPONENTS = D3D_SIF_TEXTURE_COMPONENTS, + D3D_SIF_FORCE_DWORD = 0x7FFFFFFF, + }; + + enum D3D_SHADER_INPUT_TYPE + { + D3D_SIT_CBUFFER = 0, + D3D_SIT_TBUFFER = (D3D_SIT_CBUFFER + 1), + D3D_SIT_TEXTURE = (D3D_SIT_TBUFFER + 1), + D3D_SIT_SAMPLER = (D3D_SIT_TEXTURE + 1), + D3D_SIT_UAV_RWTYPED = (D3D_SIT_SAMPLER + 1), + D3D_SIT_STRUCTURED = (D3D_SIT_UAV_RWTYPED + 1), + D3D_SIT_UAV_RWSTRUCTURED = (D3D_SIT_STRUCTURED + 1), + D3D_SIT_BYTEADDRESS = (D3D_SIT_UAV_RWSTRUCTURED + 1), + D3D_SIT_UAV_RWBYTEADDRESS = (D3D_SIT_BYTEADDRESS + 1), + D3D_SIT_UAV_APPEND_STRUCTURED = (D3D_SIT_UAV_RWBYTEADDRESS + 1), + D3D_SIT_UAV_CONSUME_STRUCTURED = (D3D_SIT_UAV_APPEND_STRUCTURED + 1), + D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER = (D3D_SIT_UAV_CONSUME_STRUCTURED + 1), + D3D_SIT_RTACCELERATIONSTRUCTURE = (D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER + 1), + D3D_SIT_UAV_FEEDBACKTEXTURE = (D3D_SIT_RTACCELERATIONSTRUCTURE + 1), + D3D10_SIT_CBUFFER = D3D_SIT_CBUFFER, + D3D10_SIT_TBUFFER = D3D_SIT_TBUFFER, + D3D10_SIT_TEXTURE = D3D_SIT_TEXTURE, + D3D10_SIT_SAMPLER = D3D_SIT_SAMPLER, + D3D11_SIT_UAV_RWTYPED = D3D_SIT_UAV_RWTYPED, + D3D11_SIT_STRUCTURED = D3D_SIT_STRUCTURED, + D3D11_SIT_UAV_RWSTRUCTURED = D3D_SIT_UAV_RWSTRUCTURED, + D3D11_SIT_BYTEADDRESS = D3D_SIT_BYTEADDRESS, + D3D11_SIT_UAV_RWBYTEADDRESS = D3D_SIT_UAV_RWBYTEADDRESS, + D3D11_SIT_UAV_APPEND_STRUCTURED = D3D_SIT_UAV_APPEND_STRUCTURED, + D3D11_SIT_UAV_CONSUME_STRUCTURED = D3D_SIT_UAV_CONSUME_STRUCTURED, + D3D11_SIT_UAV_RWSTRUCTURED_WITH_COUNTER = D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER, + }; + + enum D3D_SHADER_VARIABLE_CLASS + { + D3D_SVC_SCALAR = 0, + D3D_SVC_VECTOR = (D3D_SVC_SCALAR + 1), + D3D_SVC_MATRIX_ROWS = (D3D_SVC_VECTOR + 1), + D3D_SVC_MATRIX_COLUMNS = (D3D_SVC_MATRIX_ROWS + 1), + D3D_SVC_OBJECT = (D3D_SVC_MATRIX_COLUMNS + 1), + D3D_SVC_STRUCT = (D3D_SVC_OBJECT + 1), + D3D_SVC_INTERFACE_CLASS = (D3D_SVC_STRUCT + 1), + D3D_SVC_INTERFACE_POINTER = (D3D_SVC_INTERFACE_CLASS + 1), + D3D10_SVC_SCALAR = D3D_SVC_SCALAR, + D3D10_SVC_VECTOR = D3D_SVC_VECTOR, + D3D10_SVC_MATRIX_ROWS = D3D_SVC_MATRIX_ROWS, + D3D10_SVC_MATRIX_COLUMNS = D3D_SVC_MATRIX_COLUMNS, + D3D10_SVC_OBJECT = D3D_SVC_OBJECT, + D3D10_SVC_STRUCT = D3D_SVC_STRUCT, + D3D11_SVC_INTERFACE_CLASS = D3D_SVC_INTERFACE_CLASS, + D3D11_SVC_INTERFACE_POINTER = D3D_SVC_INTERFACE_POINTER, + D3D_SVC_FORCE_DWORD = 0x7FFFFFFF, + }; + + enum D3D_SHADER_VARIABLE_FLAGS + { + D3D_SVF_USERPACKED = 1, + D3D_SVF_USED = 2, + D3D_SVF_INTERFACE_POINTER = 4, + D3D_SVF_INTERFACE_PARAMETER = 8, + D3D10_SVF_USERPACKED = D3D_SVF_USERPACKED, + D3D10_SVF_USED = D3D_SVF_USED, + D3D11_SVF_INTERFACE_POINTER = D3D_SVF_INTERFACE_POINTER, + D3D11_SVF_INTERFACE_PARAMETER = D3D_SVF_INTERFACE_PARAMETER, + D3D_SVF_FORCE_DWORD = 0x7FFFFFFF, + }; + + enum D3D_SHADER_VARIABLE_TYPE + { + D3D_SVT_VOID = 0, + D3D_SVT_BOOL = 1, + D3D_SVT_INT = 2, + D3D_SVT_FLOAT = 3, + D3D_SVT_STRING = 4, + D3D_SVT_TEXTURE = 5, + D3D_SVT_TEXTURE1D = 6, + D3D_SVT_TEXTURE2D = 7, + D3D_SVT_TEXTURE3D = 8, + D3D_SVT_TEXTURECUBE = 9, + D3D_SVT_SAMPLER = 10, + D3D_SVT_SAMPLER1D = 11, + D3D_SVT_SAMPLER2D = 12, + D3D_SVT_SAMPLER3D = 13, + D3D_SVT_SAMPLERCUBE = 14, + D3D_SVT_PIXELSHADER = 15, + D3D_SVT_VERTEXSHADER = 16, + D3D_SVT_PIXELFRAGMENT = 17, + D3D_SVT_VERTEXFRAGMENT = 18, + D3D_SVT_UINT = 19, + D3D_SVT_UINT8 = 20, + D3D_SVT_GEOMETRYSHADER = 21, + D3D_SVT_RASTERIZER = 22, + D3D_SVT_DEPTHSTENCIL = 23, + D3D_SVT_BLEND = 24, + D3D_SVT_BUFFER = 25, + D3D_SVT_CBUFFER = 26, + D3D_SVT_TBUFFER = 27, + D3D_SVT_TEXTURE1DARRAY = 28, + D3D_SVT_TEXTURE2DARRAY = 29, + D3D_SVT_RENDERTARGETVIEW = 30, + D3D_SVT_DEPTHSTENCILVIEW = 31, + D3D_SVT_TEXTURE2DMS = 32, + D3D_SVT_TEXTURE2DMSARRAY = 33, + D3D_SVT_TEXTURECUBEARRAY = 34, + D3D_SVT_HULLSHADER = 35, + D3D_SVT_DOMAINSHADER = 36, + D3D_SVT_INTERFACE_POINTER = 37, + D3D_SVT_COMPUTESHADER = 38, + D3D_SVT_DOUBLE = 39, + D3D_SVT_RWTEXTURE1D = 40, + D3D_SVT_RWTEXTURE1DARRAY = 41, + D3D_SVT_RWTEXTURE2D = 42, + D3D_SVT_RWTEXTURE2DARRAY = 43, + D3D_SVT_RWTEXTURE3D = 44, + D3D_SVT_RWBUFFER = 45, + D3D_SVT_BYTEADDRESS_BUFFER = 46, + D3D_SVT_RWBYTEADDRESS_BUFFER = 47, + D3D_SVT_STRUCTURED_BUFFER = 48, + D3D_SVT_RWSTRUCTURED_BUFFER = 49, + D3D_SVT_APPEND_STRUCTURED_BUFFER = 50, + D3D_SVT_CONSUME_STRUCTURED_BUFFER = 51, + D3D_SVT_MIN8FLOAT = 52, + D3D_SVT_MIN10FLOAT = 53, + D3D_SVT_MIN16FLOAT = 54, + D3D_SVT_MIN12INT = 55, + D3D_SVT_MIN16INT = 56, + D3D_SVT_MIN16UINT = 57, + D3D_SVT_INT16 = 58, + D3D_SVT_UINT16 = 59, + D3D_SVT_FLOAT16 = 60, + D3D_SVT_INT64 = 61, + D3D_SVT_UINT64 = 62, + D3D10_SVT_VOID = D3D_SVT_VOID, + D3D10_SVT_BOOL = D3D_SVT_BOOL, + D3D10_SVT_INT = D3D_SVT_INT, + D3D10_SVT_FLOAT = D3D_SVT_FLOAT, + D3D10_SVT_STRING = D3D_SVT_STRING, + D3D10_SVT_TEXTURE = D3D_SVT_TEXTURE, + D3D10_SVT_TEXTURE1D = D3D_SVT_TEXTURE1D, + D3D10_SVT_TEXTURE2D = D3D_SVT_TEXTURE2D, + D3D10_SVT_TEXTURE3D = D3D_SVT_TEXTURE3D, + D3D10_SVT_TEXTURECUBE = D3D_SVT_TEXTURECUBE, + D3D10_SVT_SAMPLER = D3D_SVT_SAMPLER, + D3D10_SVT_SAMPLER1D = D3D_SVT_SAMPLER1D, + D3D10_SVT_SAMPLER2D = D3D_SVT_SAMPLER2D, + D3D10_SVT_SAMPLER3D = D3D_SVT_SAMPLER3D, + D3D10_SVT_SAMPLERCUBE = D3D_SVT_SAMPLERCUBE, + D3D10_SVT_PIXELSHADER = D3D_SVT_PIXELSHADER, + D3D10_SVT_VERTEXSHADER = D3D_SVT_VERTEXSHADER, + D3D10_SVT_PIXELFRAGMENT = D3D_SVT_PIXELFRAGMENT, + D3D10_SVT_VERTEXFRAGMENT = D3D_SVT_VERTEXFRAGMENT, + D3D10_SVT_UINT = D3D_SVT_UINT, + D3D10_SVT_UINT8 = D3D_SVT_UINT8, + D3D10_SVT_GEOMETRYSHADER = D3D_SVT_GEOMETRYSHADER, + D3D10_SVT_RASTERIZER = D3D_SVT_RASTERIZER, + D3D10_SVT_DEPTHSTENCIL = D3D_SVT_DEPTHSTENCIL, + D3D10_SVT_BLEND = D3D_SVT_BLEND, + D3D10_SVT_BUFFER = D3D_SVT_BUFFER, + D3D10_SVT_CBUFFER = D3D_SVT_CBUFFER, + D3D10_SVT_TBUFFER = D3D_SVT_TBUFFER, + D3D10_SVT_TEXTURE1DARRAY = D3D_SVT_TEXTURE1DARRAY, + D3D10_SVT_TEXTURE2DARRAY = D3D_SVT_TEXTURE2DARRAY, + D3D10_SVT_RENDERTARGETVIEW = D3D_SVT_RENDERTARGETVIEW, + D3D10_SVT_DEPTHSTENCILVIEW = D3D_SVT_DEPTHSTENCILVIEW, + D3D10_SVT_TEXTURE2DMS = D3D_SVT_TEXTURE2DMS, + D3D10_SVT_TEXTURE2DMSARRAY = D3D_SVT_TEXTURE2DMSARRAY, + D3D10_SVT_TEXTURECUBEARRAY = D3D_SVT_TEXTURECUBEARRAY, + D3D11_SVT_HULLSHADER = D3D_SVT_HULLSHADER, + D3D11_SVT_DOMAINSHADER = D3D_SVT_DOMAINSHADER, + D3D11_SVT_INTERFACE_POINTER = D3D_SVT_INTERFACE_POINTER, + D3D11_SVT_COMPUTESHADER = D3D_SVT_COMPUTESHADER, + D3D11_SVT_DOUBLE = D3D_SVT_DOUBLE, + D3D11_SVT_RWTEXTURE1D = D3D_SVT_RWTEXTURE1D, + D3D11_SVT_RWTEXTURE1DARRAY = D3D_SVT_RWTEXTURE1DARRAY, + D3D11_SVT_RWTEXTURE2D = D3D_SVT_RWTEXTURE2D, + D3D11_SVT_RWTEXTURE2DARRAY = D3D_SVT_RWTEXTURE2DARRAY, + D3D11_SVT_RWTEXTURE3D = D3D_SVT_RWTEXTURE3D, + D3D11_SVT_RWBUFFER = D3D_SVT_RWBUFFER, + D3D11_SVT_BYTEADDRESS_BUFFER = D3D_SVT_BYTEADDRESS_BUFFER, + D3D11_SVT_RWBYTEADDRESS_BUFFER = D3D_SVT_RWBYTEADDRESS_BUFFER, + D3D11_SVT_STRUCTURED_BUFFER = D3D_SVT_STRUCTURED_BUFFER, + D3D11_SVT_RWSTRUCTURED_BUFFER = D3D_SVT_RWSTRUCTURED_BUFFER, + D3D11_SVT_APPEND_STRUCTURED_BUFFER = D3D_SVT_APPEND_STRUCTURED_BUFFER, + D3D11_SVT_CONSUME_STRUCTURED_BUFFER = D3D_SVT_CONSUME_STRUCTURED_BUFFER, + D3D_SVT_FORCE_DWORD = 0x7FFFFFFF, + }; + + enum D3D_SRV_DIMENSION + { + D3D_SRV_DIMENSION_UNKNOWN = 0, + D3D_SRV_DIMENSION_BUFFER = 1, + D3D_SRV_DIMENSION_TEXTURE1D = 2, + D3D_SRV_DIMENSION_TEXTURE1DARRAY = 3, + D3D_SRV_DIMENSION_TEXTURE2D = 4, + D3D_SRV_DIMENSION_TEXTURE2DARRAY = 5, + D3D_SRV_DIMENSION_TEXTURE2DMS = 6, + D3D_SRV_DIMENSION_TEXTURE2DMSARRAY = 7, + D3D_SRV_DIMENSION_TEXTURE3D = 8, + D3D_SRV_DIMENSION_TEXTURECUBE = 9, + D3D_SRV_DIMENSION_TEXTURECUBEARRAY = 10, + D3D_SRV_DIMENSION_BUFFEREX = 11, + D3D10_SRV_DIMENSION_UNKNOWN = D3D_SRV_DIMENSION_UNKNOWN, + D3D10_SRV_DIMENSION_BUFFER = D3D_SRV_DIMENSION_BUFFER, + D3D10_SRV_DIMENSION_TEXTURE1D = D3D_SRV_DIMENSION_TEXTURE1D, + D3D10_SRV_DIMENSION_TEXTURE1DARRAY = D3D_SRV_DIMENSION_TEXTURE1DARRAY, + D3D10_SRV_DIMENSION_TEXTURE2D = D3D_SRV_DIMENSION_TEXTURE2D, + D3D10_SRV_DIMENSION_TEXTURE2DARRAY = D3D_SRV_DIMENSION_TEXTURE2DARRAY, + D3D10_SRV_DIMENSION_TEXTURE2DMS = D3D_SRV_DIMENSION_TEXTURE2DMS, + D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY = D3D_SRV_DIMENSION_TEXTURE2DMSARRAY, + D3D10_SRV_DIMENSION_TEXTURE3D = D3D_SRV_DIMENSION_TEXTURE3D, + D3D10_SRV_DIMENSION_TEXTURECUBE = D3D_SRV_DIMENSION_TEXTURECUBE, + D3D10_1_SRV_DIMENSION_UNKNOWN = D3D_SRV_DIMENSION_UNKNOWN, + D3D10_1_SRV_DIMENSION_BUFFER = D3D_SRV_DIMENSION_BUFFER, + D3D10_1_SRV_DIMENSION_TEXTURE1D = D3D_SRV_DIMENSION_TEXTURE1D, + D3D10_1_SRV_DIMENSION_TEXTURE1DARRAY = D3D_SRV_DIMENSION_TEXTURE1DARRAY, + D3D10_1_SRV_DIMENSION_TEXTURE2D = D3D_SRV_DIMENSION_TEXTURE2D, + D3D10_1_SRV_DIMENSION_TEXTURE2DARRAY = D3D_SRV_DIMENSION_TEXTURE2DARRAY, + D3D10_1_SRV_DIMENSION_TEXTURE2DMS = D3D_SRV_DIMENSION_TEXTURE2DMS, + D3D10_1_SRV_DIMENSION_TEXTURE2DMSARRAY = D3D_SRV_DIMENSION_TEXTURE2DMSARRAY, + D3D10_1_SRV_DIMENSION_TEXTURE3D = D3D_SRV_DIMENSION_TEXTURE3D, + D3D10_1_SRV_DIMENSION_TEXTURECUBE = D3D_SRV_DIMENSION_TEXTURECUBE, + D3D10_1_SRV_DIMENSION_TEXTURECUBEARRAY = D3D_SRV_DIMENSION_TEXTURECUBEARRAY, + D3D11_SRV_DIMENSION_UNKNOWN = D3D_SRV_DIMENSION_UNKNOWN, + D3D11_SRV_DIMENSION_BUFFER = D3D_SRV_DIMENSION_BUFFER, + D3D11_SRV_DIMENSION_TEXTURE1D = D3D_SRV_DIMENSION_TEXTURE1D, + D3D11_SRV_DIMENSION_TEXTURE1DARRAY = D3D_SRV_DIMENSION_TEXTURE1DARRAY, + D3D11_SRV_DIMENSION_TEXTURE2D = D3D_SRV_DIMENSION_TEXTURE2D, + D3D11_SRV_DIMENSION_TEXTURE2DARRAY = D3D_SRV_DIMENSION_TEXTURE2DARRAY, + D3D11_SRV_DIMENSION_TEXTURE2DMS = D3D_SRV_DIMENSION_TEXTURE2DMS, + D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY = D3D_SRV_DIMENSION_TEXTURE2DMSARRAY, + D3D11_SRV_DIMENSION_TEXTURE3D = D3D_SRV_DIMENSION_TEXTURE3D, + D3D11_SRV_DIMENSION_TEXTURECUBE = D3D_SRV_DIMENSION_TEXTURECUBE, + D3D11_SRV_DIMENSION_TEXTURECUBEARRAY = D3D_SRV_DIMENSION_TEXTURECUBEARRAY, + D3D11_SRV_DIMENSION_BUFFEREX = D3D_SRV_DIMENSION_BUFFEREX, + }; + + enum D3D_TESSELLATOR_DOMAIN + { + D3D_TESSELLATOR_DOMAIN_UNDEFINED = 0, + D3D_TESSELLATOR_DOMAIN_ISOLINE = 1, + D3D_TESSELLATOR_DOMAIN_TRI = 2, + D3D_TESSELLATOR_DOMAIN_QUAD = 3, + D3D11_TESSELLATOR_DOMAIN_UNDEFINED = D3D_TESSELLATOR_DOMAIN_UNDEFINED, + D3D11_TESSELLATOR_DOMAIN_ISOLINE = D3D_TESSELLATOR_DOMAIN_ISOLINE, + D3D11_TESSELLATOR_DOMAIN_TRI = D3D_TESSELLATOR_DOMAIN_TRI, + D3D11_TESSELLATOR_DOMAIN_QUAD = D3D_TESSELLATOR_DOMAIN_QUAD, + }; + + enum D3D_TESSELLATOR_OUTPUT_PRIMITIVE + { + D3D_TESSELLATOR_OUTPUT_UNDEFINED = 0, + D3D_TESSELLATOR_OUTPUT_POINT = 1, + D3D_TESSELLATOR_OUTPUT_LINE = 2, + D3D_TESSELLATOR_OUTPUT_TRIANGLE_CW = 3, + D3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW = 4, + D3D11_TESSELLATOR_OUTPUT_UNDEFINED = D3D_TESSELLATOR_OUTPUT_UNDEFINED, + D3D11_TESSELLATOR_OUTPUT_POINT = D3D_TESSELLATOR_OUTPUT_POINT, + D3D11_TESSELLATOR_OUTPUT_LINE = D3D_TESSELLATOR_OUTPUT_LINE, + D3D11_TESSELLATOR_OUTPUT_TRIANGLE_CW = D3D_TESSELLATOR_OUTPUT_TRIANGLE_CW, + D3D11_TESSELLATOR_OUTPUT_TRIANGLE_CCW = D3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW, + }; + + enum D3D_TESSELLATOR_PARTITIONING + { + D3D_TESSELLATOR_PARTITIONING_UNDEFINED = 0, + D3D_TESSELLATOR_PARTITIONING_INTEGER = 1, + D3D_TESSELLATOR_PARTITIONING_POW2 = 2, + D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = 3, + D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = 4, + D3D11_TESSELLATOR_PARTITIONING_UNDEFINED = D3D_TESSELLATOR_PARTITIONING_UNDEFINED, + D3D11_TESSELLATOR_PARTITIONING_INTEGER = D3D_TESSELLATOR_PARTITIONING_INTEGER, + D3D11_TESSELLATOR_PARTITIONING_POW2 = D3D_TESSELLATOR_PARTITIONING_POW2, + D3D11_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD = D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD, + D3D11_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN = D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN, + }; +} + +namespace REX::W32 +{ + using D3DCOLOR = std::uint32_t; + + struct D3DRECT + { + std::int32_t x1; + std::int32_t y1; + std::int32_t x2; + std::int32_t y2; + }; + + struct D3DVECTOR + { + float x; + float y; + float z; + }; + + struct D3D_SHADER_MACRO + { + const char* name; + const char* definition; + }; + + struct XMCOLOR + { + public: + union + { + struct + { + std::uint8_t b; + std::uint8_t g; + std::uint8_t r; + std::uint8_t a; + }; + std::uint32_t c; + }; + }; + static_assert(sizeof(XMCOLOR) == 0x4); + + struct XMFLOAT3 + { + public: + float x; + float y; + float z; + }; + static_assert(sizeof(XMFLOAT3) == 0xC); + + struct XMFLOAT4 + { + public: + float x; + float y; + float z; + float w; + }; + static_assert(sizeof(XMFLOAT4) == 0x10); + + struct XMFLOAT4X4 + { + float m[4][4]; + }; + static_assert(sizeof(XMFLOAT4X4) == 0x40); +} + +namespace REX::W32 +{ + using PFN_DESTRUCTION_CALLBACK = void(__stdcall*)(void* a_data); +} + +namespace REX::W32 +{ + struct __declspec(novtable, uuid("8BA5FB08-5195-40e2-AC58-0D989C3A0102")) + ID3DBlob : public IUnknown + { + virtual void* GetBufferPointer(void) = 0; + virtual std::size_t GetBufferSize(void) = 0; + }; + + struct __declspec(novtable, uuid("A06EB39A-50DA-425B-8C31-4EECD6C270F3")) + ID3DDestructionNotifier : public IUnknown + { + virtual HRESULT RegisterDestructionCallback(PFN_DESTRUCTION_CALLBACK a_callbackFn, void* a_data, std::uint32_t* a_callbackID) = 0; + virtual HRESULT UnregisterDestructionCallback(std::uint32_t a_callbackID) = 0; + }; + + struct __declspec(novtable) // uuid(?) + ID3DInclude : public IUnknown + { + virtual HRESULT Open(D3D_INCLUDE_TYPE a_includeType, const char* a_fileName, const void* a_parentData, const void** a_data, std::uint32_t* a_bytes) = 0; + virtual HRESULT Close(const void* a_data) = 0; + }; +} + +namespace REX::W32 +{ + inline constexpr IID IID_ID3DBlob{ 0xA06EB39A, 0x50DA, 0x425B, { 0x8C, 0x31, 0x4E, 0xEC, 0xD6, 0xC2, 0x70, 0xF3 } }; + inline constexpr IID IID_ID3DDestructionNotifier{ 0xA06EB39A, 0x50DA, 0x425B, { 0x8C, 0x31, 0x4E, 0xEC, 0xD6, 0xC2, 0x70, 0xF3 } }; +} diff --git a/include/REX/W32/DBGHELP.h b/include/REX/W32/DBGHELP.h new file mode 100644 index 00000000..350b3ebb --- /dev/null +++ b/include/REX/W32/DBGHELP.h @@ -0,0 +1,22 @@ +#pragma once + +namespace REX::W32 +{ + // symbol name undecoration flags + inline constexpr auto UNDNAME_NO_MS_KEYWORDS{ 0x00000002u }; + inline constexpr auto UNDNAME_NO_FUNCTION_RETURNS{ 0x00000004u }; + inline constexpr auto UNDNAME_NO_ALLOCATION_MODEL{ 0x00000008u }; + inline constexpr auto UNDNAME_NO_ALLOCATION_LANGUAGE{ 0x00000010u }; + inline constexpr auto UNDNAME_NO_THISTYPE{ 0x00000060u }; + inline constexpr auto UNDNAME_NO_ACCESS_SPECIFIERS{ 0x00000080u }; + inline constexpr auto UNDNAME_NO_THROW_SIGNATURES{ 0x00000100u }; + inline constexpr auto UNDNAME_NO_RETURN_UDT_MODEL{ 0x00000400u }; + inline constexpr auto UNDNAME_NAME_ONLY{ 0x00001000u }; + inline constexpr auto UNDNAME_NO_ARGUMENTS{ 0x00002000u }; +} + +namespace REX::W32 +{ + std::uint32_t UnDecorateSymbolName(const char* a_name, char* a_buf, std::uint32_t a_bufLen, std::uint32_t a_flags) noexcept; + std::uint32_t UnDecorateSymbolNameW(const wchar_t* a_name, wchar_t* a_buf, std::uint32_t a_bufLen, std::uint32_t a_flags) noexcept; +} diff --git a/include/REX/W32/DINPUT.h b/include/REX/W32/DINPUT.h new file mode 100644 index 00000000..85f4e539 --- /dev/null +++ b/include/REX/W32/DINPUT.h @@ -0,0 +1,499 @@ +#pragma once + +#include "REX/W32/COM.h" +#include "REX/W32/D3D.h" + +namespace REX::W32 +{ + struct IDirectInput8A; + struct IDirectInputDevice8A; + struct IDirectInputEffect; +} + +namespace REX::W32 +{ + enum DIK : std::uint32_t + { + DIK_ESCAPE = 0x1, + DIK_1 = 0x2, + DIK_2 = 0x3, + DIK_3 = 0x4, + DIK_4 = 0x5, + DIK_5 = 0x6, + DIK_6 = 0x7, + DIK_7 = 0x8, + DIK_8 = 0x9, + DIK_9 = 0xA, + DIK_0 = 0xB, + DIK_MINUS = 0xC, + DIK_EQUALS = 0xD, + DIK_BACK = 0xE, + DIK_TAB = 0xF, + DIK_Q = 0x10, + DIK_W = 0x11, + DIK_E = 0x12, + DIK_R = 0x13, + DIK_T = 0x14, + DIK_Y = 0x15, + DIK_U = 0x16, + DIK_I = 0x17, + DIK_O = 0x18, + DIK_P = 0x19, + DIK_LBRACKET = 0x1A, + DIK_RBRACKET = 0x1B, + DIK_RETURN = 0x1C, + DIK_LCONTROL = 0x1D, + DIK_A = 0x1E, + DIK_S = 0x1F, + DIK_D = 0x20, + DIK_F = 0x21, + DIK_G = 0x22, + DIK_H = 0x23, + DIK_J = 0x24, + DIK_K = 0x25, + DIK_L = 0x26, + DIK_SEMICOLON = 0x27, + DIK_APOSTROPHE = 0x28, + DIK_GRAVE = 0x29, + DIK_LSHIFT = 0x2A, + DIK_BACKSLASH = 0x2B, + DIK_Z = 0x2C, + DIK_X = 0x2D, + DIK_C = 0x2E, + DIK_V = 0x2F, + DIK_B = 0x30, + DIK_N = 0x31, + DIK_M = 0x32, + DIK_COMMA = 0x33, + DIK_PERIOD = 0x34, + DIK_SLASH = 0x35, + DIK_RSHIFT = 0x36, + DIK_MULTIPLY = 0x37, + DIK_LMENU = 0x38, + DIK_SPACE = 0x39, + DIK_CAPITAL = 0x3A, + DIK_F1 = 0x3B, + DIK_F2 = 0x3C, + DIK_F3 = 0x3D, + DIK_F4 = 0x3E, + DIK_F5 = 0x3F, + DIK_F6 = 0x40, + DIK_F7 = 0x41, + DIK_F8 = 0x42, + DIK_F9 = 0x43, + DIK_F10 = 0x44, + DIK_NUMLOCK = 0x45, + DIK_SCROLL = 0x46, + DIK_NUMPAD7 = 0x47, + DIK_NUMPAD8 = 0x48, + DIK_NUMPAD9 = 0x49, + DIK_SUBTRACT = 0x4A, + DIK_NUMPAD4 = 0x4B, + DIK_NUMPAD5 = 0x4C, + DIK_NUMPAD6 = 0x4D, + DIK_ADD = 0x4E, + DIK_NUMPAD1 = 0x4F, + DIK_NUMPAD2 = 0x50, + DIK_NUMPAD3 = 0x51, + DIK_NUMPAD0 = 0x52, + DIK_DECIMAL = 0x53, + DIK_OEM_102 = 0x56, + DIK_F11 = 0x57, + DIK_F12 = 0x58, + DIK_F13 = 0x64, + DIK_F14 = 0x65, + DIK_F15 = 0x66, + DIK_KANA = 0x70, + DIK_ABNT_C1 = 0x73, + DIK_CONVERT = 0x79, + DIK_NOCONVERT = 0x7B, + DIK_YEN = 0x7D, + DIK_ABNT_C2 = 0x7E, + DIK_NUMPADEQUALS = 0x8D, + DIK_PREVTRACK = 0x90, + DIK_AT = 0x91, + DIK_COLON = 0x92, + DIK_UNDERLINE = 0x93, + DIK_KANJI = 0x94, + DIK_STOP = 0x95, + DIK_AX = 0x96, + DIK_UNLABELED = 0x97, + DIK_NEXTTRACK = 0x99, + DIK_NUMPADENTER = 0x9C, + DIK_RCONTROL = 0x9D, + DIK_MUTE = 0xA0, + DIK_CALCULATOR = 0xA1, + DIK_PLAYPAUSE = 0xA2, + DIK_MEDIASTOP = 0xA4, + DIK_VOLUMEDOWN = 0xAE, + DIK_VOLUMEUP = 0xB0, + DIK_WEBHOME = 0xB2, + DIK_NUMPADCOMMA = 0xB3, + DIK_DIVIDE = 0xB5, + DIK_SYSRQ = 0xB7, + DIK_RMENU = 0xB8, + DIK_PAUSE = 0xC5, + DIK_HOME = 0xC7, + DIK_UP = 0xC8, + DIK_PRIOR = 0xC9, + DIK_LEFT = 0xCB, + DIK_RIGHT = 0xCD, + DIK_END = 0xCF, + DIK_DOWN = 0xD0, + DIK_NEXT = 0xD1, + DIK_INSERT = 0xD2, + DIK_DELETE = 0xD3, + DIK_LWIN = 0xDB, + DIK_RWIN = 0xDC, + DIK_APPS = 0xDD, + DIK_POWER = 0xDE, + DIK_SLEEP = 0xDF, + DIK_WAKE = 0xE3, + DIK_WEBSEARCH = 0xE5, + DIK_WEBFAVORITES = 0xE6, + DIK_WEBREFRESH = 0xE7, + DIK_WEBSTOP = 0xE8, + DIK_WEBFORWARD = 0xE9, + DIK_WEBBACK = 0xEA, + DIK_MYCOMPUTER = 0xEB, + DIK_MAIL = 0xEC, + DIK_MEDIASELECT = 0xED, + DIK_BACKSPACE = DIK_BACK, + DIK_NUMPADSTAR = DIK_MULTIPLY, + DIK_LALT = DIK_LMENU, + DIK_CAPSLOCK = DIK_CAPITAL, + DIK_NUMPADMINUS = DIK_SUBTRACT, + DIK_NUMPADPLUS = DIK_ADD, + DIK_NUMPADPERIOD = DIK_DECIMAL, + DIK_NUMPADSLASH = DIK_DIVIDE, + DIK_RALT = DIK_RMENU, + DIK_UPARROW = DIK_UP, + DIK_PGUP = DIK_PRIOR, + DIK_LEFTARROW = DIK_LEFT, + DIK_RIGHTARROW = DIK_RIGHT, + DIK_DOWNARROW = DIK_DOWN, + DIK_PGDN = DIK_NEXT + }; +} + +namespace REX::W32 +{ + struct DIENVELOPE; + struct DIOBJECTDATAFORMAT; + + struct DIACTIONA + { + std::uintptr_t appData; + std::uint32_t semantic; + std::uint32_t flags; + union + { + const char* actionName; + std::uint32_t resIdString; + }; + GUID guidInstance; + std::uint32_t objID; + std::uint32_t how; + }; + + struct DIACTIONFORMATA + { + std::uint32_t size; + std::uint32_t actionSize; + std::uint32_t dataSize; + std::uint32_t numActions; + DIACTIONA* action; + GUID guidActionMap; + std::uint32_t genre; + std::uint32_t bufferSize; + std::int32_t axisMin; + std::int32_t axisMax; + HINSTANCE instString; + FILETIME timeStamp; + std::uint32_t crc; + char actionMap[MAX_PATH]; + }; + + struct DICOLORSET + { + std::uint32_t size; + D3DCOLOR textFore; + D3DCOLOR textHighlight; + D3DCOLOR calloutLine; + D3DCOLOR calloutHighlight; + D3DCOLOR border; + D3DCOLOR controlFill; + D3DCOLOR highlightFill; + D3DCOLOR areaFill; + }; + + struct DICONFIGUREDEVICESPARAMSA + { + std::uint32_t size; + std::uint32_t users; + char* userNames; + std::uint32_t formatsSize; + DIACTIONFORMATA* formats; + HWND hwnd; + DICOLORSET dics; + IUnknown* unkDDSTarget; + }; + + struct DIDATAFORMAT + { + std::uint32_t size; + std::uint32_t objSize; + std::uint32_t flags; + std::uint32_t dataSize; + std::uint32_t numObjs; + DIOBJECTDATAFORMAT* odf; + }; + + struct DIDEVCAPS + { + std::uint32_t size; + std::uint32_t flags; + std::uint32_t devType; + std::uint32_t axes; + std::uint32_t buttons; + std::uint32_t povs; + std::uint32_t ffSamplePeriod; + std::uint32_t ffMinTimeResolution; + std::uint32_t firmwareRevision; + std::uint32_t hardwareRevision; + std::uint32_t ffDriverVersion; + }; + + struct DIDEVICEIMAGEINFOA + { + char imagePath[MAX_PATH]; + std::uint32_t flags; + std::uint32_t viewID; + RECT overlay; + std::uint32_t objID; + std::uint32_t validPts; + POINT calloutLine[5]; + RECT calloutRect; + std::uint32_t textAlign; + }; + + struct DIDEVICEIMAGEINFOHEADERA + { + std::uint32_t size; + std::uint32_t sizeImageInfo; + std::uint32_t views; + std::uint32_t buttons; + std::uint32_t axes; + std::uint32_t povs; + std::uint32_t bufferSize; + std::uint32_t bufferUsed; + DIDEVICEIMAGEINFOA* imageInfoArray; + }; + + struct DIDEVICEINSTANCEA + { + std::uint32_t size; + GUID guidInstance; + GUID guidProduct; + std::uint32_t devType; + char instanceName[MAX_PATH]; + char productName[MAX_PATH]; + GUID guidFFDriver; + + // DIRECTINPUT_VERSION >= 0x0500 + std::uint16_t usagePage; + std::uint16_t usage; + }; + + struct DIDEVICEOBJECTDATA + { + std::uint32_t ofs; + std::uint32_t data; + std::uint32_t timeStamp; + std::uint32_t sequence; + std::uintptr_t appData; + }; + + struct DIDEVICEOBJECTINSTANCEA + { + std::uint32_t size; + GUID guidType; + std::uint32_t ofs; + std::uint32_t type; + std::uint32_t flags; + char name[MAX_PATH]; + + // DIRECTINPUT_VERSION >= 0x0500 + std::uint32_t ffMaxForce; + std::uint32_t ffForceResolution; + std::uint16_t collectionNumber; + std::uint16_t designatorIndex; + std::uint16_t usagePage; + std::uint16_t usage; + std::uint32_t dimension; + std::uint16_t exponent; + std::uint16_t reportId; + }; + + struct DIEFFECT + { + std::uint32_t size; + std::uint32_t flags; + std::uint32_t duration; + std::uint32_t samplePeriod; + std::uint32_t gain; + std::uint32_t triggerButton; + std::uint32_t triggerRepeatInterval; + std::uint32_t axesSize; + std::uint32_t* axes; + std::int32_t* direction; + DIENVELOPE* envelope; + std::uint32_t typeSpecificParamsSize; + void* typeSpecificParams; + std::uint32_t startDelay; + }; + + struct DIENVELOPE + { + std::uint32_t size; + std::uint32_t attackLevel; + std::uint32_t attackTime; + std::uint32_t fadeLevel; + std::uint32_t fadeTime; + }; + + struct DIEFFECTINFOA + { + std::uint32_t size; + GUID guid; + std::uint32_t effectType; + std::uint32_t staticParams; + std::uint32_t dynamicParams; + char name[MAX_PATH]; + }; + + struct DIEFFESCAPE + { + std::uint32_t size; + std::uint32_t command; + void* inBuffer; + std::uint32_t inBufferSize; + void* outBuffer; + std::uint32_t outBufferSize; + }; + + struct DIFILEEFFECT + { + std::uint32_t size; + GUID guidEffect; + const DIEFFECT* effect; + char friendlyName[MAX_PATH]; + }; + + struct DIMOUSESTATE2 + { + std::int32_t x; + std::int32_t y; + std::int32_t z; + std::uint8_t rgbButtons[8]; + }; + + struct DIOBJECTDATAFORMAT + { + const GUID* guid; + std::uint32_t ofs; + std::uint32_t type; + std::uint32_t flags; + }; + + struct DIPROPHEADER + { + std::uint32_t size; + std::uint32_t headerSize; + std::uint32_t obj; + std::uint32_t how; + }; +} + +namespace REX::W32 +{ + using LPDICONFIGUREDEVICESCALLBACK = BOOL(__stdcall*)(IUnknown*, void*); + using LPDIENUMCREATEDEFFECTOBJECTSCALLBACK = BOOL(__stdcall*)(IDirectInputEffect*, void*); + using LPDIENUMDEVICESBYSEMANTICSCBA = BOOL(__stdcall*)(const DIDEVICEINSTANCEA*, IDirectInputDevice8A*, std::uint32_t, std::uint32_t, void*); + using LPDIENUMDEVICESCALLBACKA = BOOL(__stdcall*)(const DIDEVICEINSTANCEA*, void*); + using LPDIENUMDEVICEOBJECTSCALLBACKA = BOOL(__stdcall*)(const DIDEVICEOBJECTINSTANCEA*, void*); + using LPDIENUMEFFECTSCALLBACKA = BOOL(__stdcall*)(const DIEFFECTINFOA*, void*); + using LPDIENUMEFFECTSINFILECALLBACK = BOOL(__stdcall*)(const DIFILEEFFECT*, void*); +} + +namespace REX::W32 +{ + struct __declspec(novtable, uuid("BF798030-483A-4DA2-AA99-5D64ED369700")) + IDirectInput8A : public IUnknown + { + virtual HRESULT CreateDevice(const GUID&, IDirectInputDevice8A**, IUnknown*) noexcept = 0; + virtual HRESULT EnumDevices(std::uint32_t, LPDIENUMDEVICESCALLBACKA, void*, std::uint32_t) noexcept = 0; + virtual HRESULT GetDeviceStatus(const GUID&) noexcept = 0; + virtual HRESULT RunControlPanel(HWND, std::uint32_t) noexcept = 0; + virtual HRESULT Initialize(HINSTANCE, std::uint32_t) noexcept = 0; + virtual HRESULT FindDevice(const GUID&, const char*, GUID*) noexcept = 0; + virtual HRESULT EnumDevicesBySemantics(const char*, DIACTIONFORMATA*, LPDIENUMDEVICESBYSEMANTICSCBA, void*, std::uint32_t) noexcept = 0; + virtual HRESULT ConfigureDevices(LPDICONFIGUREDEVICESCALLBACK, DICONFIGUREDEVICESPARAMSA*, std::uint32_t, void*) noexcept = 0; + }; + + struct __declspec(novtable, uuid("54D41080-DC15-4833-A41B-748F73A38179")) + IDirectInputDevice8A : public IUnknown + { + virtual HRESULT GetCapabilities(DIDEVCAPS*) noexcept = 0; + virtual HRESULT EnumObjects(LPDIENUMDEVICEOBJECTSCALLBACKA, void*, std::uint32_t) noexcept = 0; + virtual HRESULT GetProperty(const GUID&, DIPROPHEADER*) noexcept = 0; + virtual HRESULT SetProperty(const GUID&, const DIPROPHEADER*) noexcept = 0; + virtual HRESULT Acquire() noexcept = 0; + virtual HRESULT Unacquire() noexcept = 0; + virtual HRESULT GetDeviceState(std::uint32_t, void*) noexcept = 0; + virtual HRESULT GetDeviceData(std::uint32_t, DIDEVICEOBJECTDATA*, std::uint32_t*, std::uint32_t) noexcept = 0; + virtual HRESULT SetDataFormat(const DIDATAFORMAT*) noexcept = 0; + virtual HRESULT SetEventNotification(HANDLE) noexcept = 0; + virtual HRESULT SetCooperativeLevel(HWND, std::uint32_t) noexcept = 0; + virtual HRESULT GetObjectInfo(DIDEVICEOBJECTINSTANCEA*, std::uint32_t, std::uint32_t) noexcept = 0; + virtual HRESULT GetDeviceInfo(DIDEVICEINSTANCEA*) noexcept = 0; + virtual HRESULT RunControlPanel(HWND, std::uint32_t) noexcept = 0; + virtual HRESULT Initialize(HINSTANCE, std::uint32_t, const GUID&) noexcept = 0; + virtual HRESULT CreateEffect(const GUID&, const DIEFFECT*, IDirectInputEffect*, IUnknown*) noexcept = 0; + virtual HRESULT EnumEffects(LPDIENUMEFFECTSCALLBACKA, void*, std::uint32_t) noexcept = 0; + virtual HRESULT GetEffectInfo(DIEFFECTINFOA*, const GUID&) noexcept = 0; + virtual HRESULT GetForceFeedbackState(std::uint32_t*) noexcept = 0; + virtual HRESULT SendForceFeedbackCommand(std::uint32_t) noexcept = 0; + virtual HRESULT EnumCreatedEffectObjects(LPDIENUMCREATEDEFFECTOBJECTSCALLBACK, void*, std::uint32_t) noexcept = 0; + virtual HRESULT Escape(DIEFFESCAPE*) noexcept = 0; + virtual HRESULT Poll() noexcept = 0; + virtual HRESULT SendDeviceData(std::uint32_t, const DIDEVICEOBJECTDATA*, std::uint32_t*, std::uint32_t) noexcept = 0; + virtual HRESULT EnumEffectsInFile(const char*, LPDIENUMEFFECTSINFILECALLBACK, void*, std::uint32_t) noexcept = 0; + virtual HRESULT WriteEffectToFile(const char*, std::uint32_t, DIFILEEFFECT*, std::uint32_t) noexcept = 0; + virtual HRESULT BuildActionMap(DIACTIONFORMATA*, const char*, std::uint32_t) noexcept = 0; + virtual HRESULT SetActionMap(DIACTIONFORMATA*, const char*, std::uint32_t) noexcept = 0; + virtual HRESULT GetImageInfo(DIDEVICEIMAGEINFOHEADERA*) noexcept = 0; + }; + + struct __declspec(novtable, uuid("E7E1F7C0-88D2-11D0-9AD0-00A0C9A06E35")) + IDirectInputEffect : public IUnknown + { + virtual HRESULT Initialize(HINSTANCE, std::uint32_t, const GUID&) noexcept = 0; + virtual HRESULT GetEffectGuid(GUID*) noexcept = 0; + virtual HRESULT GetParameters(DIEFFECT*, std::uint32_t) noexcept = 0; + virtual HRESULT SetParameters(const DIEFFECT*, std::uint32_t) noexcept = 0; + virtual HRESULT Start(std::uint32_t, std::uint32_t) noexcept = 0; + virtual HRESULT Stop() noexcept = 0; + virtual HRESULT GetEffectStatus(std::uint32_t*) noexcept = 0; + virtual HRESULT Download() noexcept = 0; + virtual HRESULT Unload() noexcept = 0; + virtual HRESULT Escape(DIEFFESCAPE*) noexcept = 0; + }; +} + +namespace REX::W32 +{ + inline constexpr IID IID_IDirectInput8A{ 0xBF798030, 0x483A, 0x4DA2, { 0xAA, 0x99, 0x5D, 0x64, 0xED, 0x36, 0x97, 0x00 } }; + inline constexpr IID IID_IDirectInputDevice8A{ 0x54D41080, 0xDC15, 0x4833, { 0xA4, 0x1B, 0x74, 0x8F, 0x73, 0xA3, 0x81, 0x79 } }; + inline constexpr IID IID_IDirectInputEffect{ 0xE7E1F7C0, 0x88D2, 0x11D0, { 0x9A, 0xD0, 0x00, 0xA0, 0xC9, 0xA0, 0x6E, 0x35 } }; +} diff --git a/include/REX/W32/DXGI.h b/include/REX/W32/DXGI.h new file mode 100644 index 00000000..022ebcfc --- /dev/null +++ b/include/REX/W32/DXGI.h @@ -0,0 +1,549 @@ +#pragma once + +#include "REX/W32/COM.h" + +namespace REX::W32 +{ + struct IDXGIAdapter; + struct IDXGIAdapter1; + struct IDXGIDevice; + struct IDXGIDevice1; + struct IDXGIDeviceSubObject; + struct IDXGIFactory1; + struct IDXGIKeyedMutex; + struct IDXGIObject; + struct IDXGIOutput; + struct IDXGIResource; + struct IDXGISurface; + struct IDXGISurface1; + struct IDXGISwapChain; +} + +namespace REX::W32 +{ + enum DXGI_ADAPTER_FLAG + { + DXGI_ADAPTER_FLAG_NONE = 0, + DXGI_ADAPTER_FLAG_REMOTE = 1, + DXGI_ADAPTER_FLAG_SOFTWARE = 2, + DXGI_ADAPTER_FLAG_FORCE_DWORD = 0xFFFFFFFF, + }; + + enum DXGI_COLOR_SPACE_TYPE + { + DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 = 0, + DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 = 1, + DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709 = 2, + DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020 = 3, + DXGI_COLOR_SPACE_RESERVED = 4, + DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 = 5, + DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 = 6, + DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601 = 7, + DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 = 8, + DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709 = 9, + DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 = 10, + DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 = 11, + DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 = 12, + DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_LEFT_P2020 = 13, + DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020 = 14, + DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020 = 15, + DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020 = 16, + DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020 = 17, + DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020 = 18, + DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020 = 19, + DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P709 = 20, + DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P2020 = 21, + DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P709 = 22, + DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P2020 = 23, + DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020 = 24, + DXGI_COLOR_SPACE_CUSTOM = 0xFFFFFFFF, + }; + + enum DXGI_FORMAT + { + DXGI_FORMAT_UNKNOWN = 0, + DXGI_FORMAT_R32G32B32A32_TYPELESS = 1, + DXGI_FORMAT_R32G32B32A32_FLOAT = 2, + DXGI_FORMAT_R32G32B32A32_UINT = 3, + DXGI_FORMAT_R32G32B32A32_SINT = 4, + DXGI_FORMAT_R32G32B32_TYPELESS = 5, + DXGI_FORMAT_R32G32B32_FLOAT = 6, + DXGI_FORMAT_R32G32B32_UINT = 7, + DXGI_FORMAT_R32G32B32_SINT = 8, + DXGI_FORMAT_R16G16B16A16_TYPELESS = 9, + DXGI_FORMAT_R16G16B16A16_FLOAT = 10, + DXGI_FORMAT_R16G16B16A16_UNORM = 11, + DXGI_FORMAT_R16G16B16A16_UINT = 12, + DXGI_FORMAT_R16G16B16A16_SNORM = 13, + DXGI_FORMAT_R16G16B16A16_SINT = 14, + DXGI_FORMAT_R32G32_TYPELESS = 15, + DXGI_FORMAT_R32G32_FLOAT = 16, + DXGI_FORMAT_R32G32_UINT = 17, + DXGI_FORMAT_R32G32_SINT = 18, + DXGI_FORMAT_R32G8X24_TYPELESS = 19, + DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20, + DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21, + DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22, + DXGI_FORMAT_R10G10B10A2_TYPELESS = 23, + DXGI_FORMAT_R10G10B10A2_UNORM = 24, + DXGI_FORMAT_R10G10B10A2_UINT = 25, + DXGI_FORMAT_R11G11B10_FLOAT = 26, + DXGI_FORMAT_R8G8B8A8_TYPELESS = 27, + DXGI_FORMAT_R8G8B8A8_UNORM = 28, + DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29, + DXGI_FORMAT_R8G8B8A8_UINT = 30, + DXGI_FORMAT_R8G8B8A8_SNORM = 31, + DXGI_FORMAT_R8G8B8A8_SINT = 32, + DXGI_FORMAT_R16G16_TYPELESS = 33, + DXGI_FORMAT_R16G16_FLOAT = 34, + DXGI_FORMAT_R16G16_UNORM = 35, + DXGI_FORMAT_R16G16_UINT = 36, + DXGI_FORMAT_R16G16_SNORM = 37, + DXGI_FORMAT_R16G16_SINT = 38, + DXGI_FORMAT_R32_TYPELESS = 39, + DXGI_FORMAT_D32_FLOAT = 40, + DXGI_FORMAT_R32_FLOAT = 41, + DXGI_FORMAT_R32_UINT = 42, + DXGI_FORMAT_R32_SINT = 43, + DXGI_FORMAT_R24G8_TYPELESS = 44, + DXGI_FORMAT_D24_UNORM_S8_UINT = 45, + DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46, + DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47, + DXGI_FORMAT_R8G8_TYPELESS = 48, + DXGI_FORMAT_R8G8_UNORM = 49, + DXGI_FORMAT_R8G8_UINT = 50, + DXGI_FORMAT_R8G8_SNORM = 51, + DXGI_FORMAT_R8G8_SINT = 52, + DXGI_FORMAT_R16_TYPELESS = 53, + DXGI_FORMAT_R16_FLOAT = 54, + DXGI_FORMAT_D16_UNORM = 55, + DXGI_FORMAT_R16_UNORM = 56, + DXGI_FORMAT_R16_UINT = 57, + DXGI_FORMAT_R16_SNORM = 58, + DXGI_FORMAT_R16_SINT = 59, + DXGI_FORMAT_R8_TYPELESS = 60, + DXGI_FORMAT_R8_UNORM = 61, + DXGI_FORMAT_R8_UINT = 62, + DXGI_FORMAT_R8_SNORM = 63, + DXGI_FORMAT_R8_SINT = 64, + DXGI_FORMAT_A8_UNORM = 65, + DXGI_FORMAT_R1_UNORM = 66, + DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67, + DXGI_FORMAT_R8G8_B8G8_UNORM = 68, + DXGI_FORMAT_G8R8_G8B8_UNORM = 69, + DXGI_FORMAT_BC1_TYPELESS = 70, + DXGI_FORMAT_BC1_UNORM = 71, + DXGI_FORMAT_BC1_UNORM_SRGB = 72, + DXGI_FORMAT_BC2_TYPELESS = 73, + DXGI_FORMAT_BC2_UNORM = 74, + DXGI_FORMAT_BC2_UNORM_SRGB = 75, + DXGI_FORMAT_BC3_TYPELESS = 76, + DXGI_FORMAT_BC3_UNORM = 77, + DXGI_FORMAT_BC3_UNORM_SRGB = 78, + DXGI_FORMAT_BC4_TYPELESS = 79, + DXGI_FORMAT_BC4_UNORM = 80, + DXGI_FORMAT_BC4_SNORM = 81, + DXGI_FORMAT_BC5_TYPELESS = 82, + DXGI_FORMAT_BC5_UNORM = 83, + DXGI_FORMAT_BC5_SNORM = 84, + DXGI_FORMAT_B5G6R5_UNORM = 85, + DXGI_FORMAT_B5G5R5A1_UNORM = 86, + DXGI_FORMAT_B8G8R8A8_UNORM = 87, + DXGI_FORMAT_B8G8R8X8_UNORM = 88, + DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89, + DXGI_FORMAT_B8G8R8A8_TYPELESS = 90, + DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91, + DXGI_FORMAT_B8G8R8X8_TYPELESS = 92, + DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93, + DXGI_FORMAT_BC6H_TYPELESS = 94, + DXGI_FORMAT_BC6H_UF16 = 95, + DXGI_FORMAT_BC6H_SF16 = 96, + DXGI_FORMAT_BC7_TYPELESS = 97, + DXGI_FORMAT_BC7_UNORM = 98, + DXGI_FORMAT_BC7_UNORM_SRGB = 99, + DXGI_FORMAT_AYUV = 100, + DXGI_FORMAT_Y410 = 101, + DXGI_FORMAT_Y416 = 102, + DXGI_FORMAT_NV12 = 103, + DXGI_FORMAT_P010 = 104, + DXGI_FORMAT_P016 = 105, + DXGI_FORMAT_420_OPAQUE = 106, + DXGI_FORMAT_YUY2 = 107, + DXGI_FORMAT_Y210 = 108, + DXGI_FORMAT_Y216 = 109, + DXGI_FORMAT_NV11 = 110, + DXGI_FORMAT_AI44 = 111, + DXGI_FORMAT_IA44 = 112, + DXGI_FORMAT_P8 = 113, + DXGI_FORMAT_A8P8 = 114, + DXGI_FORMAT_B4G4R4A4_UNORM = 115, + + DXGI_FORMAT_P208 = 130, + DXGI_FORMAT_V208 = 131, + DXGI_FORMAT_V408 = 132, + + DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE = 189, + DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE = 190, + + DXGI_FORMAT_FORCE_UINT = 0xFFFFFFFF, + }; + + enum DXGI_MODE_ROTATION + { + DXGI_MODE_ROTATION_UNSPECIFIED = 0, + DXGI_MODE_ROTATION_IDENTITY = 1, + DXGI_MODE_ROTATION_ROTATE90 = 2, + DXGI_MODE_ROTATION_ROTATE180 = 3, + DXGI_MODE_ROTATION_ROTATE270 = 4, + }; + + enum DXGI_MODE_SCALING + { + DXGI_MODE_SCALING_UNSPECIFIED = 0, + DXGI_MODE_SCALING_CENTERED = 1, + DXGI_MODE_SCALING_STRETCHED = 2, + }; + + enum DXGI_MODE_SCANLINE_ORDER + { + DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED = 0, + DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE = 1, + DXGI_MODE_SCANLINE_ORDER_UPPER_FIELD_FIRST = 2, + DXGI_MODE_SCANLINE_ORDER_LOWER_FIELD_FIRST = 3, + }; + + enum DXGI_RESIDENCY + { + DXGI_RESIDENCY_FULLY_RESIDENT = 1, + DXGI_RESIDENCY_RESIDENT_IN_SHARED_MEMORY = 2, + DXGI_RESIDENCY_EVICTED_TO_DISK = 3, + }; + + enum DXGI_SWAP_EFFECT + { + DXGI_SWAP_EFFECT_DISCARD = 0, + DXGI_SWAP_EFFECT_SEQUENTIAL = 1, + DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL = 3, + DXGI_SWAP_EFFECT_FLIP_DISCARD = 4, + }; + + enum DXGI_SWAP_CHAIN_FLAG + { + DXGI_SWAP_CHAIN_FLAG_NONPREROTATED = 1, + DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH = 2, + DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE = 4, + DXGI_SWAP_CHAIN_FLAG_RESTRICTED_CONTENT = 8, + DXGI_SWAP_CHAIN_FLAG_RESTRICT_SHARED_RESOURCE_DRIVER = 16, + DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY = 32, + DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT = 64, + DXGI_SWAP_CHAIN_FLAG_FOREGROUND_LAYER = 128, + DXGI_SWAP_CHAIN_FLAG_FULLSCREEN_VIDEO = 256, + DXGI_SWAP_CHAIN_FLAG_YUV_VIDEO = 512, + DXGI_SWAP_CHAIN_FLAG_HW_PROTECTED = 1024, + DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING = 2048, + DXGI_SWAP_CHAIN_FLAG_RESTRICTED_TO_ALL_HOLOGRAPHIC_DISPLAYS = 4096, + }; +} + +namespace REX::W32 +{ + struct D3DCOLORVALUE + { + float r; + float g; + float b; + float a; + }; + + using DXGI_RGBA = D3DCOLORVALUE; + using DXGI_USAGE = std::uint32_t; + + struct LUID + { + std::uint32_t lo; + std::int32_t hi; + }; +} + +namespace REX::W32 +{ + struct DXGI_ADAPTER_DESC + { + wchar_t description[128]; + std::uint32_t vendorId; + std::uint32_t deviceId; + std::uint32_t subSysId; + std::uint32_t revision; + std::size_t dedicatedVideoMemory; + std::size_t dedicatedSystemMemory; + std::size_t sharedSystemMemory; + LUID adapterLuid; + }; + + struct DXGI_ADAPTER_DESC1 + { + wchar_t description[128]; + std::uint32_t vendorId; + std::uint32_t deviceId; + std::uint32_t subSysId; + std::uint32_t revision; + std::size_t dedicatedVideoMemory; + std::size_t dedicatedSystemMemory; + std::size_t sharedSystemMemory; + LUID adapterLuid; + std::uint32_t flags; + }; + + struct DXGI_DISPLAY_COLOR_SPACE + { + float primaryCoordinates[8][2]; + float whitePoints[16][2]; + }; + + struct DXGI_FRAME_STATISTICS + { + std::uint32_t presentCount; + std::uint32_t presentRefreshCount; + std::uint32_t syncRefreshCount; + std::int64_t syncQPCTime; + std::int64_t syncGPUTime; + }; + + struct DXGI_RGB + { + float red; + float green; + float blue; + }; + + struct DXGI_GAMMA_CONTROL + { + DXGI_RGB scale; + DXGI_RGB offset; + DXGI_RGB gammaCurve[1025]; + }; + + struct DXGI_GAMMA_CONTROL_CAPABILITIES + { + BOOL scaleAndOffsetSupported; + float maxConvertedValue; + float minConvertedValue; + std::uint32_t numGammaControlPoints; + float controlPointPositions[1025]; + }; + + struct DXGI_MAPPED_RECT + { + std::int32_t pitch; + std::uint8_t* bits; + }; + + struct DXGI_RATIONAL + { + std::uint32_t numerator; + std::uint32_t denominator; + }; + + struct DXGI_MODE_DESC + { + std::uint32_t width; + std::uint32_t height; + DXGI_RATIONAL refreshRate; + DXGI_FORMAT format; + DXGI_MODE_SCANLINE_ORDER scanlineOrdering; + DXGI_MODE_SCALING scaling; + }; + + struct DXGI_OUTPUT_DESC + { + wchar_t deviceName[32]; + RECT desktopCoordinates; + BOOL attachedToDesktop; + DXGI_MODE_ROTATION rotation; + HMONITOR monitor; + }; + + struct DXGI_SAMPLE_DESC + { + std::uint32_t count; + std::uint32_t quality; + }; + + struct DXGI_SHARED_RESOURCE + { + HANDLE handle; + }; + + struct DXGI_SURFACE_DESC + { + std::uint32_t width; + std::uint32_t height; + DXGI_FORMAT format; + DXGI_SAMPLE_DESC sampleDesc; + }; + + struct DXGI_SWAP_CHAIN_DESC + { + DXGI_MODE_DESC bufferDesc; + DXGI_SAMPLE_DESC sampleDesc; + DXGI_USAGE bufferUsage; + std::uint32_t bufferCount; + HWND outputWindow; + BOOL windowed; + DXGI_SWAP_EFFECT swapEffect; + std::uint32_t flags; + }; +} + +namespace REX::W32 +{ + struct __declspec(novtable, uuid("aec22fb8-76f3-4639-9be0-28eb43a67a2e")) + IDXGIObject : public IUnknown + { + virtual HRESULT SetPrivateData(const GUID& a_iid, std::uint32_t a_dataSize, const void* a_data) = 0; + virtual HRESULT SetPrivateDataInterface(const GUID& a_iid, const IUnknown* a_unknown) = 0; + virtual HRESULT GetPrivateData(const GUID& a_iid, std::uint32_t* a_dataSize, void* a_data) = 0; + virtual HRESULT GetParent(const GUID& a_iid, void** a_parent) = 0; + }; + + struct __declspec(novtable, uuid("3d3e0379-f9de-4d58-bb6c-18d62992f1a6")) + IDXGIDeviceSubObject : public IDXGIObject + { + virtual HRESULT GetDevice(const GUID& a_iid, void** a_device) = 0; + }; + + struct __declspec(novtable, uuid("035f3ab4-482e-4e50-b41f-8a7f8bd8960b")) + IDXGIResource : public IDXGIDeviceSubObject + { + virtual HRESULT GetSharedHandle(HANDLE* a_sharedHandle) = 0; + virtual HRESULT GetUsage(DXGI_USAGE* a_usage) = 0; + virtual HRESULT SetEvictionPriority(std::uint32_t a_evictionPriority) = 0; + virtual HRESULT GetEvictionPriority(std::uint32_t* a_evictionPriority) = 0; + }; + + struct __declspec(novtable, uuid("9d8e1289-d7b3-465f-8126-250e349af85d")) + IDXGIKeyedMutex : public IDXGIDeviceSubObject + { + virtual HRESULT AcquireSync(std::uint64_t a_key, std::uint32_t a_milliseconds) = 0; + virtual HRESULT ReleaseSync(std::uint64_t a_key) = 0; + }; + + struct __declspec(novtable, uuid("cafcb56c-6ac3-4889-bf47-9e23bbd260ec")) + IDXGISurface : public IDXGIDeviceSubObject + { + virtual HRESULT GetDesc(DXGI_SURFACE_DESC* a_desc) = 0; + virtual HRESULT Map(DXGI_MAPPED_RECT* a_lockedRect, std::uint32_t a_mapFlags) = 0; + virtual HRESULT Unmap(void) = 0; + }; + + struct __declspec(novtable, uuid("4AE63092-6327-4c1b-80AE-BFE12EA32B86")) + IDXGISurface1 : public IDXGISurface + { + virtual HRESULT GetDC(BOOL a_discard, HDC* a_hdc) = 0; + virtual HRESULT ReleaseDC(RECT* a_dirtyRect) = 0; + }; + + struct __declspec(novtable, uuid("2411e7e1-12ac-4ccf-bd14-9798e8534dc0")) + IDXGIAdapter : public IDXGIObject + { + virtual HRESULT EnumOutputs(std::uint32_t a_outputSize, IDXGIOutput** a_output) = 0; + virtual HRESULT GetDesc(DXGI_ADAPTER_DESC* a_desc) = 0; + virtual HRESULT CheckInterfaceSupport(const GUID& a_iid, std::int64_t* a_umdVersion) = 0; + }; + + struct __declspec(novtable, uuid("29038f61-3839-4626-91fd-086879011a05")) + IDXGIAdapter1 : public IDXGIAdapter + { + virtual HRESULT GetDesc1(DXGI_ADAPTER_DESC1* a_desc) = 0; + }; + + struct __declspec(novtable, uuid("ae02eedb-c735-4690-8d52-5a8dc20213aa")) + IDXGIOutput : public IDXGIObject + { + virtual HRESULT GetDesc(DXGI_OUTPUT_DESC* a_desc) = 0; + virtual HRESULT GetDisplayModeList(DXGI_FORMAT a_enumFormat, std::uint32_t a_flags, std::uint32_t* a_numModes, DXGI_MODE_DESC* a_desc) = 0; + virtual HRESULT FindClosestMatchingMode(const DXGI_MODE_DESC* a_modeToMatch, DXGI_MODE_DESC* a_closestMatch, IUnknown* a_concernedDevice) = 0; + virtual HRESULT WaitForVBlank(void) = 0; + virtual HRESULT TakeOwnership(IUnknown* a_device, BOOL a_exclusive) = 0; + virtual void ReleaseOwnership(void) = 0; + virtual HRESULT GetGammaControlCapabilities(DXGI_GAMMA_CONTROL_CAPABILITIES* a_gammaCaps) = 0; + virtual HRESULT SetGammaControl(const DXGI_GAMMA_CONTROL* a_array) = 0; + virtual HRESULT GetGammaControl(DXGI_GAMMA_CONTROL* a_array) = 0; + virtual HRESULT SetDisplaySurface(IDXGISurface* a_scanoutSurface) = 0; + virtual HRESULT GetDisplaySurfaceData(IDXGISurface* a_destination) = 0; + virtual HRESULT GetFrameStatistics(DXGI_FRAME_STATISTICS* a_stats) = 0; + }; + + struct __declspec(novtable, uuid("310d36a0-d2e7-4c0a-aa04-6a9d23b8886a")) + IDXGISwapChain : public IDXGIDeviceSubObject + { + virtual HRESULT Present(std::uint32_t a_syncInterval, std::uint32_t a_flags) = 0; + virtual HRESULT GetBuffer(std::uint32_t a_buffer, const GUID& a_iid, void** a_surface) = 0; + virtual HRESULT SetFullscreenState(BOOL a_fullscreen, IDXGIOutput* a_target) = 0; + virtual HRESULT GetFullscreenState(BOOL* a_fullscreen, IDXGIOutput** a_target) = 0; + virtual HRESULT GetDesc(DXGI_SWAP_CHAIN_DESC* a_desc) = 0; + virtual HRESULT ResizeBuffers(std::uint32_t a_bufferCount, std::uint32_t a_width, std::uint32_t a_height, DXGI_FORMAT a_newFormat, std::uint32_t a_swapChainFlags) = 0; + virtual HRESULT ResizeTarget(const DXGI_MODE_DESC* a_newTargetParameters) = 0; + virtual HRESULT GetContainingOutput(IDXGIOutput** a_output) = 0; + virtual HRESULT GetFrameStatistics(DXGI_FRAME_STATISTICS* a_stats) = 0; + virtual HRESULT GetLastPresentCount(std::uint32_t* a_lastPresentCount) = 0; + }; + + struct __declspec(novtable, uuid("7b7166ec-21c7-44ae-b21a-c9ae321ae369")) + IDXGIFactory : public IDXGIObject + { + virtual HRESULT EnumAdapters(std::uint32_t a_adapterSize, IDXGIAdapter** a_adapter) = 0; + virtual HRESULT MakeWindowAssociation(HWND a_windowHandle, std::uint32_t a_flags) = 0; + virtual HRESULT GetWindowAssociation(HWND* a_windowHandle) = 0; + virtual HRESULT CreateSwapChain(IUnknown* a_device, DXGI_SWAP_CHAIN_DESC* a_desc, IDXGISwapChain** a_swapChain) = 0; + virtual HRESULT CreateSoftwareAdapter(HMODULE a_module, IDXGIAdapter** a_adapter) = 0; + }; + + struct __declspec(novtable, uuid("770aae78-f26f-4dba-a829-253c83d1b387")) + IDXGIFactory1 : public IDXGIFactory + { + virtual HRESULT EnumAdapters1(std::uint32_t a_adapterSize, IDXGIAdapter1** a_adapter) = 0; + virtual BOOL IsCurrent(void) = 0; + }; + + struct __declspec(novtable, uuid("54ec77fa-1377-44e6-8c32-88fd5f44c84c")) + IDXGIDevice : public IDXGIObject + { + virtual HRESULT GetAdapter(IDXGIAdapter** a_adapter) = 0; + virtual HRESULT CreateSurface(const DXGI_SURFACE_DESC* a_desc, std::uint32_t a_numSurfaces, DXGI_USAGE a_usage, const DXGI_SHARED_RESOURCE* a_sharedResource, IDXGISurface** a_surface) = 0; + virtual HRESULT QueryResourceResidency(IUnknown* const* a_resources, DXGI_RESIDENCY* a_residencyStatus, std::uint32_t a_numResources) = 0; + virtual HRESULT SetGPUThreadPriority(std::int32_t a_priority) = 0; + virtual HRESULT GetGPUThreadPriority(std::int32_t* a_priority) = 0; + }; + + struct __declspec(novtable, uuid("77db970f-6276-48ba-ba28-070143b4392c")) + IDXGIDevice1 : public IDXGIDevice + { + virtual HRESULT SetMaximumFrameLatency(std::uint32_t a_maxLatency) = 0; + virtual HRESULT GetMaximumFrameLatency(std::uint32_t* a_maxLatency) = 0; + }; +} + +namespace REX::W32 +{ + HRESULT CreateDXGIFactory(const IID& a_iid, void** a_factory) noexcept; + HRESULT CreateDXGIFactory1(const IID& a_iid, void** a_factory) noexcept; +} + +namespace REX::W32 +{ + inline constexpr IID IID_IDXGIAdapter{ 0x2411E7E1, 0x12AC, 0x4CCF, { 0xBD, 0x14, 0x97, 0x98, 0xE8, 0x53, 0x4D, 0xC0 } }; + inline constexpr IID IID_IDXGIAdapter1{ 0x29038F61, 0x3839, 0x4626, { 0x91, 0xFD, 0x08, 0x68, 0x79, 0x01, 0x1A, 0x05 } }; + inline constexpr IID IID_IDXGIObject{ 0xAEC22Fb8, 0x76F3, 0x4639, { 0x9B, 0xE0, 0x28, 0xEB, 0x43, 0xA6, 0x7A, 0x2E } }; + inline constexpr IID IID_IDXGIDevice{ 0x54EC77FA, 0x1377, 0x44E6, { 0x8C, 0x32, 0x88, 0xFD, 0x5F, 0x44, 0xC8, 0x4C } }; + inline constexpr IID IID_IDXGIDevice1{ 0x77DB970F, 0x6276, 0x48BA, { 0xBA, 0x28, 0x07, 0x01, 0x43, 0xB4, 0x39, 0x2C } }; + inline constexpr IID IID_IDXGIDeviceSubObject{ 0x3D3E0379, 0xF9DE, 0x4D58, { 0xBB, 0x6C, 0x18, 0xD6, 0x29, 0x92, 0xF1, 0xA6 } }; + inline constexpr IID IID_IDXGIFactory{ 0x7B7166EC, 0x21C7, 0x44AE, { 0xB2, 0x1A, 0xC9, 0xAE, 0x32, 0x1A, 0xE3, 0x69 } }; + inline constexpr IID IID_IDXGIFactory1{ 0x770AAE78, 0xF26F, 0x4DBA, { 0xA8, 0x29, 0x25, 0x3C, 0x83, 0xD1, 0xB3, 0x87 } }; + inline constexpr IID IID_IDXGIKeyedMutex{ 0x9D8E1289, 0xD7B3, 0x465F, { 0x81, 0x26, 0x25, 0x0E, 0x34, 0x9A, 0xF8, 0x5D } }; + inline constexpr IID IID_IDXGIOutput{ 0xAE02EEDB, 0xC735, 0x4690, { 0x8D, 0x52, 0x5A, 0x8D, 0xC2, 0x02, 0x13, 0xAA } }; + inline constexpr IID IID_IDXGIResource{ 0x035F3AB4, 0x482E, 0x4E50, { 0xB4, 0x1F, 0x8A, 0x7F, 0x8B, 0xD8, 0x96, 0x0B } }; + inline constexpr IID IID_IDXGISurface{ 0xCAFCB56C, 0x6AC3, 0x4889, { 0xBF, 0x47, 0x9E, 0x23, 0xBB, 0xD2, 0x60, 0xEC } }; + inline constexpr IID IID_IDXGISurface1{ 0x4AE63092, 0x6327, 0x4C1B, { 0x80, 0xAE, 0xBF, 0xE1, 0x2E, 0xA3, 0x2B, 0x86 } }; + inline constexpr IID IID_IDXGISwapChain{ 0x310D36A0, 0xD2E7, 0x4C0A, { 0xAA, 0x04, 0x6A, 0x9D, 0x23, 0xB8, 0x88, 0x6A } }; +} diff --git a/include/REX/W32/DXGI_2.h b/include/REX/W32/DXGI_2.h new file mode 100644 index 00000000..aca5932d --- /dev/null +++ b/include/REX/W32/DXGI_2.h @@ -0,0 +1,272 @@ +#pragma once + +#include "REX/W32/DXGI.h" + +namespace REX::W32 +{ + struct IDXGIAdapter2; + struct IDXGIDevice2; + struct IDXGIDisplayControl; + struct IDXGIFactory2; + struct IDXGIOutput1; + struct IDXGIOutputDuplication; + struct IDXGIResource1; + struct IDXGISurface2; + struct IDXGISwapChain1; +} + +namespace REX::W32 +{ + enum DXGI_ALPHA_MODE + { + DXGI_ALPHA_MODE_UNSPECIFIED = 0, + DXGI_ALPHA_MODE_PREMULTIPLIED = 1, + DXGI_ALPHA_MODE_STRAIGHT = 2, + DXGI_ALPHA_MODE_IGNORE = 3, + DXGI_ALPHA_MODE_FORCE_DWORD = 0xFFFFFFFF, + }; + + enum DXGI_COMPUTE_PREEMPTION_GRANULARITY + { + DXGI_COMPUTE_PREEMPTION_DMA_BUFFER_BOUNDARY = 0, + DXGI_COMPUTE_PREEMPTION_DISPATCH_BOUNDARY = 1, + DXGI_COMPUTE_PREEMPTION_THREAD_GROUP_BOUNDARY = 2, + DXGI_COMPUTE_PREEMPTION_THREAD_BOUNDARY = 3, + DXGI_COMPUTE_PREEMPTION_INSTRUCTION_BOUNDARY = 4, + }; + + enum DXGI_GRAPHICS_PREEMPTION_GRANULARITY + { + DXGI_GRAPHICS_PREEMPTION_DMA_BUFFER_BOUNDARY = 0, + DXGI_GRAPHICS_PREEMPTION_PRIMITIVE_BOUNDARY = 1, + DXGI_GRAPHICS_PREEMPTION_TRIANGLE_BOUNDARY = 2, + DXGI_GRAPHICS_PREEMPTION_PIXEL_BOUNDARY = 3, + DXGI_GRAPHICS_PREEMPTION_INSTRUCTION_BOUNDARY = 4, + }; + + enum DXGI_OFFER_RESOURCE_PRIORITY + { + DXGI_OFFER_RESOURCE_PRIORITY_LOW = 1, + DXGI_OFFER_RESOURCE_PRIORITY_NORMAL = (DXGI_OFFER_RESOURCE_PRIORITY_LOW + 1), + DXGI_OFFER_RESOURCE_PRIORITY_HIGH = (DXGI_OFFER_RESOURCE_PRIORITY_NORMAL + 1) + }; + + enum DXGI_OUTDUPL_POINTER_SHAPE_TYPE + { + DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MONOCHROME = 0x1, + DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR = 0x2, + DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MASKED_COLOR = 0x4, + }; + + enum DXGI_SCALING + { + DXGI_SCALING_STRETCH = 0, + DXGI_SCALING_NONE = 1, + DXGI_SCALING_ASPECT_RATIO_STRETCH = 2, + }; +} + +namespace REX::W32 +{ + struct DXGI_ADAPTER_DESC2 + { + wchar_t description[128]; + std::uint32_t vendorID; + std::uint32_t deviceID; + std::uint32_t subSysID; + std::uint32_t revision; + std::size_t dedicatedVideoMemory; + std::size_t dedicatedSystemMemory; + std::size_t sharedSystemMemory; + LUID adapterLUID; + std::uint32_t flags; + DXGI_GRAPHICS_PREEMPTION_GRANULARITY graphicsPreemptionGranularity; + DXGI_COMPUTE_PREEMPTION_GRANULARITY computePreemptionGranularity; + }; + + struct DXGI_MODE_DESC1 + { + std::uint32_t width; + std::uint32_t height; + DXGI_RATIONAL refreshRate; + DXGI_FORMAT format; + DXGI_MODE_SCANLINE_ORDER scanlineOrdering; + DXGI_MODE_SCALING scaling; + BOOL stereo; + }; + + struct DXGI_OUTDUPL_DESC + { + DXGI_MODE_DESC modeDesc; + DXGI_MODE_ROTATION rotation; + BOOL desktopImageInSystemMemory; + }; + + struct DXGI_OUTDUPL_POINTER_POSITION + { + POINT position; + BOOL visible; + }; + + struct DXGI_OUTDUPL_FRAME_INFO + { + std::int64_t lastPresentTime; + std::int64_t lastMouseUpdateTime; + std::uint32_t accumulatedFrames; + BOOL rectsCoalesced; + BOOL protectedContentMaskedOut; + DXGI_OUTDUPL_POINTER_POSITION pointerPosition; + std::uint32_t totalMetadataBufferSize; + std::uint32_t pointerShapeBufferSize; + }; + + struct DXGI_OUTDUPL_MOVE_RECT + { + POINT sourcePoint; + RECT destinationRect; + }; + + struct DXGI_OUTDUPL_POINTER_SHAPE_INFO + { + std::uint32_t type; + std::uint32_t width; + std::uint32_t height; + std::uint32_t pitch; + POINT hotSpot; + }; + + struct DXGI_PRESENT_PARAMETERS + { + std::uint32_t dirtyRectsCount; + RECT* dirtyRects; + RECT* scrollRect; + POINT* scrollOffset; + }; + + struct DXGI_SWAP_CHAIN_DESC1 + { + std::uint32_t width; + std::uint32_t height; + DXGI_FORMAT format; + BOOL stereo; + DXGI_SAMPLE_DESC sampleDesc; + DXGI_USAGE bufferUsage; + std::uint32_t bufferCount; + DXGI_SCALING scaling; + DXGI_SWAP_EFFECT swapEffect; + DXGI_ALPHA_MODE alphaMode; + std::uint32_t flags; + }; + + struct DXGI_SWAP_CHAIN_FULLSCREEN_DESC + { + DXGI_RATIONAL refreshRate; + DXGI_MODE_SCANLINE_ORDER scanlineOrdering; + DXGI_MODE_SCALING scaling; + BOOL windowed; + }; +} + +namespace REX::W32 +{ + struct __declspec(novtable, uuid("0AA1AE0A-FA0E-4B84-8644-E05FF8E5ACB5")) + IDXGIAdapter2 : public IDXGIAdapter1 + { + virtual HRESULT GetDesc2(DXGI_ADAPTER_DESC2* a_desc) = 0; + }; + + struct __declspec(novtable, uuid("05008617-FBFD-4051-A790-144884B4F6A9")) + IDXGIDevice2 : public IDXGIDevice1 + { + virtual HRESULT OfferResources(std::uint32_t a_numResources, IDXGIResource* const* a_resources, DXGI_OFFER_RESOURCE_PRIORITY a_priority) = 0; + virtual HRESULT ReclaimResources(std::uint32_t a_numResources, IDXGIResource* const* a_resources, BOOL* a_discarded) = 0; + virtual HRESULT EnqueueSetEvent(HANDLE a_event) = 0; + }; + + struct __declspec(novtable, uuid("EA9DBF1A-C88E-4486-854A-98AA0138F30C")) + IDXGIDisplayControl : public IUnknown + { + virtual BOOL IsStereoEnabled(void) = 0; + virtual void SetStereoEnabled(BOOL a_enabled) = 0; + }; + + struct __declspec(novtable, uuid("50C83A1C-E072-4C48-87B0-3630FA36A6D0")) + IDXGIFactory2 : public IDXGIFactory1 + { + virtual BOOL IsWindowedStereoEnabled(void) = 0; + virtual HRESULT CreateSwapChainForHwnd(IUnknown* a_device, HWND a_wnd, const DXGI_SWAP_CHAIN_DESC1* a_desc, const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* a_fullscreenDesc, IDXGIOutput* a_restrictToOutput, IDXGISwapChain1** a_swapChain) = 0; + virtual HRESULT CreateSwapChainForCoreWindow(IUnknown* a_device, IUnknown* a_window, const DXGI_SWAP_CHAIN_DESC1* a_desc, IDXGIOutput* a_restrictToOutput, IDXGISwapChain1** a_swapChain) = 0; + virtual HRESULT GetSharedResourceAdapterLuid(HANDLE a_resource, LUID* a_luid) = 0; + virtual HRESULT RegisterStereoStatusWindow(HWND a_wnd, std::uint32_t a_msg, std::uint32_t* a_cookie) = 0; + virtual HRESULT RegisterStereoStatusEvent(HANDLE a_event, std::uint32_t* a_cookie) = 0; + virtual void UnregisterStereoStatus(std::uint32_t a_cookie) = 0; + virtual HRESULT RegisterOcclusionStatusWindow(HWND a_wnd, std::uint32_t a_msg, std::uint32_t* a_cookie) = 0; + virtual HRESULT RegisterOcclusionStatusEvent(HANDLE a_event, std::uint32_t* a_cookie) = 0; + virtual void UnregisterOcclusionStatus(std::uint32_t dwCookie) = 0; + virtual HRESULT CreateSwapChainForComposition(IUnknown* a_device, const DXGI_SWAP_CHAIN_DESC1* a_desc, IDXGIOutput* a_restrictToOutput, IDXGISwapChain1** a_swapChain) = 0; + }; + + struct __declspec(novtable, uuid("00CDDEA8-939B-4B83-A340-A685226666CC")) + IDXGIOutput1 : public IDXGIOutput + { + virtual HRESULT GetDisplayModeList1(DXGI_FORMAT a_enumFormat, std::uint32_t a_flags, std::uint32_t* a_numModes, DXGI_MODE_DESC1* a_desc) = 0; + virtual HRESULT FindClosestMatchingMode1(const DXGI_MODE_DESC1* a_modeToMatch, DXGI_MODE_DESC1* a_closestMatch, IUnknown* a_concernedDevice) = 0; + virtual HRESULT GetDisplaySurfaceData1(IDXGIResource* a_destination) = 0; + virtual HRESULT DuplicateOutput(IUnknown* a_device, IDXGIOutputDuplication** a_outputDuplication) = 0; + }; + + struct __declspec(novtable, uuid("191CFAC3-A341-470D-B26E-A864F428319C")) + IDXGIOutputDuplication : public IDXGIObject + { + virtual void GetDesc(DXGI_OUTDUPL_DESC* a_desc) = 0; + virtual HRESULT AcquireNextFrame(std::uint32_t a_timeoutInMilliseconds, DXGI_OUTDUPL_FRAME_INFO* a_frameInfo, IDXGIResource** a_desktopResource) = 0; + virtual HRESULT GetFrameDirtyRects(std::uint32_t a_dirtyRectsBufferSize, RECT* a_dirtyRectsBuffer, std::uint32_t* a_dirtyRectsBufferSizeRequired) = 0; + virtual HRESULT GetFrameMoveRects(std::uint32_t a_moveRectsBufferSize, DXGI_OUTDUPL_MOVE_RECT* a_moveRectBuffer, std::uint32_t* a_moveRectsBufferSizeRequired) = 0; + virtual HRESULT GetFramePointerShape(std::uint32_t a_pointerShapeBufferSize, void* a_pointerShapeBuffer, std::uint32_t* a_pointerShapeBufferSizeRequired, DXGI_OUTDUPL_POINTER_SHAPE_INFO* a_pointerShapeInfo) = 0; + virtual HRESULT MapDesktopSurface(DXGI_MAPPED_RECT* a_lockedRect) = 0; + virtual HRESULT UnMapDesktopSurface(void) = 0; + virtual HRESULT ReleaseFrame(void) = 0; + }; + + struct __declspec(novtable, uuid("30961379-4609-4A41-998E-54FE567EE0C1")) + IDXGIResource1 : public IDXGIResource + { + virtual HRESULT CreateSubresourceSurface(std::uint32_t a_index, IDXGISurface2** a_surface) = 0; + virtual HRESULT CreateSharedHandle(const SECURITY_ATTRIBUTES* a_attributes, std::uint32_t a_access, const wchar_t* a_name, HANDLE* a_handle) = 0; + }; + + struct __declspec(novtable, uuid("ABA496DD-B617-4CB8-A866-BC44D7EB1FA2")) + IDXGISurface2 : public IDXGISurface1 + { + virtual HRESULT GetResource(const IID& a_iid, void** a_parentResource, std::uint32_t* a_subresourceIndex) = 0; + }; + + struct __declspec(novtable, uuid("790A45F7-0D42-4876-983A-0A55CFE6F4AA")) + IDXGISwapChain1 : public IDXGISwapChain + { + virtual HRESULT GetDesc1(DXGI_SWAP_CHAIN_DESC1* a_desc) = 0; + virtual HRESULT GetFullscreenDesc(DXGI_SWAP_CHAIN_FULLSCREEN_DESC* a_desc) = 0; + virtual HRESULT GetHwnd(HWND* a_wnd) = 0; + virtual HRESULT GetCoreWindow(const IID& a_iid, void** a_unk) = 0; + virtual HRESULT Present1(std::uint32_t a_syncInterval, std::uint32_t a_presentFlags, const DXGI_PRESENT_PARAMETERS* a_presentParameters) = 0; + virtual BOOL IsTemporaryMonoSupported(void) = 0; + virtual HRESULT GetRestrictToOutput(IDXGIOutput** a_restrictToOutput) = 0; + virtual HRESULT SetBackgroundColor(const DXGI_RGBA* a_color) = 0; + virtual HRESULT GetBackgroundColor(DXGI_RGBA* a_color) = 0; + virtual HRESULT SetRotation(DXGI_MODE_ROTATION a_rotation) = 0; + virtual HRESULT GetRotation(DXGI_MODE_ROTATION* a_rotation) = 0; + }; +} + +namespace REX::W32 +{ + inline constexpr IID IID_IDXGIAdapter2{ 0x0AA1AE0A, 0xFA0E, 0x4B84, { 0x86, 0x44, 0xE0, 0x5F, 0xF8, 0xE5, 0xAC, 0xB5 } }; + inline constexpr IID IID_IDXGIDevice2{ 0x05008617, 0xFBFD, 0x4051, { 0xA7, 0x90, 0x14, 0x48, 0x84, 0xB4, 0xF6, 0xA9 } }; + inline constexpr IID IID_IDXGIDisplayControl{ 0xEA9DBF1A, 0xC88E, 0x4486, { 0x85, 0x4A, 0x98, 0xAA, 0x01, 0x38, 0xF3, 0x0C } }; + inline constexpr IID IID_IDXGIFactory2{ 0x50C83A1C, 0xE072, 0x4C48, { 0x87, 0xB0, 0x36, 0x30, 0xFA, 0x36, 0xA6, 0xD0 } }; + inline constexpr IID IID_IDXGIOutput1{ 0x00CDDEA8, 0x939B, 0x4B83, { 0xA3, 0x40, 0xA6, 0x85, 0x22, 0x66, 0x66, 0xCC } }; + inline constexpr IID IID_IDXGIOutputDuplication{ 0x191CFAC3, 0xA341, 0x470D, { 0xB2, 0x6E, 0xA8, 0x64, 0xF4, 0x28, 0x31, 0x9C } }; + inline constexpr IID IID_IDXGIResource1{ 0x30961379, 0x4609, 0x4A41, { 0x99, 0x8E, 0x54, 0xFE, 0x56, 0x7E, 0xE0, 0xC1 } }; + inline constexpr IID IID_IDXGISurface2{ 0xABA496DD, 0xB617, 0x4CB8, { 0xA8, 0x66, 0xBC, 0x44, 0xD7, 0xEB, 0x1F, 0xA2 } }; + inline constexpr IID IID_IDXGISwapChain1{ 0x790A45F7, 0x0D42, 0x4876, { 0x98, 0x3A, 0x0A, 0x55, 0xCF, 0xE6, 0xF4, 0xAA } }; +} diff --git a/include/REX/W32/DXGI_3.h b/include/REX/W32/DXGI_3.h new file mode 100644 index 00000000..04333f6d --- /dev/null +++ b/include/REX/W32/DXGI_3.h @@ -0,0 +1,148 @@ +#pragma once + +#include "REX/W32/DXGI_2.h" + +namespace REX::W32 +{ + struct IDXGIDecodeSwapChain; + struct IDXGIDevice3; + struct IDXGIFactory3; + struct IDXGIFactoryMedia; + struct IDXGIOutput2; + struct IDXGIOutput3; + struct IDXGISwapChain2; + struct IDXGISwapChainMedia; +} + +namespace REX::W32 +{ + enum DXGI_FRAME_PRESENTATION_MODE + { + DXGI_FRAME_PRESENTATION_MODE_COMPOSED = 0, + DXGI_FRAME_PRESENTATION_MODE_OVERLAY = 1, + DXGI_FRAME_PRESENTATION_MODE_NONE = 2, + DXGI_FRAME_PRESENTATION_MODE_COMPOSITION_FAILURE = 3, + }; + + enum DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS + { + DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAG_NOMINAL_RANGE = 0x1, + DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAG_BT709 = 0x2, + DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAG_xvYCC = 0x4, + }; + + enum DXGI_OVERLAY_SUPPORT_FLAG + { + DXGI_OVERLAY_SUPPORT_FLAG_DIRECT = 0x1, + DXGI_OVERLAY_SUPPORT_FLAG_SCALING = 0x2, + }; +} + +namespace REX::W32 +{ + struct DXGI_DECODE_SWAP_CHAIN_DESC + { + std::uint32_t flags; + }; + + struct DXGI_FRAME_STATISTICS_MEDIA + { + std::uint32_t presentCount; + std::uint32_t presentRefreshCount; + std::uint32_t syncRefreshCount; + std::int64_t syncQPCTime; + std::int64_t syncGPUTime; + DXGI_FRAME_PRESENTATION_MODE compositionMode; + std::uint32_t approvedPresentDuration; + }; + + struct DXGI_MATRIX_3X2_F + { + float _11; + float _12; + float _21; + float _22; + float _31; + float _32; + }; +} + +namespace REX::W32 +{ + struct __declspec(novtable, uuid("2633066B-4514-4C7A-8FD8-12EA98059D18")) + IDXGIDecodeSwapChain : public IUnknown + { + virtual HRESULT PresentBuffer(std::uint32_t a_bufferToPresent, std::uint32_t a_syncInterval, std::uint32_t a_flags) = 0; + virtual HRESULT SetSourceRect(const RECT* a_rect) = 0; + virtual HRESULT SetTargetRect(const RECT* a_rect) = 0; + virtual HRESULT SetDestSize(std::uint32_t a_width, std::uint32_t a_height) = 0; + virtual HRESULT GetSourceRect(RECT* a_rect) = 0; + virtual HRESULT GetTargetRect(RECT* a_rect) = 0; + virtual HRESULT GetDestSize(std::uint32_t* a_width, std::uint32_t* a_height) = 0; + virtual HRESULT SetColorSpace(DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS a_colorSpace) = 0; + virtual DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS GetColorSpace(void) = 0; + }; + + struct __declspec(novtable, uuid("6007896C-3244-4AFD-BF18-A6D3BEDA5023")) + IDXGIDevice3 : public IDXGIDevice2 + { + virtual void Trim(void) = 0; + }; + + struct __declspec(novtable, uuid("25483823-CD46-4C7D-86CA-47AA95B837BD")) + IDXGIFactory3 : public IDXGIFactory2 + { + virtual std::uint32_t GetCreationFlags(void) = 0; + }; + + struct __declspec(novtable, uuid("41E7D1F2-A591-4F7B-A2E5-FA9C843E1C12")) + IDXGIFactoryMedia : public IUnknown + { + virtual HRESULT CreateSwapChainForCompositionSurfaceHandle(IUnknown* a_device, HANDLE a_surface, const DXGI_SWAP_CHAIN_DESC1* a_desc, IDXGIOutput* a_restrictToOutput, IDXGISwapChain1** a_swapChain) = 0; + virtual HRESULT CreateDecodeSwapChainForCompositionSurfaceHandle(IUnknown* a_device, HANDLE a_surface, DXGI_DECODE_SWAP_CHAIN_DESC* a_desc, IDXGIResource* a_yuvDecodeBuffers, IDXGIOutput* a_restrictToOutput, IDXGIDecodeSwapChain** a_swapChain) = 0; + }; + + struct __declspec(novtable, uuid("595E39D1-2724-4663-99B1-DA969DE28364")) + IDXGIOutput2 : public IDXGIOutput1 + { + virtual BOOL SupportsOverlays(void) = 0; + }; + + struct __declspec(novtable, uuid("8A6BB301-7E7E-41F4-A8E0-5B32F7F99B18")) + IDXGIOutput3 : public IDXGIOutput2 + { + virtual HRESULT CheckOverlaySupport(DXGI_FORMAT a_enumFormat, IUnknown* a_concernedDevice, std::uint32_t* a_flags) = 0; + }; + + struct __declspec(novtable, uuid("A8BE2AC4-199F-4946-B331-79599FB98DE7")) + IDXGISwapChain2 : public IDXGISwapChain1 + { + virtual HRESULT SetSourceSize(std::uint32_t a_width, std::uint32_t a_height) = 0; + virtual HRESULT GetSourceSize(std::uint32_t* a_width, std::uint32_t* a_height) = 0; + virtual HRESULT SetMaximumFrameLatency(std::uint32_t a_maxLatency) = 0; + virtual HRESULT GetMaximumFrameLatency(std::uint32_t* a_maxLatency) = 0; + virtual HANDLE GetFrameLatencyWaitableObject(void) = 0; + virtual HRESULT SetMatrixTransform(const DXGI_MATRIX_3X2_F* a_matrix) = 0; + virtual HRESULT GetMatrixTransform(DXGI_MATRIX_3X2_F* a_matrix) = 0; + }; + + struct __declspec(novtable, uuid("DD95B90B-F05F-4F6A-BD65-25BFB264BD84")) + IDXGISwapChainMedia : public IUnknown + { + virtual HRESULT GetFrameStatisticsMedia(DXGI_FRAME_STATISTICS_MEDIA* a_stats) = 0; + virtual HRESULT SetPresentDuration(std::uint32_t a_duration) = 0; + virtual HRESULT CheckPresentDurationSupport(std::uint32_t a_desiredPresentDuration, std::uint32_t* a_closestSmallerPresentDuration, std::uint32_t* a_closestLargerPresentDuration) = 0; + }; +} + +namespace REX::W32 +{ + inline constexpr IID IID_IDXGIDecodeSwapChain{ 0x2633066B, 0x4514, 0x4C7A, { 0x8F, 0xD8, 0x12, 0xEA, 0x98, 0x05, 0x9D, 0x18 } }; + inline constexpr IID IID_IDXGIDevice3{ 0x6007896C, 0x3244, 0x4AFD, { 0xBF, 0x18, 0xA6, 0xD3, 0xBE, 0xDA, 0x50, 0x23 } }; + inline constexpr IID IID_IDXGIFactory3{ 0x25483823, 0xCD46, 0x4C7D, { 0x86, 0xCA, 0x47, 0xAA, 0x95, 0xB8, 0x37, 0xBD } }; + inline constexpr IID IID_IDXGIFactoryMedia{ 0x41E7D1F2, 0xA591, 0x4F7B, { 0xA2, 0xE5, 0xFA, 0x9C, 0x84, 0x3E, 0x1C, 0x12 } }; + inline constexpr IID IID_IDXGIOutput2{ 0x595E39D1, 0x2724, 0x4663, { 0x99, 0xB1, 0xDA, 0x96, 0x9D, 0xE2, 0x83, 0x64 } }; + inline constexpr IID IID_IDXGIOutput3{ 0x8A6BB301, 0x7E7E, 0x41F4, { 0xA8, 0xE0, 0x5B, 0x32, 0xF7, 0xF9, 0x9B, 0x18 } }; + inline constexpr IID IID_IDXGISwapChain2{ 0xA8BE2AC4, 0x199F, 0x4946, { 0xB3, 0x31, 0x79, 0x59, 0x9F, 0xB9, 0x8D, 0xE7 } }; + inline constexpr IID IID_IDXGISwapChainMedia{ 0xDD95B90B, 0xF05F, 0x4F6A, { 0xBD, 0x65, 0x25, 0xBF, 0xB2, 0x64, 0xBD, 0x84 } }; +} diff --git a/include/REX/W32/DXGI_4.h b/include/REX/W32/DXGI_4.h new file mode 100644 index 00000000..5e60b973 --- /dev/null +++ b/include/REX/W32/DXGI_4.h @@ -0,0 +1,86 @@ +#pragma once + +#include "REX/W32/DXGI_3.h" + +namespace REX::W32 +{ + struct IDXGIAdapter3; + struct IDXGIFactory4; + struct IDXGIOutput4; + struct IDXGISwapChain3; +} + +namespace REX::W32 +{ + enum DXGI_MEMORY_SEGMENT_GROUP + { + DXGI_MEMORY_SEGMENT_GROUP_LOCAL = 0, + DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL = 1, + }; + + enum DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG + { + DXGI_OVERLAY_COLOR_SPACE_SUPPORT_FLAG_PRESENT = 0x1, + }; + + enum DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG + { + DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_PRESENT = 0x1, + DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_OVERLAY_PRESENT = 0x2, + }; +} + +namespace REX::W32 +{ + struct DXGI_QUERY_VIDEO_MEMORY_INFO + { + std::uint64_t budget; + std::uint64_t currentUsage; + std::uint64_t availableForReservation; + std::uint64_t currentReservation; + }; +} + +namespace REX::W32 +{ + struct __declspec(novtable, uuid("645967A4-1392-4310-A798-8053CE3E93FD")) + IDXGIAdapter3 : public IDXGIAdapter2 + { + virtual HRESULT RegisterHardwareContentProtectionTeardownStatusEvent(HANDLE a_event, std::uint32_t* a_cookie) = 0; + virtual void UnregisterHardwareContentProtectionTeardownStatus(std::uint32_t a_cookie) = 0; + virtual HRESULT QueryVideoMemoryInfo(std::uint32_t a_nodeIndex, DXGI_MEMORY_SEGMENT_GROUP a_memorySegmentGroup, DXGI_QUERY_VIDEO_MEMORY_INFO* a_videoMemoryInfo) = 0; + virtual HRESULT SetVideoMemoryReservation(std::uint32_t a_nodeIndex, DXGI_MEMORY_SEGMENT_GROUP a_memorySegmentGroup, std::uint64_t a_reservation) = 0; + virtual HRESULT RegisterVideoMemoryBudgetChangeNotificationEvent(HANDLE a_event, std::uint32_t* a_cookie) = 0; + virtual void UnregisterVideoMemoryBudgetChangeNotification(std::uint32_t a_cookie) = 0; + }; + + struct __declspec(novtable, uuid("1BC6EA02-EF36-464F-BF0C-21CA39E5168A")) + IDXGIFactory4 : public IDXGIFactory3 + { + virtual HRESULT EnumAdapterByLuid(LUID a_luid, const IID& a_iid, void** a_adapter) = 0; + virtual HRESULT EnumWarpAdapter(const IID& a_iid, void** a_adapter) = 0; + }; + + struct __declspec(novtable, uuid("DC7DCA35-2196-414D-9F53-617884032A60")) + IDXGIOutput4 : public IDXGIOutput3 + { + virtual HRESULT CheckOverlayColorSpaceSupport(DXGI_FORMAT a_format, DXGI_COLOR_SPACE_TYPE a_colorSpace, IUnknown* a_concernedDevice, std::uint32_t* a_flags) = 0; + }; + + struct __declspec(novtable, uuid("94D99BDB-F1F8-4AB0-B236-7DA0170EDAB1")) + IDXGISwapChain3 : public IDXGISwapChain2 + { + virtual std::uint32_t GetCurrentBackBufferIndex(void) = 0; + virtual HRESULT CheckColorSpaceSupport(DXGI_COLOR_SPACE_TYPE a_colorSpace, std::uint32_t* a_colorSpaceSupport) = 0; + virtual HRESULT SetColorSpace1(DXGI_COLOR_SPACE_TYPE a_colorSpace) = 0; + virtual HRESULT ResizeBuffers1(std::uint32_t a_bufferCount, std::uint32_t a_width, std::uint32_t a_height, DXGI_FORMAT a_format, std::uint32_t a_swapChainFlags, const std::uint32_t* a_creationNodeMask, IUnknown* const* a_presentQueue) = 0; + }; +} + +namespace REX::W32 +{ + inline constexpr IID IID_IDXGIAdapter3{ 0x645967A4, 0x1392, 0x4310, { 0xA7, 0x98, 0x80, 0x53, 0xCE, 0x3E, 0x93, 0xFD } }; + inline constexpr IID IID_IDXGIFactory4{ 0x1BC6EA02, 0xEF36, 0x464F, { 0xBF, 0x0C, 0x21, 0xCA, 0x39, 0xE5, 0x16, 0x8A } }; + inline constexpr IID IID_IDXGIOutput4{ 0xDC7DCA35, 0x2196, 0x414D, { 0x9F, 0x53, 0x61, 0x78, 0x84, 0x03, 0x2A, 0x60 } }; + inline constexpr IID IID_IDXGISwapChain3{ 0x94D99BDB, 0xF1F8, 0x4AB0, { 0xB2, 0x36, 0x7D, 0xA0, 0x17, 0x0E, 0xDA, 0xB1 } }; +} diff --git a/include/REX/W32/DXGI_5.h b/include/REX/W32/DXGI_5.h new file mode 100644 index 00000000..7ebf3b70 --- /dev/null +++ b/include/REX/W32/DXGI_5.h @@ -0,0 +1,94 @@ +#pragma once + +#include "REX/W32/DXGI_4.h" + +namespace REX::W32 +{ + struct IDXGIDevice4; + struct IDXGIFactory5; + struct IDXGIOutput5; + struct IDXGISwapChain4; +} + +namespace REX::W32 +{ + enum DXGI_FEATURE + { + DXGI_FEATURE_PRESENT_ALLOW_TEARING = 0, + }; + + enum DXGI_HDR_METADATA_TYPE + { + DXGI_HDR_METADATA_TYPE_NONE = 0, + DXGI_HDR_METADATA_TYPE_HDR10 = 1, + DXGI_HDR_METADATA_TYPE_HDR10PLUS = 2, + }; + + enum DXGI_OFFER_RESOURCE_FLAGS + { + DXGI_OFFER_RESOURCE_FLAG_ALLOW_DECOMMIT = 0x1, + }; + + enum DXGI_RECLAIM_RESOURCE_RESULTS + { + DXGI_RECLAIM_RESOURCE_RESULT_OK = 0, + DXGI_RECLAIM_RESOURCE_RESULT_DISCARDED = 1, + DXGI_RECLAIM_RESOURCE_RESULT_NOT_COMMITTED = 2, + }; +} + +namespace REX::W32 +{ + struct DXGI_HDR_METADATA_HDR10 + { + std::uint16_t redPrimary[2]; + std::uint16_t GreenPrimary[2]; + std::uint16_t bluePrimary[2]; + std::uint16_t whitePoint[2]; + std::uint32_t maxMasteringLuminance; + std::uint32_t minMasteringLuminance; + std::uint16_t maxContentLightLevel; + std::uint16_t maxFrameAverageLightLevel; + }; + + struct DXGI_HDR_METADATA_HDR10PLUS + { + std::uint8_t data[72]; + }; +} + +namespace REX::W32 +{ + struct __declspec(novtable, uuid("95B4F95F-D8DA-4CA4-9EE6-3B76D5968A10")) + IDXGIDevice4 : public IDXGIDevice3 + { + virtual HRESULT OfferResources1(std::uint32_t a_numResources, IDXGIResource* const* a_resources, DXGI_OFFER_RESOURCE_PRIORITY a_priority, std::uint32_t a_flags) = 0; + virtual HRESULT ReclaimResources1(std::uint32_t a_numResources, IDXGIResource* const* a_resources, DXGI_RECLAIM_RESOURCE_RESULTS* a_results) = 0; + }; + + struct __declspec(novtable, uuid("7632E1F5-EE65-4DCA-87FD-84CD75F8838D")) + IDXGIFactory5 : public IDXGIFactory4 + { + virtual HRESULT CheckFeatureSupport(DXGI_FEATURE a_feature, void* a_featureSupportData, std::uint32_t a_featureSupportDataSize) = 0; + }; + + struct __declspec(novtable, uuid("80A07424-AB52-42EB-833C-0C42FD282D98")) + IDXGIOutput5 : public IDXGIOutput4 + { + virtual HRESULT DuplicateOutput1(IUnknown* a_device, std::uint32_t a_flags, std::uint32_t a_supportedFormatsCount, const DXGI_FORMAT* a_supportedFormats, IDXGIOutputDuplication** a_outputDuplication) = 0; + }; + + struct __declspec(novtable, uuid("3D585D5A-BD4A-489E-B1F4-3DBCB6452FFB")) + IDXGISwapChain4 : public IDXGISwapChain3 + { + virtual HRESULT SetHDRMetaData(DXGI_HDR_METADATA_TYPE a_type, std::uint32_t a_size, void* a_metaData) = 0; + }; +} + +namespace REX::W32 +{ + inline constexpr IID IID_IDXGIDevice4{ 0x95B4F95F, 0xD8DA, 0x4CA4, { 0x9E, 0xE6, 0x3B, 0x76, 0xD5, 0x96, 0x8A, 0x10 } }; + inline constexpr IID IID_IDXGIFactory5{ 0x7632E1F5, 0xEE65, 0x4DCA, { 0x87, 0xFD, 0x84, 0xCD, 0x75, 0xF8, 0x83, 0x8D } }; + inline constexpr IID IID_IDXGIOutput5{ 0x80A07424, 0xAB52, 0x42EB, { 0x83, 0x3C, 0x0C, 0x42, 0xFD, 0x28, 0x2D, 0x98 } }; + inline constexpr IID IID_IDXGISwapChain4{ 0x3D585D5A, 0xBD4A, 0x489E, { 0xB1, 0xF4, 0x3D, 0xBC, 0xB6, 0x45, 0x2F, 0xFB } }; +} diff --git a/include/REX/W32/DXGI_6.h b/include/REX/W32/DXGI_6.h new file mode 100644 index 00000000..1d291599 --- /dev/null +++ b/include/REX/W32/DXGI_6.h @@ -0,0 +1,114 @@ +#pragma once + +#include "REX/W32/DXGI_5.h" + +namespace REX::W32 +{ + struct IDXGIAdapter4; + struct IDXGIFactory6; + struct IDXGIFactory7; + struct IDXGIOutput6; +} + +namespace REX::W32 +{ + enum DXGI_ADAPTER_FLAG3 + { + DXGI_ADAPTER_FLAG3_NONE = 0, + DXGI_ADAPTER_FLAG3_REMOTE = 1, + DXGI_ADAPTER_FLAG3_SOFTWARE = 2, + DXGI_ADAPTER_FLAG3_ACG_COMPATIBLE = 4, + DXGI_ADAPTER_FLAG3_SUPPORT_MONITORED_FENCES = 8, + DXGI_ADAPTER_FLAG3_SUPPORT_NON_MONITORED_FENCES = 0x10, + DXGI_ADAPTER_FLAG3_KEYED_MUTEX_CONFORMANCE = 0x20, + DXGI_ADAPTER_FLAG3_FORCE_DWORD = 0xFFFFFFFF, + }; + + enum DXGI_GPU_PREFERENCE + { + DXGI_GPU_PREFERENCE_UNSPECIFIED = 0, + DXGI_GPU_PREFERENCE_MINIMUM_POWER = (DXGI_GPU_PREFERENCE_UNSPECIFIED + 1), + DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE = (DXGI_GPU_PREFERENCE_MINIMUM_POWER + 1), + }; + + enum DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAGS + { + DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_FULLSCREEN = 1, + DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_WINDOWED = 2, + DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_CURSOR_STRETCHED = 4, + }; +} + +namespace REX::W32 +{ + struct DXGI_ADAPTER_DESC3 + { + wchar_t description[128]; + std::uint32_t vendorID; + std::uint32_t deviceID; + std::uint32_t subSysID; + std::uint32_t revision; + std::size_t dedicatedVideoMemory; + std::size_t dedicatedSystemMemory; + std::size_t sharedSystemMemory; + LUID adapterLUID; + DXGI_ADAPTER_FLAG3 flags; + DXGI_GRAPHICS_PREEMPTION_GRANULARITY graphicsPreemptionGranularity; + DXGI_COMPUTE_PREEMPTION_GRANULARITY computePreemptionGranularity; + }; + + struct DXGI_OUTPUT_DESC1 + { + wchar_t deviceName[32]; + RECT desktopCoordinates; + BOOL attachedToDesktop; + DXGI_MODE_ROTATION rotation; + HMONITOR monitor; + std::uint32_t bitsPerColor; + DXGI_COLOR_SPACE_TYPE colorSpace; + float redPrimary[2]; + float greenPrimary[2]; + float bluePrimary[2]; + float whitePoint[2]; + float minLuminance; + float maxLuminance; + float maxFullFrameLuminance; + }; +} + +namespace REX::W32 +{ + struct __declspec(novtable, uuid("3C8D99D1-4FBF-4181-A82C-AF66BF7BD24E")) + IDXGIAdapter4 : public IDXGIAdapter3 + { + virtual HRESULT GetDesc3(DXGI_ADAPTER_DESC3* a_desc) = 0; + }; + + struct __declspec(novtable, uuid("C1B6694F-FF09-44A9-B03C-77900A0A1D17")) + IDXGIFactory6 : public IDXGIFactory5 + { + virtual HRESULT EnumAdapterByGpuPreference(std::uint32_t a_adapterFlags, DXGI_GPU_PREFERENCE a_gpuPreference, const IID& a_iid, void** a_adapter) = 0; + }; + + struct __declspec(novtable, uuid("A4966EED-76DB-44DA-84C1-EE9A7AFB20A8")) + IDXGIFactory7 : public IDXGIFactory6 + { + virtual HRESULT RegisterAdaptersChangedEvent(HANDLE a_event, std::uint32_t* a_cookie) = 0; + virtual HRESULT UnregisterAdaptersChangedEvent(std::uint32_t a_cookie) = 0; + }; + + struct __declspec(novtable, uuid("068346E8-AAEC-4B84-ADD7-137F513F77A1")) + IDXGIOutput6 : public IDXGIOutput5 + { + virtual HRESULT GetDesc1(DXGI_OUTPUT_DESC1* a_desc) = 0; + virtual HRESULT CheckHardwareCompositionSupport(std::uint32_t* a_flags) = 0; + }; +} + +namespace REX::W32 +{ + inline constexpr IID IID_IDXGIAdapter4{ 0x3C8D99D1, 0x4FBF, 0x4181, { 0xA8, 0x2C, 0xAF, 0x66, 0xBF, 0x7B, 0xD2, 0x4E } }; + inline constexpr IID IID_IDXGIFactory6{ 0xC1B6694F, 0xFF09, 0x44A9, { 0xB0, 0x3C, 0x77, 0x90, 0x0A, 0x0A, 0x1D, 0x17 } }; + inline constexpr IID IID_IDXGIFactory7{ 0xA4966EED, 0x76DB, 0x44DA, { 0x84, 0xC1, 0xEE, 0x9A, 0x7A, 0xFB, 0x20, 0xA8 } }; + inline constexpr IID IID_IDXGIOutput6{ 0x068346E8, 0xAAEC, 0x4B84, { 0xAD, 0xD7, 0x13, 0x7F, 0x51, 0x3F, 0x77, 0xA1 } }; +} diff --git a/include/REX/W32/KERNEL32.h b/include/REX/W32/KERNEL32.h new file mode 100644 index 00000000..cd470a3a --- /dev/null +++ b/include/REX/W32/KERNEL32.h @@ -0,0 +1,545 @@ +#pragma once + +#include "REX/W32/BASE.h" + +namespace REX::W32 +{ + // standard access + inline constexpr auto STANDARD_RIGHTS_REQUIRED{ 0x000F0000 }; + inline constexpr auto STANDARD_RIGHTS_ALL{ 0x001F0000 }; + + // code page identifiers + inline constexpr auto CP_UTF8{ 65001u }; + + // memory allocation types + inline constexpr auto MEM_COMMIT{ 0x00001000u }; + inline constexpr auto MEM_RESERVE{ 0x00002000u }; + inline constexpr auto MEM_DECOMMIT{ 0x00004000u }; + inline constexpr auto MEM_RELEASE{ 0x00008000u }; + inline constexpr auto MEM_FREE{ 0x00010000u }; + inline constexpr auto MEM_RESET{ 0x00080000u }; + inline constexpr auto MEM_RESET_UNDO{ 0x01000000u }; + + // memory page protection attributes + inline constexpr auto PAGE_NOACCESS{ 0x00000001u }; + inline constexpr auto PAGE_READONLY{ 0x00000002u }; + inline constexpr auto PAGE_READWRITE{ 0x00000004u }; + inline constexpr auto PAGE_WRITECOPY{ 0x00000008u }; + inline constexpr auto PAGE_EXECUTE{ 0x00000010u }; + inline constexpr auto PAGE_EXECUTE_READ{ 0x00000020u }; + inline constexpr auto PAGE_EXECUTE_READWRITE{ 0x00000040u }; + + // memory section + inline constexpr auto SECTION_QUERY{ 0x00000001 }; + inline constexpr auto SECTION_MAP_WRITE{ 0x00000002 }; + inline constexpr auto SECTION_MAP_READ{ 0x00000004 }; + inline constexpr auto SECTION_MAP_EXECUTE{ 0x00000008 }; + inline constexpr auto SECTION_EXTEND_SIZE{ 0x00000010 }; + inline constexpr auto SECTION_MAP_EXECUTE_EXPLICIT{ 0x00000020 }; + inline constexpr auto SECTION_ALL_ACCESS{ + STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_WRITE | SECTION_MAP_READ | SECTION_MAP_EXECUTE | SECTION_EXTEND_SIZE + }; + + // file attributes + inline constexpr auto FILE_ATTRIBUTE_READONLY{ 0x00000001u }; + inline constexpr auto FILE_ATTRIBUTE_HIDDEN{ 0x00000002u }; + inline constexpr auto FILE_ATTRIBUTE_SYSTEM{ 0x00000004u }; + inline constexpr auto FILE_ATTRIBUTE_DIRECTORY{ 0x00000010u }; + inline constexpr auto FILE_ATTRIBUTE_ARCHIVE{ 0x00000020u }; + inline constexpr auto FILE_ATTRIBUTE_DEVICE{ 0x00000040 }; + inline constexpr auto FILE_ATTRIBUTE_NORMAL{ 0x00000080 }; + inline constexpr auto FILE_ATTRIBUTE_TEMPORARY{ 0x00000100 }; + inline constexpr auto FILE_ATTRIBUTE_SPARSE_FILE{ 0x00000200 }; + inline constexpr auto FILE_ATTRIBUTE_REPARSE_POINT{ 0x00000400 }; + inline constexpr auto FILE_ATTRIBUTE_COMPRESSED{ 0x00000800 }; + inline constexpr auto FILE_ATTRIBUTE_OFFLINE{ 0x00001000 }; + inline constexpr auto FILE_ATTRIBUTE_NOT_CONTENT_INDEXED{ 0x00002000 }; + inline constexpr auto FILE_ATTRIBUTE_ENCRYPTED{ 0x00004000 }; + inline constexpr auto FILE_ATTRIBUTE_INTEGRITY_STREAM{ 0x00008000 }; + inline constexpr auto FILE_ATTRIBUTE_VIRTUAL{ 0x00010000 }; + inline constexpr auto FILE_ATTRIBUTE_NO_SCRUB_DATA{ 0x00020000 }; + inline constexpr auto FILE_ATTRIBUTE_EA{ 0x00040000 }; + inline constexpr auto FILE_ATTRIBUTE_PINNED{ 0x00080000 }; + inline constexpr auto FILE_ATTRIBUTE_UNPINNED{ 0x00100000 }; + inline constexpr auto FILE_ATTRIBUTE_RECALL_ON_OPEN{ 0x00040000 }; + inline constexpr auto FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS{ 0x00400000 }; + + // file creation diposition + inline constexpr auto CREATE_NEW{ 1 }; + inline constexpr auto CREATE_ALWAYS{ 2 }; + inline constexpr auto OPEN_EXISTING{ 3 }; + inline constexpr auto OPEN_ALWAYS{ 4 }; + inline constexpr auto TRUNCATE_EXISTING{ 5 }; + + // file share mode + inline constexpr auto FILE_SHARE_READ{ 0x00000001 }; + inline constexpr auto FILE_SHARE_WRITE{ 0x00000002 }; + inline constexpr auto FILE_SHARE_DELETE{ 0x00000004 }; + + // file mapping flags + inline constexpr auto FILE_MAP_ALL_ACCESS{ SECTION_ALL_ACCESS }; + inline constexpr auto FILE_MAP_COPY{ 0x00000001u }; + inline constexpr auto FILE_MAP_WRITE{ 0x00000002u }; + inline constexpr auto FILE_MAP_READ{ 0x00000004u }; + inline constexpr auto FILE_MAP_EXECUTE{ 0x00000020u }; + inline constexpr auto FILE_MAP_LARGE_PAGES{ 0x20000000u }; + inline constexpr auto FILE_MAP_TARGETS_INVALID{ 0x40000000u }; + inline constexpr auto FILE_MAP_RESERVE{ 0x80000000u }; + + // file open mode flags + inline constexpr auto GENERIC_READ{ 0x80000000L }; + inline constexpr auto GENERIC_WRITE{ 0x40000000L }; + inline constexpr auto GENERIC_EXECUTE{ 0x20000000L }; + inline constexpr auto GENERIC_ALL{ 0x10000000L }; + + // pe image header + inline constexpr auto IMAGE_DOS_SIGNATURE{ 0x5A4Du }; + inline constexpr auto IMAGE_NT_SIGNATURE{ 0x00004550u }; + inline constexpr auto IMAGE_NT_OPTIONAL_HDR32_MAGIC{ 0x10Bu }; + inline constexpr auto IMAGE_NT_OPTIONAL_HDR64_MAGIC{ 0x20Bu }; + + // pe image directory entries + inline constexpr auto IMAGE_DIRECTORY_ENTRY_EXPORT{ 0u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_IMPORT{ 1u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_RESOURCE{ 2u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_EXCEPTION{ 3u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_SECURITY{ 4u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_BASERELOC{ 5u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_DEBUG{ 6u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_ARCHITECTURE{ 7u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_GLOBALPTR{ 8u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_TLS{ 9u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG{ 10u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT{ 11u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_IAT{ 12u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT{ 13u }; + inline constexpr auto IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR{ 14u }; + inline constexpr auto IMAGE_NUMBEROF_DIRECTORY_ENTRIES{ 16u }; + + // pe image ordinal + inline constexpr auto IMAGE_ORDINAL_FLAG32{ 0x80000000u }; + inline constexpr auto IMAGE_ORDINAL_FLAG64{ 0x8000000000000000ull }; + + // pe image section header characteristics + inline constexpr auto IMAGE_SCN_MEM_SHARED{ 0x10000000u }; + inline constexpr auto IMAGE_SCN_MEM_EXECUTE{ 0x20000000u }; + inline constexpr auto IMAGE_SCN_MEM_READ{ 0x40000000u }; + inline constexpr auto IMAGE_SCN_MEM_WRITE{ 0x80000000u }; + inline constexpr auto IMAGE_SIZEOF_SECTION_HEADER{ 40u }; + inline constexpr auto IMAGE_SIZEOF_SHORT_NAME{ 8u }; + + // process creation flags + inline constexpr auto DEBUG_PROCESS{ 0x00000001u }; + inline constexpr auto DEBUG_ONLY_THIS_PROCESS{ 0x00000002u }; + inline constexpr auto CREATE_SUSPENDED{ 0x00000004u }; + inline constexpr auto DETACHED_PROCESS{ 0x00000008u }; + inline constexpr auto CREATE_NEW_CONSOLE{ 0x00000010u }; + inline constexpr auto NORMAL_PRIORITY_CLASS{ 0x00000020u }; + inline constexpr auto IDLE_PRIORITY_CLASS{ 0x00000040u }; + inline constexpr auto HIGH_PRIORITY_CLASS{ 0x00000080u }; + inline constexpr auto REALTIME_PRIORITY_CLASS{ 0x00000100u }; + inline constexpr auto CREATE_NEW_PROCESS_GROUP{ 0x00000200u }; + inline constexpr auto CREATE_UNICODE_ENVIRONMENT{ 0x00000400u }; + inline constexpr auto CREATE_FORCEDOS{ 0x00002000u }; + inline constexpr auto BELOW_NORMAL_PRIORITY_CLASS{ 0x00004000u }; + inline constexpr auto ABOVE_NORMAL_PRIORITY_CLASS{ 0x00008000u }; + inline constexpr auto INHERIT_PARENT_AFFINITY{ 0x00010000u }; + inline constexpr auto CREATE_PROTECTED_PROCESS{ 0x00040000u }; + inline constexpr auto EXTENDED_STARTUPINFO_PRESENT{ 0x00080000u }; + inline constexpr auto PROCESS_MODE_BACKGROUND_BEGIN{ 0x00100000u }; + inline constexpr auto PROCESS_MODE_BACKGROUND_END{ 0x00200000u }; + inline constexpr auto CREATE_SECURE_PROCESS{ 0x00400000 }; + inline constexpr auto CREATE_BREAKAWAY_FROM_JOB{ 0x01000000u }; + inline constexpr auto CREATE_PRESERVE_CODE_AUTHZ_LEVEL{ 0x02000000u }; + inline constexpr auto CREATE_DEFAULT_ERROR_MODE{ 0x04000000u }; + inline constexpr auto CREATE_NO_WINDOW{ 0x08000000u }; + + // locale map flags + inline constexpr auto LCMAP_LOWERCASE{ 0x00000100u }; + inline constexpr auto LCMAP_UPPERCASE{ 0x00000200u }; + inline constexpr auto LCMAP_TITLECASE{ 0x00000300u }; + inline constexpr auto LCMAP_SORTKEY{ 0x00000400u }; + inline constexpr auto LCMAP_BYTEREV{ 0x00000800u }; + inline constexpr auto LCMAP_HIRAGANA{ 0x00100000u }; + inline constexpr auto LCMAP_KATAKANA{ 0x00200000u }; + inline constexpr auto LCMAP_HALFWIDTH{ 0x00400000u }; + inline constexpr auto LCMAP_FULLWIDTH{ 0x00800000u }; + inline constexpr auto LCMAP_LINGUISTIC_CASING{ 0x01000000u }; + inline constexpr auto LCMAP_SIMPLIFIED_CHINESE{ 0x02000000u }; + inline constexpr auto LCMAP_TRADITIONAL_CHINESE{ 0x04000000u }; + + // locale names + inline constexpr auto LOCALE_NAME_USER_DEFAULT{ nullptr }; + inline constexpr auto LOCALE_NAME_INVARIANT{ L"" }; + inline constexpr auto LOCALE_NAME_SYSTEM_DEFAULT{ L"!x-sys-default-locale" }; +} + +namespace REX::W32 +{ + struct IMAGE_DATA_DIRECTORY + { + std::uint32_t virtualAddress; + std::uint32_t size; + }; + static_assert(sizeof(IMAGE_DATA_DIRECTORY) == 0x8); + + struct IMAGE_DOS_HEADER + { + std::uint16_t magic; + std::uint16_t cblp; + std::uint16_t cp; + std::uint16_t crlc; + std::uint16_t cparhdr; + std::uint16_t minalloc; + std::uint16_t maxalloc; + std::uint16_t ss; + std::uint16_t sp; + std::uint16_t csum; + std::uint16_t ip; + std::uint16_t cs; + std::uint16_t lfarlc; + std::uint16_t ovno; + std::uint16_t res[4]; + std::uint16_t oemid; + std::uint16_t oeminfo; + std::uint16_t res2[10]; + std::int32_t lfanew; + }; + static_assert(sizeof(IMAGE_DOS_HEADER) == 0x40); + + struct IMAGE_FILE_HEADER + { + std::uint16_t machine; + std::uint16_t sectionCount; + std::uint32_t timeDateStamp; + std::uint32_t symbolTablePtr; + std::uint32_t symbolCount; + std::uint16_t optionalHeaderSize; + std::uint16_t characteristics; + }; + static_assert(sizeof(IMAGE_FILE_HEADER) == 0x14); + + struct IMAGE_IMPORT_BY_NAME + { + std::uint16_t hint; + char name[1]; + }; + static_assert(sizeof(IMAGE_IMPORT_BY_NAME) == 0x4); + + struct IMAGE_IMPORT_DESCRIPTOR + { + union + { + std::uint32_t characteristics; + std::uint32_t firstThunkOriginal; + }; + + std::uint32_t timeDateStamp; + std::uint32_t forwarderChain; + std::uint32_t name; + std::uint32_t firstThunk; + }; + static_assert(sizeof(IMAGE_IMPORT_DESCRIPTOR) == 0x14); + + struct IMAGE_OPTIONAL_HEADER64 + { + std::uint16_t magic; + std::uint8_t linkerVersionMajor; + std::uint8_t linkerVersionMinor; + std::uint32_t codeSize; + std::uint32_t initializedDataSize; + std::uint32_t uninitializedDataSize; + std::uint32_t entryPointAddress; + std::uint32_t codeBase; + std::uint64_t imageBase; + std::uint32_t sectionAlignment; + std::uint32_t fileAlignment; + std::uint16_t osVersionMajor; + std::uint16_t osVersionMinor; + std::uint16_t imageVersionMajor; + std::uint16_t imageVersionMinor; + std::uint16_t subsystemVersionMajor; + std::uint16_t subsystemVersionMinor; + std::uint32_t win32Version; + std::uint32_t imageSize; + std::uint32_t headersSize; + std::uint32_t checksum; + std::uint16_t subsystem; + std::uint16_t dllCharacteristics; + std::uint64_t stackReserveSize; + std::uint64_t stackCommitSize; + std::uint64_t heapReserveSize; + std::uint64_t heapCommitSize; + std::uint32_t loaderFlags; + std::uint32_t rvaAndSizesCount; + IMAGE_DATA_DIRECTORY dataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; + }; + static_assert(sizeof(IMAGE_OPTIONAL_HEADER64) == 0xF0); + + struct IMAGE_NT_HEADERS64 + { + std::uint32_t signature; + IMAGE_FILE_HEADER fileHeader; + IMAGE_OPTIONAL_HEADER64 optionalHeader; + }; + static_assert(sizeof(IMAGE_NT_HEADERS64) == 0x108); + + struct IMAGE_SECTION_HEADER + { + std::uint8_t name[IMAGE_SIZEOF_SHORT_NAME]; + union + { + std::uint32_t physicalAddress; + std::uint32_t virtualSize; + }; + std::uint32_t virtualAddress; + std::uint32_t rawDataSize; + std::uint32_t rawDataPtr; + std::uint32_t relocationsPtr; + std::uint32_t lineNumbersPtr; + std::uint16_t relocationsCount; + std::uint16_t lineNumbersCount; + std::uint32_t characteristics; + }; + static_assert(sizeof(IMAGE_SECTION_HEADER) == 0x28); + + struct IMAGE_THUNK_DATA64 + { + union + { + std::uint64_t forwarderString; + std::uint64_t function; + std::uint64_t ordinal; + std::uint64_t address; + }; + }; + static_assert(sizeof(IMAGE_THUNK_DATA64) == 0x8); + + struct MEMORY_BASIC_INFORMATION + { + void* baseAddress; + void* allocationBase; + std::uint32_t allocationProtect; + std::uint16_t partitionID; + std::size_t regionSize; + std::uint32_t state; + std::uint32_t protect; + std::uint32_t type; + }; + static_assert(sizeof(MEMORY_BASIC_INFORMATION) == 0x30); + + struct NLSVERSIONINFO + { + std::uint32_t nlsVersionInfoSize; + std::uint32_t nlsVersion; + std::uint32_t definedVersion; + std::uint32_t effectiveID; + GUID guidCustomVersion; + }; + static_assert(sizeof(NLSVERSIONINFO) == 0x20); + + struct PROCESS_INFORMATION + { + void* process; + void* thread; + std::uint32_t processID; + std::uint32_t threadID; + }; + static_assert(sizeof(PROCESS_INFORMATION) == 0x18); + + struct STARTUPINFOA + { + std::uint32_t size; + char* reserved0; + char* desktop; + char* title; + std::uint32_t x; + std::uint32_t y; + std::uint32_t xSize; + std::uint32_t ySize; + std::uint32_t xCountChars; + std::uint32_t yCountChars; + std::uint32_t fillAttribute; + std::uint32_t flags; + std::uint16_t showWindow; + std::uint16_t reserved1; + std::uint8_t* reserved2; + void* stdIn; + void* stdOut; + void* stdErr; + }; + static_assert(sizeof(STARTUPINFOA) == 0x68); + + struct STARTUPINFOW + { + std::uint32_t size; + wchar_t* reserved0; + wchar_t* desktop; + wchar_t* title; + std::uint32_t x; + std::uint32_t y; + std::uint32_t xSize; + std::uint32_t ySize; + std::uint32_t xCountChars; + std::uint32_t yCountChars; + std::uint32_t fillAttribute; + std::uint32_t flags; + std::uint16_t showWindow; + std::uint16_t reserved1; + std::uint8_t* reserved2; + void* stdIn; + void* stdOut; + void* stdErr; + }; + static_assert(sizeof(STARTUPINFOW) == 0x68); + + struct SYSTEM_INFO + { + union + { + std::uint32_t oemID; + struct + { + std::uint16_t processorArch; + std::uint16_t reserved; + }; + }; + std::uint32_t pageSize; + void* appAddressMin; + void* appAddressMax; + std::uintptr_t processorActiveMask; + std::uint32_t processorCount; + std::uint32_t processorType; + std::uint32_t allocationGranularity; + std::uint16_t processorLevel; + std::uint16_t processorRevision; + }; + static_assert(sizeof(SYSTEM_INFO) == 0x30); + + struct WIN32_FIND_DATAA + { + std::uint32_t fileAttributes; + FILETIME creationTime; + FILETIME lastAccessTime; + FILETIME lastWriteTime; + std::uint32_t fileSizeHi; + std::uint32_t fileSizeLo; + std::uint32_t reserved0; + std::uint32_t reserved1; + char fileName[MAX_PATH]; + char fileNameAlt[14]; + }; + static_assert(sizeof(WIN32_FIND_DATAA) == 0x140); + + struct WIN32_FIND_DATAW + { + std::uint32_t fileAttributes; + FILETIME creationTime; + FILETIME lastAccessTime; + FILETIME lastWriteTime; + std::uint32_t fileSizeHi; + std::uint32_t fileSizeLo; + std::uint32_t reserved0; + std::uint32_t reserved1; + wchar_t fileName[MAX_PATH]; + wchar_t fileNameAlt[14]; + }; + static_assert(sizeof(WIN32_FIND_DATAW) == 0x250); +} + +namespace REX::W32 +{ + using THREAD_START_ROUTINE = std::uint32_t(void* a_param); +} + +namespace REX::W32 +{ + bool CloseHandle(HANDLE a_handle) noexcept; + HANDLE CreateFileA(const char* a_fileName, std::uint32_t a_desiredAccess, std::uint32_t a_shareMode, SECURITY_ATTRIBUTES* a_attributes, std::uint32_t a_creationDisposition, std::uint32_t a_flags, HANDLE a_templateFile); + HANDLE CreateFileW(const wchar_t* a_fileName, std::uint32_t a_desiredAccess, std::uint32_t a_shareMode, SECURITY_ATTRIBUTES* a_attributes, std::uint32_t a_creationDisposition, std::uint32_t a_flags, HANDLE a_templateFile); + HANDLE CreateFileMappingA(HANDLE a_file, SECURITY_ATTRIBUTES* a_attributes, std::uint32_t a_protect, std::uint32_t a_maxSizeHigh, std::uint32_t a_maxSizeLow, const char* a_name) noexcept; + HANDLE CreateFileMappingW(HANDLE a_file, SECURITY_ATTRIBUTES* a_attributes, std::uint32_t a_protect, std::uint32_t a_maxSizeHigh, std::uint32_t a_maxSizeLow, const wchar_t* a_name) noexcept; + bool CreateProcessA(const char* a_name, char* a_cmd, SECURITY_ATTRIBUTES* a_procAttr, SECURITY_ATTRIBUTES* a_threadAttr, bool a_inheritHandles, std::uint32_t a_flags, void* a_env, const char* a_curDir, STARTUPINFOA* a_startInfo, PROCESS_INFORMATION* a_procInfo) noexcept; + bool CreateProcessW(const wchar_t* a_name, wchar_t* a_cmd, SECURITY_ATTRIBUTES* a_procAttr, SECURITY_ATTRIBUTES* a_threadAttr, bool a_inheritHandles, std::uint32_t a_flags, void* a_env, const wchar_t* a_curDir, STARTUPINFOW* a_startInfo, PROCESS_INFORMATION* a_procInfo) noexcept; + HANDLE CreateRemoteThread(HANDLE a_process, SECURITY_ATTRIBUTES* a_threadAttr, std::size_t a_stackSize, THREAD_START_ROUTINE* a_startAddr, void* a_param, std::uint32_t a_flags, std::uint32_t* a_threadID) noexcept; + HANDLE CreateSemaphoreA(SECURITY_ATTRIBUTES* a_semaphoreAttr, std::int32_t a_initCount, std::int32_t a_maxCount, const char* a_name); + HANDLE CreateThread(SECURITY_ATTRIBUTES* a_threadAttr, std::size_t a_stackSize, THREAD_START_ROUTINE* a_startAddr, void* a_param, std::uint32_t a_flags, std::uint32_t* a_threadID) noexcept; + void DeleteCriticalSection(CRITICAL_SECTION* a_criticalSection); + void EnterCriticalSection(CRITICAL_SECTION* a_criticalSection); + std::uint32_t ExpandEnvironmentStringsA(const char* a_src, char* a_dst, std::uint32_t a_dstLen) noexcept; + std::uint32_t ExpandEnvironmentStringsW(const wchar_t* a_src, wchar_t* a_dst, std::uint32_t a_dstLen) noexcept; + bool FindClose(HANDLE a_file) noexcept; + HANDLE FindFirstFileA(const char* a_name, WIN32_FIND_DATAA* a_data) noexcept; + HANDLE FindFirstFileW(const wchar_t* a_name, WIN32_FIND_DATAW* a_data) noexcept; + bool FindNextFileA(HANDLE a_file, WIN32_FIND_DATAA* a_data) noexcept; + bool FindNextFileW(HANDLE a_file, WIN32_FIND_DATAW* a_data) noexcept; + bool FlushInstructionCache(HANDLE a_process, const void* a_baseAddr, std::size_t a_size) noexcept; + bool FreeLibrary(HMODULE a_module) noexcept; + bool GetComputerNameA(char* a_buffer, std::uint32_t* a_size) noexcept; + bool GetComputerNameW(wchar_t* a_buffer, std::uint32_t* a_size) noexcept; + std::uint32_t GetCurrentDirectoryA(std::uint32_t a_size, char* a_buffer) noexcept; + std::uint32_t GetCurrentDirectoryW(std::uint32_t a_size, wchar_t* a_buffer) noexcept; + HMODULE GetCurrentModule() noexcept; + HANDLE GetCurrentProcess() noexcept; + std::uint32_t GetCurrentThreadId() noexcept; + std::uint32_t GetEnvironmentVariableA(const char* a_name, char* a_buf, std::uint32_t a_bufLen) noexcept; + std::uint32_t GetEnvironmentVariableW(const wchar_t* a_name, wchar_t* a_buf, std::uint32_t a_bufLen) noexcept; + bool GetFileSizeEx(HANDLE a_file, LARGE_INTEGER* a_fileSize) noexcept; + std::uint32_t GetLastError() noexcept; + std::uint32_t GetModuleFileNameA(HMODULE a_module, char* a_name, std::uint32_t a_nameLen) noexcept; + std::uint32_t GetModuleFileNameW(HMODULE a_module, wchar_t* a_name, std::uint32_t a_nameLen) noexcept; + HMODULE GetModuleHandleA(const char* a_name) noexcept; + HMODULE GetModuleHandleW(const wchar_t* a_name) noexcept; + std::uint32_t GetPrivateProfileIntA(const char* a_app, const char* a_key, std::int32_t a_default, const char* a_name) noexcept; + std::uint32_t GetPrivateProfileIntW(const wchar_t* a_app, const wchar_t* a_key, std::int32_t a_default, const wchar_t* a_name) noexcept; + std::uint32_t GetPrivateProfileStringA(const char* a_app, const char* a_key, const char* a_default, char* a_buf, std::uint32_t a_bufLen, const char* a_name) noexcept; + std::uint32_t GetPrivateProfileStringW(const wchar_t* a_app, const wchar_t* a_key, const wchar_t* a_default, wchar_t* a_buf, std::uint32_t a_bufLen, const wchar_t* a_name) noexcept; + void* GetProcAddress(HMODULE a_module, const char* a_name) noexcept; + std::string_view GetProcPath(HMODULE a_handle); + void GetSystemInfo(SYSTEM_INFO* a_info) noexcept; + bool IMAGE_SNAP_BY_ORDINAL64(std::uint64_t a_ordinal) noexcept; + IMAGE_SECTION_HEADER* IMAGE_FIRST_SECTION(const IMAGE_NT_HEADERS64* a_header) noexcept; + bool InitializeCriticalSectionAndSpinCount(CRITICAL_SECTION* a_criticalSection, std::uint32_t a_spinCount); + std::uint32_t InterlockedCompareExchange(volatile std::uint32_t* a_target, std::uint32_t a_value, std::uint32_t a_compare) noexcept; + std::uint64_t InterlockedCompareExchange64(volatile std::uint64_t* a_target, std::uint64_t a_value, std::uint64_t a_compare) noexcept; + std::uint32_t InterlockedDecrement(volatile std::uint32_t* a_target) noexcept; + std::uint64_t InterlockedDecrement64(volatile std::uint64_t* a_target) noexcept; + std::uint32_t InterlockedExchange(volatile std::uint32_t* a_target, std::uint32_t a_value) noexcept; + std::uint64_t InterlockedExchange64(volatile std::uint64_t* a_target, std::uint64_t a_value) noexcept; + std::uint32_t InterlockedIncrement(volatile std::uint32_t* a_target) noexcept; + std::uint64_t InterlockedIncrement64(volatile std::uint64_t* a_target) noexcept; + bool IsDebuggerPresent() noexcept; + std::int32_t LCMapStringEx(const wchar_t* a_locale, std::uint32_t a_flags, const wchar_t* a_src, std::int32_t a_srcLen, wchar_t* a_dst, std::int32_t a_dstLen, NLSVERSIONINFO* a_info, void* a_reserved, std::intptr_t a_sortHandle) noexcept; + void LeaveCriticalSection(CRITICAL_SECTION* a_criticalSection); + HMODULE LoadLibraryA(const char* a_name) noexcept; + HMODULE LoadLibraryW(const wchar_t* a_name) noexcept; + void* MapViewOfFile(HANDLE a_object, std::uint32_t a_desiredAccess, std::uint32_t a_fileOffsetHi, std::uint32_t a_fileOffsetLo, std::size_t a_numBytes) noexcept; + void* MapViewOfFileEx(HANDLE a_object, std::uint32_t a_desiredAccess, std::uint32_t a_fileOffsetHi, std::uint32_t a_fileOffsetLo, std::size_t a_numBytes, void* a_baseAddr) noexcept; + std::int32_t MultiByteToWideChar(std::uint32_t a_codePage, std::uint32_t a_flags, const char* a_src, std::int32_t a_srcLen, wchar_t* a_dst, std::int32_t a_dstLen) noexcept; + HANDLE OpenFileMappingA(std::uint32_t a_desiredAccess, bool a_inheritHandle, const char* a_name) noexcept; + HANDLE OpenFileMappingW(std::uint32_t a_desiredAccess, bool a_inheritHandle, const wchar_t* a_name) noexcept; + void OutputDebugStringA(const char* a_str) noexcept; + void OutputDebugStringW(const wchar_t* a_str) noexcept; + bool QueryPerformanceCounter(std::int64_t* a_counter) noexcept; + bool QueryPerformanceFrequency(std::int64_t* a_frequency) noexcept; + std::uint32_t ResumeThread(HANDLE a_handle) noexcept; + bool SetEnvironmentVariableA(const char* a_name, const char* a_value) noexcept; + bool SetEnvironmentVariableW(const wchar_t* a_name, const wchar_t* a_value) noexcept; + void Sleep(std::uint32_t a_milliseconds) noexcept; + bool TerminateProcess(HANDLE a_process, std::uint32_t a_exitCode) noexcept; + void* TlsGetValue(std::uint32_t a_index) noexcept; + bool TlsSetValue(std::uint32_t a_index, void* a_value) noexcept; + bool UnmapViewOfFile(const void* a_baseAddress) noexcept; + void* VirtualAlloc(void* a_address, std::size_t a_size, std::uint32_t a_type, std::uint32_t a_protect) noexcept; + void* VirtualAllocEx(HANDLE a_process, void* a_address, std::size_t a_size, std::uint32_t a_type, std::uint32_t a_protect) noexcept; + bool VirtualFree(void* a_address, std::size_t a_size, std::uint32_t a_type) noexcept; + bool VirtualFreeEx(HANDLE a_process, void* a_address, std::size_t a_size, std::uint32_t a_type) noexcept; + bool VirtualProtect(void* a_address, std::size_t a_size, std::uint32_t a_newProtect, std::uint32_t* a_oldProtect) noexcept; + bool VirtualProtectEx(HANDLE a_process, void* a_address, std::size_t a_size, std::uint32_t a_newProtect, std::uint32_t* a_oldProtect) noexcept; + std::size_t VirtualQuery(const void* a_address, MEMORY_BASIC_INFORMATION* a_buf, std::size_t a_bufLen) noexcept; + std::size_t VirtualQueryEx(HANDLE a_process, const void* a_address, MEMORY_BASIC_INFORMATION* a_buf, std::size_t a_bufLen) noexcept; + std::uint32_t WaitForSingleObject(HANDLE a_handle, std::uint32_t a_milliseconds) noexcept; + std::uint32_t WaitForSingleObjectEx(HANDLE a_handle, std::uint32_t a_milliseconds, bool a_alertable) noexcept; + std::int32_t WideCharToMultiByte(std::uint32_t a_codePage, std::uint32_t a_flags, const wchar_t* a_src, std::int32_t a_srcLen, char* a_dst, std::int32_t a_dstLen, const char* a_default, std::int32_t* a_defaultLen); + bool WriteProcessMemory(HANDLE a_process, void* a_address, const void* a_buf, std::size_t a_bufLen, std::size_t* a_bufWritten) noexcept; +} diff --git a/include/REX/W32/OLE32.h b/include/REX/W32/OLE32.h new file mode 100644 index 00000000..517861ec --- /dev/null +++ b/include/REX/W32/OLE32.h @@ -0,0 +1,8 @@ +#pragma once + +#include "REX/W32/BASE.h" + +namespace REX::W32 +{ + void CoTaskMemFree(void* a_block) noexcept; +} diff --git a/include/REX/W32/SHELL32.h b/include/REX/W32/SHELL32.h new file mode 100644 index 00000000..e99e7d29 --- /dev/null +++ b/include/REX/W32/SHELL32.h @@ -0,0 +1,34 @@ +#pragma once + +#include "REX/W32/BASE.h" + +namespace REX::W32 +{ + // known folder ids + inline constexpr GUID FOLDERID_Documents{ 0xFDD39AD0u, 0x238Fu, 0x46AFu, { 0xADu, 0xB4u, 0x6Cu, 0x85u, 0x48u, 0x03u, 0x69u, 0xC7u } }; + inline constexpr GUID FOLDERID_Pictures{ 0x33E28130u, 0x4E1Eu, 0x4676u, { 0x83u, 0x5Au, 0x98u, 0x39u, 0x5Cu, 0x3Bu, 0xC3u, 0xBBu } }; + inline constexpr GUID FOLDERID_ProgramData{ 0x62AB5D82u, 0xFDC1u, 0x4DC3u, { 0xA9u, 0xDDu, 0x07u, 0x0Du, 0x1Du, 0x49u, 0x5Du, 0x97u } }; + + // known folder flags + inline constexpr auto KF_FLAG_DEFAULT{ 0x00000000u }; + inline constexpr auto KF_FLAG_FORCE_APP_DATA_REDIRECTION{ 0x00080000u }; + inline constexpr auto KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET{ 0x00040000u }; + inline constexpr auto KF_FLAG_FORCE_PACKAGE_REDIRECTION{ 0x00020000u }; + inline constexpr auto KF_FLAG_NO_PACKAGE_REDIRECTION{ 0x00010000u }; + inline constexpr auto KF_FLAG_FORCE_APPCONTAINER_REDIRECTION{ 0x00020000u }; + inline constexpr auto KF_FLAG_NO_APPCONTAINER_REDIRECTION{ 0x00010000u }; + inline constexpr auto KF_FLAG_CREATE{ 0x00008000u }; + inline constexpr auto KF_FLAG_DONT_VERIFY{ 0x00004000u }; + inline constexpr auto KF_FLAG_DONT_UNEXPAND{ 0x00002000u }; + inline constexpr auto KF_FLAG_NO_ALIAS{ 0x00001000u }; + inline constexpr auto KF_FLAG_INIT{ 0x00000800u }; + inline constexpr auto KF_FLAG_DEFAULT_PATH{ 0x00000400u }; + inline constexpr auto KF_FLAG_NOT_PARENT_RELATIVE{ 0x00000200u }; + inline constexpr auto KF_FLAG_SIMPLE_IDLIST{ 0x00000100u }; + inline constexpr auto KF_FLAG_ALIAS_ONLY{ 0x80000000u }; +} + +namespace REX::W32 +{ + std::int32_t SHGetKnownFolderPath(const GUID& a_id, std::uint32_t a_flags, void* a_token, wchar_t** a_path) noexcept; +} diff --git a/include/REX/W32/USER32.h b/include/REX/W32/USER32.h new file mode 100644 index 00000000..f3325fa0 --- /dev/null +++ b/include/REX/W32/USER32.h @@ -0,0 +1,293 @@ +#pragma once + +#include "REX/W32/BASE.h" + +namespace REX::W32 +{ + enum GWLP : std::int32_t + { + GWLP_USERDATA = -21, + GWLP_ID = -12, + GWLP_HWNDPARENT = -8, + GWLP_HINSTANCE = -6, + GWLP_WNDPROC = -4, + }; + + enum WM : std::uint32_t + { + WM_NULL = 0x0000u, + WM_CREATE = 0x0001u, + WM_DESTROY = 0x0002u, + WM_MOVE = 0x0003u, + WM_SIZE = 0x0005u, + WM_ACTIVATE = 0x0006u, + WM_SETFOCUS = 0x0007u, + WM_KILLFOCUS = 0x0008u, + WM_ENABLE = 0x000Au, + WM_SETREDRAW = 0x000Bu, + WM_SETTEXT = 0x000Cu, + WM_GETTEXT = 0x000Du, + WM_GETTEXTLENGTH = 0x000Eu, + WM_PAINT = 0x000Fu, + WM_CLOSE = 0x0010u, + WM_QUIT = 0x0012u, + WM_ERASEBKGND = 0x0014u, + WM_SHOWWINDOW = 0x0018u, + WM_ACTIVATEAPP = 0x001Cu, + WM_FONTCHANGE = 0x001Du, + WM_TIMECHANGE = 0x001Eu, + WM_CANCELMODE = 0x001Fu, + WM_SETCURSOR = 0x0020u, + WM_MOUSEACTIVATE = 0x0021u, + WM_CHILDACTIVATE = 0x0022u, + }; + + enum VK : std::uint32_t + { + VK_LBUTTON = 0x1, + VK_RBUTTON = 0x2, + VK_CANCEL = 0x3, + VK_MBUTTON = 0x4, + VK_XBUTTON1 = 0x5, + VK_XBUTTON2 = 0x6, + VK_BACK = 0x8, + VK_TAB = 0x9, + VK_RESERVED_0A = 0xA, + VK_RESERVED_0B = 0xB, + VK_CLEAR = 0xC, + VK_RETURN = 0xD, + VK_SHIFT = 0x10, + VK_CONTROL = 0x11, + VK_MENU = 0x12, + VK_PAUSE = 0x13, + VK_CAPITAL = 0x14, + VK_KANA = 0x15, + VK_HANGUEL = 0x15, + VK_HANGUL = 0x15, + VK_IME_ON = 0x16, + VK_JUNJA = 0x17, + VK_FINAL = 0x18, + VK_HANJA = 0x19, + VK_KANJI = VK_HANJA, + VK_IME_OFF = 0x1A, + VK_ESCAPE = 0x1B, + VK_CONVERT = 0x1C, + VK_NONCONVERT = 0x1D, + VK_ACCEPT = 0x1E, + VK_MODECHANGE = 0x1F, + VK_SPACE = 0x20, + VK_PRIOR = 0x21, + VK_NEXT = 0x22, + VK_END = 0x23, + VK_HOME = 0x24, + VK_LEFT = 0x25, + VK_UP = 0x26, + VK_RIGHT = 0x27, + VK_DOWN = 0x28, + VK_SELECT = 0x29, + VK_PRINT = 0x2A, + VK_EXECUTE = 0x2B, + VK_SNAPSHOT = 0x2C, + VK_INSERT = 0x2D, + VK_DELETE = 0x2E, + VK_HELP = 0x2F, + VK_0 = 0x30, + VK_1 = 0x31, + VK_2 = 0x32, + VK_3 = 0x33, + VK_4 = 0x34, + VK_5 = 0x35, + VK_6 = 0x36, + VK_7 = 0x37, + VK_8 = 0x38, + VK_9 = 0x39, + VK_A = 0x41, + VK_B = 0x42, + VK_C = 0x43, + VK_D = 0x44, + VK_E = 0x45, + VK_F = 0x46, + VK_G = 0x47, + VK_H = 0x48, + VK_I = 0x49, + VK_J = 0x4A, + VK_K = 0x4B, + VK_L = 0x4C, + VK_M = 0x4D, + VK_N = 0x4E, + VK_O = 0x4F, + VK_P = 0x50, + VK_Q = 0x51, + VK_R = 0x52, + VK_S = 0x53, + VK_T = 0x54, + VK_U = 0x55, + VK_V = 0x56, + VK_W = 0x57, + VK_X = 0x58, + VK_Y = 0x59, + VK_Z = 0x5A, + VK_LWIN = 0x5B, + VK_RWIN = 0x5C, + VK_APPS = 0x5D, + VK_RESERVED_5E = 0x5E, + VK_SLEEP = 0x5F, + VK_NUMPAD0 = 0x60, + VK_NUMPAD1 = 0x61, + VK_NUMPAD2 = 0x62, + VK_NUMPAD3 = 0x63, + VK_NUMPAD4 = 0x64, + VK_NUMPAD5 = 0x65, + VK_NUMPAD6 = 0x66, + VK_NUMPAD7 = 0x67, + VK_NUMPAD8 = 0x68, + VK_NUMPAD9 = 0x69, + VK_MULTIPLY = 0x6A, + VK_ADD = 0x6B, + VK_SEPARATOR = 0x6C, + VK_SUBTRACT = 0x6D, + VK_DECIMAL = 0x6E, + VK_DIVIDE = 0x6F, + VK_F1 = 0x70, + VK_F2 = 0x71, + VK_F3 = 0x72, + VK_F4 = 0x73, + VK_F5 = 0x74, + VK_F6 = 0x75, + VK_F7 = 0x76, + VK_F8 = 0x77, + VK_F9 = 0x78, + VK_F10 = 0x79, + VK_F11 = 0x7A, + VK_F12 = 0x7B, + VK_F13 = 0x7C, + VK_F14 = 0x7D, + VK_F15 = 0x7E, + VK_F16 = 0x7F, + VK_F17 = 0x80, + VK_F18 = 0x81, + VK_F19 = 0x82, + VK_F20 = 0x83, + VK_F21 = 0x84, + VK_F22 = 0x85, + VK_F23 = 0x86, + VK_F24 = 0x87, + VK_NUMLOCK = 0x90, + VK_SCROLL = 0x91, + VK_OEMSPECIFIC_92 = 0x92, + VK_OEMSPECIFIC_93 = 0x93, + VK_OEMSPECIFIC_94 = 0x94, + VK_OEMSPECIFIC_95 = 0x95, + VK_OEMSPECIFIC_96 = 0x96, + VK_LSHIFT = 0xA0, + VK_RSHIFT = 0xA1, + VK_LCONTROL = 0xA2, + VK_RCONTROL = 0xA3, + VK_LMENU = 0xA4, + VK_RMENU = 0xA5, + VK_BROWSER_BACK = 0xA6, + VK_BROWSER_FORWARD = 0xA7, + VK_BROWSER_REFRESH = 0xA8, + VK_BROWSER_STOP = 0xA9, + VK_BROWSER_SEARCH = 0xAA, + VK_BROWSER_FAVORITES = 0xAB, + VK_BROWSER_HOME = 0xAC, + VK_VOLUME_MUTE = 0xAD, + VK_VOLUME_DOWN = 0xAE, + VK_VOLUME_UP = 0xAF, + VK_MEDIA_NEXT_TRACK = 0xB0, + VK_MEDIA_PREV_TRACK = 0xB1, + VK_MEDIA_STOP = 0xB2, + VK_MEDIA_PLAY_PAUSE = 0xB3, + VK_LAUNCH_MAIL = 0xB4, + VK_LAUNCH_MEDIA_SELECT = 0xB5, + VK_LAUNCH_APP1 = 0xB6, + VK_LAUNCH_APP2 = 0xB7, + VK_RESERVED_B8 = 0xB8, + VK_RESERVED_B9 = 0xB9, + VK_OEM_1 = 0xBA, + VK_OEM_PLUS = 0xBB, + VK_OEM_COMMA = 0xBC, + VK_OEM_MINUS = 0xBD, + VK_OEM_PERIOD = 0xBE, + VK_OEM_2 = 0xBF, + VK_OEM_3 = 0xC0, + VK_RESERVED_C1 = 0xC1, + VK_RESERVED_C2 = 0xC2, + VK_RESERVED_C3 = 0xC3, + VK_RESERVED_C4 = 0xC4, + VK_RESERVED_C5 = 0xC5, + VK_RESERVED_C6 = 0xC6, + VK_RESERVED_C7 = 0xC7, + VK_RESERVED_C8 = 0xC8, + VK_RESERVED_C9 = 0xC9, + VK_RESERVED_CA = 0xCA, + VK_RESERVED_CB = 0xCB, + VK_RESERVED_CC = 0xCC, + VK_RESERVED_CD = 0xCD, + VK_RESERVED_CE = 0xCE, + VK_RESERVED_CF = 0xCF, + VK_RESERVED_D0 = 0xD0, + VK_RESERVED_D1 = 0xD1, + VK_RESERVED_D2 = 0xD2, + VK_RESERVED_D3 = 0xD3, + VK_RESERVED_D4 = 0xD4, + VK_RESERVED_D5 = 0xD5, + VK_RESERVED_D6 = 0xD6, + VK_RESERVED_D7 = 0xD7, + VK_OEM_4 = 0xDB, + VK_OEM_5 = 0xDC, + VK_OEM_6 = 0xDD, + VK_OEM_7 = 0xDE, + VK_OEM_8 = 0xDF, + VK_RESERVED_E0 = 0xE0, + VK_OEMSPECIFIC_E1 = 0xE1, + VK_OEM_102 = 0xE2, + VK_OEMSPECIFIC_E3 = 0xE3, + VK_OEMSPECIFIC_E4 = 0xE4, + VK_PROCESSKEY = 0xE5, + VK_OEMSPECIFIC_E6 = 0xE6, + VK_PACKET = 0xE7, + VK_OEMSPECIFIC_E9 = 0xE9, + VK_OEMSPECIFIC_EA = 0xEA, + VK_OEMSPECIFIC_EB = 0xEB, + VK_OEMSPECIFIC_EC = 0xEC, + VK_OEMSPECIFIC_ED = 0xED, + VK_OEMSPECIFIC_EE = 0xEE, + VK_OEMSPECIFIC_EF = 0xEF, + VK_OEMSPECIFIC_F0 = 0xF0, + VK_OEMSPECIFIC_F1 = 0xF1, + VK_OEMSPECIFIC_F2 = 0xF2, + VK_OEMSPECIFIC_F3 = 0xF3, + VK_OEMSPECIFIC_F4 = 0xF4, + VK_OEMSPECIFIC_F5 = 0xF5, + VK_ATTN = 0xF6, + VK_CRSEL = 0xF7, + VK_EXSEL = 0xF8, + VK_EREOF = 0xF9, + VK_PLAY = 0xFA, + VK_ZOOM = 0xFB, + VK_NONAME = 0xFC, + VK_PA1 = 0xFD, + VK_OEM_CLEAR = 0xFE, + VK_RESERVED_FF = 0xFF, + }; +} + +namespace REX::W32 +{ + using WNDPROC = std::intptr_t (*)(HWND, std::uint32_t, std::uintptr_t, std::intptr_t); +} + +namespace REX::W32 +{ + bool GetClientRect(HWND a_wnd, RECT* a_rect) noexcept; + std::int32_t GetKeyNameTextA(std::int32_t a_param, char* a_buf, std::int32_t a_bufLen) noexcept; + std::int32_t GetKeyNameTextW(std::int32_t a_param, wchar_t* a_buf, std::int32_t a_bufLen) noexcept; + std::int16_t GetKeyState(std::int32_t a_key) noexcept; + bool GetWindowRect(HWND a_wnd, RECT* a_rect) noexcept; + std::int32_t MessageBoxA(HWND a_wnd, const char* a_text, const char* a_caption, std::uint32_t a_type) noexcept; + std::int32_t MessageBoxW(HWND a_wnd, const wchar_t* a_text, const wchar_t* a_caption, std::uint32_t a_type) noexcept; + std::intptr_t SetWindowLongPtrA(HWND a_wnd, std::int32_t a_index, std::intptr_t a_newPtr) noexcept; + std::int32_t ShowCursor(bool a_show) noexcept; +} diff --git a/include/REX/W32/VERSION.h b/include/REX/W32/VERSION.h new file mode 100644 index 00000000..25c72d90 --- /dev/null +++ b/include/REX/W32/VERSION.h @@ -0,0 +1,13 @@ +#pragma once + +namespace REX::W32 +{ + bool GetFileVersionInfoA(const char* a_name, std::uint32_t a_handle, std::uint32_t a_dataLen, void* a_data) noexcept; + std::uint32_t GetFileVersionInfoSizeA(const char* a_name, std::uint32_t* a_handle) noexcept; + //std::uint32_t GetFileVersionInfoSizeExA(std::uint32_t a_flags, const char* a_name, std::uint32_t* a_handle) noexcept; + std::uint32_t GetFileVersionInfoSizeExW(std::uint32_t a_flags, const wchar_t* a_name, std::uint32_t* a_handle) noexcept; + std::uint32_t GetFileVersionInfoSizeW(const wchar_t* a_name, std::uint32_t* a_handle) noexcept; + bool GetFileVersionInfoW(const wchar_t* a_name, std::uint32_t a_handle, std::uint32_t a_dataLen, void* a_data) noexcept; + bool VerQueryValueA(const void* a_block, const char* a_subBlock, void** a_buf, std::uint32_t* a_bufLen) noexcept; + bool VerQueryValueW(const void* a_block, const wchar_t* a_subBlock, void** a_buf, std::uint32_t* a_bufLen) noexcept; +} diff --git a/include/REX/W32/WS2_32.h b/include/REX/W32/WS2_32.h new file mode 100644 index 00000000..bb28ff85 --- /dev/null +++ b/include/REX/W32/WS2_32.h @@ -0,0 +1,206 @@ +#pragma once + +#include "REX/W32/BASE.h" + +namespace REX::W32 +{ + // winsock2 values + inline constexpr auto INADDR_ANY{ 0x00000000u }; + inline constexpr auto INADDR_LOOPBACK{ 0x7f000001u }; + inline constexpr auto INADDR_BROADCAST{ 0xffffffffu }; + inline constexpr auto INADDR_NONE{ 0xffffffffu }; +} + +namespace REX::W32 +{ + enum ADDRESS_FAMILY : std::uint16_t + { + AF_UNSPEC = 0, + AF_UNIX = 1, + AF_INET = 2, + AF_IMPLINK = 3, + AF_PUP = 4, + AF_CHAOS = 5, + AF_NS = 6, + AF_IPX = AF_NS, + AF_ISO = 7, + AF_OSI = AF_ISO, + AF_ECMA = 8, + AF_DATAKIT = 9, + AF_CCITT = 10, + AF_SNA = 11, + AF_DECnet = 12, + AF_DLI = 13, + AF_LAT = 14, + AF_HYLINK = 15, + AF_APPLETALK = 16, + AF_NETBIOS = 17, + AF_VOICEVIEW = 18, + AF_FIREFOX = 19, + AF_UNKNOWN1 = 20, + AF_BAN = 21, + AF_ATM = 22, + AF_INET6 = 23, + AF_CLUSTER = 24, + AF_12844 = 25, + AF_IRDA = 26, + AF_NETDES = 28, + }; + + enum WSA_ERROR : std::int32_t + { + WSABASEERR = 10000L, + WSAEINTR = 10004L, + WSAEBADF = 10009L, + WSAEACCES = 10013L, + WSAEFAULT = 10014L, + WSAEINVAL = 10022L, + WSAEMFILE = 10024L, + WSAEWOULDBLOCK = 10035L, + WSAEINPROGRESS = 10036L, + WSAEALREADY = 10037L, + WSAENOTSOCK = 10038L, + WSAEDESTADDRREQ = 10039L, + WSAEMSGSIZE = 10040L, + WSAEPROTOTYPE = 10041L, + WSAENOPROTOOPT = 10042L, + WSAEPROTONOSUPPORT = 10043L, + WSAESOCKTNOSUPPORT = 10044L, + WSAEOPNOTSUPP = 10045L, + WSAEPFNOSUPPORT = 10046L, + WSAEAFNOSUPPORT = 10047L, + WSAEADDRINUSE = 10048L, + WSAEADDRNOTAVAIL = 10049L, + WSAENETDOWN = 10050L, + WSAENETUNREACH = 10051L, + WSAENETRESET = 10052L, + WSAECONNABORTED = 10053L, + WSAECONNRESET = 10054L, + WSAENOBUFS = 10055L, + WSAEISCONN = 10056L, + WSAENOTCONN = 10057L, + WSAESHUTDOWN = 10058L, + WSAETOOMANYREFS = 10059L, + WSAETIMEDOUT = 10060L, + WSAECONNREFUSED = 10061L, + WSAELOOP = 10062L, + WSAENAMETOOLONG = 10063L, + WSAEHOSTDOWN = 10064L, + WSAEHOSTUNREACH = 10065L, + WSAENOTEMPTY = 10066L, + WSAEPROCLIM = 10067L, + WSAEUSERS = 10068L, + WSAEDQUOT = 10069L, + WSAESTALE = 10070L, + WSAEREMOTE = 10071L, + WSASYSNOTREADY = 10091L, + WSAVERNOTSUPPORTED = 10092L, + WSANOTINITIALISED = 10093L, + WSAEDISCON = 10101L, + WSAENOMORE = 10102L, + WSAECANCELLED = 10103L, + WSAEINVALIDPROCTABLE = 10104L, + WSAEINVALIDPROVIDER = 10105L, + WSAEPROVIDERFAILEDINIT = 10106L, + WSASYSCALLFAILURE = 10107L, + WSASERVICE_NOT_FOUND = 10108L, + WSATYPE_NOT_FOUND = 10109L, + WSA_E_NO_MORE = 10110L, + WSA_E_CANCELLED = 10111L, + WSAEREFUSED = 10112L, + WSAHOST_NOT_FOUND = 11001L, + WSATRY_AGAIN = 11002L, + WSANO_RECOVERY = 11003L, + WSANO_DATA = 11004L, + WSA_QOS_RECEIVERS = 11005L, + WSA_QOS_SENDERS = 11006L, + WSA_QOS_NO_SENDERS = 11007L, + WSA_QOS_NO_RECEIVERS = 11008L, + WSA_QOS_REQUEST_CONFIRMED = 11009L, + WSA_QOS_ADMISSION_FAILURE = 11010L, + WSA_QOS_POLICY_FAILURE = 11011L, + WSA_QOS_BAD_STYLE = 11012L, + WSA_QOS_BAD_OBJECT = 11013L, + WSA_QOS_TRAFFIC_CTRL_ERROR = 11014L, + WSA_QOS_GENERIC_ERROR = 11015L, + WSA_QOS_ESERVICETYPE = 11016L, + WSA_QOS_EFLOWSPEC = 11017L, + WSA_QOS_EPROVSPECBUF = 11018L, + WSA_QOS_EFILTERSTYLE = 11019L, + WSA_QOS_EFILTERTYPE = 11020L, + WSA_QOS_EFILTERCOUNT = 11021L, + WSA_QOS_EOBJLENGTH = 11022L, + WSA_QOS_EFLOWCOUNT = 11023L, + WSA_QOS_EUNKOWNPSOBJ = 11024L, + WSA_QOS_EPOLICYOBJ = 11025L, + WSA_QOS_EFLOWDESC = 11026L, + WSA_QOS_EPSFLOWSPEC = 11027L, + WSA_QOS_EPSFILTERSPEC = 11028L, + WSA_QOS_ESDMODEOBJ = 11029L, + WSA_QOS_ESHAPERATEOBJ = 11030L, + WSA_QOS_RESERVED_PETYPE = 11031L, + WSA_SECURE_HOST_NOT_FOUND = 11032L, + WSA_IPSEC_NAME_POLICY_ERROR = 11033L, + }; + + using SOCKET = std::uintptr_t; + + struct sockaddr + { + ADDRESS_FAMILY sa_family; + char sa_data[14]; + }; + + // Originally a struct with several #defines that served as aliases to members + // The defines screwed a lot of things up, so it was made a union. + // This means it won't have compatibility with code that uses in_addrs directly and + // also refers to it by its full type identifier (i.e. `struct in_addr`). + union in_addr + { + union in_addr_D + { + struct + { + std::uint8_t s_b1, s_b2, s_b3, s_b4; + } S_un_b; + + struct + { + std::uint16_t s_w1, s_w2; + } S_un_w; + + std::uint32_t S_addr; + } S_un; + + // getting around the #DEFINEs in inaddr.h + struct + { + std::uint8_t s_net; + std::uint8_t s_host; + std::uint8_t s_lh; + std::uint8_t s_impno; + }; + + struct + { + std::uint16_t _s_w1, s_imp; + }; + + std::uint32_t s_addr; + }; + + struct sockaddr_in + { + ADDRESS_FAMILY sin_family; + std::uint16_t sin_port; + in_addr sin_addr; + char sin_zero[8]; + }; +} + +namespace REX::W32 +{ + std::uint16_t htons(std::uint16_t a_host) noexcept; + std::uint32_t ntohl(std::uint32_t a_net) noexcept; + std::int32_t WSAGetLastError() noexcept; +} diff --git a/include/REX/W32/XINPUT.h b/include/REX/W32/XINPUT.h new file mode 100644 index 00000000..071a97aa --- /dev/null +++ b/include/REX/W32/XINPUT.h @@ -0,0 +1,80 @@ +#pragma once + +namespace REX::W32 +{ + inline constexpr std::uint16_t XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE{ 7849 }; + inline constexpr std::uint16_t XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE{ 8689 }; + inline constexpr std::uint8_t XINPUT_GAMEPAD_TRIGGER_THRESHOLD{ 30 }; +} + +namespace REX::W32 +{ + enum XINPUT_GAMEPAD_BUTTON : std::uint16_t + { + XINPUT_GAMEPAD_DPAD_UP = 0x0001, + XINPUT_GAMEPAD_DPAD_DOWN = 0x0002, + XINPUT_GAMEPAD_DPAD_LEFT = 0x0004, + XINPUT_GAMEPAD_DPAD_RIGHT = 0x0008, + XINPUT_GAMEPAD_START = 0x0010, + XINPUT_GAMEPAD_BACK = 0x0020, + XINPUT_GAMEPAD_LEFT_THUMB = 0x0040, + XINPUT_GAMEPAD_RIGHT_THUMB = 0x0080, + XINPUT_GAMEPAD_LEFT_SHOULDER = 0x0100, + XINPUT_GAMEPAD_RIGHT_SHOULDER = 0x0200, + XINPUT_GAMEPAD_A = 0x1000, + XINPUT_GAMEPAD_B = 0x2000, + XINPUT_GAMEPAD_X = 0x4000, + XINPUT_GAMEPAD_Y = 0x8000, + XINPUT_GAMEPAD_BUTTON_MASK = XINPUT_GAMEPAD_DPAD_UP | XINPUT_GAMEPAD_DPAD_DOWN | XINPUT_GAMEPAD_DPAD_LEFT | XINPUT_GAMEPAD_DPAD_RIGHT | XINPUT_GAMEPAD_START | XINPUT_GAMEPAD_BACK | XINPUT_GAMEPAD_LEFT_THUMB | XINPUT_GAMEPAD_RIGHT_THUMB | XINPUT_GAMEPAD_LEFT_SHOULDER | XINPUT_GAMEPAD_RIGHT_SHOULDER | XINPUT_GAMEPAD_A | XINPUT_GAMEPAD_B | XINPUT_GAMEPAD_X | XINPUT_GAMEPAD_Y, + }; +} + +namespace REX::W32 +{ + struct XINPUT_BATTERY_INFORMATION + { + std::uint8_t batteryType; + std::uint8_t batteryLevel; + }; + + struct XINPUT_GAMEPAD + { + std::uint16_t buttons; + std::uint8_t leftTrigger; + std::uint8_t rightTrigger; + std::int16_t thumbLX; + std::int16_t thumbLY; + std::int16_t thumbRX; + std::int16_t thumbRY; + }; + + struct XINPUT_KEYSTROKE + { + std::uint16_t virtualKey; + std::uint16_t unicode; + std::uint16_t flags; + std::uint8_t userIndex; + std::uint8_t hidCode; + }; + + struct XINPUT_STATE + { + std::uint32_t packetNumber; + XINPUT_GAMEPAD gamepad; + }; + + struct XINPUT_VIBRATION + { + std::uint16_t leftMotorSpeed; + std::uint16_t rightMotorSpeed; + }; + + struct XINPUT_CAPABILITIES + { + std::uint8_t type; + std::uint8_t subType; + std::uint16_t flags; + XINPUT_GAMEPAD gamepad; + XINPUT_VIBRATION vibration; + }; +} diff --git a/include/SFSE/Impl/DInputAPI.h b/include/SFSE/Impl/DInputAPI.h deleted file mode 100644 index eeb7ce19..00000000 --- a/include/SFSE/Impl/DInputAPI.h +++ /dev/null @@ -1,595 +0,0 @@ -#pragma once - -#include "WinAPI.h" - -// TODO: This should probably be behind some sort of pragma that allows linking with dinput and dinput8 -namespace RE::DirectInput8 -{ - using DWORD = std::uint32_t; - using LONG = std::int32_t; - using WORD = std::uint16_t; - using BYTE = std::uint8_t; - using UINT = std::uint32_t; - using CHAR = char; - - using LPSTR = char*; - using LPCSTR = const char*; - - using UINT_PTR = std::uintptr_t; - using HANDLE = void*; - using LPDWORD = DWORD*; - using LPVOID = void*; - using LPLONG = LONG*; - using LPWORD = WORD*; - - using GUID = SFSE::WinAPI::GUID; - using LPGUID = GUID*; - using REFGUID = const GUID&; - using FILETIME = SFSE::WinAPI::FILETIME; - using RECT = SFSE::WinAPI::RECT; - using POINT = SFSE::WinAPI::POINT; - - using IID = GUID; - using REFIID = const IID&; - using LPIID = IID*; - using D3DCOLOR = std::uint32_t; - - using HRESULT = SFSE::WinAPI::HRESULT; - using HWND = SFSE::WinAPI::HWND; - using HINSTANCE = SFSE::WinAPI::HINSTANCE; - - enum DIKey : uint32_t - { - DIK_ESCAPE = 0x1, - DIK_1 = 0x2, - DIK_2 = 0x3, - DIK_3 = 0x4, - DIK_4 = 0x5, - DIK_5 = 0x6, - DIK_6 = 0x7, - DIK_7 = 0x8, - DIK_8 = 0x9, - DIK_9 = 0xA, - DIK_0 = 0xB, - DIK_MINUS = 0xC, - DIK_EQUALS = 0xD, - DIK_BACK = 0xE, - DIK_TAB = 0xF, - DIK_Q = 0x10, - DIK_W = 0x11, - DIK_E = 0x12, - DIK_R = 0x13, - DIK_T = 0x14, - DIK_Y = 0x15, - DIK_U = 0x16, - DIK_I = 0x17, - DIK_O = 0x18, - DIK_P = 0x19, - DIK_LBRACKET = 0x1A, - DIK_RBRACKET = 0x1B, - DIK_RETURN = 0x1C, - DIK_LCONTROL = 0x1D, - DIK_A = 0x1E, - DIK_S = 0x1F, - DIK_D = 0x20, - DIK_F = 0x21, - DIK_G = 0x22, - DIK_H = 0x23, - DIK_J = 0x24, - DIK_K = 0x25, - DIK_L = 0x26, - DIK_SEMICOLON = 0x27, - DIK_APOSTROPHE = 0x28, - DIK_GRAVE = 0x29, - DIK_LSHIFT = 0x2A, - DIK_BACKSLASH = 0x2B, - DIK_Z = 0x2C, - DIK_X = 0x2D, - DIK_C = 0x2E, - DIK_V = 0x2F, - DIK_B = 0x30, - DIK_N = 0x31, - DIK_M = 0x32, - DIK_COMMA = 0x33, - DIK_PERIOD = 0x34, - DIK_SLASH = 0x35, - DIK_RSHIFT = 0x36, - DIK_MULTIPLY = 0x37, - DIK_LMENU = 0x38, - DIK_SPACE = 0x39, - DIK_CAPITAL = 0x3A, - DIK_F1 = 0x3B, - DIK_F2 = 0x3C, - DIK_F3 = 0x3D, - DIK_F4 = 0x3E, - DIK_F5 = 0x3F, - DIK_F6 = 0x40, - DIK_F7 = 0x41, - DIK_F8 = 0x42, - DIK_F9 = 0x43, - DIK_F10 = 0x44, - DIK_NUMLOCK = 0x45, - DIK_SCROLL = 0x46, - DIK_NUMPAD7 = 0x47, - DIK_NUMPAD8 = 0x48, - DIK_NUMPAD9 = 0x49, - DIK_SUBTRACT = 0x4A, - DIK_NUMPAD4 = 0x4B, - DIK_NUMPAD5 = 0x4C, - DIK_NUMPAD6 = 0x4D, - DIK_ADD = 0x4E, - DIK_NUMPAD1 = 0x4F, - DIK_NUMPAD2 = 0x50, - DIK_NUMPAD3 = 0x51, - DIK_NUMPAD0 = 0x52, - DIK_DECIMAL = 0x53, - DIK_OEM_102 = 0x56, - DIK_F11 = 0x57, - DIK_F12 = 0x58, - DIK_F13 = 0x64, - DIK_F14 = 0x65, - DIK_F15 = 0x66, - DIK_KANA = 0x70, - DIK_ABNT_C1 = 0x73, - DIK_CONVERT = 0x79, - DIK_NOCONVERT = 0x7B, - DIK_YEN = 0x7D, - DIK_ABNT_C2 = 0x7E, - DIK_NUMPADEQUALS = 0x8D, - DIK_PREVTRACK = 0x90, - DIK_AT = 0x91, - DIK_COLON = 0x92, - DIK_UNDERLINE = 0x93, - DIK_KANJI = 0x94, - DIK_STOP = 0x95, - DIK_AX = 0x96, - DIK_UNLABELED = 0x97, - DIK_NEXTTRACK = 0x99, - DIK_NUMPADENTER = 0x9C, - DIK_RCONTROL = 0x9D, - DIK_MUTE = 0xA0, - DIK_CALCULATOR = 0xA1, - DIK_PLAYPAUSE = 0xA2, - DIK_MEDIASTOP = 0xA4, - DIK_VOLUMEDOWN = 0xAE, - DIK_VOLUMEUP = 0xB0, - DIK_WEBHOME = 0xB2, - DIK_NUMPADCOMMA = 0xB3, - DIK_DIVIDE = 0xB5, - DIK_SYSRQ = 0xB7, - DIK_RMENU = 0xB8, - DIK_PAUSE = 0xC5, - DIK_HOME = 0xC7, - DIK_UP = 0xC8, - DIK_PRIOR = 0xC9, - DIK_LEFT = 0xCB, - DIK_RIGHT = 0xCD, - DIK_END = 0xCF, - DIK_DOWN = 0xD0, - DIK_NEXT = 0xD1, - DIK_INSERT = 0xD2, - DIK_DELETE = 0xD3, - DIK_LWIN = 0xDB, - DIK_RWIN = 0xDC, - DIK_APPS = 0xDD, - DIK_POWER = 0xDE, - DIK_SLEEP = 0xDF, - DIK_WAKE = 0xE3, - DIK_WEBSEARCH = 0xE5, - DIK_WEBFAVORITES = 0xE6, - DIK_WEBREFRESH = 0xE7, - DIK_WEBSTOP = 0xE8, - DIK_WEBFORWARD = 0xE9, - DIK_WEBBACK = 0xEA, - DIK_MYCOMPUTER = 0xEB, - DIK_MAIL = 0xEC, - DIK_MEDIASELECT = 0xED, - DIK_BACKSPACE = DIK_BACK, - DIK_NUMPADSTAR = DIK_MULTIPLY, - DIK_LALT = DIK_LMENU, - DIK_CAPSLOCK = DIK_CAPITAL, - DIK_NUMPADMINUS = DIK_SUBTRACT, - DIK_NUMPADPLUS = DIK_ADD, - DIK_NUMPADPERIOD = DIK_DECIMAL, - DIK_NUMPADSLASH = DIK_DIVIDE, - DIK_RALT = DIK_RMENU, - DIK_UPARROW = DIK_UP, - DIK_PGUP = DIK_PRIOR, - DIK_LEFTARROW = DIK_LEFT, - DIK_RIGHTARROW = DIK_RIGHT, - DIK_DOWNARROW = DIK_DOWN, - DIK_PGDN = DIK_NEXT - }; - - struct DIMOUSESTATE2__ - { - LONG lX; - LONG lY; - LONG lZ; - BYTE rgbButtons[8]; - }; - - static_assert(sizeof(DIMOUSESTATE2__) == 0x14); - using DIMOUSESTATE2 = DIMOUSESTATE2__; - using LPDIMOUSESTATE2 = DIMOUSESTATE2*; - - struct DIDEVICEOBJECTDATA__ - { - DWORD dwOfs; // 00 - DWORD dwData; // 04 - DWORD dwTimeStamp; // 08 - DWORD dwSequence; // 0C - UINT_PTR uAppData; // 10 - }; - - static_assert(sizeof(DIDEVICEOBJECTDATA__) == 0x18); - using DIDEVICEOBJECTDATA = DIDEVICEOBJECTDATA__; - using LPDIDEVICEOBJECTDATA = DIDEVICEOBJECTDATA*; - using LPCDIDEVICEOBJECTDATA = const DIDEVICEOBJECTDATA*; - - struct DIDEVICEINSTANCEA__ - { - DWORD dwSize; - GUID guidInstance; - GUID guidProduct; - DWORD dwDevType; - CHAR tszInstanceName[SFSE::WinAPI::MAX_PATH]; - CHAR tszProductName[SFSE::WinAPI::MAX_PATH]; - GUID guidFFDriver; // DIRECTINPUT_VERSION >= 0x0500 - WORD wUsagePage; - WORD wUsage; - }; - - using DIDEVICEINSTANCEA = DIDEVICEINSTANCEA__; - using LPDIDEVICEINSTANCEA = DIDEVICEINSTANCEA*; - using LPCDIDEVICEINSTANCEA = const DIDEVICEINSTANCEA*; - - struct DIDEVICEOBJECTINSTANCEA__ - { - DWORD dwSize; - GUID guidType; - DWORD dwOfs; - DWORD dwType; - DWORD dwFlags; - CHAR tszName[SFSE::WinAPI::MAX_PATH]; - // #if(DIRECTINPUT_VERSION >= 0x0500) - DWORD dwFFMaxForce; - DWORD dwFFForceResolution; - WORD wCollectionNumber; - WORD wDesignatorIndex; - WORD wUsagePage; - WORD wUsage; - DWORD dwDimension; - WORD wExponent; - WORD wReportId; - // #endif /* DIRECTINPUT_VERSION >= 0x0500 */ - }; - - using DIDEVICEOBJECTINSTANCEA = DIDEVICEOBJECTINSTANCEA__; - using LPDIDEVICEOBJECTINSTANCEA = DIDEVICEOBJECTINSTANCEA*; - using LPCDIDEVICEOBJECTINSTANCEA = const DIDEVICEOBJECTINSTANCEA*; - - using LPDIENUMDEVICEOBJECTSCALLBACKA = bool(__stdcall*)(LPCDIDEVICEOBJECTINSTANCEA, LPVOID); - - struct DIPROPHEADER__ - { - DWORD dwSize; - DWORD dwHeaderSize; - DWORD dwObj; - DWORD dwHow; - }; - - using DIPROPHEADER = DIPROPHEADER__; - using LPDIPROPHEADER = DIPROPHEADER*; - using LPCDIPROPHEADER = const DIPROPHEADER*; - - struct DIDEVCAPS__ - { - DWORD dwSize; - DWORD dwFlags; - DWORD dwDevType; - DWORD dwAxes; - DWORD dwButtons; - DWORD dwPOVs; - DWORD dwFFSamplePeriod; // -- fields here are Dinput >= 0x0500 - DWORD dwFFMinTimeResolution; - DWORD dwFirmwareRevision; - DWORD dwHardwareRevision; - DWORD dwFFDriverVersion; - }; - - static_assert(sizeof(DIDEVCAPS__) == 0x2C); - using DIDEVCAPS = DIDEVCAPS__; - using LPDIDEVCAPS = DIDEVCAPS*; - using LPCDIDEVCAPS = const DIDEVCAPS*; - - struct _DIDEVICEIMAGEINFOA - { - CHAR tszImagePath[SFSE::WinAPI::MAX_PATH]; - DWORD dwFlags; - DWORD dwViewID; - RECT rcOverlay; - DWORD dwObjID; - DWORD dwcValidPts; - POINT rgptCalloutLine[5]; - RECT rcCalloutRect; - DWORD dwTextAlign; - }; - - using DIDEVICEIMAGEINFOA = _DIDEVICEIMAGEINFOA; - using LPDIDEVICEIMAGEINFOA = DIDEVICEIMAGEINFOA*; - using LPCDIDEVICEIMAGEINFOA = const DIDEVICEIMAGEINFOA*; - - struct _DIOBJECTDATAFORMAT - { - const GUID* pguid; - DWORD dwOfs; - DWORD dwType; - DWORD dwFlags; - }; - - using DIOBJECTDATAFORMAT = _DIOBJECTDATAFORMAT; - using LPDIOBJECTDATAFORMAT = DIOBJECTDATAFORMAT*; - using LPCDIOBJECTDATAFORMAT = const DIOBJECTDATAFORMAT*; - - struct _DIDATAFORMAT - { - DWORD dwSize; - DWORD dwObjSize; - DWORD dwFlags; - DWORD dwDataSize; - DWORD dwNumObjs; - LPDIOBJECTDATAFORMAT rgodf; - }; - - using DIDATAFORMAT = _DIDATAFORMAT; - using LPDIDATAFORMAT = DIDATAFORMAT*; - using LPCDIDATAFORMAT = const DIDATAFORMAT*; - - struct DIENVELOPE__ - { - DWORD dwSize; /* sizeof(DIENVELOPE) */ - DWORD dwAttackLevel; - DWORD dwAttackTime; /* Microseconds */ - DWORD dwFadeLevel; - DWORD dwFadeTime; /* Microseconds */ - }; - - using DIENVELOPE = DIENVELOPE__; - using LPDIENVELOPE = DIENVELOPE*; - using LPCDIENVELOPE = const DIENVELOPE*; - - struct DIEFFECTINFOA__ - { - DWORD dwSize; - GUID guid; - DWORD dwEffType; - DWORD dwStaticParams; - DWORD dwDynamicParams; - CHAR tszName[SFSE::WinAPI::MAX_PATH]; - }; - - using DIEFFECTINFOA = DIEFFECTINFOA__; - using LPDIEFFECTINFOA = DIEFFECTINFOA*; - using LPCDIEFFECTINFOA = const DIEFFECTINFOA*; - - using LPDIENUMEFFECTSCALLBACKA = bool(__stdcall*)(LPCDIEFFECTINFOA, LPVOID); - - struct DIEFFECT__ - { - DWORD dwSize; /* sizeof(DIEFFECT) */ - DWORD dwFlags; /* DIEFF_* */ - DWORD dwDuration; /* Microseconds */ - DWORD dwSamplePeriod; /* Microseconds */ - DWORD dwGain; - DWORD dwTriggerButton; /* or DIEB_NOTRIGGER */ - DWORD dwTriggerRepeatInterval; /* Microseconds */ - DWORD cAxes; /* Number of axes */ - LPDWORD rgdwAxes; /* Array of axes */ - LPLONG rglDirection; /* Array of directions */ - LPDIENVELOPE lpEnvelope; /* Optional */ - DWORD cbTypeSpecificParams; /* Size of params */ - LPVOID lpvTypeSpecificParams; /* Pointer to params */ - DWORD dwStartDelay; /* Microseconds */ // -- fields here are Dinput >= 0x0600 - }; - - using DIEFFECT = DIEFFECT__; - using LPDIEFFECT = DIEFFECT*; - using LPCDIEFFECT = const DIEFFECT*; - - struct DIEFFESCAPE__ - { - DWORD dwSize; - DWORD dwCommand; - LPVOID lpvInBuffer; - DWORD cbInBuffer; - LPVOID lpvOutBuffer; - DWORD cbOutBuffer; - }; - - using DIEFFESCAPE = DIEFFESCAPE__; - using LPDIEFFESCAPE = DIEFFESCAPE*; - using LPCDIEFFESCAPE = const DIEFFESCAPE*; - - struct DIFILEEFFECT__ - { - DWORD dwSize; - GUID GuidEffect; - LPCDIEFFECT lpDiEffect; - CHAR szFriendlyName[SFSE::WinAPI::MAX_PATH]; - }; - - using DIFILEEFFECT = DIFILEEFFECT__; - using LPDIFILEEFFECT = DIFILEEFFECT*; - using LPCDIFILEEFFECT = const DIFILEEFFECT*; - - struct _DIACTIONA - { - UINT_PTR uAppData; - DWORD dwSemantic; - DWORD dwFlags; - - union - { - LPCSTR lptszActionName; - UINT uResIdString; - }; - - GUID guidInstance; - DWORD dwObjID; - DWORD dwHow; - }; - - using DIACTIONA = _DIACTIONA; - using LPDIACTIONA = DIACTIONA*; - - struct _DIACTIONFORMATA - { - DWORD dwSize; - DWORD dwActionSize; - DWORD dwDataSize; - DWORD dwNumActions; - LPDIACTIONA rgoAction; - GUID guidActionMap; - DWORD dwGenre; - DWORD dwBufferSize; - LONG lAxisMin; - LONG lAxisMax; - HINSTANCE hInstString; - FILETIME ftTimeStamp; - DWORD dwCRC; - CHAR tszActionMap[SFSE::WinAPI::MAX_PATH]; - }; - - using DIACTIONFORMATA = _DIACTIONFORMATA; - using LPDIACTIONFORMATA = DIACTIONFORMATA*; - using LPCDIACTIONFORMATA = const DIACTIONFORMATA*; - - struct _DIDEVICEIMAGEINFOHEADERA - { - DWORD dwSize; - DWORD dwSizeImageInfo; - DWORD dwcViews; - DWORD dwcButtons; - DWORD dwcAxes; - DWORD dwcPOVs; - DWORD dwBufferSize; - DWORD dwBufferUsed; - LPDIDEVICEIMAGEINFOA lprgImageInfoArray; - }; - - using DIDEVICEIMAGEINFOHEADERA = _DIDEVICEIMAGEINFOHEADERA; - using LPDIDEVICEIMAGEINFOHEADERA = DIDEVICEIMAGEINFOHEADERA*; - using LPCDIDEVICEIMAGEINFOHEADERA = const DIDEVICEIMAGEINFOHEADERA*; - - struct _DICOLORSET - { - DWORD dwSize; - D3DCOLOR cTextFore; - D3DCOLOR cTextHighlight; - D3DCOLOR cCalloutLine; - D3DCOLOR cCalloutHighlight; - D3DCOLOR cBorder; - D3DCOLOR cControlFill; - D3DCOLOR cHighlightFill; - D3DCOLOR cAreaFill; - }; - - using DICOLORSET = _DICOLORSET; - - struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) IUnknown - { - virtual HRESULT QueryInterface(const GUID&, void**) noexcept = 0; - virtual std::uint32_t AddRef() noexcept = 0; - virtual std::uint32_t Release() noexcept = 0; - }; - - using LPUNKNOWN = IUnknown*; - - struct _DICONFIGUREDEVICESPARAMSA - { - DWORD dwSize; - DWORD dwcUsers; - LPSTR lptszUserNames; - DWORD dwcFormats; - LPDIACTIONFORMATA lprgFormats; - HWND hwnd; - DICOLORSET dics; - IUnknown* lpUnkDDSTarget; - }; - - using DICONFIGUREDEVICESPARAMSA = _DICONFIGUREDEVICESPARAMSA; - - struct __declspec(novtable) IDirectInputEffect : public IUnknown - { - virtual HRESULT Initialize(HINSTANCE, DWORD, REFGUID) noexcept = 0; - virtual HRESULT GetEffectGuid(LPGUID) noexcept = 0; - virtual HRESULT GetParameters(LPDIEFFECT, DWORD) noexcept = 0; - virtual HRESULT SetParameters(LPCDIEFFECT, DWORD) noexcept = 0; - virtual HRESULT Start(std::uint32_t, std::uint32_t) noexcept = 0; - virtual HRESULT Stop() noexcept = 0; - virtual HRESULT GetEffectStatus(std::uint32_t*) noexcept = 0; - virtual HRESULT Download() noexcept = 0; - virtual HRESULT Unload() noexcept = 0; - virtual HRESULT Escape(LPDIEFFESCAPE) noexcept = 0; - }; - - using LPDIRECTINPUTEFFECT = IDirectInputEffect*; - using LPCDIRECTINPUTEFFECT = const IDirectInputEffect*; - - using LPDIENUMCREATEDEFFECTOBJECTSCALLBACK = bool(__stdcall*)(LPDIRECTINPUTEFFECT, void*); - using LPDICONFIGUREDEVICESCALLBACK = bool(__stdcall*)(IUnknown*, void*); - using LPDIENUMDEVICESCALLBACKA = bool(__stdcall*)(const DIDEVICEINSTANCEA*, void*); - - using LPDIENUMEFFECTSCALLBACKA = bool(__stdcall*)(const DIEFFECTINFOA*, void*); - - using LPDIENUMEFFECTSINFILECALLBACK = bool(__stdcall*)(const DIFILEEFFECT*, void*); - - struct __declspec(novtable) IDirectInputDevice8A : public IUnknown - { - virtual HRESULT GetCapabilities(DIDEVCAPS*) noexcept = 0; - virtual HRESULT EnumObjects(LPDIENUMDEVICEOBJECTSCALLBACKA, void*, std::uint32_t) noexcept = 0; - virtual HRESULT GetProperty(std::uint32_t, DIPROPHEADER*) noexcept = 0; - virtual HRESULT SetProperty(std::uint32_t, const DIPROPHEADER*) noexcept = 0; - virtual HRESULT Acquire() noexcept = 0; - virtual HRESULT Unacquire() noexcept = 0; - virtual HRESULT GetDeviceState(std::uint32_t, void*) noexcept = 0; - virtual HRESULT GetDeviceData(std::uint32_t, DIDEVICEOBJECTDATA*, std::uint32_t*, std::uint32_t) noexcept = 0; - virtual HRESULT SetDataFormat(const DIDATAFORMAT*) noexcept = 0; - virtual HRESULT SetEventNotification(HANDLE) noexcept = 0; - virtual HRESULT SetCooperativeLevel(HWND, std::uint32_t) noexcept = 0; - virtual HRESULT GetObjectInfo(DIDEVICEOBJECTINSTANCEA*, std::uint32_t, std::uint32_t) noexcept = 0; - virtual HRESULT GetDeviceInfo(DIDEVICEINSTANCEA*) noexcept = 0; - virtual HRESULT RunControlPanel(HWND, std::uint32_t) noexcept = 0; - virtual HRESULT Initialize(HINSTANCE, std::uint32_t, const GUID&) noexcept = 0; - virtual HRESULT CreateEffect(const GUID&, const DIEFFECT*, IDirectInputEffect*, IUnknown*) noexcept = 0; - virtual HRESULT EnumEffects(LPDIENUMEFFECTSCALLBACKA, void*, std::uint32_t) noexcept = 0; - virtual HRESULT GetEffectInfo(DIEFFECTINFOA*, const GUID&) noexcept = 0; - virtual HRESULT GetForceFeedbackState(std::uint32_t*) noexcept = 0; - virtual HRESULT SendForceFeedbackCommand(std::uint32_t) noexcept = 0; - virtual HRESULT EnumCreatedEffectObjects(LPDIENUMCREATEDEFFECTOBJECTSCALLBACK, void*, std::uint32_t) noexcept = 0; - virtual HRESULT Escape(DIEFFESCAPE*) noexcept = 0; - virtual HRESULT Poll() noexcept = 0; - virtual HRESULT SendDeviceData(std::uint32_t, const DIDEVICEOBJECTDATA*, std::uint32_t*, std::uint32_t) noexcept = 0; - virtual HRESULT EnumEffectsInFile(const char*, LPDIENUMEFFECTSINFILECALLBACK, void*, std::uint32_t) noexcept = 0; - virtual HRESULT WriteEffectToFile(const char*, std::uint32_t, DIFILEEFFECT*, std::uint32_t) noexcept = 0; - virtual HRESULT BuildActionMap(DIACTIONFORMATA*, const char*, std::uint32_t) noexcept = 0; - virtual HRESULT SetActionMap(DIACTIONFORMATA*, const char*, std::uint32_t) noexcept = 0; - virtual HRESULT GetImageInfo(DIDEVICEIMAGEINFOHEADERA*) noexcept = 0; - }; - - using LPDIENUMDEVICESBYSEMANTICSCBA = bool(__stdcall*)(const DIDEVICEINSTANCEA*, IDirectInputDevice8A*, DWORD, DWORD, LPVOID); - - struct __declspec(novtable) IDirectInput8A : public IUnknown - { - virtual HRESULT CreateDevice(const GUID&, IDirectInputDevice8A**, IUnknown*) noexcept = 0; - virtual HRESULT EnumDevices(std::uint32_t, LPDIENUMDEVICESCALLBACKA, void*, std::uint32_t) noexcept = 0; - virtual HRESULT GetDeviceStatus(const GUID&) noexcept = 0; - virtual HRESULT RunControlPanel(HWND, std::uint32_t) noexcept = 0; - virtual HRESULT Initialize(HINSTANCE, std::uint32_t) noexcept = 0; - virtual HRESULT FindDevice(const GUID&, const char*, GUID*) noexcept = 0; - virtual HRESULT EnumDevicesBySemantics(const char*, LPDIACTIONFORMATA, LPDIENUMDEVICESBYSEMANTICSCBA, void*, std::uint32_t) noexcept = 0; - virtual HRESULT ConfigureDevices(LPDICONFIGUREDEVICESCALLBACK, DICONFIGUREDEVICESPARAMSA*, std::uint32_t, void*) noexcept = 0; - }; - -} diff --git a/include/SFSE/Impl/PCH.h b/include/SFSE/Impl/PCH.h index b2625b27..ddda6aab 100644 --- a/include/SFSE/Impl/PCH.h +++ b/include/SFSE/Impl/PCH.h @@ -1,11 +1,7 @@ #pragma once /* +++++++++++++++++++++++++ C++23 Standard Library +++++++++++++++++++++++++ */ - -// Concepts library #include - -// Utilities library #include #include #include @@ -28,30 +24,22 @@ #include #include #include - -// Dynamic memory management #include #include #include #include - -// Numeric limits #include #include #include #include #include #include - -// Error handling #include #include #include #include #include #include - -// Strings library #include #include #include @@ -60,8 +48,6 @@ #include #include #include - -// Containers library #include #include #include @@ -74,18 +60,10 @@ #include #include #include - -// Iterators library #include - -// Ranges library #include - -// Algorithms library #include #include - -// Numerics library #include #include #include @@ -95,12 +73,8 @@ #include #include #include - -// Localization library #include #include - -// Input/output library #include #include #include @@ -115,17 +89,9 @@ #include #include #include - -// Filesystem library #include - -// Regular Expressions library #include - -// Atomic Operations library #include - -// Thread support library #include #include #include @@ -144,9 +110,9 @@ static_assert(std::is_integral_v && sizeof(std::time_t) == sizeof(s #include #pragma warning(pop) -#include "SFSE/Impl/DInputAPI.h" -#include "SFSE/Impl/WinAPI.h" -#include "SFSE/Impl/XInputAPI.h" +#include "REX/REX.h" +#include "REX/W32/KERNEL32.h" +#include "REX/W32/USER32.h" #define AsAddress(ptr) std::bit_cast(ptr) #define AsPointer(addr) std::bit_cast(addr) @@ -608,8 +574,8 @@ namespace SFSE::stl [[nodiscard]] inline auto utf8_to_utf16(const std::string_view a_in) noexcept -> std::optional { const auto cvt = [&](wchar_t* a_dst, const std::size_t a_length) { - return WinAPI::MultiByteToWideChar( - WinAPI::CP_UTF8, 0, a_in.data(), static_cast(a_in.length()), a_dst, static_cast(a_length)); + return REX::W32::MultiByteToWideChar( + REX::W32::CP_UTF8, 0, a_in.data(), static_cast(a_in.length()), a_dst, static_cast(a_length)); }; const auto len = cvt(nullptr, 0); @@ -628,8 +594,8 @@ namespace SFSE::stl [[nodiscard]] inline auto utf16_to_utf8(const std::wstring_view a_in) noexcept -> std::optional { const auto cvt = [&](char* a_dst, const std::size_t a_length) { - return WinAPI::WideCharToMultiByte( - WinAPI::CP_UTF8, 0, a_in.data(), static_cast(a_in.length()), a_dst, static_cast(a_length), nullptr, nullptr); + return REX::W32::WideCharToMultiByte( + REX::W32::CP_UTF8, 0, a_in.data(), static_cast(a_in.length()), a_dst, static_cast(a_length), nullptr, nullptr); }; const auto len = cvt(nullptr, 0); @@ -661,14 +627,13 @@ namespace SFSE::stl }(); const auto caption = []() { - const auto maxPath = WinAPI::GetMaxPath(); std::vector buf; - buf.reserve(maxPath); - buf.resize(maxPath / 2); + buf.reserve(REX::W32::MAX_PATH); + buf.resize(REX::W32::MAX_PATH / 2); std::uint32_t result; do { buf.resize(buf.size() * 2); - result = WinAPI::GetModuleFileName(WinAPI::GetCurrentModule(), buf.data(), static_cast(buf.size())); + result = REX::W32::GetModuleFileNameW(REX::W32::GetCurrentModule(), buf.data(), static_cast(buf.size())); } while (result && result == buf.size() && buf.size() <= (std::numeric_limits::max)()); if (result && result != buf.size()) { @@ -681,8 +646,8 @@ namespace SFSE::stl spdlog::log(spdlog::source_loc{ a_loc.file_name(), static_cast(a_loc.line()), a_loc.function_name() }, spdlog::level::critical, a_msg); if (a_fail) { - WinAPI::MessageBox(nullptr, body.c_str(), (caption.empty() ? nullptr : caption.c_str()), 0); - WinAPI::TerminateProcess(WinAPI::GetCurrentProcess(), EXIT_FAILURE); + REX::W32::MessageBoxW(nullptr, body.c_str(), (caption.empty() ? nullptr : caption.c_str()), 0); + REX::W32::TerminateProcess(REX::W32::GetCurrentProcess(), EXIT_FAILURE); } return true; } @@ -741,14 +706,12 @@ namespace RE { using namespace std::literals; namespace stl = SFSE::stl; - namespace WinAPI = SFSE::WinAPI; } namespace REL { using namespace std::literals; namespace stl = SFSE::stl; - namespace WinAPI = SFSE::WinAPI; } #include "REL/REL.h" diff --git a/include/SFSE/Impl/WinAPI.h b/include/SFSE/Impl/WinAPI.h deleted file mode 100644 index cf3d662c..00000000 --- a/include/SFSE/Impl/WinAPI.h +++ /dev/null @@ -1,1456 +0,0 @@ -#pragma once - -#ifdef _INC_WINAPIFAMILY -# error Windows API detected. Please move any Windows API includes after CommonLibSF, or remove them. -#else - -namespace SFSE::WinAPI -{ - // general constants - inline const auto INVALID_HANDLE_VALUE{ reinterpret_cast(static_cast(-1)) }; - inline constexpr auto MAX_PATH{ 260u }; - - // standard access - inline constexpr auto STANDARD_RIGHTS_REQUIRED{ 0x000F0000 }; - inline constexpr auto STANDARD_RIGHTS_ALL{ 0x001F0000 }; - - // code page identifiers - inline constexpr auto CP_UTF8{ 65001u }; - - // pe image header - inline constexpr auto IMAGE_DOS_SIGNATURE{ 0x5A4Du }; - inline constexpr auto IMAGE_NT_SIGNATURE{ 0x00004550u }; - inline constexpr auto IMAGE_NT_OPTIONAL_HDR32_MAGIC{ 0x10Bu }; - inline constexpr auto IMAGE_NT_OPTIONAL_HDR64_MAGIC{ 0x20Bu }; - - // pe image directory entries - inline constexpr auto IMAGE_DIRECTORY_ENTRY_EXPORT{ 0u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_IMPORT{ 1u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_RESOURCE{ 2u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_EXCEPTION{ 3u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_SECURITY{ 4u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_BASERELOC{ 5u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_DEBUG{ 6u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_ARCHITECTURE{ 7u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_GLOBALPTR{ 8u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_TLS{ 9u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG{ 10u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT{ 11u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_IAT{ 12u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT{ 13u }; - inline constexpr auto IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR{ 14u }; - inline constexpr auto IMAGE_NUMBEROF_DIRECTORY_ENTRIES{ 16u }; - - // pe image ordinal - inline constexpr auto IMAGE_ORDINAL_FLAG32{ 0x80000000u }; - inline constexpr auto IMAGE_ORDINAL_FLAG64{ 0x8000000000000000ull }; - - // pe image section header characteristics - inline constexpr auto IMAGE_SCN_MEM_SHARED{ 0x10000000u }; - inline constexpr auto IMAGE_SCN_MEM_EXECUTE{ 0x20000000u }; - inline constexpr auto IMAGE_SCN_MEM_READ{ 0x40000000u }; - inline constexpr auto IMAGE_SCN_MEM_WRITE{ 0x80000000u }; - inline constexpr auto IMAGE_SIZEOF_SECTION_HEADER{ 40u }; - inline constexpr auto IMAGE_SIZEOF_SHORT_NAME{ 8u }; - - // memory allocation types - inline constexpr auto MEM_COMMIT{ 0x00001000u }; - inline constexpr auto MEM_RESERVE{ 0x00002000u }; - inline constexpr auto MEM_DECOMMIT{ 0x00004000u }; - inline constexpr auto MEM_RELEASE{ 0x00008000u }; - inline constexpr auto MEM_FREE{ 0x00010000u }; - inline constexpr auto MEM_RESET{ 0x00080000u }; - inline constexpr auto MEM_RESET_UNDO{ 0x01000000u }; - - // memory page protection attributes - inline constexpr auto PAGE_NOACCESS{ 0x00000001u }; - inline constexpr auto PAGE_READONLY{ 0x00000002u }; - inline constexpr auto PAGE_READWRITE{ 0x00000004u }; - inline constexpr auto PAGE_WRITECOPY{ 0x00000008u }; - inline constexpr auto PAGE_EXECUTE{ 0x00000010u }; - inline constexpr auto PAGE_EXECUTE_READ{ 0x00000020u }; - inline constexpr auto PAGE_EXECUTE_READWRITE{ 0x00000040u }; - - // memory section - inline constexpr auto SECTION_QUERY{ 0x00000001 }; - inline constexpr auto SECTION_MAP_WRITE{ 0x00000002 }; - inline constexpr auto SECTION_MAP_READ{ 0x00000004 }; - inline constexpr auto SECTION_MAP_EXECUTE{ 0x00000008 }; - inline constexpr auto SECTION_EXTEND_SIZE{ 0x00000010 }; - inline constexpr auto SECTION_MAP_EXECUTE_EXPLICIT{ 0x00000020 }; - inline constexpr auto SECTION_ALL_ACCESS{ - STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_WRITE | SECTION_MAP_READ | SECTION_MAP_EXECUTE | SECTION_EXTEND_SIZE - }; - - // file attributes - inline constexpr auto FILE_ATTRIBUTE_READONLY{ 0x00000001u }; - inline constexpr auto FILE_ATTRIBUTE_HIDDEN{ 0x00000002u }; - inline constexpr auto FILE_ATTRIBUTE_SYSTEM{ 0x00000004u }; - inline constexpr auto FILE_ATTRIBUTE_DIRECTORY{ 0x00000010u }; - inline constexpr auto FILE_ATTRIBUTE_ARCHIVE{ 0x00000020u }; - - // file mapping flags - inline constexpr auto FILE_MAP_ALL_ACCESS{ SECTION_ALL_ACCESS }; - inline constexpr auto FILE_MAP_COPY{ 0x00000001u }; - inline constexpr auto FILE_MAP_WRITE{ 0x00000002u }; - inline constexpr auto FILE_MAP_READ{ 0x00000004u }; - inline constexpr auto FILE_MAP_EXECUTE{ 0x00000020u }; - inline constexpr auto FILE_MAP_LARGE_PAGES{ 0x20000000u }; - inline constexpr auto FILE_MAP_TARGETS_INVALID{ 0x40000000u }; - inline constexpr auto FILE_MAP_RESERVE{ 0x80000000u }; - - // file open mode flags - inline constexpr auto GENERIC_READ{ 0x80000000L }; - inline constexpr auto GENERIC_WRITE{ 0x40000000L }; - inline constexpr auto GENERIC_EXECUTE{ 0x20000000L }; - inline constexpr auto GENERIC_ALL{ 0x10000000L }; - - // known folder flags - inline constexpr auto KF_FLAG_DEFAULT{ 0x00000000u }; - inline constexpr auto KF_FLAG_FORCE_APP_DATA_REDIRECTION{ 0x00080000u }; - inline constexpr auto KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET{ 0x00040000u }; - inline constexpr auto KF_FLAG_FORCE_PACKAGE_REDIRECTION{ 0x00020000u }; - inline constexpr auto KF_FLAG_NO_PACKAGE_REDIRECTION{ 0x00010000u }; - inline constexpr auto KF_FLAG_FORCE_APPCONTAINER_REDIRECTION{ 0x00020000u }; - inline constexpr auto KF_FLAG_NO_APPCONTAINER_REDIRECTION{ 0x00010000u }; - inline constexpr auto KF_FLAG_CREATE{ 0x00008000u }; - inline constexpr auto KF_FLAG_DONT_VERIFY{ 0x00004000u }; - inline constexpr auto KF_FLAG_DONT_UNEXPAND{ 0x00002000u }; - inline constexpr auto KF_FLAG_NO_ALIAS{ 0x00001000u }; - inline constexpr auto KF_FLAG_INIT{ 0x00000800u }; - inline constexpr auto KF_FLAG_DEFAULT_PATH{ 0x00000400u }; - inline constexpr auto KF_FLAG_NOT_PARENT_RELATIVE{ 0x00000200u }; - inline constexpr auto KF_FLAG_SIMPLE_IDLIST{ 0x00000100u }; - inline constexpr auto KF_FLAG_ALIAS_ONLY{ 0x80000000u }; - - // string normalization forms - inline constexpr auto NORM_FORM_OTHER{ 0x0 }; - inline constexpr auto NORM_FORM_C{ 0x1 }; - inline constexpr auto NORM_FORM_D{ 0x2 }; - inline constexpr auto NORM_FORM_KC{ 0x5 }; - inline constexpr auto NORM_FORM_KD{ 0x6 }; - - // locale map flags - inline constexpr auto LCMAP_LOWERCASE{ 0x00000100u }; - inline constexpr auto LCMAP_UPPERCASE{ 0x00000200u }; - inline constexpr auto LCMAP_TITLECASE{ 0x00000300u }; - inline constexpr auto LCMAP_SORTKEY{ 0x00000400u }; - inline constexpr auto LCMAP_BYTEREV{ 0x00000800u }; - inline constexpr auto LCMAP_HIRAGANA{ 0x00100000u }; - inline constexpr auto LCMAP_KATAKANA{ 0x00200000u }; - inline constexpr auto LCMAP_HALFWIDTH{ 0x00400000u }; - inline constexpr auto LCMAP_FULLWIDTH{ 0x00800000u }; - inline constexpr auto LCMAP_LINGUISTIC_CASING{ 0x01000000u }; - inline constexpr auto LCMAP_SIMPLIFIED_CHINESE{ 0x02000000u }; - inline constexpr auto LCMAP_TRADITIONAL_CHINESE{ 0x04000000u }; - - // locale names - inline constexpr auto LOCALE_NAME_USER_DEFAULT{ nullptr }; - inline constexpr auto LOCALE_NAME_INVARIANT{ L"" }; - inline constexpr auto LOCALE_NAME_SYSTEM_DEFAULT{ L"!x-sys-default-locale" }; - - // process creation flags - inline constexpr auto DEBUG_PROCESS{ 0x00000001u }; - inline constexpr auto DEBUG_ONLY_THIS_PROCESS{ 0x00000002u }; - inline constexpr auto CREATE_SUSPENDED{ 0x00000004u }; - inline constexpr auto DETACHED_PROCESS{ 0x00000008u }; - inline constexpr auto CREATE_NEW_CONSOLE{ 0x00000010u }; - inline constexpr auto NORMAL_PRIORITY_CLASS{ 0x00000020u }; - inline constexpr auto IDLE_PRIORITY_CLASS{ 0x00000040u }; - inline constexpr auto HIGH_PRIORITY_CLASS{ 0x00000080u }; - inline constexpr auto REALTIME_PRIORITY_CLASS{ 0x00000100u }; - inline constexpr auto CREATE_NEW_PROCESS_GROUP{ 0x00000200u }; - inline constexpr auto CREATE_UNICODE_ENVIRONMENT{ 0x00000400u }; - inline constexpr auto CREATE_FORCEDOS{ 0x00002000u }; - inline constexpr auto BELOW_NORMAL_PRIORITY_CLASS{ 0x00004000u }; - inline constexpr auto ABOVE_NORMAL_PRIORITY_CLASS{ 0x00008000u }; - inline constexpr auto INHERIT_PARENT_AFFINITY{ 0x00010000u }; - inline constexpr auto CREATE_PROTECTED_PROCESS{ 0x00040000u }; - inline constexpr auto EXTENDED_STARTUPINFO_PRESENT{ 0x00080000u }; - inline constexpr auto PROCESS_MODE_BACKGROUND_BEGIN{ 0x00100000u }; - inline constexpr auto PROCESS_MODE_BACKGROUND_END{ 0x00200000u }; - inline constexpr auto CREATE_SECURE_PROCESS{ 0x00400000 }; - inline constexpr auto CREATE_BREAKAWAY_FROM_JOB{ 0x01000000u }; - inline constexpr auto CREATE_PRESERVE_CODE_AUTHZ_LEVEL{ 0x02000000u }; - inline constexpr auto CREATE_DEFAULT_ERROR_MODE{ 0x04000000u }; - inline constexpr auto CREATE_NO_WINDOW{ 0x08000000u }; - - // symbol name undecoration flags - inline constexpr auto UNDNAME_NO_MS_KEYWORDS{ 0x00000002u }; - inline constexpr auto UNDNAME_NO_FUNCTION_RETURNS{ 0x00000004u }; - inline constexpr auto UNDNAME_NO_ALLOCATION_MODEL{ 0x00000008u }; - inline constexpr auto UNDNAME_NO_ALLOCATION_LANGUAGE{ 0x00000010u }; - inline constexpr auto UNDNAME_NO_THISTYPE{ 0x00000060u }; - inline constexpr auto UNDNAME_NO_ACCESS_SPECIFIERS{ 0x00000080u }; - inline constexpr auto UNDNAME_NO_THROW_SIGNATURES{ 0x00000100u }; - inline constexpr auto UNDNAME_NO_RETURN_UDT_MODEL{ 0x00000400u }; - inline constexpr auto UNDNAME_NAME_ONLY{ 0x00001000u }; - inline constexpr auto UNDNAME_NO_ARGUMENTS{ 0x00002000u }; - - // winsock2 values - inline constexpr auto INADDR_ANY{ 0x00000000u }; - inline constexpr auto INADDR_LOOPBACK{ 0x7f000001u }; - inline constexpr auto INADDR_BROADCAST{ 0xffffffffu }; - inline constexpr auto INADDR_NONE{ 0xffffffffu }; - - using THREAD_START_ROUTINE = std::uint32_t(void* a_param); - - using UINT_PTR = std::uintptr_t; - - enum class AFType : std::uint16_t - { - AF_UNSPEC = 0, - AF_UNIX = 1, - AF_INET = 2, - AF_IMPLINK = 3, - AF_PUP = 4, - AF_CHAOS = 5, - AF_NS = 6, - AF_IPX = AF_NS, - AF_ISO = 7, - AF_OSI = AF_ISO, - AF_ECMA = 8, - AF_DATAKIT = 9, - AF_CCITT = 10, - AF_SNA = 11, - AF_DECnet = 12, - AF_DLI = 13, - AF_LAT = 14, - AF_HYLINK = 15, - AF_APPLETALK = 16, - AF_NETBIOS = 17, - AF_VOICEVIEW = 18, - AF_FIREFOX = 19, - AF_UNKNOWN1 = 20, - AF_BAN = 21, - AF_ATM = 22, - AF_INET6 = 23, - AF_CLUSTER = 24, - AF_12844 = 25, - AF_IRDA = 26, - AF_NETDES = 28, - }; - - using ADDRESS_FAMILY = AFType; - - struct CRITICAL_SECTION - { - public: - // members - void* debugInfo; // 00 - std::int32_t lockCount; // 08 - std::int32_t recursionCount; // 0C - void* owningThread; // 10 - void* lockSemaphore; // 18 - std::uint64_t* spinCount; // 20 - }; - static_assert(sizeof(CRITICAL_SECTION) == 0x28); - - struct FILETIME - { - // members - std::uint32_t lo; // 00 - std::uint32_t hi; // 04 - }; - static_assert(sizeof(FILETIME) == 0x8); - - struct GUID - { - std::uint32_t data1; - std::uint16_t data2; - std::uint16_t data3; - std::uint8_t data4[8]; - }; - static_assert(sizeof(GUID) == 0x10); - - // known folder ids - inline constexpr GUID FOLDERID_DOCUMENTS{ 0xFDD39AD0u, 0x238Fu, 0x46AFu, 0xADu, 0xB4u, 0x6Cu, 0x85u, 0x48u, 0x03u, 0x69u, 0xC7u }; - inline constexpr GUID FOLDERID_PICTURES{ 0x33E28130u, 0x4E1Eu, 0x4676u, 0x83u, 0x5Au, 0x98u, 0x39u, 0x5Cu, 0x3Bu, 0xC3u, 0xBBu }; - inline constexpr GUID FOLDERID_PROGRAMDATA{ 0x62AB5D82u, 0xFDC1u, 0x4DC3u, 0xA9u, 0xDDu, 0x07u, 0x0Du, 0x1Du, 0x49u, 0x5Du, 0x97u }; - - using HRESULT = std::uint32_t; - - struct HWND__; - using HWND = HWND__*; - - struct HINSTANCE__; - using HINSTANCE = HINSTANCE__*; - using HMODULE = HINSTANCE; - - struct HKEY__; - using HKEY = HKEY__*; - - inline auto HKEY_CLASSES_ROOT{ reinterpret_cast(0x80000000ull) }; - inline auto HKEY_CURRENT_USER{ reinterpret_cast(0x80000001ull) }; - inline auto HKEY_LOCAL_MACHINE{ reinterpret_cast(0x80000002ull) }; - - struct IMAGE_DATA_DIRECTORY - { - std::uint32_t virtualAddress; - std::uint32_t size; - }; - static_assert(sizeof(IMAGE_DATA_DIRECTORY) == 0x8); - - struct IMAGE_DOS_HEADER - { - std::uint16_t magic; - std::uint16_t cblp; - std::uint16_t cp; - std::uint16_t crlc; - std::uint16_t cparhdr; - std::uint16_t minalloc; - std::uint16_t maxalloc; - std::uint16_t ss; - std::uint16_t sp; - std::uint16_t csum; - std::uint16_t ip; - std::uint16_t cs; - std::uint16_t lfarlc; - std::uint16_t ovno; - std::uint16_t res[4]; - std::uint16_t oemid; - std::uint16_t oeminfo; - std::uint16_t res2[10]; - std::int32_t lfanew; - }; - static_assert(sizeof(IMAGE_DOS_HEADER) == 0x40); - - struct IMAGE_FILE_HEADER - { - std::uint16_t machine; - std::uint16_t sectionCount; - std::uint32_t timeDateStamp; - std::uint32_t symbolTablePtr; - std::uint32_t symbolCount; - std::uint16_t optionalHeaderSize; - std::uint16_t characteristics; - }; - static_assert(sizeof(IMAGE_FILE_HEADER) == 0x14); - - struct IMAGE_IMPORT_BY_NAME - { - std::uint16_t hint; - char name[1]; - }; - static_assert(sizeof(IMAGE_IMPORT_BY_NAME) == 0x4); - - struct IMAGE_IMPORT_DESCRIPTOR - { - union - { - std::uint32_t characteristics; - std::uint32_t firstThunkOriginal; - }; - - std::uint32_t timeDateStamp; - std::uint32_t forwarderChain; - std::uint32_t name; - std::uint32_t firstThunk; - }; - static_assert(sizeof(IMAGE_IMPORT_DESCRIPTOR) == 0x14); - - struct IMAGE_OPTIONAL_HEADER64 - { - std::uint16_t magic; - std::uint8_t linkerVersionMajor; - std::uint8_t linkerVersionMinor; - std::uint32_t codeSize; - std::uint32_t initializedDataSize; - std::uint32_t uninitializedDataSize; - std::uint32_t entryPointAddress; - std::uint32_t codeBase; - std::uint64_t imageBase; - std::uint32_t sectionAlignment; - std::uint32_t fileAlignment; - std::uint16_t osVersionMajor; - std::uint16_t osVersionMinor; - std::uint16_t imageVersionMajor; - std::uint16_t imageVersionMinor; - std::uint16_t subsystemVersionMajor; - std::uint16_t subsystemVersionMinor; - std::uint32_t win32Version; - std::uint32_t imageSize; - std::uint32_t headersSize; - std::uint32_t checksum; - std::uint16_t subsystem; - std::uint16_t dllCharacteristics; - std::uint64_t stackReserveSize; - std::uint64_t stackCommitSize; - std::uint64_t heapReserveSize; - std::uint64_t heapCommitSize; - std::uint32_t loaderFlags; - std::uint32_t rvaAndSizesCount; - IMAGE_DATA_DIRECTORY dataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; - }; - static_assert(sizeof(IMAGE_OPTIONAL_HEADER64) == 0xF0); - - struct IMAGE_NT_HEADERS64 - { - std::uint32_t signature; - IMAGE_FILE_HEADER fileHeader; - IMAGE_OPTIONAL_HEADER64 optionalHeader; - }; - static_assert(sizeof(IMAGE_NT_HEADERS64) == 0x108); - - struct IMAGE_SECTION_HEADER - { - std::uint8_t name[IMAGE_SIZEOF_SHORT_NAME]; - union - { - std::uint32_t physicalAddress; - std::uint32_t virtualSize; - }; - std::uint32_t virtualAddress; - std::uint32_t rawDataSize; - std::uint32_t rawDataPtr; - std::uint32_t relocationsPtr; - std::uint32_t lineNumbersPtr; - std::uint16_t relocationsCount; - std::uint16_t lineNumbersCount; - std::uint32_t characteristics; - }; - static_assert(sizeof(IMAGE_SECTION_HEADER) == 0x28); - - struct IMAGE_THUNK_DATA64 - { - union - { - std::uint64_t forwarderString; // PBYTE - std::uint64_t function; // PDWORD - std::uint64_t ordinal; - std::uint64_t address; // PIMAGE_IMPORT_BY_NAME - }; - }; - static_assert(sizeof(IMAGE_THUNK_DATA64) == 0x8); - - struct MEMORY_BASIC_INFORMATION - { - void* baseAddress; - void* allocationBase; - std::uint32_t allocationProtect; - std::uint16_t partitionID; - std::size_t regionSize; - std::uint32_t state; - std::uint32_t protect; - std::uint32_t type; - }; - static_assert(sizeof(MEMORY_BASIC_INFORMATION) == 0x30); - - struct NLSVERSIONINFO; - - struct POINT - { - std::int32_t x; - std::int32_t y; - }; - - struct PROCESS_INFORMATION - { - void* process; - void* thread; - std::uint32_t processID; - std::uint32_t threadID; - }; - static_assert(sizeof(PROCESS_INFORMATION) == 0x18); - - struct RECT - { - std::int32_t left; - std::int32_t top; - std::int32_t right; - std::int32_t bottom; - }; - - struct SECURITY_ATTRIBUTES - { - std::uint32_t length; - void* securityDescriptor; - bool inheritHandle; - }; - static_assert(sizeof(SECURITY_ATTRIBUTES) == 0x18); - - using SOCKET = UINT_PTR; - - struct sockaddr - { - ADDRESS_FAMILY sa_family; - char sa_data[14]; - }; - - // Originally a struct with several #defines that served as aliases to members - // The defines screwed a lot of things up, so it was made a union. - // This means it won't have compatibility with code that uses in_addrs directly and - // also refers to it by its full type identifier (i.e. `struct in_addr`). - union in_addr - { - union in_addr_D - { - struct - { - std::uint8_t s_b1, s_b2, s_b3, s_b4; - } S_un_b; - - struct - { - std::uint16_t s_w1, s_w2; - } S_un_w; - - std::uint32_t S_addr; - } S_un; - - // getting around the #DEFINEs in inaddr.h - struct - { - std::uint8_t s_net; - std::uint8_t s_host; - std::uint8_t s_lh; - std::uint8_t s_impno; - }; - - struct - { - std::uint16_t _s_w1, s_imp; - }; - - std::uint32_t s_addr; - }; - - struct sockaddr_in - { - ADDRESS_FAMILY sin_family; - std::uint16_t sin_port; - in_addr sin_addr; - char sin_zero[8]; - }; - - struct STARTUPINFOA - { - std::uint32_t size; - char* reserved0; - char* desktop; - char* title; - std::uint32_t x; - std::uint32_t y; - std::uint32_t xSize; - std::uint32_t ySize; - std::uint32_t xCountChars; - std::uint32_t yCountChars; - std::uint32_t fillAttribute; - std::uint32_t flags; - std::uint16_t showWindow; - std::uint16_t reserved1; - std::uint8_t* reserved2; - void* stdIn; - void* stdOut; - void* stdErr; - }; - static_assert(sizeof(STARTUPINFOA) == 0x68); - - struct STARTUPINFOW - { - std::uint32_t size; - wchar_t* reserved0; - wchar_t* desktop; - wchar_t* title; - std::uint32_t x; - std::uint32_t y; - std::uint32_t xSize; - std::uint32_t ySize; - std::uint32_t xCountChars; - std::uint32_t yCountChars; - std::uint32_t fillAttribute; - std::uint32_t flags; - std::uint16_t showWindow; - std::uint16_t reserved1; - std::uint8_t* reserved2; - void* stdIn; - void* stdOut; - void* stdErr; - }; - static_assert(sizeof(STARTUPINFOW) == 0x68); - - struct SYSTEM_INFO - { - union - { - std::uint32_t oemID; - struct - { - std::uint16_t processorArch; - std::uint16_t reserved; - }; - }; - std::uint32_t pageSize; - void* appAddressMin; - void* appAddressMax; - std::uintptr_t processorActiveMask; - std::uint32_t processorCount; - std::uint32_t processorType; - std::uint32_t allocationGranularity; - std::uint16_t processorLevel; - std::uint16_t processorRevision; - }; - static_assert(sizeof(SYSTEM_INFO) == 0x30); - - union ULARGE_INTEGER - { - struct - { - std::uint32_t lo; - std::uint32_t hi; - }; - std::uint64_t value; - }; - - struct WIN32_FIND_DATAA - { - // members - std::uint32_t fileAttributes; - FILETIME creationTime; - FILETIME lastAccessTime; - FILETIME lastWriteTime; - std::uint32_t fileSizeHi; - std::uint32_t fileSizeLo; - std::uint32_t reserved0; - std::uint32_t reserved1; - char fileName[MAX_PATH]; - char fileNameAlt[14]; - }; - static_assert(sizeof(WIN32_FIND_DATAA) == 0x140); - - struct WIN32_FIND_DATAW - { - // members - std::uint32_t fileAttributes; - FILETIME creationTime; - FILETIME lastAccessTime; - FILETIME lastWriteTime; - std::uint32_t fileSizeHi; - std::uint32_t fileSizeLo; - std::uint32_t reserved0; - std::uint32_t reserved1; - wchar_t fileName[MAX_PATH]; - wchar_t fileNameAlt[14]; - }; - static_assert(sizeof(WIN32_FIND_DATAW) == 0x250); - - enum class WSAError : std::int32_t - { - WSABASEERR = 10000L, - WSAEINTR = 10004L, - WSAEBADF = 10009L, - WSAEACCES = 10013L, - WSAEFAULT = 10014L, - WSAEINVAL = 10022L, - WSAEMFILE = 10024L, - WSAEWOULDBLOCK = 10035L, - WSAEINPROGRESS = 10036L, - WSAEALREADY = 10037L, - WSAENOTSOCK = 10038L, - WSAEDESTADDRREQ = 10039L, - WSAEMSGSIZE = 10040L, - WSAEPROTOTYPE = 10041L, - WSAENOPROTOOPT = 10042L, - WSAEPROTONOSUPPORT = 10043L, - WSAESOCKTNOSUPPORT = 10044L, - WSAEOPNOTSUPP = 10045L, - WSAEPFNOSUPPORT = 10046L, - WSAEAFNOSUPPORT = 10047L, - WSAEADDRINUSE = 10048L, - WSAEADDRNOTAVAIL = 10049L, - WSAENETDOWN = 10050L, - WSAENETUNREACH = 10051L, - WSAENETRESET = 10052L, - WSAECONNABORTED = 10053L, - WSAECONNRESET = 10054L, - WSAENOBUFS = 10055L, - WSAEISCONN = 10056L, - WSAENOTCONN = 10057L, - WSAESHUTDOWN = 10058L, - WSAETOOMANYREFS = 10059L, - WSAETIMEDOUT = 10060L, - WSAECONNREFUSED = 10061L, - WSAELOOP = 10062L, - WSAENAMETOOLONG = 10063L, - WSAEHOSTDOWN = 10064L, - WSAEHOSTUNREACH = 10065L, - WSAENOTEMPTY = 10066L, - WSAEPROCLIM = 10067L, - WSAEUSERS = 10068L, - WSAEDQUOT = 10069L, - WSAESTALE = 10070L, - WSAEREMOTE = 10071L, - WSASYSNOTREADY = 10091L, - WSAVERNOTSUPPORTED = 10092L, - WSANOTINITIALISED = 10093L, - WSAEDISCON = 10101L, - WSAENOMORE = 10102L, - WSAECANCELLED = 10103L, - WSAEINVALIDPROCTABLE = 10104L, - WSAEINVALIDPROVIDER = 10105L, - WSAEPROVIDERFAILEDINIT = 10106L, - WSASYSCALLFAILURE = 10107L, - WSASERVICE_NOT_FOUND = 10108L, - WSATYPE_NOT_FOUND = 10109L, - WSA_E_NO_MORE = 10110L, - WSA_E_CANCELLED = 10111L, - WSAEREFUSED = 10112L, - WSAHOST_NOT_FOUND = 11001L, - WSATRY_AGAIN = 11002L, - WSANO_RECOVERY = 11003L, - WSANO_DATA = 11004L, - WSA_QOS_RECEIVERS = 11005L, - WSA_QOS_SENDERS = 11006L, - WSA_QOS_NO_SENDERS = 11007L, - WSA_QOS_NO_RECEIVERS = 11008L, - WSA_QOS_REQUEST_CONFIRMED = 11009L, - WSA_QOS_ADMISSION_FAILURE = 11010L, - WSA_QOS_POLICY_FAILURE = 11011L, - WSA_QOS_BAD_STYLE = 11012L, - WSA_QOS_BAD_OBJECT = 11013L, - WSA_QOS_TRAFFIC_CTRL_ERROR = 11014L, - WSA_QOS_GENERIC_ERROR = 11015L, - WSA_QOS_ESERVICETYPE = 11016L, - WSA_QOS_EFLOWSPEC = 11017L, - WSA_QOS_EPROVSPECBUF = 11018L, - WSA_QOS_EFILTERSTYLE = 11019L, - WSA_QOS_EFILTERTYPE = 11020L, - WSA_QOS_EFILTERCOUNT = 11021L, - WSA_QOS_EOBJLENGTH = 11022L, - WSA_QOS_EFLOWCOUNT = 11023L, - WSA_QOS_EUNKOWNPSOBJ = 11024L, - WSA_QOS_EPOLICYOBJ = 11025L, - WSA_QOS_EFLOWDESC = 11026L, - WSA_QOS_EPSFLOWSPEC = 11027L, - WSA_QOS_EPSFILTERSPEC = 11028L, - WSA_QOS_ESDMODEOBJ = 11029L, - WSA_QOS_ESHAPERATEOBJ = 11030L, - WSA_QOS_RESERVED_PETYPE = 11031L, - WSA_SECURE_HOST_NOT_FOUND = 11032L, - WSA_IPSEC_NAME_POLICY_ERROR = 11033L, - }; - - enum VKEnum : std::uint32_t - { - VK_LBUTTON = 0x1, - VK_RBUTTON = 0x2, - VK_CANCEL = 0x3, - VK_MBUTTON = 0x4, - VK_XBUTTON1 = 0x5, - VK_XBUTTON2 = 0x6, - VK_BACK = 0x8, - VK_TAB = 0x9, - VK_RESERVED_0A = 0xA, - VK_RESERVED_0B = 0xB, - VK_CLEAR = 0xC, - VK_RETURN = 0xD, - VK_SHIFT = 0x10, - VK_CONTROL = 0x11, - VK_MENU = 0x12, - VK_PAUSE = 0x13, - VK_CAPITAL = 0x14, - VK_KANA = 0x15, - VK_HANGUEL = 0x15, - VK_HANGUL = 0x15, - VK_IME_ON = 0x16, - VK_JUNJA = 0x17, - VK_FINAL = 0x18, - VK_HANJA = 0x19, - VK_KANJI = VK_HANJA, - VK_IME_OFF = 0x1A, - VK_ESCAPE = 0x1B, - VK_CONVERT = 0x1C, - VK_NONCONVERT = 0x1D, - VK_ACCEPT = 0x1E, - VK_MODECHANGE = 0x1F, - VK_SPACE = 0x20, - VK_PRIOR = 0x21, - VK_NEXT = 0x22, - VK_END = 0x23, - VK_HOME = 0x24, - VK_LEFT = 0x25, - VK_UP = 0x26, - VK_RIGHT = 0x27, - VK_DOWN = 0x28, - VK_SELECT = 0x29, - VK_PRINT = 0x2A, - VK_EXECUTE = 0x2B, - VK_SNAPSHOT = 0x2C, - VK_INSERT = 0x2D, - VK_DELETE = 0x2E, - VK_HELP = 0x2F, - VK_0 = 0x30, - VK_1 = 0x31, - VK_2 = 0x32, - VK_3 = 0x33, - VK_4 = 0x34, - VK_5 = 0x35, - VK_6 = 0x36, - VK_7 = 0x37, - VK_8 = 0x38, - VK_9 = 0x39, - VK_A = 0x41, - VK_B = 0x42, - VK_C = 0x43, - VK_D = 0x44, - VK_E = 0x45, - VK_F = 0x46, - VK_G = 0x47, - VK_H = 0x48, - VK_I = 0x49, - VK_J = 0x4A, - VK_K = 0x4B, - VK_L = 0x4C, - VK_M = 0x4D, - VK_N = 0x4E, - VK_O = 0x4F, - VK_P = 0x50, - VK_Q = 0x51, - VK_R = 0x52, - VK_S = 0x53, - VK_T = 0x54, - VK_U = 0x55, - VK_V = 0x56, - VK_W = 0x57, - VK_X = 0x58, - VK_Y = 0x59, - VK_Z = 0x5A, - VK_LWIN = 0x5B, - VK_RWIN = 0x5C, - VK_APPS = 0x5D, - VK_RESERVED_5E = 0x5E, - VK_SLEEP = 0x5F, - VK_NUMPAD0 = 0x60, - VK_NUMPAD1 = 0x61, - VK_NUMPAD2 = 0x62, - VK_NUMPAD3 = 0x63, - VK_NUMPAD4 = 0x64, - VK_NUMPAD5 = 0x65, - VK_NUMPAD6 = 0x66, - VK_NUMPAD7 = 0x67, - VK_NUMPAD8 = 0x68, - VK_NUMPAD9 = 0x69, - VK_MULTIPLY = 0x6A, - VK_ADD = 0x6B, - VK_SEPARATOR = 0x6C, - VK_SUBTRACT = 0x6D, - VK_DECIMAL = 0x6E, - VK_DIVIDE = 0x6F, - VK_F1 = 0x70, - VK_F2 = 0x71, - VK_F3 = 0x72, - VK_F4 = 0x73, - VK_F5 = 0x74, - VK_F6 = 0x75, - VK_F7 = 0x76, - VK_F8 = 0x77, - VK_F9 = 0x78, - VK_F10 = 0x79, - VK_F11 = 0x7A, - VK_F12 = 0x7B, - VK_F13 = 0x7C, - VK_F14 = 0x7D, - VK_F15 = 0x7E, - VK_F16 = 0x7F, - VK_F17 = 0x80, - VK_F18 = 0x81, - VK_F19 = 0x82, - VK_F20 = 0x83, - VK_F21 = 0x84, - VK_F22 = 0x85, - VK_F23 = 0x86, - VK_F24 = 0x87, - VK_NUMLOCK = 0x90, - VK_SCROLL = 0x91, - VK_OEMSPECIFIC_92 = 0x92, - VK_OEMSPECIFIC_93 = 0x93, - VK_OEMSPECIFIC_94 = 0x94, - VK_OEMSPECIFIC_95 = 0x95, - VK_OEMSPECIFIC_96 = 0x96, - VK_LSHIFT = 0xA0, - VK_RSHIFT = 0xA1, - VK_LCONTROL = 0xA2, - VK_RCONTROL = 0xA3, - VK_LMENU = 0xA4, - VK_RMENU = 0xA5, - VK_BROWSER_BACK = 0xA6, - VK_BROWSER_FORWARD = 0xA7, - VK_BROWSER_REFRESH = 0xA8, - VK_BROWSER_STOP = 0xA9, - VK_BROWSER_SEARCH = 0xAA, - VK_BROWSER_FAVORITES = 0xAB, - VK_BROWSER_HOME = 0xAC, - VK_VOLUME_MUTE = 0xAD, - VK_VOLUME_DOWN = 0xAE, - VK_VOLUME_UP = 0xAF, - VK_MEDIA_NEXT_TRACK = 0xB0, - VK_MEDIA_PREV_TRACK = 0xB1, - VK_MEDIA_STOP = 0xB2, - VK_MEDIA_PLAY_PAUSE = 0xB3, - VK_LAUNCH_MAIL = 0xB4, - VK_LAUNCH_MEDIA_SELECT = 0xB5, - VK_LAUNCH_APP1 = 0xB6, - VK_LAUNCH_APP2 = 0xB7, - VK_RESERVED_B8 = 0xB8, - VK_RESERVED_B9 = 0xB9, - VK_OEM_1 = 0xBA, - VK_OEM_PLUS = 0xBB, - VK_OEM_COMMA = 0xBC, - VK_OEM_MINUS = 0xBD, - VK_OEM_PERIOD = 0xBE, - VK_OEM_2 = 0xBF, - VK_OEM_3 = 0xC0, - VK_RESERVED_C1 = 0xC1, - VK_RESERVED_C2 = 0xC2, - VK_RESERVED_C3 = 0xC3, - VK_RESERVED_C4 = 0xC4, - VK_RESERVED_C5 = 0xC5, - VK_RESERVED_C6 = 0xC6, - VK_RESERVED_C7 = 0xC7, - VK_RESERVED_C8 = 0xC8, - VK_RESERVED_C9 = 0xC9, - VK_RESERVED_CA = 0xCA, - VK_RESERVED_CB = 0xCB, - VK_RESERVED_CC = 0xCC, - VK_RESERVED_CD = 0xCD, - VK_RESERVED_CE = 0xCE, - VK_RESERVED_CF = 0xCF, - VK_RESERVED_D0 = 0xD0, - VK_RESERVED_D1 = 0xD1, - VK_RESERVED_D2 = 0xD2, - VK_RESERVED_D3 = 0xD3, - VK_RESERVED_D4 = 0xD4, - VK_RESERVED_D5 = 0xD5, - VK_RESERVED_D6 = 0xD6, - VK_RESERVED_D7 = 0xD7, - VK_OEM_4 = 0xDB, - VK_OEM_5 = 0xDC, - VK_OEM_6 = 0xDD, - VK_OEM_7 = 0xDE, - VK_OEM_8 = 0xDF, - VK_RESERVED_E0 = 0xE0, - VK_OEMSPECIFIC_E1 = 0xE1, - VK_OEM_102 = 0xE2, - VK_OEMSPECIFIC_E3 = 0xE3, - VK_OEMSPECIFIC_E4 = 0xE4, - VK_PROCESSKEY = 0xE5, - VK_OEMSPECIFIC_E6 = 0xE6, - VK_PACKET = 0xE7, - VK_OEMSPECIFIC_E9 = 0xE9, - VK_OEMSPECIFIC_EA = 0xEA, - VK_OEMSPECIFIC_EB = 0xEB, - VK_OEMSPECIFIC_EC = 0xEC, - VK_OEMSPECIFIC_ED = 0xED, - VK_OEMSPECIFIC_EE = 0xEE, - VK_OEMSPECIFIC_EF = 0xEF, - VK_OEMSPECIFIC_F0 = 0xF0, - VK_OEMSPECIFIC_F1 = 0xF1, - VK_OEMSPECIFIC_F2 = 0xF2, - VK_OEMSPECIFIC_F3 = 0xF3, - VK_OEMSPECIFIC_F4 = 0xF4, - VK_OEMSPECIFIC_F5 = 0xF5, - VK_ATTN = 0xF6, - VK_CRSEL = 0xF7, - VK_EXSEL = 0xF8, - VK_EREOF = 0xF9, - VK_PLAY = 0xFA, - VK_ZOOM = 0xFB, - VK_NONAME = 0xFC, - VK_PA1 = 0xFD, - VK_OEM_CLEAR = 0xFE, - VK_RESERVED_FF = 0xFF - }; - - bool CloseHandle( - void* a_handle) noexcept; - - void CoTaskMemFree( - void* a_block) noexcept; - - void* CreateFileMapping( - void* a_file, - SECURITY_ATTRIBUTES* a_attributes, - std::uint32_t a_protect, - std::uint32_t a_maxSizeHigh, - std::uint32_t a_maxSizeLow, - const char* a_name) noexcept; - - void* CreateFileMapping( - void* a_file, - SECURITY_ATTRIBUTES* a_attributes, - std::uint32_t a_protect, - std::uint32_t a_maxSizeHigh, - std::uint32_t a_maxSizeLow, - const wchar_t* a_name) noexcept; - - bool CreateProcess( - const char* a_name, - char* a_cmd, - SECURITY_ATTRIBUTES* a_procAttr, - SECURITY_ATTRIBUTES* a_threadAttr, - bool a_inherit, - std::uint32_t a_flags, - void* a_env, - const char* a_curDir, - STARTUPINFOA* a_startInfo, - PROCESS_INFORMATION* a_procInfo) noexcept; - - bool CreateProcess( - const wchar_t* a_name, - wchar_t* a_cmd, - SECURITY_ATTRIBUTES* a_procAttr, - SECURITY_ATTRIBUTES* a_threadAttr, - bool a_inherit, - std::uint32_t a_flags, - void* a_env, - const wchar_t* a_curDir, - STARTUPINFOW* a_startInfo, - PROCESS_INFORMATION* a_procInfo) noexcept; - - void* CreateRemoteThread( - void* a_process, - SECURITY_ATTRIBUTES* a_threadAttr, - std::size_t a_stackSize, - THREAD_START_ROUTINE* a_startAddr, - void* a_param, - std::uint32_t a_flags, - std::uint32_t* a_threadID) noexcept; - - void* CreateThread( - SECURITY_ATTRIBUTES* a_threadAttr, - std::size_t a_stackSize, - THREAD_START_ROUTINE* a_startAddr, - void* a_param, - std::uint32_t a_flags, - std::uint32_t* a_threadID) noexcept; - - std::uint32_t ExpandEnvironmentStrings( - const char* a_src, - char* a_dst, - std::uint32_t a_dstLen) noexcept; - - std::uint32_t ExpandEnvironmentStrings( - const wchar_t* a_src, - wchar_t* a_dst, - std::uint32_t a_dstLen) noexcept; - - [[nodiscard]] bool FindClose( - void* a_file) noexcept; - - [[nodiscard]] void* FindFirstFile( - const char* a_name, - WIN32_FIND_DATAA* a_data) noexcept; - - [[nodiscard]] void* FindFirstFile( - const wchar_t* a_name, - WIN32_FIND_DATAW* a_data) noexcept; - - [[nodiscard]] bool FindNextFile( - void* a_file, - WIN32_FIND_DATAA* a_data) noexcept; - - [[nodiscard]] bool FindNextFile( - void* a_file, - WIN32_FIND_DATAW* a_data) noexcept; - - bool FlushInstructionCache( - void* a_process, - const void* a_baseAddr, - std::size_t a_size) noexcept; - - bool FreeLibrary( - HMODULE a_module) noexcept; - - [[nodiscard]] std::uint32_t GetCurrentDirectory( - std::uint32_t a_size, - char* a_buffer) noexcept; - - [[nodiscard]] void* GetCurrentModule() noexcept; - - [[nodiscard]] void* GetCurrentProcess() noexcept; - - [[nodiscard]] std::uint32_t GetCurrentThreadID() noexcept; - - [[nodiscard]] std::uint32_t GetEnvironmentVariable( - const char* a_name, - char* a_buffer, - std::uint32_t a_size) noexcept; - - [[nodiscard]] std::uint32_t GetEnvironmentVariable( - const wchar_t* a_name, - wchar_t* a_buffer, - std::uint32_t a_size) noexcept; - - [[nodiscard]] bool GetFileVersionInfo( - const char* a_name, - std::uint32_t a_handle, - std::uint32_t a_dataLen, - void* a_data) noexcept; - - [[nodiscard]] bool GetFileVersionInfo( - const wchar_t* a_name, - std::uint32_t a_handle, - std::uint32_t a_dataLen, - void* a_data) noexcept; - - [[nodiscard]] std::uint32_t GetFileVersionInfoSize( - const char* a_name, - std::uint32_t* a_handle) noexcept; - - [[nodiscard]] std::uint32_t GetFileVersionInfoSize( - const wchar_t* a_name, - std::uint32_t* a_handle) noexcept; - - [[nodiscard]] std::int32_t GetKeyNameText( - std::int32_t a_param, - char* a_buffer, - std::int32_t a_bufferLen) noexcept; - - [[nodiscard]] std::int32_t GetKeyNameText( - std::int32_t a_param, - wchar_t* a_buffer, - std::int32_t a_bufferLen) noexcept; - - [[nodiscard]] std::int16_t GetKeyState( - std::int32_t a_key) noexcept; - - [[nodiscard]] std::uint32_t GetLastError() noexcept; - - [[nodiscard]] std::size_t GetMaxPath() noexcept; - - [[nodiscard]] std::uint32_t GetModuleFileName( - void* a_module, - char* a_name, - std::uint32_t a_nameLen) noexcept; - - [[nodiscard]] std::uint32_t GetModuleFileName( - void* a_module, - wchar_t* a_name, - std::uint32_t a_nameLen) noexcept; - - [[nodiscard]] HMODULE GetModuleHandle( - const char* a_name) noexcept; - - [[nodiscard]] HMODULE GetModuleHandle( - const wchar_t* a_name) noexcept; - - [[nodiscard]] std::uint32_t GetPrivateProfileString( - const char* a_app, - const char* a_key, - const char* a_default, - char* a_out, - std::uint32_t a_outLen, - const char* a_name) noexcept; - - [[nodiscard]] std::uint32_t GetPrivateProfileString( - const wchar_t* a_app, - const wchar_t* a_key, - const wchar_t* a_default, - wchar_t* a_out, - std::uint32_t a_outLen, - const wchar_t* a_name) noexcept; - - [[nodiscard]] void* GetProcAddress( - void* a_module, - const char* a_name) noexcept; - - [[nodiscard]] std::string_view GetProcPath( - HMODULE a_handle) noexcept; - - void GetSystemInfo( - SYSTEM_INFO* a_info) noexcept; - - [[nodiscard]] std::uint16_t htons(std::uint16_t hostshort) noexcept; - - [[nodiscard]] bool IMAGE_SNAP_BY_ORDINAL64( - std::uint64_t a_ordinal) noexcept; - - [[nodiscard]] IMAGE_SECTION_HEADER* IMAGE_FIRST_SECTION( - const IMAGE_NT_HEADERS64* a_header) noexcept; - - [[nodiscard]] bool IsDebuggerPresent() noexcept; - - std::int32_t LCMapStringEx( - const wchar_t* a_locale, - std::uint32_t a_flags, - const wchar_t* a_src, - std::int32_t a_srcLen, - wchar_t* a_dest, - std::int32_t a_destLen, - NLSVERSIONINFO* a_info, - void* a_reserved, - std::intptr_t a_sortHandle) noexcept; - - [[nodiscard]] HMODULE LoadLibrary( - const char* a_name) noexcept; - - [[nodiscard]] HMODULE LoadLibrary( - const wchar_t* a_name) noexcept; - - [[nodiscard]] void* MapViewOfFile( - void* a_object, - std::uint32_t a_desiredAccess, - std::uint32_t a_fileOffsetHigh, - std::uint32_t a_fileOffsetLow, - std::size_t a_numBytesToMap) noexcept; - - [[nodiscard]] void* MapViewOfFileEx( - void* a_object, - std::uint32_t a_desiredAccess, - std::uint32_t a_fileOffsetHigh, - std::uint32_t a_fileOffsetLow, - std::size_t a_numBytesToMap, - void* a_baseAddress) noexcept; - - std::int32_t MessageBox( - void* a_wnd, - const char* a_text, - const char* a_caption, - std::uint32_t a_type) noexcept; - - std::int32_t MessageBox( - void* a_wnd, - const wchar_t* a_text, - const wchar_t* a_caption, - std::uint32_t a_type) noexcept; - - [[nodiscard]] std::int32_t MultiByteToWideChar( - std::uint32_t a_codePage, - std::uint32_t a_flags, - const char* a_str, - std::int32_t a_strLen, - wchar_t* a_wstr, - std::int32_t a_wstrLen); - - [[nodiscard]] std::int32_t NormalizeString( - std::int32_t a_normForm, - const wchar_t* a_src, - std::int32_t a_srcLen, - wchar_t* a_dest, - std::int32_t a_destLen); - - [[nodiscard]] std::uint32_t ntohl(std::uint32_t netlong) noexcept; - - [[nodiscard]] void* OpenFileMapping( - std::uint32_t a_desiredAccess, - bool a_inheritHandle, - const char* a_name) noexcept; - - [[nodiscard]] void* OpenFileMapping( - std::uint32_t a_desiredAccess, - bool a_inheritHandle, - const wchar_t* a_name) noexcept; - - void OutputDebugString( - const char* a_outStr) noexcept; - - void OutputDebugString( - const wchar_t* a_outStr) noexcept; - - std::int32_t RegGetValue( - HKEY a_key, - const char* a_subKey, - const char* a_value, - std::uint32_t a_flags, - std::uint32_t* a_type, - void* a_data, - std::uint32_t* a_dataLen); - - std::int32_t RegGetValue( - HKEY a_key, - const wchar_t* a_subKey, - const wchar_t* a_value, - std::uint32_t a_flags, - std::uint32_t* a_type, - void* a_data, - std::uint32_t* a_dataLen); - - std::uint32_t ResumeThread( - void* a_handle) noexcept; - - bool SetEnvironmentVariable( - const char* a_name, - const char* a_value) noexcept; - - bool SetEnvironmentVariable( - const wchar_t* a_name, - const wchar_t* a_value) noexcept; - - [[nodiscard]] std::int32_t SHGetKnownFolderPath( - const GUID& a_id, - std::uint32_t a_flags, - void* a_token, - wchar_t** a_path) noexcept; - - [[nodiscard]] std::int32_t ShowCursor( - bool a_show) noexcept; - - void Sleep( - std::uint32_t a_milliseconds) noexcept; - - bool TerminateProcess( - void* a_process, - std::uint32_t a_exitCode) noexcept; - - [[nodiscard]] void* TlsGetValue( - std::uint32_t a_index) noexcept; - - bool TlsSetValue( - std::uint32_t a_index, - void* a_value) noexcept; - - [[nodiscard]] std::uint32_t UnDecorateSymbolName( - const char* a_name, - char* a_out, - std::uint32_t a_outLenMax, - std::uint32_t a_flags) noexcept; - - [[nodiscard]] std::uint32_t UnDecorateSymbolName( - const wchar_t* a_name, - wchar_t* a_out, - std::uint32_t a_outLenMax, - std::uint32_t a_flags) noexcept; - - [[nodiscard]] bool UnmapViewOfFile( - const void* a_baseAddress) noexcept; - - [[nodiscard]] bool VerQueryValue( - const void* a_block, - const char* a_subBlock, - void** a_buffer, - std::uint32_t* a_bufferLen) noexcept; - - [[nodiscard]] bool VerQueryValue( - const void* a_block, - const wchar_t* a_subBlock, - void** a_buffer, - std::uint32_t* a_bufferLen) noexcept; - - void* VirtualAlloc( - void* a_address, - std::size_t a_size, - std::uint32_t a_type, - std::uint32_t a_protect) noexcept; - - void* VirtualAllocEx( - void* a_process, - void* a_address, - std::size_t a_size, - std::uint32_t a_type, - std::uint32_t a_protect) noexcept; - - bool VirtualFree( - void* a_address, - std::size_t a_size, - std::uint32_t a_type) noexcept; - - bool VirtualFreeEx( - void* a_process, - void* a_address, - std::size_t a_size, - std::uint32_t a_type) noexcept; - - [[nodiscard]] bool VirtualProtect( - void* a_address, - std::size_t a_size, - std::uint32_t a_newProtect, - std::uint32_t* a_oldProtect) noexcept; - - [[nodiscard]] bool VirtualProtectEx( - void* a_process, - void* a_address, - std::size_t a_size, - std::uint32_t a_newProtect, - std::uint32_t* a_oldProtect) noexcept; - - [[nodiscard]] std::size_t VirtualQuery( - const void* a_address, - MEMORY_BASIC_INFORMATION* a_buffer, - std::size_t a_bufferLen) noexcept; - - [[nodiscard]] std::size_t VirtualQueryEx( - void* a_process, - const void* a_address, - MEMORY_BASIC_INFORMATION* a_buffer, - std::size_t a_bufferLen) noexcept; - - [[nodiscard]] std::uint32_t WaitForSingleObject( - void* a_handle, - std::uint32_t a_milliseconds) noexcept; - - [[nodiscard]] std::uint32_t WaitForSingleObjectEx( - void* a_handle, - std::uint32_t a_milliseconds, - bool a_alertable) noexcept; - - [[nodiscard]] std::int32_t WideCharToMultiByte( - std::uint32_t a_codePage, - std::uint32_t a_flags, - const wchar_t* a_wstr, - std::int32_t a_wstrLen, - char* a_str, - std::int32_t a_strLen, - const char* a_default, - std::int32_t* a_defaultLen); - - [[nodiscard]] std::int32_t WSAGetLastError() noexcept; - - [[nodiscard]] bool WriteProcessMemory( - void* a_process, - void* a_address, - const void* a_buffer, - std::size_t a_bufferLen, - std::size_t* a_bufferWritten) noexcept; -} - -#endif // _INC_WINAPIFAMILY - -namespace RE::DirectX -{ - struct XMCOLOR - { - public: - // members - union - { - struct - { - uint8_t b; - uint8_t g; - uint8_t r; - uint8_t a; - }; - uint32_t c; - }; - }; - static_assert(sizeof(XMCOLOR) == 0x4); - - struct XMFLOAT3 - { - public: - // members - float x; - float y; - float z; - }; - static_assert(sizeof(XMFLOAT3) == 0xC); - - struct XMFLOAT4 - { - public: - // members - float x; - float y; - float z; - float w; - }; - static_assert(sizeof(XMFLOAT4) == 0x10); - - struct XMFLOAT4X4 - { - public: - // members - float m[4][4]; - }; - static_assert(sizeof(XMFLOAT4X4) == 0x40); -} diff --git a/include/SFSE/Impl/XInputAPI.h b/include/SFSE/Impl/XInputAPI.h deleted file mode 100644 index df3578d7..00000000 --- a/include/SFSE/Impl/XInputAPI.h +++ /dev/null @@ -1,80 +0,0 @@ -#pragma once - -// TODO: This should probably be behind some sort of pragma that allows linking with xinput -namespace RE::XInput -{ - struct __XINPUT_GAMEPAD - { - std::uint16_t wButtons; - std::byte bLeftTrigger; - std::byte bRightTrigger; - std::int16_t sThumbLX; - std::int16_t sThumbLY; - std::int16_t sThumbRX; - std::int16_t sThumbRY; - }; - - using XINPUT_GAMEPAD = __XINPUT_GAMEPAD; - - struct __XINPUT_STATE - { - std::uint32_t dwPacketNumber; - __XINPUT_GAMEPAD Gamepad; - }; - - using XINPUT_STATE = __XINPUT_STATE; - - struct __XINPUT_KEYSTROKE - { - std::uint16_t VirtualKey; - std::uint16_t Unicode; - std::uint16_t Flags; - std::uint8_t UserIndex; - std::uint8_t HidCode; - }; - - using XINPUT_KEYSTROKE = __XINPUT_KEYSTROKE; - - struct __XINPUT_VIBRATION - { - std::uint16_t wLeftMotorSpeed; - std::uint16_t wRightMotorSpeed; - }; - - using XINPUT_VIBRATION = __XINPUT_VIBRATION; - - struct __XINPUT_CAPABILITIES - { - std::uint8_t Type; - std::uint8_t SubType; - std::uint16_t Flags; - XINPUT_GAMEPAD Gamepad; - XINPUT_VIBRATION Vibration; - }; - - using XINPUT_CAPABILITIES = __XINPUT_CAPABILITIES; - - enum XInputButton : std::uint16_t - { - XINPUT_GAMEPAD_DPAD_UP = 0x0001, - XINPUT_GAMEPAD_DPAD_DOWN = 0x0002, - XINPUT_GAMEPAD_DPAD_LEFT = 0x0004, - XINPUT_GAMEPAD_DPAD_RIGHT = 0x0008, - XINPUT_GAMEPAD_START = 0x0010, - XINPUT_GAMEPAD_BACK = 0x0020, - XINPUT_GAMEPAD_LEFT_THUMB = 0x0040, - XINPUT_GAMEPAD_RIGHT_THUMB = 0x0080, - XINPUT_GAMEPAD_LEFT_SHOULDER = 0x0100, - XINPUT_GAMEPAD_RIGHT_SHOULDER = 0x0200, - XINPUT_GAMEPAD_A = 0x1000, - XINPUT_GAMEPAD_B = 0x2000, - XINPUT_GAMEPAD_X = 0x4000, - XINPUT_GAMEPAD_Y = 0x8000 - }; - - static constexpr std::uint16_t XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE = 7849; - static constexpr std::uint16_t XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE = 8689; - static constexpr std::uint8_t XINPUT_GAMEPAD_TRIGGER_THRESHOLD = 30; - - static constexpr std::uint16_t XINPUT_BUTTON_MASK = XINPUT_GAMEPAD_DPAD_UP | XINPUT_GAMEPAD_DPAD_DOWN | XINPUT_GAMEPAD_DPAD_LEFT | XINPUT_GAMEPAD_DPAD_RIGHT | XINPUT_GAMEPAD_START | XINPUT_GAMEPAD_BACK | XINPUT_GAMEPAD_LEFT_THUMB | XINPUT_GAMEPAD_RIGHT_THUMB | XINPUT_GAMEPAD_LEFT_SHOULDER | XINPUT_GAMEPAD_RIGHT_SHOULDER | XINPUT_GAMEPAD_A | XINPUT_GAMEPAD_B | XINPUT_GAMEPAD_X | XINPUT_GAMEPAD_Y; -} diff --git a/include/SFSE/Trampoline.h b/include/SFSE/Trampoline.h index 952383e5..d7b761c5 100644 --- a/include/SFSE/Trampoline.h +++ b/include/SFSE/Trampoline.h @@ -76,7 +76,7 @@ namespace SFSE stl::report_and_fail("failed to create trampoline"sv); } - set_trampoline(mem, a_size, [](void* a_mem, std::size_t) { WinAPI::VirtualFree(a_mem, 0, WinAPI::MEM_RELEASE); }); + set_trampoline(mem, a_size, [](void* a_mem, std::size_t) { REX::W32::VirtualFree(a_mem, 0, REX::W32::MEM_RELEASE); }); } void set_trampoline(void* a_trampoline, const std::size_t a_size) { set_trampoline(a_trampoline, a_size, {}); } diff --git a/scripts/IDAPDB.py b/scripts/IDAPDB.py index abb3bd2c..a90feee0 100644 --- a/scripts/IDAPDB.py +++ b/scripts/IDAPDB.py @@ -34,13 +34,13 @@ def manip(pdb_file, new_pdb_file): data = f.read() data = re.sub(r"\bRE::DirectInput8::", "", data) data = re.sub(r"\bRE::DirectX::", "", data) - data = re.sub(r"\bSFSE::WinAPI::", "", data) + data = re.sub(r"\bREX::W32::", "", data) data = re.sub(r"\bSFSE::stl::", "stl::", data) data = re.sub(r"\bRE::", "", data) # get the mangled names too data = re.sub("@DirectInput8@RE@@", "@@", data) data = re.sub("@DirectX@RE@@", "@@", data) - data = re.sub("@WinAPI@SFSE@@", "@@", data) + data = re.sub("@W32@REX@@", "@@", data) data = re.sub("@stl@SFSE@@", "@stl@@", data) data = re.sub("@RE@@", "@@", data) with open(yaml_file, "w") as f: diff --git a/src/RE/B/BSSystemFile.cpp b/src/RE/B/BSSystemFile.cpp index 81f84131..d5d0dacd 100644 --- a/src/RE/B/BSSystemFile.cpp +++ b/src/RE/B/BSSystemFile.cpp @@ -1,10 +1,12 @@ #include "RE/B/BSSystemFile.h" +#include "REX/W32/KERNEL32.h" + namespace RE { BSSystemFile::BSSystemFile() : flags(1), - file(WinAPI::INVALID_HANDLE_VALUE) + file(REX::W32::INVALID_HANDLE_VALUE) {} BSSystemFile::~BSSystemFile() @@ -20,14 +22,14 @@ namespace RE [[maybe_unused]] std::uint64_t a_unk1, bool a_write, ShareMode a_shareMode) : - file(WinAPI::INVALID_HANDLE_VALUE) + file(REX::W32::INVALID_HANDLE_VALUE) { flags = 0; if (a_read) { - flags |= WinAPI::GENERIC_READ; + flags |= REX::W32::GENERIC_READ; } if (a_write) { - flags |= WinAPI::GENERIC_WRITE; + flags |= REX::W32::GENERIC_WRITE; } auto ret = DoOpen(a_path, a_accessMode, a_openMode, a_shareMode); SetErrorCode(ret); @@ -50,7 +52,7 @@ namespace RE BSSystemFile& BSSystemFile::operator=(BSSystemFile& a_lhs) { // close the file if the handle is valid - if (file != WinAPI::INVALID_HANDLE_VALUE) { + if (file != REX::W32::INVALID_HANDLE_VALUE) { DoClose(); } file = a_lhs.file; @@ -68,7 +70,7 @@ namespace RE void BSSystemFile::Invalidate() { - file = WinAPI::INVALID_HANDLE_VALUE; + file = REX::W32::INVALID_HANDLE_VALUE; flags = 1; } @@ -101,7 +103,7 @@ namespace RE void BSSystemFile::SetErrorCode(ErrorCode a_errorCode) { - flags &= WinAPI::GENERIC_READ; + flags &= REX::W32::GENERIC_READ; flags |= static_cast(a_errorCode); } diff --git a/src/RE/I/idTCP.cpp b/src/RE/I/idTCP.cpp index bb01e709..191aa88d 100644 --- a/src/RE/I/idTCP.cpp +++ b/src/RE/I/idTCP.cpp @@ -4,119 +4,113 @@ namespace RE { const char* NET_ErrorString() { - using WSAError = WinAPI::WSAError; - - const auto code = static_cast(WinAPI::WSAGetLastError()); - switch (code) { - case WSAError::WSAEINTR: + switch (REX::W32::WSAGetLastError()) { + case REX::W32::WSAEINTR: return "WSAEINTR"; - case WSAError::WSAEBADF: + case REX::W32::WSAEBADF: return "WSAEBADF"; - case WSAError::WSAEACCES: + case REX::W32::WSAEACCES: return "WSAEACCES"; - case WSAError::WSAEDISCON: + case REX::W32::WSAEDISCON: return "WSAEDISCON"; - case WSAError::WSAEFAULT: + case REX::W32::WSAEFAULT: return "WSAEFAULT"; - case WSAError::WSAEINVAL: + case REX::W32::WSAEINVAL: return "WSAEINVAL"; - case WSAError::WSAEMFILE: + case REX::W32::WSAEMFILE: return "WSAEMFILE"; - case WSAError::WSAEWOULDBLOCK: + case REX::W32::WSAEWOULDBLOCK: return "WSAEWOULDBLOCK"; - case WSAError::WSAEINPROGRESS: + case REX::W32::WSAEINPROGRESS: return "WSAEINPROGRESS"; - case WSAError::WSAEALREADY: + case REX::W32::WSAEALREADY: return "WSAEALREADY"; - case WSAError::WSAENOTSOCK: + case REX::W32::WSAENOTSOCK: return "WSAENOTSOCK"; - case WSAError::WSAEDESTADDRREQ: + case REX::W32::WSAEDESTADDRREQ: return "WSAEDESTADDRREQ"; - case WSAError::WSAEMSGSIZE: + case REX::W32::WSAEMSGSIZE: return "WSAEMSGSIZE"; - case WSAError::WSAEPROTOTYPE: + case REX::W32::WSAEPROTOTYPE: return "WSAEPROTOTYPE"; - case WSAError::WSAENOPROTOOPT: + case REX::W32::WSAENOPROTOOPT: return "WSAENOPROTOOPT"; - case WSAError::WSAEPROTONOSUPPORT: + case REX::W32::WSAEPROTONOSUPPORT: return "WSAEPROTONOSUPPORT"; - case WSAError::WSAESOCKTNOSUPPORT: + case REX::W32::WSAESOCKTNOSUPPORT: return "WSAESOCKTNOSUPPORT"; - case WSAError::WSAEOPNOTSUPP: + case REX::W32::WSAEOPNOTSUPP: return "WSAEOPNOTSUPP"; - case WSAError::WSAEPFNOSUPPORT: + case REX::W32::WSAEPFNOSUPPORT: return "WSAEPFNOSUPPORT"; - case WSAError::WSAEAFNOSUPPORT: + case REX::W32::WSAEAFNOSUPPORT: return "WSAEAFNOSUPPORT"; - case WSAError::WSAEADDRINUSE: + case REX::W32::WSAEADDRINUSE: return "WSAEADDRINUSE"; - case WSAError::WSAEADDRNOTAVAIL: + case REX::W32::WSAEADDRNOTAVAIL: return "WSAEADDRNOTAVAIL"; - case WSAError::WSAENETDOWN: + case REX::W32::WSAENETDOWN: return "WSAENETDOWN"; - case WSAError::WSAENETUNREACH: + case REX::W32::WSAENETUNREACH: return "WSAENETUNREACH"; - case WSAError::WSAENETRESET: + case REX::W32::WSAENETRESET: return "WSAENETRESET"; - case WSAError::WSAECONNABORTED: + case REX::W32::WSAECONNABORTED: return "WSWSAECONNABORTEDAEINTR"; - case WSAError::WSAECONNRESET: + case REX::W32::WSAECONNRESET: return "WSAECONNRESET"; - case WSAError::WSAENOBUFS: + case REX::W32::WSAENOBUFS: return "WSAENOBUFS"; - case WSAError::WSAEISCONN: + case REX::W32::WSAEISCONN: return "WSAEISCONN"; - case WSAError::WSAENOTCONN: + case REX::W32::WSAENOTCONN: return "WSAENOTCONN"; - case WSAError::WSAESHUTDOWN: + case REX::W32::WSAESHUTDOWN: return "WSAESHUTDOWN"; - case WSAError::WSAETOOMANYREFS: + case REX::W32::WSAETOOMANYREFS: return "WSAETOOMANYREFS"; - case WSAError::WSAETIMEDOUT: + case REX::W32::WSAETIMEDOUT: return "WSAETIMEDOUT"; - case WSAError::WSAECONNREFUSED: + case REX::W32::WSAECONNREFUSED: return "WSAECONNREFUSED"; - case WSAError::WSAELOOP: + case REX::W32::WSAELOOP: return "WSAELOOP"; - case WSAError::WSAENAMETOOLONG: + case REX::W32::WSAENAMETOOLONG: return "WSAENAMETOOLONG"; - case WSAError::WSAEHOSTDOWN: + case REX::W32::WSAEHOSTDOWN: return "WSAEHOSTDOWN"; - case WSAError::WSASYSNOTREADY: + case REX::W32::WSASYSNOTREADY: return "WSASYSNOTREADY"; - case WSAError::WSAVERNOTSUPPORTED: + case REX::W32::WSAVERNOTSUPPORTED: return "WSAVERNOTSUPPORTED"; - case WSAError::WSANOTINITIALISED: + case REX::W32::WSANOTINITIALISED: return "WSANOTINITIALISED"; - case WSAError::WSAHOST_NOT_FOUND: + case REX::W32::WSAHOST_NOT_FOUND: return "WSAHOST_NOT_FOUND"; - case WSAError::WSATRY_AGAIN: + case REX::W32::WSATRY_AGAIN: return "WSATRY_AGAIN"; - case WSAError::WSANO_RECOVERY: + case REX::W32::WSANO_RECOVERY: return "WSANO_RECOVERY"; - case WSAError::WSANO_DATA: + case REX::W32::WSANO_DATA: return "WSANO_DATA"; default: return "NO ERROR"; } } - void Net_SockadrToNetadr(WinAPI::sockaddr* s, netadr_t* a) + void Net_SockadrToNetadr(REX::W32::sockaddr* a_saddr, netadr_t* a_naddr) { - using AFType = WinAPI::AFType; - using sockaddr_in = WinAPI::sockaddr_in; - - if (s->sa_family == AFType::AF_INET) { - const auto sin = reinterpret_cast(s); + if (a_saddr->sa_family == REX::W32::AF_INET) { + const auto sin = reinterpret_cast(a_saddr); auto ip = sin->sin_addr.s_addr; - *reinterpret_cast(&a->ip) = ip; - a->port = WinAPI::htons(sin->sin_port); - ip = WinAPI::ntohl(ip); + *reinterpret_cast(&a_naddr->ip) = ip; + a_naddr->port = REX::W32::htons(sin->sin_port); + ip = REX::W32::ntohl(ip); - if (ip == WinAPI::INADDR_LOOPBACK) { - a->type = netadrtype_t::NA_LOOPBACK; + if (ip == REX::W32::INADDR_LOOPBACK) { + a_naddr->type = netadrtype_t::NA_LOOPBACK; } else { - a->type = netadrtype_t::NA_IP; + a_naddr->type = netadrtype_t::NA_IP; } } } diff --git a/src/REL/ID.cpp b/src/REL/ID.cpp index 38a3ecdc..f79964ae 100644 --- a/src/REL/ID.cpp +++ b/src/REL/ID.cpp @@ -1,5 +1,7 @@ #include "REL/ID.h" +#include "REX/W32/KERNEL32.h" + namespace REL { namespace database @@ -28,11 +30,11 @@ namespace REL { close(); - WinAPI::ULARGE_INTEGER bytes; + REX::W32::ULARGE_INTEGER bytes; bytes.value = a_size; - _mapping = WinAPI::OpenFileMapping( - WinAPI::FILE_MAP_READ | WinAPI::FILE_MAP_WRITE, + _mapping = REX::W32::OpenFileMappingW( + REX::W32::FILE_MAP_READ | REX::W32::FILE_MAP_WRITE, false, a_name.data()); @@ -41,9 +43,9 @@ namespace REL return false; } - _view = WinAPI::MapViewOfFile( + _view = REX::W32::MapViewOfFile( _mapping, - WinAPI::FILE_MAP_READ | WinAPI::FILE_MAP_WRITE, + REX::W32::FILE_MAP_READ | REX::W32::FILE_MAP_WRITE, 0, 0, bytes.value); @@ -60,19 +62,19 @@ namespace REL { close(); - WinAPI::ULARGE_INTEGER bytes; + REX::W32::ULARGE_INTEGER bytes; bytes.value = a_size; - _mapping = WinAPI::OpenFileMapping( - WinAPI::FILE_MAP_READ | WinAPI::FILE_MAP_WRITE, + _mapping = REX::W32::OpenFileMappingW( + REX::W32::FILE_MAP_READ | REX::W32::FILE_MAP_WRITE, false, a_name.data()); if (!_mapping) { - _mapping = WinAPI::CreateFileMapping( - WinAPI::INVALID_HANDLE_VALUE, + _mapping = REX::W32::CreateFileMappingW( + REX::W32::INVALID_HANDLE_VALUE, nullptr, - WinAPI::PAGE_READWRITE, + REX::W32::PAGE_READWRITE, bytes.hi, bytes.lo, a_name.data()); @@ -82,9 +84,9 @@ namespace REL } } - _view = WinAPI::MapViewOfFile( + _view = REX::W32::MapViewOfFile( _mapping, - WinAPI::FILE_MAP_READ | WinAPI::FILE_MAP_WRITE, + REX::W32::FILE_MAP_READ | REX::W32::FILE_MAP_WRITE, 0, 0, bytes.value); @@ -99,12 +101,12 @@ namespace REL constexpr void memory_map::close() { if (_view) { - (void)WinAPI::UnmapViewOfFile(_view); + REX::W32::UnmapViewOfFile(_view); _view = nullptr; } if (_mapping) { - (void)WinAPI::CloseHandle(_mapping); + REX::W32::CloseHandle(_mapping); _mapping = nullptr; } } @@ -169,7 +171,7 @@ namespace REL file /= std::format("{}\\versionlib-{}", database::LookUpDir, version.string("-")); _platform = Platform::kUnknown; - if (WinAPI::GetModuleHandle(L"steam_api64")) { + if (REX::W32::GetModuleHandleW(L"steam_api64")) { _platform = Platform::kSteam; _is_steam = true; } else { diff --git a/src/REX/W32.cpp b/src/REX/W32.cpp new file mode 100644 index 00000000..469fe4bf --- /dev/null +++ b/src/REX/W32.cpp @@ -0,0 +1,809 @@ +#include "REX/W32/ADVAPI32.h" +#include "REX/W32/BCRYPT.h" +#include "REX/W32/DBGHELP.h" +#include "REX/W32/DXGI.h" +#include "REX/W32/KERNEL32.h" +#include "REX/W32/OLE32.h" +#include "REX/W32/SHELL32.h" +#include "REX/W32/USER32.h" +#include "REX/W32/VERSION.h" + +// ADVAPI32 + +REX_W32_IMPORT(std::int32_t, RegGetValueA, REX::W32::HKEY, const char*, const char*, std::uint32_t, std::uint32_t*, void*, std::uint32_t*); +REX_W32_IMPORT(std::int32_t, RegGetValueW, REX::W32::HKEY, const wchar_t*, const wchar_t*, std::uint32_t, std::uint32_t*, void*, std::uint32_t*); + +namespace REX::W32 +{ + std::int32_t RegGetValueA(HKEY a_key, const char* a_subKey, const char* a_value, std::uint32_t a_flags, std::uint32_t* a_type, void* a_data, std::uint32_t* a_dataLen) + { + return ::W32_IMPL_RegGetValueA(a_key, a_subKey, a_value, a_flags, a_type, a_data, a_dataLen); + } + + std::int32_t RegGetValueW(HKEY a_key, const wchar_t* a_subKey, const wchar_t* a_value, std::uint32_t a_flags, std::uint32_t* a_type, void* a_data, std::uint32_t* a_dataLen) + { + return ::W32_IMPL_RegGetValueW(a_key, a_subKey, a_value, a_flags, a_type, a_data, a_dataLen); + } +} + +// BCRYPT + +REX_W32_IMPORT(REX::W32::NTSTATUS, BCryptOpenAlgorithmProvider, REX::W32::BCRYPT_ALG_HANDLE*, const wchar_t*, const wchar_t*, std::uint32_t); +REX_W32_IMPORT(REX::W32::NTSTATUS, BCryptCloseAlgorithmProvider, REX::W32::BCRYPT_ALG_HANDLE, std::uint32_t); +REX_W32_IMPORT(REX::W32::NTSTATUS, BCryptCreateHash, REX::W32::BCRYPT_ALG_HANDLE, BCRYPT_HASH_HANDLE*, std::uint8_t*, std::uint32_t, std::uint8_t*, std::uint32_t, std::uint32_t); +REX_W32_IMPORT(REX::W32::NTSTATUS, BCryptDestroyHash, REX::W32::BCRYPT_HASH_HANDLE); +REX_W32_IMPORT(REX::W32::NTSTATUS, BCryptFinishHash, REX::W32::BCRYPT_HASH_HANDLE, std::uint8_t*, std::uint32_t, std::uint32_t); +REX_W32_IMPORT(REX::W32::NTSTATUS, BCryptGetProperty, REX::W32::BCRYPT_HANDLE, const wchar_t*, std::uint8_t*, std::uint32_t, std::uint32_t*, std::uint32_t); +REX_W32_IMPORT(REX::W32::NTSTATUS, BCryptHashData, REX::W32::BCRYPT_HASH_HANDLE, std::uint8_t*, std::uint32_t, std::uint32_t); + +namespace REX::W32 +{ + NTSTATUS BCryptOpenAlgorithmProvider(BCRYPT_ALG_HANDLE* a_algorithm, const wchar_t* a_id, const wchar_t* a_impl, std::uint32_t a_flags) + { + return ::W32_IMPL_BCryptOpenAlgorithmProvider(a_algorithm, a_id, a_impl, a_flags); + } + + NTSTATUS BCryptCloseAlgorithmProvider(BCRYPT_ALG_HANDLE a_algorithm, std::uint32_t a_flags) + { + return ::W32_IMPL_BCryptCloseAlgorithmProvider(a_algorithm, a_flags); + } + + NTSTATUS BCryptCreateHash(BCRYPT_ALG_HANDLE a_algorithm, BCRYPT_HASH_HANDLE* a_hash, std::uint8_t* a_hashObject, std::uint32_t a_hashObjectSize, std::uint8_t* a_secret, std::uint32_t a_secretSize, std::uint32_t a_flags) + { + return ::W32_IMPL_BCryptCreateHash(a_algorithm, a_hash, a_hashObject, a_hashObjectSize, a_secret, a_secretSize, a_flags); + } + + NTSTATUS BCryptDestroyHash(BCRYPT_HASH_HANDLE a_hash) + { + return ::W32_IMPL_BCryptDestroyHash(a_hash); + } + + NTSTATUS BCryptFinishHash(BCRYPT_HASH_HANDLE a_hash, std::uint8_t* a_output, std::uint32_t a_outputSize, std::uint32_t a_flags) + { + return ::W32_IMPL_BCryptFinishHash(a_hash, a_output, a_outputSize, a_flags); + } + + NTSTATUS BCryptGetProperty(BCRYPT_HANDLE a_object, const wchar_t* a_property, std::uint8_t* a_output, std::uint32_t a_outputSize, std::uint32_t* a_result, std::uint32_t a_flags) + { + return ::W32_IMPL_BCryptGetProperty(a_object, a_property, a_output, a_outputSize, a_result, a_flags); + } + + NTSTATUS BCryptHashData(BCRYPT_HASH_HANDLE a_hash, std::uint8_t* a_input, std::uint32_t a_inputSize, std::uint32_t a_flags) + { + return ::W32_IMPL_BCryptHashData(a_hash, a_input, a_inputSize, a_flags); + } +} + +// DBGHELP + +REX_W32_IMPORT(std::uint32_t, UnDecorateSymbolName, const char*, char*, std::uint32_t, std::uint32_t); +REX_W32_IMPORT(std::uint32_t, UnDecorateSymbolNameW, const wchar_t*, wchar_t*, std::uint32_t, std::uint32_t); + +namespace REX::W32 +{ + std::uint32_t UnDecorateSymbolName(const char* a_name, char* a_buf, std::uint32_t a_bufLen, std::uint32_t a_flags) noexcept + { + return ::W32_IMPL_UnDecorateSymbolName(a_name, a_buf, a_bufLen, a_flags); + } + + std::uint32_t UnDecorateSymbolNameW(const wchar_t* a_name, wchar_t* a_buf, std::uint32_t a_bufLen, std::uint32_t a_flags) noexcept + { + return ::W32_IMPL_UnDecorateSymbolNameW(a_name, a_buf, a_bufLen, a_flags); + } +} + +// DXGI + +REX_W32_IMPORT(std::int32_t, CreateDXGIFactory, const IID&, void**); +REX_W32_IMPORT(std::int32_t, CreateDXGIFactory1, const IID&, void**); + +namespace REX::W32 +{ + HRESULT CreateDXGIFactory(const IID& a_iid, void** a_factory) noexcept + { + return ::W32_IMPL_CreateDXGIFactory(a_iid, a_factory); + } + + HRESULT CreateDXGIFactory1(const IID& a_iid, void** a_factory) noexcept + { + return ::W32_IMPL_CreateDXGIFactory1(a_iid, a_factory); + } +} + +// KERNEL32 + +REX_W32_IMPORT(REX::W32::BOOL, CloseHandle, REX::W32::HANDLE); +REX_W32_IMPORT(REX::W32::HANDLE, CreateFileA, const char*, std::uint32_t, std::uint32_t, REX::W32::SECURITY_ATTRIBUTES*, std::uint32_t, std::uint32_t, REX::W32::HANDLE); +REX_W32_IMPORT(REX::W32::HANDLE, CreateFileW, const wchar_t*, std::uint32_t, std::uint32_t, REX::W32::SECURITY_ATTRIBUTES*, std::uint32_t, std::uint32_t, REX::W32::HANDLE); +REX_W32_IMPORT(REX::W32::HANDLE, CreateFileMappingA, REX::W32::HANDLE, REX::W32::SECURITY_ATTRIBUTES*, std::uint32_t, std::uint32_t, std::uint32_t, const char*); +REX_W32_IMPORT(REX::W32::HANDLE, CreateFileMappingW, REX::W32::HANDLE, REX::W32::SECURITY_ATTRIBUTES*, std::uint32_t, std::uint32_t, std::uint32_t, const wchar_t*); +REX_W32_IMPORT(REX::W32::BOOL, CreateProcessA, const char*, char*, REX::W32::SECURITY_ATTRIBUTES*, REX::W32::SECURITY_ATTRIBUTES*, REX::W32::BOOL, std::uint32_t, void*, const char*, REX::W32::STARTUPINFOA*, REX::W32::PROCESS_INFORMATION*); +REX_W32_IMPORT(REX::W32::BOOL, CreateProcessW, const wchar_t*, wchar_t*, REX::W32::SECURITY_ATTRIBUTES*, REX::W32::SECURITY_ATTRIBUTES*, REX::W32::BOOL, std::uint32_t, void*, const wchar_t*, REX::W32::STARTUPINFOW*, REX::W32::PROCESS_INFORMATION*); +REX_W32_IMPORT(REX::W32::HANDLE, CreateRemoteThread, REX::W32::HANDLE, REX::W32::SECURITY_ATTRIBUTES*, std::size_t, REX::W32::THREAD_START_ROUTINE*, void*, std::uint32_t, std::uint32_t*); +REX_W32_IMPORT(REX::W32::HANDLE, CreateSemaphoreA, REX::W32::SECURITY_ATTRIBUTES*, std::int32_t, std::int32_t, const char*); +REX_W32_IMPORT(REX::W32::HANDLE, CreateThread, REX::W32::SECURITY_ATTRIBUTES*, std::size_t, REX::W32::THREAD_START_ROUTINE*, void*, std::uint32_t, std::uint32_t*); +REX_W32_IMPORT(void, DeleteCriticalSection, REX::W32::CRITICAL_SECTION*); +REX_W32_IMPORT(void, EnterCriticalSection, REX::W32::CRITICAL_SECTION*); +REX_W32_IMPORT(std::uint32_t, ExpandEnvironmentStringsA, const char*, char*, std::uint32_t); +REX_W32_IMPORT(std::uint32_t, ExpandEnvironmentStringsW, const wchar_t*, wchar_t*, std::uint32_t); +REX_W32_IMPORT(REX::W32::BOOL, FindClose, REX::W32::HANDLE); +REX_W32_IMPORT(REX::W32::HANDLE, FindFirstFileA, const char*, REX::W32::WIN32_FIND_DATAA*); +REX_W32_IMPORT(REX::W32::HANDLE, FindFirstFileW, const wchar_t*, REX::W32::WIN32_FIND_DATAW*); +REX_W32_IMPORT(REX::W32::BOOL, FindNextFileA, REX::W32::HANDLE, REX::W32::WIN32_FIND_DATAA*); +REX_W32_IMPORT(REX::W32::BOOL, FindNextFileW, REX::W32::HANDLE, REX::W32::WIN32_FIND_DATAW*); +REX_W32_IMPORT(REX::W32::BOOL, FlushInstructionCache, REX::W32::HANDLE, const void*, std::size_t); +REX_W32_IMPORT(REX::W32::BOOL, FreeLibrary, REX::W32::HMODULE); +REX_W32_IMPORT(REX::W32::BOOL, GetComputerNameA, char*, std::uint32_t*); +REX_W32_IMPORT(REX::W32::BOOL, GetComputerNameW, wchar_t*, std::uint32_t*); +REX_W32_IMPORT(std::uint32_t, GetCurrentDirectoryA, std::uint32_t, char*); +REX_W32_IMPORT(std::uint32_t, GetCurrentDirectoryW, std::uint32_t, wchar_t*); +REX_W32_IMPORT(REX::W32::HANDLE, GetCurrentProcess); +REX_W32_IMPORT(std::uint32_t, GetCurrentThreadId); +REX_W32_IMPORT(std::uint32_t, GetEnvironmentVariableA, const char*, char*, std::uint32_t); +REX_W32_IMPORT(std::uint32_t, GetEnvironmentVariableW, const wchar_t*, wchar_t*, std::uint32_t); +REX_W32_IMPORT(REX::W32::BOOL, GetFileSizeEx, REX::W32::HANDLE, REX::W32::LARGE_INTEGER*); +REX_W32_IMPORT(std::uint32_t, GetLastError); +REX_W32_IMPORT(std::uint32_t, GetModuleFileNameA, REX::W32::HMODULE, char*, std::uint32_t); +REX_W32_IMPORT(std::uint32_t, GetModuleFileNameW, REX::W32::HMODULE, wchar_t*, std::uint32_t); +REX_W32_IMPORT(REX::W32::HMODULE, GetModuleHandleA, const char*); +REX_W32_IMPORT(REX::W32::HMODULE, GetModuleHandleW, const wchar_t*); +REX_W32_IMPORT(std::uint32_t, GetPrivateProfileIntA, const char*, const char*, std::int32_t, const char*); +REX_W32_IMPORT(std::uint32_t, GetPrivateProfileIntW, const wchar_t*, const wchar_t*, std::int32_t, const wchar_t*); +REX_W32_IMPORT(std::uint32_t, GetPrivateProfileStringA, const char*, const char*, const char*, char*, std::uint32_t, const char*); +REX_W32_IMPORT(std::uint32_t, GetPrivateProfileStringW, const wchar_t*, const wchar_t*, const wchar_t*, wchar_t*, std::uint32_t, const wchar_t*); +REX_W32_IMPORT(void*, GetProcAddress, REX::W32::HMODULE, const char*); +REX_W32_IMPORT(void, GetSystemInfo, REX::W32::SYSTEM_INFO*); +REX_W32_IMPORT(REX::W32::BOOL, InitializeCriticalSectionAndSpinCount, REX::W32::CRITICAL_SECTION*, std::uint32_t); +REX_W32_IMPORT(REX::W32::BOOL, IsDebuggerPresent); +REX_W32_IMPORT(std::int32_t, LCMapStringEx, const wchar_t*, std::uint32_t, const wchar_t*, std::int32_t, wchar_t*, std::int32_t, REX::W32::NLSVERSIONINFO*, void*, std::intptr_t); +REX_W32_IMPORT(void, LeaveCriticalSection, REX::W32::CRITICAL_SECTION*); +REX_W32_IMPORT(REX::W32::HMODULE, LoadLibraryA, const char*); +REX_W32_IMPORT(REX::W32::HMODULE, LoadLibraryW, const wchar_t*); +REX_W32_IMPORT(void*, MapViewOfFile, REX::W32::HANDLE, std::uint32_t, std::uint32_t, std::uint32_t, std::size_t); +REX_W32_IMPORT(void*, MapViewOfFileEx, REX::W32::HANDLE, std::uint32_t, std::uint32_t, std::uint32_t, std::size_t, void*); +REX_W32_IMPORT(std::int32_t, MultiByteToWideChar, std::uint32_t, std::uint32_t, const char*, std::int32_t, wchar_t*, std::int32_t); +REX_W32_IMPORT(REX::W32::HANDLE, OpenFileMappingA, std::uint32_t, REX::W32::BOOL, const char*); +REX_W32_IMPORT(REX::W32::HANDLE, OpenFileMappingW, std::uint32_t, REX::W32::BOOL, const wchar_t*); +REX_W32_IMPORT(void, OutputDebugStringA, const char*); +REX_W32_IMPORT(void, OutputDebugStringW, const wchar_t*); +REX_W32_IMPORT(REX::W32::BOOL, QueryPerformanceCounter, std::int64_t*); +REX_W32_IMPORT(REX::W32::BOOL, QueryPerformanceFrequency, std::int64_t*); +REX_W32_IMPORT(std::uint32_t, ResumeThread, REX::W32::HANDLE); +REX_W32_IMPORT(REX::W32::BOOL, SetEnvironmentVariableA, const char*, const char*); +REX_W32_IMPORT(REX::W32::BOOL, SetEnvironmentVariableW, const wchar_t*, const wchar_t*); +REX_W32_IMPORT(void, Sleep, std::uint32_t); +REX_W32_IMPORT(REX::W32::BOOL, TerminateProcess, REX::W32::HANDLE, std::uint32_t); +REX_W32_IMPORT(void*, TlsGetValue, std::uint32_t); +REX_W32_IMPORT(REX::W32::BOOL, TlsSetValue, std::uint32_t, void*); +REX_W32_IMPORT(REX::W32::BOOL, UnmapViewOfFile, const void*); +REX_W32_IMPORT(void*, VirtualAlloc, void*, std::size_t, std::uint32_t, std::uint32_t); +REX_W32_IMPORT(void*, VirtualAllocEx, REX::W32::HANDLE, void*, std::size_t, std::uint32_t, std::uint32_t); +REX_W32_IMPORT(REX::W32::BOOL, VirtualFree, void*, std::size_t, std::uint32_t); +REX_W32_IMPORT(REX::W32::BOOL, VirtualFreeEx, REX::W32::HANDLE, void*, std::size_t, std::uint32_t); +REX_W32_IMPORT(REX::W32::BOOL, VirtualProtect, void*, std::size_t, std::uint32_t, std::uint32_t*); +REX_W32_IMPORT(REX::W32::BOOL, VirtualProtectEx, REX::W32::HANDLE, void*, std::size_t, std::uint32_t, std::uint32_t*); +REX_W32_IMPORT(std::size_t, VirtualQuery, const void*, MEMORY_BASIC_INFORMATION*, std::size_t); +REX_W32_IMPORT(std::size_t, VirtualQueryEx, REX::W32::HANDLE, const void*, MEMORY_BASIC_INFORMATION*, std::size_t); +REX_W32_IMPORT(std::uint32_t, WaitForSingleObject, REX::W32::HANDLE, std::uint32_t); +REX_W32_IMPORT(std::uint32_t, WaitForSingleObjectEx, REX::W32::HANDLE, std::uint32_t, REX::W32::BOOL); +REX_W32_IMPORT(std::int32_t, WideCharToMultiByte, std::uint32_t, std::uint32_t, const wchar_t*, std::int32_t, char*, std::int32_t, const char*, std::int32_t*); +REX_W32_IMPORT(REX::W32::BOOL, WriteProcessMemory, REX::W32::HANDLE, void*, const void*, std::size_t, std::size_t*); + +extern "C" REX::W32::IMAGE_DOS_HEADER __ImageBase; + +namespace REX::W32 +{ + bool CloseHandle(HANDLE a_handle) noexcept + { + return ::W32_IMPL_CloseHandle(a_handle); + } + + HANDLE CreateFileA(const char* a_fileName, std::uint32_t a_desiredAccess, std::uint32_t a_shareMode, SECURITY_ATTRIBUTES* a_attributes, std::uint32_t a_creationDisposition, std::uint32_t a_flags, HANDLE a_templateFile) + { + return ::W32_IMPL_CreateFileA(a_fileName, a_desiredAccess, a_shareMode, a_attributes, a_creationDisposition, a_flags, a_templateFile); + } + + HANDLE CreateFileW(const wchar_t* a_fileName, std::uint32_t a_desiredAccess, std::uint32_t a_shareMode, SECURITY_ATTRIBUTES* a_attributes, std::uint32_t a_creationDisposition, std::uint32_t a_flags, HANDLE a_templateFile) + { + return ::W32_IMPL_CreateFileW(a_fileName, a_desiredAccess, a_shareMode, a_attributes, a_creationDisposition, a_flags, a_templateFile); + } + + HANDLE CreateFileMappingA(HANDLE a_file, SECURITY_ATTRIBUTES* a_attributes, std::uint32_t a_protect, std::uint32_t a_maxSizeHigh, std::uint32_t a_maxSizeLow, const char* a_name) noexcept + { + return ::W32_IMPL_CreateFileMappingA(a_file, a_attributes, a_protect, a_maxSizeHigh, a_maxSizeLow, a_name); + } + + HANDLE CreateFileMappingW(HANDLE a_file, SECURITY_ATTRIBUTES* a_attributes, std::uint32_t a_protect, std::uint32_t a_maxSizeHigh, std::uint32_t a_maxSizeLow, const wchar_t* a_name) noexcept + { + return ::W32_IMPL_CreateFileMappingW(a_file, a_attributes, a_protect, a_maxSizeHigh, a_maxSizeLow, a_name); + } + + bool CreateProcessA(const char* a_name, char* a_cmd, SECURITY_ATTRIBUTES* a_procAttr, SECURITY_ATTRIBUTES* a_threadAttr, bool a_inheritHandles, std::uint32_t a_flags, void* a_env, const char* a_curDir, STARTUPINFOA* a_startInfo, PROCESS_INFORMATION* a_procInfo) noexcept + { + return ::W32_IMPL_CreateProcessA(a_name, a_cmd, a_procAttr, a_threadAttr, a_inheritHandles, a_flags, a_env, a_curDir, a_startInfo, a_procInfo); + } + + bool CreateProcessW(const wchar_t* a_name, wchar_t* a_cmd, SECURITY_ATTRIBUTES* a_procAttr, SECURITY_ATTRIBUTES* a_threadAttr, bool a_inheritHandles, std::uint32_t a_flags, void* a_env, const wchar_t* a_curDir, STARTUPINFOW* a_startInfo, PROCESS_INFORMATION* a_procInfo) noexcept + { + return ::W32_IMPL_CreateProcessW(a_name, a_cmd, a_procAttr, a_threadAttr, a_inheritHandles, a_flags, a_env, a_curDir, a_startInfo, a_procInfo); + } + + HANDLE CreateRemoteThread(HANDLE a_process, SECURITY_ATTRIBUTES* a_threadAttr, std::size_t a_stackSize, THREAD_START_ROUTINE* a_startAddr, void* a_param, std::uint32_t a_flags, std::uint32_t* a_threadID) noexcept + { + return ::W32_IMPL_CreateRemoteThread(a_process, a_threadAttr, a_stackSize, a_startAddr, a_param, a_flags, a_threadID); + } + + HANDLE CreateSemaphoreA(SECURITY_ATTRIBUTES* a_semaphoreAttr, std::int32_t a_initCount, std::int32_t a_maxCount, const char* a_name) + { + return ::W32_IMPL_CreateSemaphoreA(a_semaphoreAttr, a_initCount, a_maxCount, a_name); + } + + HANDLE CreateThread(SECURITY_ATTRIBUTES* a_threadAttr, std::size_t a_stackSize, THREAD_START_ROUTINE* a_startAddr, void* a_param, std::uint32_t a_flags, std::uint32_t* a_threadID) noexcept + { + return ::W32_IMPL_CreateThread(a_threadAttr, a_stackSize, a_startAddr, a_param, a_flags, a_threadID); + } + + void DeleteCriticalSection(CRITICAL_SECTION* a_criticalSection) + { + ::W32_IMPL_DeleteCriticalSection(a_criticalSection); + } + + void EnterCriticalSection(CRITICAL_SECTION* a_criticalSection) + { + ::W32_IMPL_EnterCriticalSection(a_criticalSection); + } + + std::uint32_t ExpandEnvironmentStringsA(const char* a_src, char* a_dst, std::uint32_t a_dstLen) noexcept + { + return ::W32_IMPL_ExpandEnvironmentStringsA(a_src, a_dst, a_dstLen); + } + + std::uint32_t ExpandEnvironmentStringsW(const wchar_t* a_src, wchar_t* a_dst, std::uint32_t a_dstLen) noexcept + { + return ::W32_IMPL_ExpandEnvironmentStringsW(a_src, a_dst, a_dstLen); + } + + bool FindClose(HANDLE a_file) noexcept + { + return ::W32_IMPL_FindClose(a_file); + } + + HANDLE FindFirstFileA(const char* a_name, WIN32_FIND_DATAA* a_data) noexcept + { + return ::W32_IMPL_FindFirstFileA(a_name, a_data); + } + + HANDLE FindFirstFileW(const wchar_t* a_name, WIN32_FIND_DATAW* a_data) noexcept + { + return ::W32_IMPL_FindFirstFileW(a_name, a_data); + } + + bool FindNextFileA(HANDLE a_file, WIN32_FIND_DATAA* a_data) noexcept + { + return ::W32_IMPL_FindNextFileA(a_file, a_data); + } + + bool FindNextFileW(HANDLE a_file, WIN32_FIND_DATAW* a_data) noexcept + { + return ::W32_IMPL_FindNextFileW(a_file, a_data); + } + + bool FlushInstructionCache(HANDLE a_process, const void* a_baseAddr, std::size_t a_size) noexcept + { + return ::W32_IMPL_FlushInstructionCache(a_process, a_baseAddr, a_size); + } + + bool FreeLibrary(HMODULE a_module) noexcept + { + return ::W32_IMPL_FreeLibrary(a_module); + } + + bool GetComputerNameA(char* a_buffer, std::uint32_t* a_size) noexcept + { + return ::W32_IMPL_GetComputerNameA(a_buffer, a_size); + } + + bool GetComputerNameW(wchar_t* a_buffer, std::uint32_t* a_size) noexcept + { + return ::W32_IMPL_GetComputerNameW(a_buffer, a_size); + } + + std::uint32_t GetCurrentDirectoryA(std::uint32_t a_size, char* a_buffer) noexcept + { + return ::W32_IMPL_GetCurrentDirectoryA(a_size, a_buffer); + } + + std::uint32_t GetCurrentDirectoryW(std::uint32_t a_size, wchar_t* a_buffer) noexcept + { + return ::W32_IMPL_GetCurrentDirectoryW(a_size, a_buffer); + } + + HMODULE GetCurrentModule() noexcept + { + return reinterpret_cast(std::addressof(__ImageBase)); + } + + HANDLE GetCurrentProcess() noexcept + { + return ::W32_IMPL_GetCurrentProcess(); + } + + std::uint32_t GetCurrentThreadId() noexcept + { + return ::W32_IMPL_GetCurrentThreadId(); + } + + std::uint32_t GetEnvironmentVariableA(const char* a_name, char* a_buf, std::uint32_t a_bufLen) noexcept + { + return ::W32_IMPL_GetEnvironmentVariableA(a_name, a_buf, a_bufLen); + } + + std::uint32_t GetEnvironmentVariableW(const wchar_t* a_name, wchar_t* a_buf, std::uint32_t a_bufLen) noexcept + { + return ::W32_IMPL_GetEnvironmentVariableW(a_name, a_buf, a_bufLen); + } + + bool GetFileSizeEx(HANDLE a_file, LARGE_INTEGER* a_fileSize) noexcept + { + return ::W32_IMPL_GetFileSizeEx(a_file, a_fileSize); + } + + std::uint32_t GetLastError() noexcept + { + return ::W32_IMPL_GetLastError(); + } + + std::uint32_t GetModuleFileNameA(HMODULE a_module, char* a_name, std::uint32_t a_nameLen) noexcept + { + return ::W32_IMPL_GetModuleFileNameA(a_module, a_name, a_nameLen); + } + + std::uint32_t GetModuleFileNameW(HMODULE a_module, wchar_t* a_name, std::uint32_t a_nameLen) noexcept + { + return ::W32_IMPL_GetModuleFileNameW(a_module, a_name, a_nameLen); + } + + HMODULE GetModuleHandleA(const char* a_name) noexcept + { + return ::W32_IMPL_GetModuleHandleA(a_name); + } + + HMODULE GetModuleHandleW(const wchar_t* a_name) noexcept + { + return ::W32_IMPL_GetModuleHandleW(a_name); + } + + std::uint32_t GetPrivateProfileIntA(const char* a_app, const char* a_key, std::int32_t a_default, const char* a_name) noexcept + { + return ::W32_IMPL_GetPrivateProfileIntA(a_app, a_key, a_default, a_name); + } + + std::uint32_t GetPrivateProfileIntW(const wchar_t* a_app, const wchar_t* a_key, std::int32_t a_default, const wchar_t* a_name) noexcept + { + return ::W32_IMPL_GetPrivateProfileIntW(a_app, a_key, a_default, a_name); + } + + std::uint32_t GetPrivateProfileStringA(const char* a_app, const char* a_key, const char* a_default, char* a_buf, std::uint32_t a_bufLen, const char* a_name) noexcept + { + return ::W32_IMPL_GetPrivateProfileStringA(a_app, a_key, a_default, a_buf, a_bufLen, a_name); + } + + std::uint32_t GetPrivateProfileStringW(const wchar_t* a_app, const wchar_t* a_key, const wchar_t* a_default, wchar_t* a_buf, std::uint32_t a_bufLen, const wchar_t* a_name) noexcept + { + return ::W32_IMPL_GetPrivateProfileStringW(a_app, a_key, a_default, a_buf, a_bufLen, a_name); + } + + void* GetProcAddress(HMODULE a_module, const char* a_name) noexcept + { + return ::W32_IMPL_GetProcAddress(a_module, a_name); + } + + std::string_view GetProcPath(HMODULE a_handle) + { + // I don't like this function... + static std::string fileName(MAX_PATH + 1, ' '); + auto res = GetModuleFileNameA(a_handle, fileName.data(), MAX_PATH + 1); + + if (res == 0) + throw std::system_error(static_cast(GetLastError()), std::system_category()); + + return { fileName.c_str(), res }; + } + + void GetSystemInfo(SYSTEM_INFO* a_info) noexcept + { + return ::W32_IMPL_GetSystemInfo(a_info); + } + + bool IMAGE_SNAP_BY_ORDINAL64(std::uint64_t a_ordinal) noexcept + { + return (a_ordinal & IMAGE_ORDINAL_FLAG64) != 0; + } + + IMAGE_SECTION_HEADER* IMAGE_FIRST_SECTION(const IMAGE_NT_HEADERS64* a_header) noexcept + { + constexpr auto opt = __builtin_offsetof(IMAGE_NT_HEADERS64, optionalHeader); + const auto optSize = a_header->fileHeader.optionalHeaderSize; + const auto section = reinterpret_cast(a_header) + opt + optSize; + return reinterpret_cast(section); + } + + bool InitializeCriticalSectionAndSpinCount(CRITICAL_SECTION* a_criticalSection, std::uint32_t a_spinCount) + { + return ::W32_IMPL_InitializeCriticalSectionAndSpinCount(a_criticalSection, a_spinCount); + } + + std::uint32_t InterlockedCompareExchange(volatile std::uint32_t* a_target, std::uint32_t a_value, std::uint32_t a_compare) noexcept + { + return _InterlockedCompareExchange((volatile long*)a_target, a_value, a_compare); + } + + std::uint64_t InterlockedCompareExchange64(volatile std::uint64_t* a_target, std::uint64_t a_value, std::uint64_t a_compare) noexcept + { + return _InterlockedCompareExchange64((volatile long long*)a_target, a_value, a_compare); + } + + std::uint32_t InterlockedDecrement(volatile std::uint32_t* a_target) noexcept + { + return _InterlockedDecrement((volatile long*)a_target); + } + + std::uint64_t InterlockedDecrement64(volatile std::uint64_t* a_target) noexcept + { + return _InterlockedDecrement64((volatile long long*)a_target); + } + + std::uint32_t InterlockedExchange(volatile std::uint32_t* a_target, std::uint32_t a_value) noexcept + { + return _InterlockedExchange((volatile long*)a_target, a_value); + } + + std::uint64_t InterlockedExchange64(volatile std::uint64_t* a_target, std::uint64_t a_value) noexcept + { + return _InterlockedExchange64((volatile long long*)a_target, a_value); + } + + std::uint32_t InterlockedIncrement(volatile std::uint32_t* a_target) noexcept + { + return _InterlockedIncrement((volatile long*)a_target); + } + + std::uint64_t InterlockedIncrement64(volatile std::uint64_t* a_target) noexcept + { + return _InterlockedIncrement64((volatile long long*)a_target); + } + + bool IsDebuggerPresent() noexcept + { + return ::W32_IMPL_IsDebuggerPresent(); + } + + std::int32_t LCMapStringEx(const wchar_t* a_locale, std::uint32_t a_flags, const wchar_t* a_src, std::int32_t a_srcLen, wchar_t* a_dst, std::int32_t a_dstLen, NLSVERSIONINFO* a_info, void* a_reserved, std::intptr_t a_sortHandle) noexcept + { + return ::W32_IMPL_LCMapStringEx(a_locale, a_flags, a_src, a_srcLen, a_dst, a_dstLen, a_info, a_reserved, a_sortHandle); + } + + void LeaveCriticalSection(CRITICAL_SECTION* a_criticalSection) + { + ::W32_IMPL_LeaveCriticalSection(a_criticalSection); + } + + HMODULE LoadLibraryA(const char* a_name) noexcept + { + return ::W32_IMPL_LoadLibraryA(a_name); + } + + HMODULE LoadLibraryW(const wchar_t* a_name) noexcept + { + return ::W32_IMPL_LoadLibraryW(a_name); + } + + void* MapViewOfFile(HANDLE a_object, std::uint32_t a_desiredAccess, std::uint32_t a_fileOffsetHi, std::uint32_t a_fileOffsetLo, std::size_t a_numBytes) noexcept + { + return ::W32_IMPL_MapViewOfFile(a_object, a_desiredAccess, a_fileOffsetHi, a_fileOffsetLo, a_numBytes); + } + + void* MapViewOfFileEx(HANDLE a_object, std::uint32_t a_desiredAccess, std::uint32_t a_fileOffsetHi, std::uint32_t a_fileOffsetLo, std::size_t a_numBytes, void* a_baseAddr) noexcept + { + return ::W32_IMPL_MapViewOfFileEx(a_object, a_desiredAccess, a_fileOffsetHi, a_fileOffsetLo, a_numBytes, a_baseAddr); + } + + std::int32_t MultiByteToWideChar(std::uint32_t a_codePage, std::uint32_t a_flags, const char* a_src, std::int32_t a_srcLen, wchar_t* a_dst, std::int32_t a_dstLen) noexcept + { + return ::W32_IMPL_MultiByteToWideChar(a_codePage, a_flags, a_src, a_srcLen, a_dst, a_dstLen); + } + + HANDLE OpenFileMappingA(std::uint32_t a_desiredAccess, bool a_inheritHandle, const char* a_name) noexcept + { + return ::W32_IMPL_OpenFileMappingA(a_desiredAccess, a_inheritHandle, a_name); + } + + HANDLE OpenFileMappingW(std::uint32_t a_desiredAccess, bool a_inheritHandle, const wchar_t* a_name) noexcept + { + return ::W32_IMPL_OpenFileMappingW(a_desiredAccess, a_inheritHandle, a_name); + } + + void OutputDebugStringA(const char* a_str) noexcept + { + ::W32_IMPL_OutputDebugStringA(a_str); + } + + void OutputDebugStringW(const wchar_t* a_str) noexcept + { + ::W32_IMPL_OutputDebugStringW(a_str); + } + + bool QueryPerformanceCounter(std::int64_t* a_counter) noexcept + { + return ::W32_IMPL_QueryPerformanceCounter(a_counter); + } + + bool QueryPerformanceFrequency(std::int64_t* a_frequency) noexcept + { + return ::W32_IMPL_QueryPerformanceFrequency(a_frequency); + } + + std::uint32_t ResumeThread(HANDLE a_handle) noexcept + { + return ::W32_IMPL_ResumeThread(a_handle); + } + + bool SetEnvironmentVariableA(const char* a_name, const char* a_value) noexcept + { + return ::W32_IMPL_SetEnvironmentVariableA(a_name, a_value); + } + + bool SetEnvironmentVariableW(const wchar_t* a_name, const wchar_t* a_value) noexcept + { + return ::W32_IMPL_SetEnvironmentVariableW(a_name, a_value); + } + + void Sleep(std::uint32_t a_milliseconds) noexcept + { + ::W32_IMPL_Sleep(a_milliseconds); + } + + bool TerminateProcess(HANDLE a_process, std::uint32_t a_exitCode) noexcept + { + return ::W32_IMPL_TerminateProcess(a_process, a_exitCode); + } + + void* TlsGetValue(std::uint32_t a_index) noexcept + { + return ::W32_IMPL_TlsGetValue(a_index); + } + + bool TlsSetValue(std::uint32_t a_index, void* a_value) noexcept + { + return ::W32_IMPL_TlsSetValue(a_index, a_value); + } + + bool UnmapViewOfFile(const void* a_baseAddress) noexcept + { + return ::W32_IMPL_UnmapViewOfFile(a_baseAddress); + } + + void* VirtualAlloc(void* a_address, std::size_t a_size, std::uint32_t a_type, std::uint32_t a_protect) noexcept + { + return ::W32_IMPL_VirtualAlloc(a_address, a_size, a_type, a_protect); + } + + void* VirtualAllocEx(HANDLE a_process, void* a_address, std::size_t a_size, std::uint32_t a_type, std::uint32_t a_protect) noexcept + { + return ::W32_IMPL_VirtualAllocEx(a_process, a_address, a_size, a_type, a_protect); + } + + bool VirtualFree(void* a_address, std::size_t a_size, std::uint32_t a_type) noexcept + { + return ::W32_IMPL_VirtualFree(a_address, a_size, a_type); + } + + bool VirtualFreeEx(HANDLE a_process, void* a_address, std::size_t a_size, std::uint32_t a_type) noexcept + { + return ::W32_IMPL_VirtualFreeEx(a_process, a_address, a_size, a_type); + } + + bool VirtualProtect(void* a_address, std::size_t a_size, std::uint32_t a_newProtect, std::uint32_t* a_oldProtect) noexcept + { + return ::W32_IMPL_VirtualProtect(a_address, a_size, a_newProtect, a_oldProtect); + } + + bool VirtualProtectEx(HANDLE a_process, void* a_address, std::size_t a_size, std::uint32_t a_newProtect, std::uint32_t* a_oldProtect) noexcept + { + return ::W32_IMPL_VirtualProtectEx(a_process, a_address, a_size, a_newProtect, a_oldProtect); + } + + std::size_t VirtualQuery(const void* a_address, MEMORY_BASIC_INFORMATION* a_buf, std::size_t a_bufLen) noexcept + { + return ::W32_IMPL_VirtualQuery(a_address, a_buf, a_bufLen); + } + + std::size_t VirtualQueryEx(HANDLE a_process, const void* a_address, MEMORY_BASIC_INFORMATION* a_buf, std::size_t a_bufLen) noexcept + { + return ::W32_IMPL_VirtualQueryEx(a_process, a_address, a_buf, a_bufLen); + } + + std::uint32_t WaitForSingleObject(HANDLE a_handle, std::uint32_t a_milliseconds) noexcept + { + return ::W32_IMPL_WaitForSingleObject(a_handle, a_milliseconds); + } + + std::uint32_t WaitForSingleObjectEx(HANDLE a_handle, std::uint32_t a_milliseconds, bool a_alertable) noexcept + { + return ::W32_IMPL_WaitForSingleObjectEx(a_handle, a_milliseconds, a_alertable); + } + + std::int32_t WideCharToMultiByte(std::uint32_t a_codePage, std::uint32_t a_flags, const wchar_t* a_src, std::int32_t a_srcLen, char* a_dst, std::int32_t a_dstLen, const char* a_default, std::int32_t* a_defaultLen) + { + return ::W32_IMPL_WideCharToMultiByte(a_codePage, a_flags, a_src, a_srcLen, a_dst, a_dstLen, a_default, a_defaultLen); + } + + bool WriteProcessMemory(HANDLE a_process, void* a_address, const void* a_buf, std::size_t a_bufLen, std::size_t* a_bufWritten) noexcept + { + return ::W32_IMPL_WriteProcessMemory(a_process, a_address, a_buf, a_bufLen, a_bufWritten); + } +} + +// OLE32 + +REX_W32_IMPORT(void, CoTaskMemFree, void*); + +namespace REX::W32 +{ + void CoTaskMemFree(void* a_block) noexcept + { + ::W32_IMPL_CoTaskMemFree(a_block); + } +} + +// SHELL32 + +REX_W32_IMPORT(std::int32_t, SHGetKnownFolderPath, const REX::W32::GUID&, std::uint32_t, void*, wchar_t**); + +namespace REX::W32 +{ + std::int32_t SHGetKnownFolderPath(const GUID& a_id, std::uint32_t a_flags, void* a_token, wchar_t** a_path) noexcept + { + return ::W32_IMPL_SHGetKnownFolderPath(a_id, a_flags, a_token, a_path); + } +} + +// USER32 + +REX_W32_IMPORT(REX::W32::BOOL, GetClientRect, REX::W32::HWND, REX::W32::RECT*); +REX_W32_IMPORT(std::int32_t, GetKeyNameTextA, std::int32_t, char*, std::int32_t); +REX_W32_IMPORT(std::int32_t, GetKeyNameTextW, std::int32_t, wchar_t*, std::int32_t); +REX_W32_IMPORT(std::int16_t, GetKeyState, std::int32_t); +REX_W32_IMPORT(REX::W32::BOOL, GetWindowRect, REX::W32::HWND, REX::W32::RECT*); +REX_W32_IMPORT(std::int32_t, MessageBoxA, REX::W32::HWND, const char*, const char*, std::uint32_t); +REX_W32_IMPORT(std::int32_t, MessageBoxW, REX::W32::HWND, const wchar_t*, const wchar_t*, std::uint32_t); +REX_W32_IMPORT(std::intptr_t, SetWindowLongPtrA, REX::W32::HWND, std::int32_t, std::intptr_t); +REX_W32_IMPORT(std::int32_t, ShowCursor, REX::W32::BOOL); + +namespace REX::W32 +{ + bool GetClientRect(HWND a_wnd, RECT* a_rect) noexcept + { + return ::W32_IMPL_GetClientRect(a_wnd, a_rect); + } + + std::int32_t GetKeyNameTextA(std::int32_t a_param, char* a_buf, std::int32_t a_bufLen) noexcept + { + return ::W32_IMPL_GetKeyNameTextA(a_param, a_buf, a_bufLen); + } + + std::int32_t GetKeyNameTextW(std::int32_t a_param, wchar_t* a_buf, std::int32_t a_bufLen) noexcept + { + return ::W32_IMPL_GetKeyNameTextW(a_param, a_buf, a_bufLen); + } + + std::int16_t GetKeyState(std::int32_t a_key) noexcept + { + return ::W32_IMPL_GetKeyState(a_key); + } + + bool GetWindowRect(HWND a_wnd, RECT* a_rect) noexcept + { + return ::W32_IMPL_GetWindowRect(a_wnd, a_rect); + } + + std::int32_t MessageBoxA(HWND a_wnd, const char* a_text, const char* a_caption, std::uint32_t a_type) noexcept + { + return ::W32_IMPL_MessageBoxA(a_wnd, a_text, a_caption, a_type); + } + + std::int32_t MessageBoxW(HWND a_wnd, const wchar_t* a_text, const wchar_t* a_caption, std::uint32_t a_type) noexcept + { + return ::W32_IMPL_MessageBoxW(a_wnd, a_text, a_caption, a_type); + } + + std::intptr_t SetWindowLongPtrA(HWND a_wnd, std::int32_t a_index, std::intptr_t a_newPtr) noexcept + { + return ::W32_IMPL_SetWindowLongPtrA(a_wnd, a_index, a_newPtr); + } + + std::int32_t ShowCursor(bool a_show) noexcept + { + return ::W32_IMPL_ShowCursor(a_show); + } +} + +// VERSION + +REX_W32_IMPORT(REX::W32::BOOL, GetFileVersionInfoA, const char*, std::uint32_t, std::uint32_t, void*); +REX_W32_IMPORT(REX::W32::BOOL, GetFileVersionInfoW, const wchar_t*, std::uint32_t, std::uint32_t, void*); +REX_W32_IMPORT(std::uint32_t, GetFileVersionInfoSizeA, const char*, std::uint32_t*); +//REX_W32_IMPORT(std::uint32_t, GetFileVersionInfoSizeExA, std::uint32_t, const char*, std::uint32_t*); +REX_W32_IMPORT(std::uint32_t, GetFileVersionInfoSizeExW, std::uint32_t, const wchar_t*, std::uint32_t*); +REX_W32_IMPORT(std::uint32_t, GetFileVersionInfoSizeW, const wchar_t*, std::uint32_t*); +REX_W32_IMPORT(REX::W32::BOOL, VerQueryValueA, const void*, const char*, void**, std::uint32_t*); +REX_W32_IMPORT(REX::W32::BOOL, VerQueryValueW, const void*, const wchar_t*, void**, std::uint32_t*); + +namespace REX::W32 +{ + bool GetFileVersionInfoA(const char* a_name, std::uint32_t a_handle, std::uint32_t a_dataLen, void* a_data) noexcept + { + return ::W32_IMPL_GetFileVersionInfoA(a_name, a_handle, a_dataLen, a_data); + } + + std::uint32_t GetFileVersionInfoSizeA(const char* a_name, std::uint32_t* a_handle) noexcept + { + return ::W32_IMPL_GetFileVersionInfoSizeA(a_name, a_handle); + } + + /* + std::uint32_t GetFileVersionInfoSizeExA(std::uint32_t a_flags, const char* a_name, std::uint32_t* a_handle) noexcept + { + return ::W32_IMPL_GetFileVersionInfoSizeExA(a_flags, a_name, a_handle); + } + */ + + std::uint32_t GetFileVersionInfoSizeExW(std::uint32_t a_flags, const wchar_t* a_name, std::uint32_t* a_handle) noexcept + { + return ::W32_IMPL_GetFileVersionInfoSizeExW(a_flags, a_name, a_handle); + } + + std::uint32_t GetFileVersionInfoSizeW(const wchar_t* a_name, std::uint32_t* a_handle) noexcept + { + return ::W32_IMPL_GetFileVersionInfoSizeW(a_name, a_handle); + } + + bool GetFileVersionInfoW(const wchar_t* a_name, std::uint32_t a_handle, std::uint32_t a_dataLen, void* a_data) noexcept + { + return ::W32_IMPL_GetFileVersionInfoW(a_name, a_handle, a_dataLen, a_data); + } + + bool VerQueryValueA(const void* a_block, const char* a_subBlock, void** a_buf, std::uint32_t* a_bufLen) noexcept + { + return ::W32_IMPL_VerQueryValueA(a_block, a_subBlock, a_buf, a_bufLen); + } + + bool VerQueryValueW(const void* a_block, const wchar_t* a_subBlock, void** a_buf, std::uint32_t* a_bufLen) noexcept + { + return ::W32_IMPL_VerQueryValueW(a_block, a_subBlock, a_buf, a_bufLen); + } +} + +// WS2_32 + +REX_W32_IMPORT(std::uint16_t, htons, std::uint16_t); +REX_W32_IMPORT(std::uint32_t, ntohl, std::uint32_t); +REX_W32_IMPORT(std::int32_t, WSAGetLastError); + +namespace REX::W32 +{ + std::uint16_t htons(std::uint16_t a_host) noexcept + { + return ::W32_IMPL_htons(a_host); + } + + std::uint32_t ntohl(std::uint32_t a_net) noexcept + { + return ::W32_IMPL_ntohl(a_net); + } + + std::int32_t WSAGetLastError() noexcept + { + return ::W32_IMPL_WSAGetLastError(); + } +} diff --git a/src/SFSE/IAT.cpp b/src/SFSE/IAT.cpp index 3f529e2e..c651d596 100644 --- a/src/SFSE/IAT.cpp +++ b/src/SFSE/IAT.cpp @@ -23,15 +23,15 @@ namespace SFSE constexpr void* GetIATPtr(void* a_module, std::string_view a_dll, std::string_view a_function) { assert(a_module); - const auto dosHeader = static_cast(a_module); - if (dosHeader->magic != WinAPI::IMAGE_DOS_SIGNATURE) { + const auto dosHeader = static_cast(a_module); + if (dosHeader->magic != REX::W32::IMAGE_DOS_SIGNATURE) { log::error("Invalid DOS header"); return nullptr; } - const auto ntHeader = stl::adjust_pointer(dosHeader, dosHeader->lfanew); - const auto& dataDir = ntHeader->optionalHeader.dataDirectory[WinAPI::IMAGE_DIRECTORY_ENTRY_IMPORT]; - const auto importDesc = stl::adjust_pointer(dosHeader, dataDir.virtualAddress); + const auto ntHeader = stl::adjust_pointer(dosHeader, dosHeader->lfanew); + const auto& dataDir = ntHeader->optionalHeader.dataDirectory[REX::W32::IMAGE_DIRECTORY_ENTRY_IMPORT]; + const auto importDesc = stl::adjust_pointer(dosHeader, dataDir.virtualAddress); for (auto import = importDesc; import->characteristics != 0; ++import) { const auto name = stl::adjust_pointer(dosHeader, import->name); @@ -39,15 +39,15 @@ namespace SFSE continue; } - const auto thunk = stl::adjust_pointer(dosHeader, import->firstThunkOriginal); + const auto thunk = stl::adjust_pointer(dosHeader, import->firstThunkOriginal); for (std::size_t i = 0; thunk[i].ordinal; ++i) { - if (WinAPI::IMAGE_SNAP_BY_ORDINAL64(thunk[i].ordinal)) { + if (REX::W32::IMAGE_SNAP_BY_ORDINAL64(thunk[i].ordinal)) { continue; } - const auto importByName = stl::adjust_pointer(dosHeader, thunk[i].address); + const auto importByName = stl::adjust_pointer(dosHeader, thunk[i].address); if (a_function.size() == strlen(importByName->name) && _strnicmp(a_function.data(), importByName->name, a_function.size()) == 0) { - return stl::adjust_pointer(dosHeader, import->firstThunk) + i; + return stl::adjust_pointer(dosHeader, import->firstThunk) + i; } } } diff --git a/src/SFSE/Impl/WinAPI.cpp b/src/SFSE/Impl/WinAPI.cpp deleted file mode 100644 index e4e90fbc..00000000 --- a/src/SFSE/Impl/WinAPI.cpp +++ /dev/null @@ -1,1059 +0,0 @@ -#include "SFSE/Impl/WinAPI.h" - -#define WIN32_LEAN_AND_MEAN - -// clang-format off -#include -#include -#include -#include -#include -// clang-format on - -#undef CreateFileMapping -#undef CreateProcess -#undef ExpandEnvironmentStrings -#undef FindFirstFile -#undef FindNextFile -#undef GetCurrentDirectory -#undef GetEnvironmentVariable -#undef GetFileVersionInfo -#undef GetFileVersionInfoSize -#undef GetKeyNameText -#undef GetModuleFileName -#undef GetModuleHandle -#undef GetPrivateProfileString -#undef IMAGE_FIRST_SECTION -#undef IMAGE_SNAP_BY_ORDINAL64 -#undef LoadLibrary -#undef MessageBox -#undef OpenFileMapping -#undef OutputDebugString -#undef RegGetValue -#undef RegQueryValueEx -#undef SetEnvironmentVariable -#undef VerQueryValue - -extern "C" IMAGE_DOS_HEADER __ImageBase; - -namespace SFSE::WinAPI -{ - bool CloseHandle( - void* a_handle) noexcept - { - return static_cast( - ::CloseHandle( - a_handle)); - } - - void CoTaskMemFree( - void* a_block) noexcept - { - ::CoTaskMemFree( - a_block); - } - - void* CreateFileMapping( - void* a_file, - SECURITY_ATTRIBUTES* a_attributes, - std::uint32_t a_protect, - std::uint32_t a_maxSizeHigh, - std::uint32_t a_maxSizeLow, - const char* a_name) noexcept - { - return CreateFileMappingA( - a_file, - reinterpret_cast(a_attributes), - a_protect, - a_maxSizeHigh, - a_maxSizeLow, - a_name); - } - - void* CreateFileMapping( - void* a_file, - SECURITY_ATTRIBUTES* a_attributes, - std::uint32_t a_protect, - std::uint32_t a_maxSizeHigh, - std::uint32_t a_maxSizeLow, - const wchar_t* a_name) noexcept - { - return CreateFileMappingW( - a_file, - reinterpret_cast(a_attributes), - a_protect, - a_maxSizeHigh, - a_maxSizeLow, - a_name); - } - - bool CreateProcess( - const char* a_name, - char* a_cmd, - SECURITY_ATTRIBUTES* a_procAttr, - SECURITY_ATTRIBUTES* a_threadAttr, - bool a_inherit, - std::uint32_t a_flags, - void* a_env, - const char* a_curDir, - STARTUPINFOA* a_startInfo, - PROCESS_INFORMATION* a_procInfo) noexcept - { - return static_cast( - CreateProcessA( - a_name, - a_cmd, - reinterpret_cast(a_procAttr), - reinterpret_cast(a_threadAttr), - a_inherit, - a_flags, - a_env, - a_curDir, - reinterpret_cast(a_startInfo), - reinterpret_cast(a_procInfo))); - } - - bool CreateProcess( - const wchar_t* a_name, - wchar_t* a_cmd, - SECURITY_ATTRIBUTES* a_procAttr, - SECURITY_ATTRIBUTES* a_threadAttr, - bool a_inherit, - std::uint32_t a_flags, - void* a_env, - const wchar_t* a_curDir, - STARTUPINFOW* a_startInfo, - PROCESS_INFORMATION* a_procInfo) noexcept - { - return static_cast( - CreateProcessW( - a_name, - a_cmd, - reinterpret_cast(a_procAttr), - reinterpret_cast(a_threadAttr), - a_inherit, - a_flags, - a_env, - a_curDir, - reinterpret_cast(a_startInfo), - reinterpret_cast(a_procInfo))); - } - - void* CreateRemoteThread( - void* a_process, - SECURITY_ATTRIBUTES* a_threadAttr, - std::size_t a_stackSize, - THREAD_START_ROUTINE* a_startAddr, - void* a_param, - std::uint32_t a_flags, - std::uint32_t* a_threadID) noexcept - { - return ::CreateRemoteThread( - a_process, - reinterpret_cast(a_threadAttr), - a_stackSize, - reinterpret_cast(a_startAddr), - a_param, - a_flags, - reinterpret_cast(a_threadID)); - } - - void* CreateThread( - SECURITY_ATTRIBUTES* a_threadAttr, - std::size_t a_stackSize, - THREAD_START_ROUTINE* a_startAddr, - void* a_param, - std::uint32_t a_flags, - std::uint32_t* a_threadID) noexcept - { - return ::CreateThread( - reinterpret_cast(a_threadAttr), - a_stackSize, - reinterpret_cast(a_startAddr), - a_param, - a_flags, - reinterpret_cast(a_threadID)); - } - - std::uint32_t ExpandEnvironmentStrings( - const char* a_src, - char* a_dst, - std::uint32_t a_dstLen) noexcept - { - return static_cast( - ExpandEnvironmentStringsA( - a_src, - a_dst, - a_dstLen)); - } - - std::uint32_t ExpandEnvironmentStrings( - const wchar_t* a_src, - wchar_t* a_dst, - std::uint32_t a_dstLen) noexcept - { - return static_cast( - ExpandEnvironmentStringsW( - a_src, - a_dst, - a_dstLen)); - } - - bool FindClose( - void* a_file) noexcept - { - return static_cast( - ::FindClose( - a_file)); - } - - void* FindFirstFile( - const char* a_name, - WIN32_FIND_DATAA* a_data) noexcept - { - return FindFirstFileA( - a_name, - reinterpret_cast(a_data)); - } - - void* FindFirstFile( - const wchar_t* a_name, - WIN32_FIND_DATAW* a_data) noexcept - { - return FindFirstFileW( - a_name, - reinterpret_cast(a_data)); - } - - bool FindNextFile( - void* a_file, - WIN32_FIND_DATAA* a_data) noexcept - { - return static_cast( - FindNextFileA( - a_file, - reinterpret_cast(a_data))); - } - - bool FindNextFile( - void* a_file, - WIN32_FIND_DATAW* a_data) noexcept - { - return static_cast( - FindNextFileW( - a_file, - reinterpret_cast(a_data))); - } - - bool FlushInstructionCache( - void* a_process, - const void* a_baseAddr, - std::size_t a_size) noexcept - { - return static_cast( - ::FlushInstructionCache( - a_process, - a_baseAddr, - a_size)); - } - - bool FreeLibrary( - HMODULE a_module) noexcept - { - return static_cast( - ::FreeLibrary( - reinterpret_cast<::HMODULE>(a_module))); - } - - std::uint32_t GetCurrentDirectory( - std::uint32_t a_bufferLen, - char* a_buffer) noexcept - { - return static_cast( - GetCurrentDirectoryA( - a_bufferLen, - a_buffer)); - } - - void* GetCurrentModule() noexcept - { - return std::addressof(__ImageBase); - } - - void* GetCurrentProcess() noexcept - { - return ::GetCurrentProcess(); - } - - std::uint32_t GetCurrentThreadID() noexcept - { - return static_cast( - GetCurrentThreadId()); - } - - std::uint32_t GetEnvironmentVariable( - const char* a_name, - char* a_buffer, - std::uint32_t a_bufferLen) noexcept - { - return static_cast( - GetEnvironmentVariableA( - a_name, - a_buffer, - a_bufferLen)); - } - - std::uint32_t GetEnvironmentVariable( - const wchar_t* a_name, - wchar_t* a_buffer, - std::uint32_t a_bufferLen) noexcept - { - return static_cast( - GetEnvironmentVariableW( - a_name, - a_buffer, - a_bufferLen)); - } - - bool GetFileVersionInfo( - const char* a_name, - std::uint32_t a_handle, - std::uint32_t a_dataLen, - void* a_data) noexcept - { - return static_cast( - GetFileVersionInfoA( - a_name, - a_handle, - a_dataLen, - a_data)); - } - - bool GetFileVersionInfo( - const wchar_t* a_name, - std::uint32_t a_handle, - std::uint32_t a_dataLen, - void* a_data) noexcept - { - return static_cast( - GetFileVersionInfoW( - a_name, - a_handle, - a_dataLen, - a_data)); - } - - std::uint32_t GetFileVersionInfoSize( - const char* a_name, - std::uint32_t* a_handle) noexcept - { - return static_cast( - GetFileVersionInfoSizeA( - a_name, - reinterpret_cast(a_handle))); - } - - std::uint32_t GetFileVersionInfoSize( - const wchar_t* a_name, - std::uint32_t* a_handle) noexcept - { - return static_cast( - GetFileVersionInfoSizeW( - a_name, - reinterpret_cast(a_handle))); - } - - std::int32_t GetKeyNameText( - std::int32_t a_param, - wchar_t* a_buffer, - std::int32_t a_bufferLen) noexcept - { - return GetKeyNameTextW( - a_param, - a_buffer, - a_bufferLen); - } - - std::int32_t GetKeyNameText( - std::int32_t a_param, - char* a_buffer, - std::int32_t a_bufferLen) noexcept - { - return GetKeyNameTextA( - a_param, - a_buffer, - a_bufferLen); - } - - std::int16_t GetKeyState( - std::int32_t a_key) noexcept - { - return ::GetKeyState(a_key); - } - - std::uint32_t GetLastError() noexcept - { - return static_cast( - ::GetLastError()); - } - - std::size_t GetMaxPath() noexcept - { - return MAX_PATH; - } - - std::uint32_t GetModuleFileName( - void* a_module, - char* a_name, - std::uint32_t a_nameLen) noexcept - { - return static_cast( - GetModuleFileNameA( - static_cast<::HMODULE>(a_module), - a_name, - a_nameLen)); - } - - std::uint32_t GetModuleFileName( - void* a_module, - wchar_t* a_name, - std::uint32_t a_nameLen) noexcept - { - return static_cast( - GetModuleFileNameW( - static_cast<::HMODULE>(a_module), - a_name, - a_nameLen)); - } - - HMODULE GetModuleHandle( - const char* a_name) noexcept - { - return reinterpret_cast( - GetModuleHandleA( - a_name)); - } - - HMODULE GetModuleHandle( - const wchar_t* a_name) noexcept - { - return reinterpret_cast( - GetModuleHandleW(a_name)); - } - - std::uint32_t GetPrivateProfileString( - const char* a_app, - const char* a_key, - const char* a_default, - char* a_out, - std::uint32_t a_outLen, - const char* a_name) noexcept - { - return static_cast( - GetPrivateProfileStringA( - a_app, - a_key, - a_default, - a_out, - a_outLen, - a_name)); - } - - std::uint32_t GetPrivateProfileString( - const wchar_t* a_app, - const wchar_t* a_key, - const wchar_t* a_default, - wchar_t* a_out, - std::uint32_t a_outLen, - const wchar_t* a_name) noexcept - { - return static_cast( - GetPrivateProfileStringW( - a_app, - a_key, - a_default, - a_out, - a_outLen, - a_name)); - } - - void* GetProcAddress( - void* a_module, - const char* a_name) noexcept - { - return reinterpret_cast( - ::GetProcAddress( - static_cast<::HMODULE>(a_module), - a_name)); - } - - std::string_view GetProcPath( - HMODULE a_handle) noexcept - { - static std::string fileName(MAX_PATH + 1, ' '); - auto res = GetModuleFileName(a_handle, fileName.data(), MAX_PATH + 1); - if (res == 0) { - fileName = "[ProcessHost]"; - res = 13; - } - - return { fileName.c_str(), res }; - } - - void GetSystemInfo( - SYSTEM_INFO* a_info) noexcept - { - ::GetSystemInfo( - reinterpret_cast(a_info)); - } - - std::uint16_t htons(std::uint16_t hostshort) noexcept - { - return ::htons(hostshort); - } - - bool IMAGE_SNAP_BY_ORDINAL64( - std::uint64_t a_ordinal) noexcept - { - return (a_ordinal & IMAGE_ORDINAL_FLAG64) != 0; - } - - IMAGE_SECTION_HEADER* IMAGE_FIRST_SECTION( - const IMAGE_NT_HEADERS64* a_header) noexcept - { - constexpr auto opt = __builtin_offsetof(IMAGE_NT_HEADERS64, optionalHeader); - const auto optSize = a_header->fileHeader.optionalHeaderSize; - const auto section = reinterpret_cast(a_header) + opt + optSize; - return reinterpret_cast(section); - } - - bool IsDebuggerPresent() noexcept - { - return static_cast( - ::IsDebuggerPresent()); - } - - std::int32_t LCMapStringEx( - const wchar_t* a_locale, - std::uint32_t a_flags, - const wchar_t* a_src, - std::int32_t a_srcLen, - wchar_t* a_dest, - std::int32_t a_destLen, - NLSVERSIONINFO* a_info, - void* a_reserved, - std::intptr_t a_sortHandle) noexcept - { - return ::LCMapStringEx( - a_locale, - a_flags, - a_src, - a_srcLen, - a_dest, - a_destLen, - reinterpret_cast(a_info), - a_reserved, - a_sortHandle); - } - - HMODULE LoadLibrary( - const char* a_name) noexcept - { - return reinterpret_cast( - LoadLibraryA( - a_name)); - } - - HMODULE LoadLibrary( - const wchar_t* a_name) noexcept - { - return reinterpret_cast( - LoadLibraryW(a_name)); - } - - void* MapViewOfFile( - void* a_object, - std::uint32_t a_desiredAccess, - std::uint32_t a_fileOffsetHigh, - std::uint32_t a_fileOffsetLow, - std::size_t a_numBytesToMap) noexcept - { - return ::MapViewOfFile( - a_object, - a_desiredAccess, - a_fileOffsetHigh, - a_fileOffsetLow, - a_numBytesToMap); - } - - void* MapViewOfFileEx( - void* a_object, - std::uint32_t a_desiredAccess, - std::uint32_t a_fileOffsetHigh, - std::uint32_t a_fileOffsetLow, - std::size_t a_numBytesToMap, - void* a_baseAddress) noexcept - { - return ::MapViewOfFileEx( - a_object, - a_desiredAccess, - a_fileOffsetHigh, - a_fileOffsetLow, - a_numBytesToMap, - a_baseAddress); - } - - std::int32_t MessageBox( - void* a_wnd, - const char* a_text, - const char* a_caption, - std::uint32_t a_type) noexcept - { - return MessageBoxA( - static_cast<::HWND>(a_wnd), - a_text, - a_caption, - a_type); - } - - std::int32_t MessageBox( - void* a_wnd, - const wchar_t* a_text, - const wchar_t* a_caption, - std::uint32_t a_type) noexcept - { - return MessageBoxW( - static_cast<::HWND>(a_wnd), - a_text, - a_caption, - a_type); - } - - std::int32_t MultiByteToWideChar( - std::uint32_t a_codePage, - std::uint32_t a_flags, - const char* a_str, - std::int32_t a_strLen, - wchar_t* a_wstr, - std::int32_t a_wstrLen) - { - return ::MultiByteToWideChar( - a_codePage, - a_flags, - a_str, - a_strLen, - a_wstr, - a_wstrLen); - } - - std::int32_t NormalizeString( - std::int32_t a_normForm, - const wchar_t* a_src, - std::int32_t a_srcLen, - wchar_t* a_dest, - std::int32_t a_destLen) - { - return ::NormalizeString( - static_cast(a_normForm), - a_src, - a_srcLen, - a_dest, - a_destLen); - } - - std::uint32_t ntohl(std::uint32_t netlong) noexcept - { - return ::ntohl(netlong); - } - - void* OpenFileMapping( - std::uint32_t a_desiredAccess, - bool a_inheritHandle, - const char* a_name) noexcept - { - return OpenFileMappingA( - a_desiredAccess, - a_inheritHandle, - a_name); - } - - void* OpenFileMapping( - std::uint32_t a_desiredAccess, - bool a_inheritHandle, - const wchar_t* a_name) noexcept - { - return OpenFileMappingW( - a_desiredAccess, - a_inheritHandle, - a_name); - } - - void OutputDebugString( - const char* a_out) noexcept - { - OutputDebugStringA( - a_out); - } - - void OutputDebugString( - const wchar_t* a_out) noexcept - { - OutputDebugStringW( - a_out); - } - - std::int32_t RegGetValue( - HKEY a_key, - const char* a_subKey, - const char* a_value, - std::uint32_t a_flags, - std::uint32_t* a_type, - void* a_data, - std::uint32_t* a_dataLen) - { - return RegGetValueA( - reinterpret_cast<::HKEY>(a_key), - a_subKey, - a_value, - a_flags, - reinterpret_cast(a_type), - a_data, - reinterpret_cast(a_dataLen)); - } - - std::int32_t RegGetValue( - HKEY a_key, - const wchar_t* a_subKey, - const wchar_t* a_value, - std::uint32_t a_flags, - std::uint32_t* a_type, - void* a_data, - std::uint32_t* a_dataLen) - { - return RegGetValueW( - reinterpret_cast<::HKEY>(a_key), - a_subKey, - a_value, - a_flags, - reinterpret_cast(a_type), - a_data, - reinterpret_cast(a_dataLen)); - } - - std::uint32_t ResumeThread( - void* a_handle) noexcept - { - return static_cast( - ::ResumeThread( - a_handle)); - } - - bool SetEnvironmentVariable( - const char* a_name, - const char* a_value) noexcept - { - return static_cast( - SetEnvironmentVariableA( - a_name, - a_value)); - } - - bool SetEnvironmentVariable( - const wchar_t* a_name, - const wchar_t* a_value) noexcept - { - return static_cast( - SetEnvironmentVariableW( - a_name, - a_value)); - } - - std::int32_t SHGetKnownFolderPath( - const GUID& a_id, - std::uint32_t a_flags, - void* a_token, - wchar_t** a_path) noexcept - { - return static_cast( - ::SHGetKnownFolderPath( - reinterpret_cast(a_id), - a_flags, - a_token, - a_path)); - } - - std::int32_t ShowCursor( - bool a_show) noexcept - { - return ::ShowCursor( - a_show); - } - - void Sleep( - std::uint32_t a_milliseconds) noexcept - { - ::Sleep(a_milliseconds); - } - - bool TerminateProcess( - void* a_process, - std::uint32_t a_exitCode) noexcept - { - return static_cast( - ::TerminateProcess( - a_process, - a_exitCode)); - } - - void* TlsGetValue( - std::uint32_t a_index) noexcept - { - return ::TlsGetValue( - a_index); - } - - bool TlsSetValue( - std::uint32_t a_index, - void* a_value) noexcept - { - return static_cast( - ::TlsSetValue( - a_index, - a_value)); - } - - std::uint32_t UnDecorateSymbolName( - const char* a_name, - char* a_out, - std::uint32_t a_outLenMax, - std::uint32_t a_flags) noexcept - { - return static_cast( - ::UnDecorateSymbolName( - a_name, - a_out, - a_outLenMax, - a_flags)); - } - - std::uint32_t UnDecorateSymbolName( - const wchar_t* a_name, - wchar_t* a_out, - std::uint32_t a_outLenMax, - std::uint32_t a_flags) noexcept - { - return static_cast( - UnDecorateSymbolNameW( - a_name, - a_out, - a_outLenMax, - a_flags)); - } - - bool UnmapViewOfFile( - const void* a_baseAddress) noexcept - { - return static_cast( - ::UnmapViewOfFile( - a_baseAddress)); - } - - bool VerQueryValue( - const void* a_block, - const char* a_subBlock, - void** a_buffer, - std::uint32_t* a_bufferLen) noexcept - { - return static_cast( - VerQueryValueA(a_block, - a_subBlock, - a_buffer, - a_bufferLen)); - } - - bool VerQueryValue( - const void* a_block, - const wchar_t* a_subBlock, - void** a_buffer, - std::uint32_t* a_bufferLen) noexcept - { - return static_cast( - VerQueryValueW( - a_block, - a_subBlock, - a_buffer, - a_bufferLen)); - } - - void* VirtualAlloc( - void* a_address, - std::size_t a_size, - std::uint32_t a_type, - std::uint32_t a_protect) noexcept - { - return ::VirtualAlloc( - a_address, - a_size, - a_type, - a_protect); - } - - void* VirtualAllocEx( - void* a_process, - void* a_address, - std::size_t a_size, - std::uint32_t a_type, - std::uint32_t a_protect) noexcept - { - return ::VirtualAllocEx( - a_process, - a_address, - a_size, - a_type, - a_protect); - } - - bool VirtualFree( - void* a_address, - std::size_t a_size, - std::uint32_t a_type) noexcept - { - return static_cast( - ::VirtualFree( - a_address, - a_size, - a_type)); - } - - bool VirtualFreeEx( - void* a_process, - void* a_address, - std::size_t a_size, - std::uint32_t a_type) noexcept - { - return static_cast( - ::VirtualFreeEx( - a_process, - a_address, - a_size, - a_type)); - } - - bool VirtualProtect( - void* a_address, - std::size_t a_size, - std::uint32_t a_newProtect, - std::uint32_t* a_oldProtect) noexcept - { - return static_cast( - ::VirtualProtect( - a_address, - a_size, - a_newProtect, - reinterpret_cast(a_oldProtect))); - } - - bool VirtualProtectEx( - void* a_process, - void* a_address, - std::size_t a_size, - std::uint32_t a_newProtect, - std::uint32_t* a_oldProtect) noexcept - { - return static_cast( - ::VirtualProtectEx( - a_process, - a_address, - a_size, - a_newProtect, - reinterpret_cast(a_oldProtect))); - } - - std::size_t VirtualQuery( - const void* a_address, - MEMORY_BASIC_INFORMATION* a_buffer, - std::size_t a_bufferLen) noexcept - { - return ::VirtualQuery( - a_address, - reinterpret_cast(a_buffer), - a_bufferLen); - } - - std::size_t VirtualQueryEx( - void* a_process, - const void* a_address, - MEMORY_BASIC_INFORMATION* a_buffer, - std::size_t a_bufferLen) noexcept - { - return ::VirtualQueryEx( - a_process, - a_address, - reinterpret_cast(a_buffer), - a_bufferLen); - } - - std::uint32_t WaitForSingleObject( - void* a_handle, - std::uint32_t a_milliseconds) noexcept - { - return static_cast( - ::WaitForSingleObject( - a_handle, - a_milliseconds)); - } - - std::uint32_t WaitForSingleObjectEx( - void* a_handle, - std::uint32_t a_milliseconds, - bool a_alertable) noexcept - { - return static_cast( - ::WaitForSingleObjectEx( - a_handle, - a_milliseconds, - a_alertable)); - } - - std::int32_t WideCharToMultiByte( - std::uint32_t a_codePage, - std::uint32_t a_flags, - const wchar_t* a_wstr, - std::int32_t a_wstrLen, - char* a_str, - std::int32_t a_strLen, - const char* a_default, - std::int32_t* a_defaultLen) - { - return ::WideCharToMultiByte( - a_codePage, - a_flags, - a_wstr, - a_wstrLen, - a_str, - a_strLen, - a_default, - a_defaultLen); - } - - std::int32_t WSAGetLastError() noexcept - { - return ::WSAGetLastError(); - } - - bool WriteProcessMemory( - void* a_process, - void* a_address, - const void* a_buffer, - std::size_t a_bufferLen, - std::size_t* a_bufferWritten) noexcept - { - return static_cast( - ::WriteProcessMemory( - a_process, - a_address, - a_buffer, - a_bufferLen, - a_bufferWritten)); - } -} diff --git a/src/SFSE/InputMap.cpp b/src/SFSE/InputMap.cpp index a74bc865..4b2a0ce9 100644 --- a/src/SFSE/InputMap.cpp +++ b/src/SFSE/InputMap.cpp @@ -1,41 +1,40 @@ #include "SFSE/InputMap.h" -#include "SFSE/Impl/XInputAPI.h" +#include "REX/W32/DINPUT.h" +#include "REX/W32/XINPUT.h" namespace SFSE { std::uint32_t InputMap::GamepadMaskToKeycode(const std::uint32_t a_keyMask) { - using XInputButton = RE::XInput::XInputButton; - switch (a_keyMask) { - case XInputButton::XINPUT_GAMEPAD_DPAD_UP: + case REX::W32::XINPUT_GAMEPAD_DPAD_UP: return kGamepadButtonOffset_DPAD_UP; - case XInputButton::XINPUT_GAMEPAD_DPAD_DOWN: + case REX::W32::XINPUT_GAMEPAD_DPAD_DOWN: return kGamepadButtonOffset_DPAD_DOWN; - case XInputButton::XINPUT_GAMEPAD_DPAD_LEFT: + case REX::W32::XINPUT_GAMEPAD_DPAD_LEFT: return kGamepadButtonOffset_DPAD_LEFT; - case XInputButton::XINPUT_GAMEPAD_DPAD_RIGHT: + case REX::W32::XINPUT_GAMEPAD_DPAD_RIGHT: return kGamepadButtonOffset_DPAD_RIGHT; - case XInputButton::XINPUT_GAMEPAD_START: + case REX::W32::XINPUT_GAMEPAD_START: return kGamepadButtonOffset_START; - case XInputButton::XINPUT_GAMEPAD_BACK: + case REX::W32::XINPUT_GAMEPAD_BACK: return kGamepadButtonOffset_BACK; - case XInputButton::XINPUT_GAMEPAD_LEFT_THUMB: + case REX::W32::XINPUT_GAMEPAD_LEFT_THUMB: return kGamepadButtonOffset_LEFT_THUMB; - case XInputButton::XINPUT_GAMEPAD_RIGHT_THUMB: + case REX::W32::XINPUT_GAMEPAD_RIGHT_THUMB: return kGamepadButtonOffset_RIGHT_THUMB; - case XInputButton::XINPUT_GAMEPAD_LEFT_SHOULDER: + case REX::W32::XINPUT_GAMEPAD_LEFT_SHOULDER: return kGamepadButtonOffset_LEFT_SHOULDER; - case XInputButton::XINPUT_GAMEPAD_RIGHT_SHOULDER: + case REX::W32::XINPUT_GAMEPAD_RIGHT_SHOULDER: return kGamepadButtonOffset_RIGHT_SHOULDER; - case XInputButton::XINPUT_GAMEPAD_A: + case REX::W32::XINPUT_GAMEPAD_A: return kGamepadButtonOffset_A; - case XInputButton::XINPUT_GAMEPAD_B: + case REX::W32::XINPUT_GAMEPAD_B: return kGamepadButtonOffset_B; - case XInputButton::XINPUT_GAMEPAD_X: + case REX::W32::XINPUT_GAMEPAD_X: return kGamepadButtonOffset_X; - case XInputButton::XINPUT_GAMEPAD_Y: + case REX::W32::XINPUT_GAMEPAD_Y: return kGamepadButtonOffset_Y; case 0x9: // Left Trigger game-defined ID return kGamepadButtonOffset_LT; @@ -48,37 +47,35 @@ namespace SFSE std::uint32_t InputMap::GamepadKeycodeToMask(const std::uint32_t a_keyCode) { - using XInputButton = RE::XInput::XInputButton; - switch (a_keyCode) { case kGamepadButtonOffset_DPAD_UP: - return XInputButton::XINPUT_GAMEPAD_DPAD_UP; + return REX::W32::XINPUT_GAMEPAD_DPAD_UP; case kGamepadButtonOffset_DPAD_DOWN: - return XInputButton::XINPUT_GAMEPAD_DPAD_DOWN; + return REX::W32::XINPUT_GAMEPAD_DPAD_DOWN; case kGamepadButtonOffset_DPAD_LEFT: - return XInputButton::XINPUT_GAMEPAD_DPAD_LEFT; + return REX::W32::XINPUT_GAMEPAD_DPAD_LEFT; case kGamepadButtonOffset_DPAD_RIGHT: - return XInputButton::XINPUT_GAMEPAD_DPAD_RIGHT; + return REX::W32::XINPUT_GAMEPAD_DPAD_RIGHT; case kGamepadButtonOffset_START: - return XInputButton::XINPUT_GAMEPAD_START; + return REX::W32::XINPUT_GAMEPAD_START; case kGamepadButtonOffset_BACK: - return XInputButton::XINPUT_GAMEPAD_BACK; + return REX::W32::XINPUT_GAMEPAD_BACK; case kGamepadButtonOffset_LEFT_THUMB: - return XInputButton::XINPUT_GAMEPAD_LEFT_THUMB; + return REX::W32::XINPUT_GAMEPAD_LEFT_THUMB; case kGamepadButtonOffset_RIGHT_THUMB: - return XInputButton::XINPUT_GAMEPAD_RIGHT_THUMB; + return REX::W32::XINPUT_GAMEPAD_RIGHT_THUMB; case kGamepadButtonOffset_LEFT_SHOULDER: - return XInputButton::XINPUT_GAMEPAD_LEFT_SHOULDER; + return REX::W32::XINPUT_GAMEPAD_LEFT_SHOULDER; case kGamepadButtonOffset_RIGHT_SHOULDER: - return XInputButton::XINPUT_GAMEPAD_RIGHT_SHOULDER; + return REX::W32::XINPUT_GAMEPAD_RIGHT_SHOULDER; case kGamepadButtonOffset_A: - return XInputButton::XINPUT_GAMEPAD_A; + return REX::W32::XINPUT_GAMEPAD_A; case kGamepadButtonOffset_B: - return XInputButton::XINPUT_GAMEPAD_B; + return REX::W32::XINPUT_GAMEPAD_B; case kGamepadButtonOffset_X: - return XInputButton::XINPUT_GAMEPAD_X; + return REX::W32::XINPUT_GAMEPAD_X; case kGamepadButtonOffset_Y: - return XInputButton::XINPUT_GAMEPAD_Y; + return REX::W32::XINPUT_GAMEPAD_Y; case kGamepadButtonOffset_LT: return 0x9; // Left Trigger game-defined ID case kGamepadButtonOffset_RT: @@ -93,9 +90,11 @@ namespace SFSE if (a_keyCode >= kMacro_MouseButtonOffset && a_keyCode < kMacro_GamepadOffset) { return GetMouseButtonName(a_keyCode); } + if (a_keyCode >= kMacro_GamepadOffset && a_keyCode < kMaxMacros) { return GetGamepadButtonName(a_keyCode); } + return GetKeyboardKeyName(a_keyCode); } @@ -103,49 +102,47 @@ namespace SFSE { std::int32_t scancode = static_cast(a_keyCode & 0xFF); - using DIKey = RE::DirectInput8::DIKey; - switch (scancode) { - case DIKey::DIK_NUMPADENTER: // Numpad Enter + case REX::W32::DIK_NUMPADENTER: // Numpad Enter scancode = 0x11C; break; - case DIKey::DIK_RCONTROL: // Right Control + case REX::W32::DIK_RCONTROL: // Right Control scancode = 0x11D; break; - case DIKey::DIK_DIVIDE: // Numpad / + case REX::W32::DIK_DIVIDE: // Numpad / scancode = 0x135; break; - case DIKey::DIK_RALT: // Right Alt + case REX::W32::DIK_RALT: // Right Alt scancode = 0x138; break; - case DIKey::DIK_HOME: // Home + case REX::W32::DIK_HOME: // Home scancode = 0x147; break; - case DIKey::DIK_UPARROW: // Up Arrow + case REX::W32::DIK_UPARROW: // Up Arrow scancode = 0x148; break; - case DIKey::DIK_PGUP: // Page Up + case REX::W32::DIK_PGUP: // Page Up scancode = 0x149; break; - case DIKey::DIK_LEFTARROW: // Left Arrow + case REX::W32::DIK_LEFTARROW: // Left Arrow scancode = 0x14B; break; - case DIKey::DIK_RIGHTARROW: // Right Arrow + case REX::W32::DIK_RIGHTARROW: // Right Arrow scancode = 0x14D; break; - case DIKey::DIK_END: // End + case REX::W32::DIK_END: // End scancode = 0x14F; break; - case DIKey::DIK_DOWNARROW: // Down Arrow + case REX::W32::DIK_DOWNARROW: // Down Arrow scancode = 0x150; break; - case DIKey::DIK_PGDN: // Page Down + case REX::W32::DIK_PGDN: // Page Down scancode = 0x151; break; - case DIKey::DIK_INSERT: // Insert + case REX::W32::DIK_INSERT: // Insert scancode = 0x152; break; - case DIKey::DIK_DELETE: // Delete + case REX::W32::DIK_DELETE: // Delete scancode = 0x153; break; } @@ -156,8 +153,8 @@ namespace SFSE lParam |= (0x1 << 24); } - wchar_t buffer[WinAPI::MAX_PATH]; - const auto length = WinAPI::GetKeyNameText(lParam, buffer, WinAPI::MAX_PATH); + wchar_t buffer[REX::W32::MAX_PATH]; + const auto length = REX::W32::GetKeyNameTextW(lParam, buffer, REX::W32::MAX_PATH); const std::wstring keyNameW{ buffer, static_cast(length) }; return stl::utf16_to_utf8(keyNameW).value_or(""s); diff --git a/src/SFSE/Interfaces.cpp b/src/SFSE/Interfaces.cpp index 8d4f396f..7352ef75 100644 --- a/src/SFSE/Interfaces.cpp +++ b/src/SFSE/Interfaces.cpp @@ -160,6 +160,6 @@ namespace SFSE const PluginVersionData* PluginVersionData::GetSingleton() noexcept { - return reinterpret_cast(WinAPI::GetProcAddress(WinAPI::GetCurrentModule(), "SFSEPlugin_Version")); + return reinterpret_cast(REX::W32::GetProcAddress(REX::W32::GetCurrentModule(), "SFSEPlugin_Version")); } } diff --git a/src/SFSE/Logger.cpp b/src/SFSE/Logger.cpp index d5cab213..7dde838c 100644 --- a/src/SFSE/Logger.cpp +++ b/src/SFSE/Logger.cpp @@ -1,7 +1,9 @@ #include "SFSE/Logger.h" - #include "SFSE/API.h" +#include "REX/W32/OLE32.h" +#include "REX/W32/SHELL32.h" + #include #include @@ -10,8 +12,8 @@ namespace SFSE::log std::optional log_directory() { wchar_t* buffer{}; - const auto result = WinAPI::SHGetKnownFolderPath(WinAPI::FOLDERID_DOCUMENTS, WinAPI::KF_FLAG_DEFAULT, nullptr, std::addressof(buffer)); - const std::unique_ptr knownPath(buffer, WinAPI::CoTaskMemFree); + const auto result = REX::W32::SHGetKnownFolderPath(REX::W32::FOLDERID_Documents, REX::W32::KF_FLAG_DEFAULT, nullptr, std::addressof(buffer)); + const std::unique_ptr knownPath(buffer, REX::W32::CoTaskMemFree); if (!knownPath || result != 0) { error("failed to get known folder path"sv); return std::nullopt; diff --git a/src/SFSE/Trampoline.cpp b/src/SFSE/Trampoline.cpp index fd650e20..eb457124 100644 --- a/src/SFSE/Trampoline.cpp +++ b/src/SFSE/Trampoline.cpp @@ -2,12 +2,15 @@ #include "SFSE/Logger.h" +#include "REX/W32/KERNEL32.h" + // xbyak brings in #ifdef SFSE_SUPPORT_XBYAK # define NOMINMAX # include # undef MEM_COMMIT # undef MEM_FREE +# undef MEM_RELEASE # undef MEM_RESERVE # undef PAGE_EXECUTE_READWRITE #endif @@ -31,33 +34,33 @@ namespace SFSE constexpr std::size_t minRange = gigabyte * 2; constexpr std::uintptr_t maxAddr = std::numeric_limits::max(); - WinAPI::SYSTEM_INFO si; - WinAPI::GetSystemInfo(&si); + REX::W32::SYSTEM_INFO si; + REX::W32::GetSystemInfo(&si); const std::uint32_t granularity = si.allocationGranularity; std::uintptr_t min = a_address >= minRange ? detail::roundup(a_address - minRange, granularity) : 0; const std::uintptr_t max = a_address < (maxAddr - minRange) ? detail::rounddown(a_address + minRange, granularity) : maxAddr; - WinAPI::MEMORY_BASIC_INFORMATION mbi; + REX::W32::MEMORY_BASIC_INFORMATION mbi; do { - if (!WinAPI::VirtualQuery(reinterpret_cast(min), std::addressof(mbi), sizeof(mbi))) { - log::error("VirtualQuery failed with code: 0x{:08X}"sv, WinAPI::GetLastError()); + if (!REX::W32::VirtualQuery(reinterpret_cast(min), std::addressof(mbi), sizeof(mbi))) { + log::error("VirtualQuery failed with code: 0x{:08X}"sv, REX::W32::GetLastError()); return nullptr; } const auto baseAddr = reinterpret_cast(mbi.baseAddress); min = baseAddr + mbi.regionSize; - if (mbi.state == WinAPI::MEM_FREE) { + if (mbi.state == REX::W32::MEM_FREE) { const std::uintptr_t addr = detail::roundup(baseAddr, granularity); // if rounding didn't advance us into the next region and the region is the required size if (addr < min && (min - addr) >= a_size) { - const auto mem = WinAPI::VirtualAlloc(reinterpret_cast(addr), a_size, WinAPI::MEM_COMMIT | WinAPI::MEM_RESERVE, WinAPI::PAGE_EXECUTE_READWRITE); + const auto mem = REX::W32::VirtualAlloc(reinterpret_cast(addr), a_size, REX::W32::MEM_COMMIT | REX::W32::MEM_RESERVE, REX::W32::PAGE_EXECUTE_READWRITE); if (mem) { return mem; } - log::warn("VirtualAlloc failed with code: 0x{:08X}"sv, WinAPI::GetLastError()); + log::warn("VirtualAlloc failed with code: 0x{:08X}"sv, REX::W32::GetLastError()); } } } while (min < max); diff --git a/xmake.lua b/xmake.lua index 273d1e54..99aca44f 100644 --- a/xmake.lua +++ b/xmake.lua @@ -9,7 +9,7 @@ set_warnings("allextra") set_encodings("utf-8") -- add rules -add_rules("mode.debug", "mode.release") +add_rules("mode.debug", "mode.releasedbg") -- require packages add_requires("xbyak") @@ -41,7 +41,7 @@ target("commonlibsf") add_options("sfse_xbyak", { public = true }) -- add system links - add_syslinks("advapi32", "dbghelp", "ole32", "shell32", "user32", "version", "Ws2_32") + add_syslinks("advapi32", "bcrypt", "dbghelp", "dxgi", "ole32", "shell32", "user32", "version", "ws2_32") -- add source files add_files("src/**.cpp") @@ -51,6 +51,7 @@ target("commonlibsf") add_headerfiles( "include/(RE/**.h)", "include/(REL/**.h)", + "include/(REX/**.h)", "include/(SFSE/**.h)" )