diff --git a/CommonLibSF/include/RE/B/BSFixedString.h b/CommonLibSF/include/RE/B/BSFixedString.h index a5d3c2a2..b5ac8620 100644 --- a/CommonLibSF/include/RE/B/BSFixedString.h +++ b/CommonLibSF/include/RE/B/BSFixedString.h @@ -193,7 +193,7 @@ namespace RE static constexpr const value_type EMPTY[]{ 0 }; // members - BSStringPool::Entry* _data{ nullptr }; // 0 + BSStringPool::Entry* _data{}; // 0 }; extern template class BSFixedString; diff --git a/CommonLibSF/include/RE/B/BSIntrusiveRefCounted.h b/CommonLibSF/include/RE/B/BSIntrusiveRefCounted.h index 96eaf441..feb6ba04 100644 --- a/CommonLibSF/include/RE/B/BSIntrusiveRefCounted.h +++ b/CommonLibSF/include/RE/B/BSIntrusiveRefCounted.h @@ -7,7 +7,7 @@ namespace RE public: SF_RTTI(BSIntrusiveRefCounted); - volatile mutable std::uint32_t refCount{ 0 }; // 00 + volatile mutable std::uint32_t refCount{}; // 00 std::uint32_t unk04; // 04 }; static_assert(sizeof(BSIntrusiveRefCounted) == 0x08); diff --git a/CommonLibSF/include/RE/B/BSStringT.h b/CommonLibSF/include/RE/B/BSStringT.h index 18670b2a..4b7adf39 100644 --- a/CommonLibSF/include/RE/B/BSStringT.h +++ b/CommonLibSF/include/RE/B/BSStringT.h @@ -114,8 +114,8 @@ namespace RE a_rhs._capacity = 0; } - pointer _data{ nullptr }; // ?? - size_type _size{ 0 }; // ?? - size_type _capacity{ 0 }; // ?? + pointer _data{}; // ?? + size_type _size{}; // ?? + size_type _capacity{}; // ?? }; } diff --git a/CommonLibSF/include/RE/F/FormTypes.h b/CommonLibSF/include/RE/F/FormTypes.h index 8ce3ef76..340069fb 100644 --- a/CommonLibSF/include/RE/F/FormTypes.h +++ b/CommonLibSF/include/RE/F/FormTypes.h @@ -231,7 +231,7 @@ namespace std { [[nodiscard]] inline std::string to_string(RE::FormType a_formType) { - return RE::FormTypeToString(a_formType); + return FormTypeToString(a_formType); } } @@ -250,7 +250,7 @@ namespace fmt template auto format(const RE::FormType& a_formType, FormatContext& a_ctx) { - return fmt::format_to(a_ctx.out(), "{}", RE::FormTypeToString(a_formType)); + return fmt::format_to(a_ctx.out(), "{}", FormTypeToString(a_formType)); } }; } @@ -265,7 +265,7 @@ namespace std template auto format(RE::FormType a_formType, FormatContext& a_ctx) { - return formatter::format(RE::FormTypeToString(a_formType), a_ctx); + return formatter::format(FormTypeToString(a_formType), a_ctx); } }; } diff --git a/CommonLibSF/include/RE/N/NativeFunctionBase.h b/CommonLibSF/include/RE/N/NativeFunctionBase.h index ae5a7130..04fc736e 100644 --- a/CommonLibSF/include/RE/N/NativeFunctionBase.h +++ b/CommonLibSF/include/RE/N/NativeFunctionBase.h @@ -125,10 +125,10 @@ namespace RE std::uint64_t _retType; // 28 TypeInfo ParameterInfo _params; // 30 bool _isStatic; // 40 - bool _isCallableFromTasklet{ false }; // 41 - bool _isLatent{ false }; // 42 + bool _isCallableFromTasklet{}; // 41 + bool _isLatent{}; // 42 std::uint8_t _pad43; // 43 - std::uint32_t _userFlags{ 0 }; // 44 + std::uint32_t _userFlags{}; // 44 BSFixedString _docString; // 48 }; static_assert(sizeof(NativeFunctionBase) == 0x50); diff --git a/CommonLibSF/include/RE/N/NiPoint3.h b/CommonLibSF/include/RE/N/NiPoint3.h index 9fd85f8b..9b96d3d7 100644 --- a/CommonLibSF/include/RE/N/NiPoint3.h +++ b/CommonLibSF/include/RE/N/NiPoint3.h @@ -39,9 +39,9 @@ namespace RE float Unitize(); // members - float x{ 0.0F }; // 0x0 - float y{ 0.0F }; // 0x4 - float z{ 0.0F }; // 0x8 + float x{}; // 0x0 + float y{}; // 0x4 + float z{}; // 0x8 }; static_assert(sizeof(NiPoint3) == 0xC); diff --git a/CommonLibSF/include/RE/N/NiSmartPointer.h b/CommonLibSF/include/RE/N/NiSmartPointer.h index 22485ac4..bfc3dace 100644 --- a/CommonLibSF/include/RE/N/NiSmartPointer.h +++ b/CommonLibSF/include/RE/N/NiSmartPointer.h @@ -136,7 +136,7 @@ namespace RE } // members - element_type* _ptr{ nullptr }; // 0 + element_type* _ptr{}; // 0 }; static_assert(sizeof(NiPointer) == 0x8); diff --git a/CommonLibSF/include/RE/RTTI.h b/CommonLibSF/include/RE/RTTI.h index c976b231..c1b17375 100644 --- a/CommonLibSF/include/RE/RTTI.h +++ b/CommonLibSF/include/RE/RTTI.h @@ -53,7 +53,7 @@ namespace RE [[nodiscard]] constexpr bool is_good() const noexcept { return _rva != 0; } // members - std::uint32_t _rva{ 0 }; // 00 + std::uint32_t _rva{}; // 00 }; static_assert(sizeof(RVA) == 0x4); diff --git a/CommonLibSF/include/RE/S/ScaleformPtr.h b/CommonLibSF/include/RE/S/ScaleformPtr.h index 8d601422..bc65879f 100644 --- a/CommonLibSF/include/RE/S/ScaleformPtr.h +++ b/CommonLibSF/include/RE/S/ScaleformPtr.h @@ -174,7 +174,7 @@ namespace RE::Scaleform } // members - element_type* _ptr{ nullptr }; // 00 + element_type* _ptr{}; // 00 }; static_assert(sizeof(Ptr) == 0x8); diff --git a/CommonLibSF/include/RE/S/Script.h b/CommonLibSF/include/RE/S/Script.h index 68591400..b0f8e381 100644 --- a/CommonLibSF/include/RE/S/Script.h +++ b/CommonLibSF/include/RE/S/Script.h @@ -82,7 +82,7 @@ namespace RE // members const char* paramName{ "" }; // 00 std::uint32_t paramType; // 08 enumeration - bool optional{ false }; // 0C + bool optional{}; // 0C }; static_assert(sizeof(SCRIPT_PARAMETER) == 0x10); diff --git a/CommonLibSF/include/REL/ID.h b/CommonLibSF/include/REL/ID.h index 242f6e86..2604e678 100644 --- a/CommonLibSF/include/REL/ID.h +++ b/CommonLibSF/include/REL/ID.h @@ -57,8 +57,8 @@ namespace REL void close(); private: - void* _mapping{ nullptr }; - void* _view{ nullptr }; + void* _mapping{}; + void* _view{}; }; class Offset2ID @@ -66,9 +66,9 @@ namespace REL public: using value_type = mapping_t; using container_type = std::vector; - using size_type = typename container_type::size_type; - using const_iterator = typename container_type::const_iterator; - using const_reverse_iterator = typename container_type::const_reverse_iterator; + using size_type = container_type::size_type; + using const_iterator = container_type::const_iterator; + using const_reverse_iterator = container_type::const_reverse_iterator; template explicit Offset2ID(ExecutionPolicy&& a_policy) @@ -151,12 +151,12 @@ namespace REL [[nodiscard]] std::size_t address_count() const noexcept { - return static_cast(_addressCount); + return _addressCount; } [[nodiscard]] std::uint64_t pointer_size() const noexcept { - return static_cast(_pointerSize); + return _pointerSize; } [[nodiscard]] std::string_view name() const noexcept @@ -172,8 +172,8 @@ namespace REL private: char _name[20]{}; Version _version; - std::uint32_t _pointerSize{ 0 }; - std::uint32_t _addressCount{ 0 }; + std::uint32_t _pointerSize{}; + std::uint32_t _addressCount{}; }; } @@ -232,7 +232,7 @@ namespace REL } static IDDatabase _instance; - inline static std::atomic_bool _initialized{ false }; + inline static std::atomic_bool _initialized{}; inline static std::mutex _initLock; database::memory_map _mmap; std::span _id2offset; @@ -275,7 +275,7 @@ namespace REL return Module::get().base(); } - std::uint64_t _id{ 0 }; + std::uint64_t _id{}; }; template diff --git a/CommonLibSF/include/REL/Module.h b/CommonLibSF/include/REL/Module.h index c9f1a8d4..46dd7b86 100644 --- a/CommonLibSF/include/REL/Module.h +++ b/CommonLibSF/include/REL/Module.h @@ -44,9 +44,9 @@ namespace REL private: friend class Module; - std::uintptr_t _proxyBase{ 0 }; - std::uintptr_t _address{ 0 }; - std::size_t _size{ 0 }; + std::uintptr_t _proxyBase{}; + std::uintptr_t _address{}; + std::size_t _size{}; }; class Module @@ -59,7 +59,7 @@ namespace REL [[nodiscard]] constexpr auto base() const noexcept { return _base; } template - [[nodiscard]] constexpr auto* pointer() const noexcept + [[nodiscard]] constexpr auto pointer() const noexcept { return std::bit_cast(base()); } diff --git a/CommonLibSF/include/REL/Offset.h b/CommonLibSF/include/REL/Offset.h index 5550eccd..adfd42f6 100644 --- a/CommonLibSF/include/REL/Offset.h +++ b/CommonLibSF/include/REL/Offset.h @@ -24,6 +24,6 @@ namespace REL } private: - std::ptrdiff_t _offset{ 0 }; + std::ptrdiff_t _offset{}; }; } diff --git a/CommonLibSF/include/REL/Relocation.h b/CommonLibSF/include/REL/Relocation.h index adcfc44a..aa8c973c 100644 --- a/CommonLibSF/include/REL/Relocation.h +++ b/CommonLibSF/include/REL/Relocation.h @@ -3,7 +3,6 @@ #include "REL/ID.h" #include "REL/Module.h" #include "REL/Offset.h" -#include "REL/Version.h" #define REL_MAKE_MEMBER_FUNCTION_POD_TYPE_HELPER_IMPL(a_nopropQual, a_propQual, ...) \ template \ @@ -153,14 +152,14 @@ 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{ 0 }; + std::uint32_t old{}; auto success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, WinAPI::PAGE_EXECUTE_READWRITE, std::addressof(old)); - if (success != 0) { + 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)); } - assert(success != 0); + assert(success); } template @@ -177,14 +176,14 @@ 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{ 0 }; + std::uint32_t old{}; auto success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, WinAPI::PAGE_EXECUTE_READWRITE, std::addressof(old)); - if (success != 0) { + 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)); } - assert(success != 0); + assert(success); }; template @@ -270,7 +269,7 @@ namespace REL private: [[nodiscard]] static std::uintptr_t base() { return Module::get().base(); } - std::uintptr_t _address{ 0 }; + std::uintptr_t _address{}; }; } diff --git a/CommonLibSF/include/REL/Version.h b/CommonLibSF/include/REL/Version.h index 275d4ec2..714ec140 100644 --- a/CommonLibSF/include/REL/Version.h +++ b/CommonLibSF/include/REL/Version.h @@ -79,7 +79,7 @@ namespace REL [[nodiscard]] static constexpr Version unpack(const std::uint32_t a_packedVersion) noexcept { - return REL::Version{ + return Version{ static_cast((a_packedVersion >> 24) & 0x0FF), static_cast((a_packedVersion >> 16) & 0x0FF), static_cast((a_packedVersion >> 4) & 0xFFF), @@ -106,7 +106,7 @@ namespace REL namespace detail { template - constexpr uint8_t read_version(std::array& result) + constexpr uint8_t read_version(std::array& result) { static_assert(C >= '0' && C <= '9', "Invalid character in semantic version literal."); static_assert(Index < 4, "Too many components in semantic version literal."); @@ -116,7 +116,7 @@ namespace REL template requires(sizeof...(Rest) > 0) - constexpr uint8_t read_version(std::array& result) + constexpr uint8_t read_version(std::array& result) { static_assert(C == '.' || (C >= '0' && C <= '9'), "Invalid character in semantic version literal."); static_assert(Index < 4, "Too many components in semantic version literal."); @@ -132,14 +132,14 @@ namespace REL } template - [[nodiscard]] constexpr REL::Version operator""_v() noexcept + [[nodiscard]] constexpr Version operator""_v() noexcept { - std::array result{ 0, 0, 0, 0 }; + std::array result{ 0, 0, 0, 0 }; detail::read_version<0, C...>(result); - return REL::Version(result); + return Version(result); } - [[nodiscard]] constexpr REL::Version operator""_v(const char* str, const std::size_t len) + [[nodiscard]] constexpr Version operator""_v(const char* str, const std::size_t len) { return Version(std::string_view(str, len)); } diff --git a/CommonLibSF/include/SFSE/API.h b/CommonLibSF/include/SFSE/API.h index 9cbf2348..b20daf1e 100644 --- a/CommonLibSF/include/SFSE/API.h +++ b/CommonLibSF/include/SFSE/API.h @@ -3,7 +3,6 @@ #include "SFSE/Impl/Stubs.h" #include "SFSE/Interfaces.h" #include "SFSE/Trampoline.h" -#include "SFSE/Version.h" #define SFSEAPI __cdecl diff --git a/CommonLibSF/include/SFSE/IAT.h b/CommonLibSF/include/SFSE/IAT.h index 7e4ee775..c16bb1c1 100644 --- a/CommonLibSF/include/SFSE/IAT.h +++ b/CommonLibSF/include/SFSE/IAT.h @@ -8,7 +8,7 @@ namespace SFSE [[nodiscard]] void* GetIATPtr(std::string_view a_dll, std::string_view a_function); template - [[nodiscard]] inline T* GetIATPtr(std::string_view a_dll, std::string_view a_function) + [[nodiscard]] T* GetIATPtr(std::string_view a_dll, std::string_view a_function) { return static_cast(GetIATPtr(std::move(a_dll), std::move(a_function))); } @@ -16,7 +16,7 @@ namespace SFSE [[nodiscard]] void* GetIATPtr(void* a_module, std::string_view a_dll, std::string_view a_function); template - [[nodiscard]] inline T* GetIATPtr(void* a_module, std::string_view a_dll, std::string_view a_function) + [[nodiscard]] T* GetIATPtr(void* a_module, std::string_view a_dll, std::string_view a_function) { return static_cast(GetIATPtr(a_module, std::move(a_dll), std::move(a_function))); } @@ -24,7 +24,7 @@ namespace SFSE std::uintptr_t PatchIAT(std::uintptr_t a_newFunc, std::string_view a_dll, std::string_view a_function); template - inline std::uintptr_t PatchIAT(F a_newFunc, const std::string_view a_dll, const std::string_view a_function) + std::uintptr_t PatchIAT(F a_newFunc, const std::string_view a_dll, const std::string_view a_function) { return PatchIAT(stl::unrestricted_cast(a_newFunc), a_dll, a_function); } diff --git a/CommonLibSF/include/SFSE/Impl/PCH.h b/CommonLibSF/include/SFSE/Impl/PCH.h index 38e20fae..347ae6aa 100644 --- a/CommonLibSF/include/SFSE/Impl/PCH.h +++ b/CommonLibSF/include/SFSE/Impl/PCH.h @@ -389,11 +389,11 @@ namespace SFSE } private: - underlying_type _impl{ 0 }; + underlying_type _impl{}; }; template - enumeration(Args...) -> enumeration, std::underlying_type_t>>; + enumeration(Args...) -> enumeration>; } } @@ -583,12 +583,12 @@ namespace SFSE void memzero(volatile T* a_ptr, const std::size_t a_size = sizeof(T)) { const auto begin = reinterpret_cast(a_ptr); - constexpr char val{ 0 }; + constexpr char val{}; std::fill_n(begin, a_size, val); } template - [[nodiscard]] inline auto pun_bits(Args... a_args) + [[nodiscard]] auto pun_bits(Args... a_args) requires(std::same_as, bool> && ...) { constexpr auto ARGC = sizeof...(Args); @@ -675,9 +675,8 @@ namespace SFSE if (result && result != buf.size()) { std::filesystem::path p(buf.begin(), buf.begin() + result); return p.filename().native(); - } else { - return L""s; } + return L""s; }(); spdlog::log(spdlog::source_loc{ a_loc.file_name(), static_cast(a_loc.line()), a_loc.function_name() }, spdlog::level::critical, a_msg); diff --git a/CommonLibSF/include/SFSE/Interfaces.h b/CommonLibSF/include/SFSE/Interfaces.h index a60b6a6f..8de3ffb5 100644 --- a/CommonLibSF/include/SFSE/Interfaces.h +++ b/CommonLibSF/include/SFSE/Interfaces.h @@ -1,7 +1,6 @@ #pragma once #include "SFSE/Impl/Stubs.h" -#include "SFSE/Version.h" namespace RE { diff --git a/CommonLibSF/include/SFSE/Trampoline.h b/CommonLibSF/include/SFSE/Trampoline.h index 14a4dba3..934fd402 100644 --- a/CommonLibSF/include/SFSE/Trampoline.h +++ b/CommonLibSF/include/SFSE/Trampoline.h @@ -84,7 +84,7 @@ namespace SFSE { const auto trampoline = static_cast(a_trampoline); if (trampoline) { - constexpr auto INT3 = static_cast(0xCC); + constexpr auto INT3 = 0xCC; std::memset(trampoline, INT3, a_size); } @@ -241,8 +241,8 @@ namespace SFSE mem->jmp = static_cast(0xFF); mem->modrm = static_cast(0x25); - mem->disp = static_cast(0); - mem->addr = static_cast(a_dst); + mem->disp = 0; + mem->addr = a_dst; } void write_6branch(const std::uintptr_t a_src, std::uintptr_t a_dst, const std::uint8_t a_modrm) @@ -263,7 +263,7 @@ namespace SFSE static_assert(sizeof(Assembly) == 0x6); #pragma pack(pop) - std::uintptr_t* mem = nullptr; + std::uintptr_t* mem; if (const auto it = _6branches.find(a_dst); it != _6branches.end()) { mem = reinterpret_cast(it->second); } else { @@ -348,8 +348,8 @@ namespace SFSE std::map _6branches; std::string _name{ "Default Trampoline"sv }; deleter_type _deleter; - std::byte* _data{ nullptr }; - std::size_t _capacity{ 0 }; - std::size_t _size{ 0 }; + std::byte* _data{}; + std::size_t _capacity{}; + std::size_t _size{}; }; } diff --git a/CommonLibSF/src/RE/N/NiPoint3.cpp b/CommonLibSF/src/RE/N/NiPoint3.cpp index 6375930a..797a6a4e 100644 --- a/CommonLibSF/src/RE/N/NiPoint3.cpp +++ b/CommonLibSF/src/RE/N/NiPoint3.cpp @@ -147,7 +147,8 @@ namespace RE auto length = Length(); if (length == 1.f) { return length; - } else if (length > FLT_EPSILON) { + } + if (length > FLT_EPSILON) { operator/=(length); } else { x = 0.0; diff --git a/CommonLibSF/src/REL/ID.cpp b/CommonLibSF/src/REL/ID.cpp index 001ee540..a62edb80 100644 --- a/CommonLibSF/src/REL/ID.cpp +++ b/CommonLibSF/src/REL/ID.cpp @@ -4,8 +4,8 @@ namespace REL { namespace database { - constexpr auto LookUpDir = "Data\\SFSE\\Plugins"sv; - constexpr std::array, 2> VendorModule{ + constexpr auto LookUpDir = "Data\\SFSE\\Plugins"sv; + constexpr std::array VendorModule{ std::make_pair("steam_api64"sv, IDDatabase::Platform::kSteam), std::make_pair("XGameRuntime"sv, IDDatabase::Platform::kMsStore), }; @@ -32,7 +32,7 @@ namespace REL { close(); - WinAPI::ULARGE_INTEGER bytes{}; + WinAPI::ULARGE_INTEGER bytes; bytes.value = a_size; _mapping = WinAPI::OpenFileMapping( @@ -64,7 +64,7 @@ namespace REL { close(); - WinAPI::ULARGE_INTEGER bytes{}; + WinAPI::ULARGE_INTEGER bytes; bytes.value = a_size; _mapping = WinAPI::OpenFileMapping( @@ -103,7 +103,7 @@ namespace REL void memory_map::close() { if (_view) { - (void)WinAPI::UnmapViewOfFile(static_cast(_view)); + (void)WinAPI::UnmapViewOfFile(_view); _view = nullptr; } @@ -161,7 +161,7 @@ namespace REL "library for this version of the game, and thus does not support it."sv, a_id, std::to_underlying(database::kDatabaseVersion)); - return static_cast(it->offset); + return it->offset; } std::wstring IDDatabase::addresslib_filename() @@ -229,7 +229,7 @@ namespace REL stl_assert(mapname.has_value(), "Failed to generate memory map name."); - const auto byteSize = static_cast(header.address_count()) * sizeof(database::mapping_t); + const auto byteSize = header.address_count() * sizeof(database::mapping_t); if (_mmap.open(mapname.value(), byteSize)) { _id2offset = { static_cast(_mmap.data()), header.address_count() }; } else if (_mmap.create(mapname.value(), byteSize)) { @@ -259,7 +259,6 @@ namespace REL a_version.string(), database::VendorModule[std::to_underlying(_platform)].first), a_failOnError); - return false; } return true; } diff --git a/CommonLibSF/src/REL/Module.cpp b/CommonLibSF/src/REL/Module.cpp index 0fd1b87f..433fedfa 100644 --- a/CommonLibSF/src/REL/Module.cpp +++ b/CommonLibSF/src/REL/Module.cpp @@ -10,7 +10,7 @@ namespace REL 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 sections = WinAPI::IMAGE_FIRST_SECTION(ntHeader); const auto size = std::min(ntHeader->fileHeader.sectionCount, _segments.size()); for (std::size_t i = 0; i < size; ++i) { diff --git a/CommonLibSF/src/REL/Version.cpp b/CommonLibSF/src/REL/Version.cpp index c7fd3f66..92e8404e 100644 --- a/CommonLibSF/src/REL/Version.cpp +++ b/CommonLibSF/src/REL/Version.cpp @@ -5,7 +5,7 @@ namespace REL constexpr Version::Version(const std::string_view a_version) { std::array powers{ 1, 1, 1, 1 }; - std::size_t position = 0; + std::size_t position{}; for (std::size_t i = 0; i < a_version.size(); ++i) { if (a_version[i] == '.') { if (++position == powers.size()) { @@ -30,18 +30,18 @@ namespace REL [[nodiscard]] std::optional get_file_version(const stl::zwstring a_filename) { - std::uint32_t dummy{ 0 }; + std::uint32_t dummy{}; std::vector buf(WinAPI::GetFileVersionInfoSize(a_filename.data(), std::addressof(dummy))); if (buf.empty()) { return std::nullopt; } - if (!WinAPI::GetFileVersionInfo(a_filename.data(), 0, static_cast(buf.size()), buf.data())) { + if (!WinAPI::GetFileVersionInfo(a_filename.data(), 0, buf.size(), buf.data())) { return std::nullopt; } - void* verBuf{ nullptr }; - std::uint32_t verLen{ 0 }; + void* verBuf{}; + std::uint32_t verLen{}; if (!WinAPI::VerQueryValue(buf.data(), L"\\StringFileInfo\\040904B0\\ProductVersion", std::addressof(verBuf), std::addressof(verLen))) { return std::nullopt; } diff --git a/CommonLibSF/src/SFSE/API.cpp b/CommonLibSF/src/SFSE/API.cpp index bdb3914e..abfa5b7d 100644 --- a/CommonLibSF/src/SFSE/API.cpp +++ b/CommonLibSF/src/SFSE/API.cpp @@ -16,13 +16,13 @@ namespace SFSE PluginHandle pluginHandle{ static_cast(-1) }; - TrampolineInterface* trampolineInterface{ nullptr }; - MessagingInterface* messagingInterface{ nullptr }; - MenuInterface* menuInterface{ nullptr }; + TrampolineInterface* trampolineInterface{}; + MessagingInterface* messagingInterface{}; + MenuInterface* menuInterface{}; std::mutex apiLock; std::vector> apiInitRegs; - bool apiInit{ false }; + bool apiInit{}; private: APIStorage() noexcept = default; diff --git a/CommonLibSF/src/SFSE/Impl/WinAPI.cpp b/CommonLibSF/src/SFSE/Impl/WinAPI.cpp index 70d49cc2..a738f1c8 100644 --- a/CommonLibSF/src/SFSE/Impl/WinAPI.cpp +++ b/CommonLibSF/src/SFSE/Impl/WinAPI.cpp @@ -41,14 +41,14 @@ namespace SFSE::WinAPI { return static_cast( ::CloseHandle( - static_cast<::HANDLE>(a_handle))); + a_handle)); } void CoTaskMemFree( void* a_block) noexcept { ::CoTaskMemFree( - static_cast<::LPVOID>(a_block)); + a_block); } void* CreateFileMapping( @@ -59,14 +59,13 @@ namespace SFSE::WinAPI std::uint32_t a_maxSizeLow, const char* a_name) noexcept { - return static_cast( - ::CreateFileMappingA( - static_cast<::HANDLE>(a_file), - reinterpret_cast<::LPSECURITY_ATTRIBUTES>(a_attributes), - static_cast<::DWORD>(a_protect), - static_cast<::DWORD>(a_maxSizeHigh), - static_cast<::DWORD>(a_maxSizeLow), - static_cast<::LPCSTR>(a_name))); + return CreateFileMappingA( + a_file, + reinterpret_cast(a_attributes), + a_protect, + a_maxSizeHigh, + a_maxSizeLow, + a_name); } void* CreateFileMapping( @@ -77,14 +76,13 @@ namespace SFSE::WinAPI std::uint32_t a_maxSizeLow, const wchar_t* a_name) noexcept { - return static_cast( - ::CreateFileMappingW( - static_cast<::HANDLE>(a_file), - reinterpret_cast<::LPSECURITY_ATTRIBUTES>(a_attributes), - static_cast<::DWORD>(a_protect), - static_cast<::DWORD>(a_maxSizeHigh), - static_cast<::DWORD>(a_maxSizeLow), - static_cast<::LPCWSTR>(a_name))); + return CreateFileMappingW( + a_file, + reinterpret_cast(a_attributes), + a_protect, + a_maxSizeHigh, + a_maxSizeLow, + a_name); } bool CreateProcess( @@ -100,17 +98,17 @@ namespace SFSE::WinAPI PROCESS_INFORMATION* a_procInfo) noexcept { return static_cast( - ::CreateProcessA( - static_cast<::LPCSTR>(a_name), - static_cast<::LPSTR>(a_cmd), - reinterpret_cast<::LPSECURITY_ATTRIBUTES>(a_procAttr), - reinterpret_cast<::LPSECURITY_ATTRIBUTES>(a_threadAttr), - static_cast<::BOOL>(a_inherit), - static_cast<::DWORD>(a_flags), - static_cast<::LPVOID>(a_env), - static_cast<::LPCSTR>(a_curDir), - reinterpret_cast<::LPSTARTUPINFOA>(a_startInfo), - reinterpret_cast<::LPPROCESS_INFORMATION>(a_procInfo))); + 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( @@ -126,17 +124,17 @@ namespace SFSE::WinAPI PROCESS_INFORMATION* a_procInfo) noexcept { return static_cast( - ::CreateProcessW( - static_cast<::LPCWSTR>(a_name), - static_cast<::LPWSTR>(a_cmd), - reinterpret_cast<::LPSECURITY_ATTRIBUTES>(a_procAttr), - reinterpret_cast<::LPSECURITY_ATTRIBUTES>(a_threadAttr), - static_cast<::BOOL>(a_inherit), - static_cast<::DWORD>(a_flags), - static_cast<::LPVOID>(a_env), - static_cast<::LPCWSTR>(a_curDir), - reinterpret_cast<::LPSTARTUPINFOW>(a_startInfo), - reinterpret_cast<::LPPROCESS_INFORMATION>(a_procInfo))); + 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( @@ -148,15 +146,14 @@ namespace SFSE::WinAPI std::uint32_t a_flags, std::uint32_t* a_threadID) noexcept { - return static_cast( - ::CreateRemoteThread( - static_cast<::HANDLE>(a_process), - reinterpret_cast<::LPSECURITY_ATTRIBUTES>(a_threadAttr), - static_cast<::SIZE_T>(a_stackSize), - reinterpret_cast<::LPTHREAD_START_ROUTINE>(a_startAddr), - static_cast<::LPVOID>(a_param), - static_cast<::DWORD>(a_flags), - reinterpret_cast<::LPDWORD>(a_threadID))); + return ::CreateRemoteThread( + a_process, + reinterpret_cast(a_threadAttr), + a_stackSize, + reinterpret_cast(a_startAddr), + a_param, + a_flags, + reinterpret_cast(a_threadID)); } void* CreateThread( @@ -167,14 +164,13 @@ namespace SFSE::WinAPI std::uint32_t a_flags, std::uint32_t* a_threadID) noexcept { - return static_cast( - ::CreateThread( - reinterpret_cast<::LPSECURITY_ATTRIBUTES>(a_threadAttr), - static_cast<::SIZE_T>(a_stackSize), - reinterpret_cast<::LPTHREAD_START_ROUTINE>(a_startAddr), - static_cast<::LPVOID>(a_param), - static_cast<::DWORD>(a_flags), - reinterpret_cast<::LPDWORD>(a_threadID))); + return ::CreateThread( + reinterpret_cast(a_threadAttr), + a_stackSize, + reinterpret_cast(a_startAddr), + a_param, + a_flags, + reinterpret_cast(a_threadID)); } std::uint32_t ExpandEnvironmentStrings( @@ -183,10 +179,10 @@ namespace SFSE::WinAPI std::uint32_t a_dstLen) noexcept { return static_cast( - ::ExpandEnvironmentStringsA( - static_cast<::LPCSTR>(a_src), - static_cast<::LPSTR>(a_dst), - static_cast<::DWORD>(a_dstLen))); + ExpandEnvironmentStringsA( + a_src, + a_dst, + a_dstLen)); } std::uint32_t ExpandEnvironmentStrings( @@ -195,10 +191,10 @@ namespace SFSE::WinAPI std::uint32_t a_dstLen) noexcept { return static_cast( - ::ExpandEnvironmentStringsW( - static_cast<::LPCWSTR>(a_src), - static_cast<::LPWSTR>(a_dst), - static_cast<::DWORD>(a_dstLen))); + ExpandEnvironmentStringsW( + a_src, + a_dst, + a_dstLen)); } bool FindClose( @@ -206,27 +202,25 @@ namespace SFSE::WinAPI { return static_cast( ::FindClose( - static_cast<::HMODULE>(a_file))); + a_file)); } void* FindFirstFile( const char* a_name, WIN32_FIND_DATAA* a_data) noexcept { - return static_cast( - ::FindFirstFileA( - static_cast<::LPCSTR>(a_name), - reinterpret_cast<::LPWIN32_FIND_DATAA>(a_data))); + return FindFirstFileA( + a_name, + reinterpret_cast(a_data)); } void* FindFirstFile( const wchar_t* a_name, WIN32_FIND_DATAW* a_data) noexcept { - return static_cast( - ::FindFirstFileW( - static_cast<::LPCWSTR>(a_name), - reinterpret_cast<::LPWIN32_FIND_DATAW>(a_data))); + return FindFirstFileW( + a_name, + reinterpret_cast(a_data)); } bool FindNextFile( @@ -234,9 +228,9 @@ namespace SFSE::WinAPI WIN32_FIND_DATAA* a_data) noexcept { return static_cast( - ::FindNextFileA( - static_cast<::HANDLE>(a_file), - reinterpret_cast<::LPWIN32_FIND_DATAA>(a_data))); + FindNextFileA( + a_file, + reinterpret_cast(a_data))); } bool FindNextFile( @@ -244,9 +238,9 @@ namespace SFSE::WinAPI WIN32_FIND_DATAW* a_data) noexcept { return static_cast( - ::FindNextFileW( - static_cast<::HANDLE>(a_file), - reinterpret_cast<::LPWIN32_FIND_DATAW>(a_data))); + FindNextFileW( + a_file, + reinterpret_cast(a_data))); } bool FlushInstructionCache( @@ -256,9 +250,9 @@ namespace SFSE::WinAPI { return static_cast( ::FlushInstructionCache( - static_cast<::HANDLE>(a_process), - static_cast<::LPCVOID>(a_baseAddr), - static_cast<::SIZE_T>(a_size))); + a_process, + a_baseAddr, + a_size)); } bool FreeLibrary( @@ -271,20 +265,18 @@ namespace SFSE::WinAPI void* GetCurrentModule() noexcept { - return static_cast( - std::addressof(__ImageBase)); + return std::addressof(__ImageBase); } void* GetCurrentProcess() noexcept { - return static_cast( - ::GetCurrentProcess()); + return ::GetCurrentProcess(); } std::uint32_t GetCurrentThreadID() noexcept { return static_cast( - ::GetCurrentThreadId()); + GetCurrentThreadId()); } std::uint32_t GetEnvironmentVariable( @@ -293,10 +285,10 @@ namespace SFSE::WinAPI std::uint32_t a_bufferLen) noexcept { return static_cast( - ::GetEnvironmentVariableA( - static_cast<::LPCSTR>(a_name), - static_cast<::LPSTR>(a_buffer), - static_cast<::DWORD>(a_bufferLen))); + GetEnvironmentVariableA( + a_name, + a_buffer, + a_bufferLen)); } std::uint32_t GetEnvironmentVariable( @@ -305,10 +297,10 @@ namespace SFSE::WinAPI std::uint32_t a_bufferLen) noexcept { return static_cast( - ::GetEnvironmentVariableW( - static_cast<::LPCWSTR>(a_name), - static_cast<::LPWSTR>(a_buffer), - static_cast<::DWORD>(a_bufferLen))); + GetEnvironmentVariableW( + a_name, + a_buffer, + a_bufferLen)); } bool GetFileVersionInfo( @@ -318,11 +310,11 @@ namespace SFSE::WinAPI void* a_data) noexcept { return static_cast( - ::GetFileVersionInfoA( - static_cast<::LPCSTR>(a_name), - static_cast<::DWORD>(a_handle), - static_cast<::DWORD>(a_dataLen), - static_cast<::LPVOID>(a_data))); + GetFileVersionInfoA( + a_name, + a_handle, + a_dataLen, + a_data)); } bool GetFileVersionInfo( @@ -332,11 +324,11 @@ namespace SFSE::WinAPI void* a_data) noexcept { return static_cast( - ::GetFileVersionInfoW( - static_cast<::LPCWSTR>(a_name), - static_cast<::DWORD>(a_handle), - static_cast<::DWORD>(a_dataLen), - static_cast<::LPVOID>(a_data))); + GetFileVersionInfoW( + a_name, + a_handle, + a_dataLen, + a_data)); } std::uint32_t GetFileVersionInfoSize( @@ -344,9 +336,9 @@ namespace SFSE::WinAPI std::uint32_t* a_handle) noexcept { return static_cast( - ::GetFileVersionInfoSizeA( - static_cast<::LPCSTR>(a_name), - reinterpret_cast<::LPDWORD>(a_handle))); + GetFileVersionInfoSizeA( + a_name, + reinterpret_cast(a_handle))); } std::uint32_t GetFileVersionInfoSize( @@ -354,9 +346,9 @@ namespace SFSE::WinAPI std::uint32_t* a_handle) noexcept { return static_cast( - ::GetFileVersionInfoSizeW( - static_cast<::LPCWSTR>(a_name), - reinterpret_cast<::LPDWORD>(a_handle))); + GetFileVersionInfoSizeW( + a_name, + reinterpret_cast(a_handle))); } std::int32_t GetKeyNameText( @@ -364,9 +356,9 @@ namespace SFSE::WinAPI wchar_t* a_buffer, std::int32_t a_bufferLen) noexcept { - return ::GetKeyNameTextW( - static_cast<::LONG>(a_param), - static_cast<::LPWSTR>(a_buffer), + return GetKeyNameTextW( + a_param, + a_buffer, a_bufferLen); } @@ -375,9 +367,9 @@ namespace SFSE::WinAPI char* a_buffer, std::int32_t a_bufferLen) noexcept { - return ::GetKeyNameTextA( - static_cast<::LONG>(a_param), - static_cast<::LPSTR>(a_buffer), + return GetKeyNameTextA( + a_param, + a_buffer, a_bufferLen); } @@ -395,7 +387,7 @@ namespace SFSE::WinAPI std::size_t GetMaxPath() noexcept { - return static_cast(MAX_PATH); + return MAX_PATH; } std::uint32_t GetModuleFileName( @@ -404,10 +396,10 @@ namespace SFSE::WinAPI std::uint32_t a_nameLen) noexcept { return static_cast( - ::GetModuleFileNameA( + GetModuleFileNameA( static_cast<::HMODULE>(a_module), - static_cast<::LPSTR>(a_name), - static_cast<::DWORD>(a_nameLen))); + a_name, + a_nameLen)); } std::uint32_t GetModuleFileName( @@ -416,25 +408,25 @@ namespace SFSE::WinAPI std::uint32_t a_nameLen) noexcept { return static_cast( - ::GetModuleFileNameW( + GetModuleFileNameW( static_cast<::HMODULE>(a_module), - static_cast<::LPWSTR>(a_name), - static_cast<::DWORD>(a_nameLen))); + a_name, + a_nameLen)); } HMODULE GetModuleHandle( const char* a_name) noexcept { return reinterpret_cast( - ::GetModuleHandleA( - static_cast<::LPCSTR>(a_name))); + GetModuleHandleA( + a_name)); } HMODULE GetModuleHandle( const wchar_t* a_name) noexcept { return reinterpret_cast( - ::GetModuleHandleW(static_cast<::LPCWSTR>(a_name))); + GetModuleHandleW(a_name)); } std::uint32_t GetPrivateProfileString( @@ -446,13 +438,13 @@ namespace SFSE::WinAPI const char* a_name) noexcept { return static_cast( - ::GetPrivateProfileStringA( - static_cast<::LPCSTR>(a_app), - static_cast<::LPCSTR>(a_key), - static_cast<::LPCSTR>(a_default), - static_cast<::LPSTR>(a_out), - static_cast<::DWORD>(a_outLen), - static_cast<::LPCSTR>(a_name))); + GetPrivateProfileStringA( + a_app, + a_key, + a_default, + a_out, + a_outLen, + a_name)); } std::uint32_t GetPrivateProfileString( @@ -464,13 +456,13 @@ namespace SFSE::WinAPI const wchar_t* a_name) noexcept { return static_cast( - ::GetPrivateProfileStringW( - static_cast<::LPCWSTR>(a_app), - static_cast<::LPCWSTR>(a_key), - static_cast<::LPCWSTR>(a_default), - static_cast<::LPWSTR>(a_out), - static_cast<::DWORD>(a_outLen), - static_cast<::LPCWSTR>(a_name))); + GetPrivateProfileStringW( + a_app, + a_key, + a_default, + a_out, + a_outLen, + a_name)); } void* GetProcAddress( @@ -480,7 +472,7 @@ namespace SFSE::WinAPI return reinterpret_cast( ::GetProcAddress( static_cast<::HMODULE>(a_module), - static_cast<::LPCSTR>(a_name))); + a_name)); } std::string_view GetProcPath( @@ -500,7 +492,7 @@ namespace SFSE::WinAPI SYSTEM_INFO* a_info) noexcept { ::GetSystemInfo( - reinterpret_cast<::LPSYSTEM_INFO>(a_info)); + reinterpret_cast(a_info)); } bool IMAGE_SNAP_BY_ORDINAL64( @@ -536,30 +528,30 @@ namespace SFSE::WinAPI std::intptr_t a_sortHandle) noexcept { return ::LCMapStringEx( - static_cast<::LPCWSTR>(a_locale), - static_cast<::DWORD>(a_flags), - static_cast<::LPCWSTR>(a_src), + a_locale, + a_flags, + a_src, a_srcLen, - static_cast<::LPWSTR>(a_dest), + a_dest, a_destLen, - reinterpret_cast<::LPNLSVERSIONINFO>(a_info), - static_cast<::LPVOID>(a_reserved), - static_cast<::LPARAM>(a_sortHandle)); + reinterpret_cast(a_info), + a_reserved, + a_sortHandle); } HMODULE LoadLibrary( const char* a_name) noexcept { return reinterpret_cast( - ::LoadLibraryA( - static_cast<::LPCSTR>(a_name))); + LoadLibraryA( + a_name)); } HMODULE LoadLibrary( const wchar_t* a_name) noexcept { return reinterpret_cast( - ::LoadLibraryW(static_cast<::LPCWSTR>(a_name))); + LoadLibraryW(a_name)); } void* MapViewOfFile( @@ -569,13 +561,12 @@ namespace SFSE::WinAPI std::uint32_t a_fileOffsetLow, std::size_t a_numBytesToMap) noexcept { - return static_cast( - ::MapViewOfFile( - static_cast<::LPVOID>(a_object), - static_cast<::DWORD>(a_desiredAccess), - static_cast<::DWORD>(a_fileOffsetHigh), - static_cast<::DWORD>(a_fileOffsetLow), - static_cast<::SIZE_T>(a_numBytesToMap))); + return ::MapViewOfFile( + a_object, + a_desiredAccess, + a_fileOffsetHigh, + a_fileOffsetLow, + a_numBytesToMap); } void* MapViewOfFileEx( @@ -586,14 +577,13 @@ namespace SFSE::WinAPI std::size_t a_numBytesToMap, void* a_baseAddress) noexcept { - return static_cast( - ::MapViewOfFileEx( - static_cast<::LPVOID>(a_object), - static_cast<::DWORD>(a_desiredAccess), - static_cast<::DWORD>(a_fileOffsetHigh), - static_cast<::DWORD>(a_fileOffsetLow), - static_cast<::SIZE_T>(a_numBytesToMap), - static_cast<::LPVOID>(a_baseAddress))); + return ::MapViewOfFileEx( + a_object, + a_desiredAccess, + a_fileOffsetHigh, + a_fileOffsetLow, + a_numBytesToMap, + a_baseAddress); } std::int32_t MessageBox( @@ -602,12 +592,11 @@ namespace SFSE::WinAPI const char* a_caption, std::uint32_t a_type) noexcept { - return static_cast( - ::MessageBoxA( - static_cast<::HWND>(a_wnd), - static_cast<::LPCSTR>(a_text), - static_cast<::LPCSTR>(a_caption), - static_cast<::UINT>(a_type))); + return MessageBoxA( + static_cast<::HWND>(a_wnd), + a_text, + a_caption, + a_type); } std::int32_t MessageBox( @@ -616,12 +605,11 @@ namespace SFSE::WinAPI const wchar_t* a_caption, std::uint32_t a_type) noexcept { - return static_cast( - ::MessageBoxW( - static_cast<::HWND>(a_wnd), - static_cast<::LPCWSTR>(a_text), - static_cast<::LPCWSTR>(a_caption), - static_cast<::UINT>(a_type))); + return MessageBoxW( + static_cast<::HWND>(a_wnd), + a_text, + a_caption, + a_type); } std::int32_t MultiByteToWideChar( @@ -633,11 +621,11 @@ namespace SFSE::WinAPI std::int32_t a_wstrLen) { return ::MultiByteToWideChar( - static_cast<::UINT>(a_codePage), - static_cast<::DWORD>(a_flags), - static_cast<::LPCCH>(a_str), + a_codePage, + a_flags, + a_str, a_strLen, - static_cast<::LPWSTR>(a_wstr), + a_wstr, a_wstrLen); } @@ -649,10 +637,10 @@ namespace SFSE::WinAPI std::int32_t a_destLen) { return ::NormalizeString( - static_cast<::NORM_FORM>(a_normForm), - static_cast<::LPCWSTR>(a_src), + static_cast(a_normForm), + a_src, a_srcLen, - static_cast<::LPWSTR>(a_dest), + a_dest, a_destLen); } @@ -661,11 +649,10 @@ namespace SFSE::WinAPI bool a_inheritHandle, const char* a_name) noexcept { - return static_cast( - ::OpenFileMappingA( - static_cast<::DWORD>(a_desiredAccess), - static_cast<::BOOL>(a_inheritHandle), - static_cast<::LPCSTR>(a_name))); + return OpenFileMappingA( + a_desiredAccess, + a_inheritHandle, + a_name); } void* OpenFileMapping( @@ -673,25 +660,24 @@ namespace SFSE::WinAPI bool a_inheritHandle, const wchar_t* a_name) noexcept { - return static_cast( - ::OpenFileMappingW( - static_cast<::DWORD>(a_desiredAccess), - static_cast<::BOOL>(a_inheritHandle), - static_cast<::LPCWSTR>(a_name))); + return OpenFileMappingW( + a_desiredAccess, + a_inheritHandle, + a_name); } void OutputDebugString( const char* a_out) noexcept { - ::OutputDebugStringA( - static_cast<::LPCSTR>(a_out)); + OutputDebugStringA( + a_out); } void OutputDebugString( const wchar_t* a_out) noexcept { - ::OutputDebugStringW( - static_cast<::LPCWSTR>(a_out)); + OutputDebugStringW( + a_out); } std::int32_t RegGetValue( @@ -703,14 +689,14 @@ namespace SFSE::WinAPI void* a_data, std::uint32_t* a_dataLen) { - return ::RegGetValueA( + return RegGetValueA( reinterpret_cast<::HKEY>(a_key), a_subKey, a_value, a_flags, - reinterpret_cast<::LPDWORD>(a_type), + reinterpret_cast(a_type), a_data, - reinterpret_cast<::LPDWORD>(a_dataLen)); + reinterpret_cast(a_dataLen)); } std::int32_t RegGetValue( @@ -722,14 +708,14 @@ namespace SFSE::WinAPI void* a_data, std::uint32_t* a_dataLen) { - return ::RegGetValueW( + return RegGetValueW( reinterpret_cast<::HKEY>(a_key), a_subKey, a_value, a_flags, - reinterpret_cast<::LPDWORD>(a_type), + reinterpret_cast(a_type), a_data, - reinterpret_cast<::LPDWORD>(a_dataLen)); + reinterpret_cast(a_dataLen)); } std::uint32_t ResumeThread( @@ -737,7 +723,7 @@ namespace SFSE::WinAPI { return static_cast( ::ResumeThread( - static_cast<::HANDLE>(a_handle))); + a_handle)); } bool SetEnvironmentVariable( @@ -745,9 +731,9 @@ namespace SFSE::WinAPI const char* a_value) noexcept { return static_cast( - ::SetEnvironmentVariableA( - static_cast<::LPCSTR>(a_name), - static_cast<::LPCSTR>(a_value))); + SetEnvironmentVariableA( + a_name, + a_value)); } bool SetEnvironmentVariable( @@ -755,9 +741,9 @@ namespace SFSE::WinAPI const wchar_t* a_value) noexcept { return static_cast( - ::SetEnvironmentVariableW( - static_cast<::LPCWSTR>(a_name), - static_cast<::LPCWSTR>(a_value))); + SetEnvironmentVariableW( + a_name, + a_value)); } std::int32_t SHGetKnownFolderPath( @@ -768,23 +754,23 @@ namespace SFSE::WinAPI { return static_cast( ::SHGetKnownFolderPath( - reinterpret_cast(a_id), - static_cast<::DWORD>(a_flags), - static_cast<::HANDLE>(a_token), - static_cast<::PWSTR*>(a_path))); + reinterpret_cast(a_id), + a_flags, + a_token, + a_path)); } std::int32_t ShowCursor( bool a_show) noexcept { return ::ShowCursor( - static_cast<::BOOL>(a_show)); + a_show); } void Sleep( std::uint32_t a_milliseconds) noexcept { - ::Sleep(static_cast(a_milliseconds)); + ::Sleep(a_milliseconds); } bool TerminateProcess( @@ -793,16 +779,15 @@ namespace SFSE::WinAPI { return static_cast( ::TerminateProcess( - static_cast<::HANDLE>(a_process), - static_cast<::UINT>(a_exitCode))); + a_process, + a_exitCode)); } void* TlsGetValue( std::uint32_t a_index) noexcept { - return static_cast( - ::TlsGetValue( - static_cast<::DWORD>(a_index))); + return ::TlsGetValue( + a_index); } bool TlsSetValue( @@ -811,8 +796,8 @@ namespace SFSE::WinAPI { return static_cast( ::TlsSetValue( - static_cast<::DWORD>(a_index), - static_cast<::LPVOID>(a_value))); + a_index, + a_value)); } std::uint32_t UnDecorateSymbolName( @@ -823,10 +808,10 @@ namespace SFSE::WinAPI { return static_cast( ::UnDecorateSymbolName( - static_cast<::PCSTR>(a_name), - static_cast<::PSTR>(a_out), - static_cast<::DWORD>(a_outLenMax), - static_cast<::DWORD>(a_flags))); + a_name, + a_out, + a_outLenMax, + a_flags)); } std::uint32_t UnDecorateSymbolName( @@ -836,11 +821,11 @@ namespace SFSE::WinAPI std::uint32_t a_flags) noexcept { return static_cast( - ::UnDecorateSymbolNameW( - static_cast<::PCWSTR>(a_name), - static_cast<::PWSTR>(a_out), - static_cast<::DWORD>(a_outLenMax), - static_cast<::DWORD>(a_flags))); + UnDecorateSymbolNameW( + a_name, + a_out, + a_outLenMax, + a_flags)); } bool UnmapViewOfFile( @@ -848,7 +833,7 @@ namespace SFSE::WinAPI { return static_cast( ::UnmapViewOfFile( - static_cast<::LPCVOID>(a_baseAddress))); + a_baseAddress)); } bool VerQueryValue( @@ -858,10 +843,10 @@ namespace SFSE::WinAPI std::uint32_t* a_bufferLen) noexcept { return static_cast( - ::VerQueryValueA(static_cast<::LPCVOID>(a_block), - static_cast<::LPCSTR>(a_subBlock), - static_cast<::LPVOID*>(a_buffer), - static_cast<::PUINT>(a_bufferLen))); + VerQueryValueA(a_block, + a_subBlock, + a_buffer, + a_bufferLen)); } bool VerQueryValue( @@ -871,11 +856,11 @@ namespace SFSE::WinAPI std::uint32_t* a_bufferLen) noexcept { return static_cast( - ::VerQueryValueW( - static_cast<::LPCVOID>(a_block), - static_cast<::LPCWSTR>(a_subBlock), - static_cast<::LPVOID*>(a_buffer), - static_cast<::PUINT>(a_bufferLen))); + VerQueryValueW( + a_block, + a_subBlock, + a_buffer, + a_bufferLen)); } void* VirtualAlloc( @@ -884,12 +869,11 @@ namespace SFSE::WinAPI std::uint32_t a_type, std::uint32_t a_protect) noexcept { - return static_cast( - ::VirtualAlloc( - static_cast<::LPVOID>(a_address), - static_cast<::SIZE_T>(a_size), - static_cast<::DWORD>(a_type), - static_cast<::DWORD>(a_protect))); + return ::VirtualAlloc( + a_address, + a_size, + a_type, + a_protect); } void* VirtualAllocEx( @@ -899,13 +883,12 @@ namespace SFSE::WinAPI std::uint32_t a_type, std::uint32_t a_protect) noexcept { - return static_cast( - ::VirtualAllocEx( - static_cast<::HANDLE>(a_process), - static_cast<::LPVOID>(a_address), - static_cast<::SIZE_T>(a_size), - static_cast<::DWORD>(a_type), - static_cast<::DWORD>(a_protect))); + return ::VirtualAllocEx( + a_process, + a_address, + a_size, + a_type, + a_protect); } bool VirtualFree( @@ -915,9 +898,9 @@ namespace SFSE::WinAPI { return static_cast( ::VirtualFree( - static_cast<::LPVOID>(a_address), - static_cast<::SIZE_T>(a_size), - static_cast<::DWORD>(a_type))); + a_address, + a_size, + a_type)); } bool VirtualFreeEx( @@ -928,10 +911,10 @@ namespace SFSE::WinAPI { return static_cast( ::VirtualFreeEx( - static_cast<::HANDLE>(a_process), - static_cast<::LPVOID>(a_address), - static_cast<::SIZE_T>(a_size), - static_cast<::DWORD>(a_type))); + a_process, + a_address, + a_size, + a_type)); } bool VirtualProtect( @@ -942,10 +925,10 @@ namespace SFSE::WinAPI { return static_cast( ::VirtualProtect( - static_cast<::LPVOID>(a_address), - static_cast<::SIZE_T>(a_size), - static_cast<::DWORD>(a_newProtect), - reinterpret_cast<::PDWORD>(a_oldProtect))); + a_address, + a_size, + a_newProtect, + reinterpret_cast(a_oldProtect))); } bool VirtualProtectEx( @@ -957,11 +940,11 @@ namespace SFSE::WinAPI { return static_cast( ::VirtualProtectEx( - static_cast<::HANDLE>(a_process), - static_cast<::LPVOID>(a_address), - static_cast<::SIZE_T>(a_size), - static_cast<::DWORD>(a_newProtect), - reinterpret_cast<::PDWORD>(a_oldProtect))); + a_process, + a_address, + a_size, + a_newProtect, + reinterpret_cast(a_oldProtect))); } std::size_t VirtualQuery( @@ -969,11 +952,10 @@ namespace SFSE::WinAPI MEMORY_BASIC_INFORMATION* a_buffer, std::size_t a_bufferLen) noexcept { - return static_cast( - ::VirtualQuery( - static_cast<::LPCVOID>(a_address), - reinterpret_cast<::PMEMORY_BASIC_INFORMATION>(a_buffer), - static_cast<::SIZE_T>(a_bufferLen))); + return ::VirtualQuery( + a_address, + reinterpret_cast(a_buffer), + a_bufferLen); } std::size_t VirtualQueryEx( @@ -982,12 +964,11 @@ namespace SFSE::WinAPI MEMORY_BASIC_INFORMATION* a_buffer, std::size_t a_bufferLen) noexcept { - return static_cast( - ::VirtualQueryEx( - static_cast<::HANDLE>(a_process), - static_cast<::LPCVOID>(a_address), - reinterpret_cast<::PMEMORY_BASIC_INFORMATION>(a_buffer), - static_cast<::SIZE_T>(a_bufferLen))); + return ::VirtualQueryEx( + a_process, + a_address, + reinterpret_cast(a_buffer), + a_bufferLen); } std::uint32_t WaitForSingleObject( @@ -996,8 +977,8 @@ namespace SFSE::WinAPI { return static_cast( ::WaitForSingleObject( - static_cast<::HANDLE>(a_handle), - static_cast<::DWORD>(a_milliseconds))); + a_handle, + a_milliseconds)); } std::uint32_t WaitForSingleObjectEx( @@ -1007,9 +988,9 @@ namespace SFSE::WinAPI { return static_cast( ::WaitForSingleObjectEx( - static_cast<::HANDLE>(a_handle), - static_cast<::DWORD>(a_milliseconds), - static_cast<::BOOL>(a_alertable))); + a_handle, + a_milliseconds, + a_alertable)); } std::int32_t WideCharToMultiByte( @@ -1023,14 +1004,14 @@ namespace SFSE::WinAPI std::int32_t* a_defaultLen) { return ::WideCharToMultiByte( - static_cast<::UINT>(a_codePage), - static_cast<::DWORD>(a_flags), - static_cast<::LPCWCH>(a_wstr), + a_codePage, + a_flags, + a_wstr, a_wstrLen, - static_cast<::LPSTR>(a_str), + a_str, a_strLen, - static_cast<::LPCCH>(a_default), - static_cast<::LPBOOL>(a_defaultLen)); + a_default, + a_defaultLen); } bool WriteProcessMemory( @@ -1042,10 +1023,10 @@ namespace SFSE::WinAPI { return static_cast( ::WriteProcessMemory( - static_cast<::HANDLE>(a_process), - static_cast<::LPVOID>(a_address), - static_cast<::LPCVOID>(a_buffer), - static_cast<::SIZE_T>(a_bufferLen), - static_cast<::SIZE_T*>(a_bufferWritten))); + a_process, + a_address, + a_buffer, + a_bufferLen, + a_bufferWritten)); } } diff --git a/CommonLibSF/src/SFSE/InputMap.cpp b/CommonLibSF/src/SFSE/InputMap.cpp index a128589c..08234f13 100644 --- a/CommonLibSF/src/SFSE/InputMap.cpp +++ b/CommonLibSF/src/SFSE/InputMap.cpp @@ -91,11 +91,11 @@ namespace SFSE { if (a_keyCode >= kMacro_MouseButtonOffset && a_keyCode < kMacro_GamepadOffset) { return GetMouseButtonName(a_keyCode); - } else if (a_keyCode >= kMacro_GamepadOffset && a_keyCode < kMaxMacros) { + } + if (a_keyCode >= kMacro_GamepadOffset && a_keyCode < kMaxMacros) { return GetGamepadButtonName(a_keyCode); - } else { - return GetKeyboardKeyName(a_keyCode); } + return GetKeyboardKeyName(a_keyCode); } std::string InputMap::GetKeyboardKeyName(const std::uint32_t a_keyCode) diff --git a/CommonLibSF/src/SFSE/Logger.cpp b/CommonLibSF/src/SFSE/Logger.cpp index 05e85522..3a1b089f 100644 --- a/CommonLibSF/src/SFSE/Logger.cpp +++ b/CommonLibSF/src/SFSE/Logger.cpp @@ -10,7 +10,7 @@ namespace SFSE { std::optional log_directory() { - wchar_t* buffer{ nullptr }; + 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); if (!knownPath || result != 0) { diff --git a/CommonLibSF/src/SFSE/Trampoline.cpp b/CommonLibSF/src/SFSE/Trampoline.cpp index abdc0cfe..bc2786b1 100644 --- a/CommonLibSF/src/SFSE/Trampoline.cpp +++ b/CommonLibSF/src/SFSE/Trampoline.cpp @@ -37,7 +37,6 @@ namespace SFSE 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; - std::uintptr_t addr; WinAPI::MEMORY_BASIC_INFORMATION mbi; do { @@ -50,16 +49,15 @@ namespace SFSE min = baseAddr + mbi.regionSize; if (mbi.state == WinAPI::MEM_FREE) { - addr = detail::roundup(baseAddr, granularity); + 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); if (mem) { return mem; - } else { - log::warn("VirtualAlloc failed with code: 0x{:08X}"sv, WinAPI::GetLastError()); } + log::warn("VirtualAlloc failed with code: 0x{:08X}"sv, WinAPI::GetLastError()); } } } while (min < max);