diff --git a/CommonLibSF/include/REL/ID.h b/CommonLibSF/include/REL/ID.h index f4adda61..242f6e86 100644 --- a/CommonLibSF/include/REL/ID.h +++ b/CommonLibSF/include/REL/ID.h @@ -48,7 +48,7 @@ namespace REL return *this; } - [[nodiscard]] void* data() noexcept { return _view; } + [[nodiscard]] void* data() const noexcept { return _view; } bool open(stl::zwstring a_name, std::size_t a_size); @@ -111,7 +111,7 @@ namespace REL using reference = stream_type&; using const_reference = const stream_type&; - istream_t(stl::zwstring a_filename, std::ios_base::openmode a_mode) : + istream_t(const stl::zwstring a_filename, const std::ios_base::openmode a_mode) : _stream(a_filename.data(), a_mode) { stl_assert(_stream.is_open(), @@ -120,7 +120,7 @@ namespace REL _stream.exceptions(std::ios::badbit | std::ios::failbit | std::ios::eofbit); } - void ignore(std::streamsize a_count) + void ignore(const std::streamsize a_count) { _stream.ignore(a_count); } @@ -244,11 +244,11 @@ namespace REL public: constexpr ID() noexcept = default; - explicit constexpr ID(std::uint64_t a_id) noexcept : + explicit constexpr ID(const std::uint64_t a_id) noexcept : _id(a_id) {} - constexpr ID& operator=(std::uint64_t a_id) noexcept + constexpr ID& operator=(const std::uint64_t a_id) noexcept { _id = a_id; return *this; diff --git a/CommonLibSF/include/REL/Module.h b/CommonLibSF/include/REL/Module.h index c7a16ab9..c9f1a8d4 100644 --- a/CommonLibSF/include/REL/Module.h +++ b/CommonLibSF/include/REL/Module.h @@ -22,7 +22,7 @@ namespace REL Segment() noexcept = default; - Segment(std::uintptr_t a_proxyBase, std::uintptr_t a_address, std::uintptr_t a_size) noexcept : + Segment(const std::uintptr_t a_proxyBase, const std::uintptr_t a_address, const std::uintptr_t a_size) noexcept : _proxyBase(a_proxyBase), _address(a_address), _size(a_size) {} @@ -64,11 +64,11 @@ namespace REL return std::bit_cast(base()); } - [[nodiscard]] constexpr auto segment(Segment::Name a_segment) noexcept { return _segments[a_segment]; } + [[nodiscard]] constexpr auto segment(const Segment::Name a_segment) const noexcept { return _segments[a_segment]; } - [[nodiscard]] constexpr auto version() noexcept { return _version; } + [[nodiscard]] constexpr auto version() const noexcept { return _version; } - [[nodiscard]] static Module& get(const std::uintptr_t a_address) noexcept; + [[nodiscard]] static Module& get(std::uintptr_t a_address) noexcept; [[nodiscard]] static Module& get(std::string_view a_filePath = {}) noexcept; diff --git a/CommonLibSF/include/REL/Pattern.h b/CommonLibSF/include/REL/Pattern.h index 60239886..f82681b8 100644 --- a/CommonLibSF/include/REL/Pattern.h +++ b/CommonLibSF/include/REL/Pattern.h @@ -8,18 +8,18 @@ namespace REL { namespace characters { - [[nodiscard]] constexpr bool hexadecimal(char a_ch) noexcept + [[nodiscard]] constexpr bool hexadecimal(const char a_ch) noexcept { return ('0' <= a_ch && a_ch <= '9') || ('A' <= a_ch && a_ch <= 'F') || ('a' <= a_ch && a_ch <= 'f'); } - [[nodiscard]] constexpr bool space(char a_ch) noexcept + [[nodiscard]] constexpr bool space(const char a_ch) noexcept { return a_ch == ' '; } - [[nodiscard]] constexpr bool wildcard(char a_ch) noexcept + [[nodiscard]] constexpr bool wildcard(const char a_ch) noexcept { return a_ch == '?'; } @@ -30,8 +30,8 @@ namespace REL namespace detail { [[nodiscard]] consteval std::byte hexacharacters_to_hexadecimal( - char a_hi, - char a_lo) noexcept + const char a_hi, + const char a_lo) noexcept { constexpr auto lut = []() noexcept { std::array< @@ -42,7 +42,7 @@ namespace REL const auto iterate = [&](std::uint8_t a_iFirst, unsigned char a_cFirst, - unsigned char a_cLast) noexcept { + const unsigned char a_cLast) noexcept { for (; a_cFirst <= a_cLast; ++a_cFirst, ++a_iFirst) { a[a_cFirst] = a_iFirst; } @@ -65,7 +65,7 @@ namespace REL class Hexadecimal { public: - [[nodiscard]] static constexpr bool match(std::byte a_byte) noexcept + [[nodiscard]] static constexpr bool match(const std::byte a_byte) noexcept { constexpr auto expected = detail::hexacharacters_to_hexadecimal( HI, @@ -134,8 +134,8 @@ namespace REL } void match_or_fail( - std::uintptr_t a_address, - std::source_location a_loc = std::source_location::current()) + const std::uintptr_t a_address, + const std::source_location& a_loc = std::source_location::current()) const noexcept { if (!this->match(a_address)) { diff --git a/CommonLibSF/include/REL/Relocation.h b/CommonLibSF/include/REL/Relocation.h index e14ca8cf..adcfc44a 100644 --- a/CommonLibSF/include/REL/Relocation.h +++ b/CommonLibSF/include/REL/Relocation.h @@ -151,7 +151,7 @@ namespace REL } } - inline void safe_write(std::uintptr_t a_dst, const void* a_src, std::size_t a_count) + 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 }; auto success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, WinAPI::PAGE_EXECUTE_READWRITE, std::addressof(old)); @@ -164,18 +164,18 @@ namespace REL } template - void safe_write(std::uintptr_t a_dst, const T& a_data) + void safe_write(const std::uintptr_t a_dst, const T& a_data) { safe_write(a_dst, std::addressof(a_data), sizeof(T)); } template - void safe_write(std::uintptr_t a_dst, std::span a_data) + void safe_write(const std::uintptr_t a_dst, std::span a_data) { safe_write(a_dst, a_data.data(), a_data.size_bytes()); } - inline void safe_fill(std::uintptr_t a_dst, std::uint8_t a_value, std::size_t a_count) + 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 }; auto success = WinAPI::VirtualProtect(reinterpret_cast(a_dst), a_count, WinAPI::PAGE_EXECUTE_READWRITE, std::addressof(old)); @@ -251,7 +251,7 @@ namespace REL return invoke(get(), std::forward(a_args)...); } - std::uintptr_t write_vfunc(std::size_t a_idx, std::uintptr_t a_newFunc) + std::uintptr_t write_vfunc(const std::size_t a_idx, const std::uintptr_t a_newFunc) requires(std::same_as) { const auto addr = address() + (sizeof(void*) * a_idx); @@ -261,7 +261,7 @@ namespace REL } template - std::uintptr_t write_vfunc(std::size_t a_idx, F a_newFunc) + std::uintptr_t write_vfunc(const std::size_t a_idx, F a_newFunc) requires(std::same_as) { return write_vfunc(a_idx, stl::unrestricted_cast(a_newFunc)); diff --git a/CommonLibSF/include/REL/Version.h b/CommonLibSF/include/REL/Version.h index 9c4c0386..275d4ec2 100644 --- a/CommonLibSF/include/REL/Version.h +++ b/CommonLibSF/include/REL/Version.h @@ -11,17 +11,17 @@ namespace REL constexpr Version() noexcept = default; - explicit constexpr Version(std::array a_version) noexcept : + explicit constexpr Version(const std::array a_version) noexcept : _impl(a_version) {} - constexpr Version(value_type a_v1, value_type a_v2 = 0, value_type a_v3 = 0, value_type a_v4 = 0) noexcept : + constexpr Version(const value_type a_v1, const value_type a_v2 = 0, const value_type a_v3 = 0, const value_type a_v4 = 0) noexcept : _impl{ a_v1, a_v2, a_v3, a_v4 } {} explicit constexpr Version(std::string_view a_version); - [[nodiscard]] constexpr reference operator[](std::size_t a_idx) noexcept { return _impl[a_idx]; } + [[nodiscard]] constexpr reference operator[](const std::size_t a_idx) noexcept { return _impl[a_idx]; } - [[nodiscard]] constexpr const_reference operator[](std::size_t a_idx) const noexcept { return _impl[a_idx]; } + [[nodiscard]] constexpr const_reference operator[](const std::size_t a_idx) const noexcept { return _impl[a_idx]; } [[nodiscard]] constexpr decltype(auto) begin() const noexcept { return _impl.begin(); } @@ -55,7 +55,7 @@ namespace REL [[nodiscard]] constexpr value_type patch() const noexcept { return _impl[2]; } [[nodiscard]] constexpr value_type build() const noexcept { return _impl[3]; } - [[nodiscard]] std::string string(std::string_view a_separator = "."sv) const + [[nodiscard]] std::string string(const std::string_view a_separator = "."sv) const { std::string result; for (auto&& ver : _impl) { @@ -66,7 +66,7 @@ namespace REL return result; } - [[nodiscard]] std::wstring wstring(std::wstring_view a_separator = L"."sv) const + [[nodiscard]] std::wstring wstring(const std::wstring_view a_separator = L"."sv) const { std::wstring result; for (auto&& ver : _impl) { @@ -77,7 +77,7 @@ namespace REL return result; } - [[nodiscard]] static constexpr Version unpack(std::uint32_t a_packedVersion) noexcept + [[nodiscard]] static constexpr Version unpack(const std::uint32_t a_packedVersion) noexcept { return REL::Version{ static_cast((a_packedVersion >> 24) & 0x0FF), @@ -139,7 +139,7 @@ namespace REL return REL::Version(result); } - [[nodiscard]] constexpr REL::Version operator""_v(const char* str, std::size_t len) + [[nodiscard]] constexpr REL::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 a3595921..9cbf2348 100644 --- a/CommonLibSF/include/SFSE/API.h +++ b/CommonLibSF/include/SFSE/API.h @@ -10,7 +10,7 @@ namespace SFSE { void Init(const LoadInterface* a_intfc, bool a_log = true) noexcept; - void RegisterForAPIInitEvent(std::function a_fn); + void RegisterForAPIInitEvent(const std::function& a_fn); PluginHandle GetPluginHandle() noexcept; diff --git a/CommonLibSF/include/SFSE/IAT.h b/CommonLibSF/include/SFSE/IAT.h index 06e02545..7e4ee775 100644 --- a/CommonLibSF/include/SFSE/IAT.h +++ b/CommonLibSF/include/SFSE/IAT.h @@ -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, std::string_view a_dll, std::string_view a_function) + inline 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 24456436..38e20fae 100644 --- a/CommonLibSF/include/SFSE/Impl/PCH.h +++ b/CommonLibSF/include/SFSE/Impl/PCH.h @@ -554,7 +554,7 @@ namespace SFSE inline constexpr auto ssizeof_v = ssizeof::value; template - [[nodiscard]] auto adjust_pointer(U* a_ptr, std::ptrdiff_t a_adjust) noexcept + [[nodiscard]] auto adjust_pointer(U* a_ptr, const std::ptrdiff_t a_adjust) noexcept { auto addr = a_ptr ? reinterpret_cast(a_ptr) + a_adjust : 0; if constexpr (std::is_const_v && std::is_volatile_v) { @@ -580,7 +580,7 @@ namespace SFSE } template - void memzero(volatile T* a_ptr, std::size_t a_size = sizeof(T)) + 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 }; @@ -606,9 +606,9 @@ namespace SFSE } } - [[nodiscard]] inline auto utf8_to_utf16(std::string_view a_in) noexcept -> std::optional + [[nodiscard]] inline auto utf8_to_utf16(const std::string_view a_in) noexcept -> std::optional { - const auto cvt = [&](wchar_t* a_dst, std::size_t a_length) { + 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)); }; @@ -626,9 +626,9 @@ namespace SFSE return out; } - [[nodiscard]] inline auto utf16_to_utf8(std::wstring_view a_in) noexcept -> std::optional + [[nodiscard]] inline auto utf16_to_utf8(const std::wstring_view a_in) noexcept -> std::optional { - const auto cvt = [&](char* a_dst, std::size_t a_length) { + 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); }; @@ -646,7 +646,7 @@ namespace SFSE return out; } - inline bool report_and_error(std::string_view a_msg, bool a_fail = true, std::source_location a_loc = std::source_location::current()) + inline bool report_and_error(std::string_view a_msg, const bool a_fail = true, const std::source_location& a_loc = std::source_location::current()) { const auto body = [&]() -> std::wstring { const std::filesystem::path p = a_loc.file_name(); @@ -689,7 +689,7 @@ namespace SFSE return true; } - [[noreturn]] inline void report_and_fail(std::string_view a_msg, std::source_location a_loc = std::source_location::current()) + [[noreturn]] inline void report_and_fail(const std::string_view a_msg, const std::source_location& a_loc = std::source_location::current()) { report_and_error(a_msg, true, a_loc); std::unreachable(); diff --git a/CommonLibSF/include/SFSE/Interfaces.h b/CommonLibSF/include/SFSE/Interfaces.h index 2f2463bc..a60b6a6f 100644 --- a/CommonLibSF/include/SFSE/Interfaces.h +++ b/CommonLibSF/include/SFSE/Interfaces.h @@ -129,25 +129,25 @@ namespace SFSE kVersion = 1 }; - constexpr void PluginVersion(REL::Version a_version) noexcept { pluginVersion = a_version.pack(); } + constexpr void PluginVersion(const REL::Version a_version) noexcept { pluginVersion = a_version.pack(); } [[nodiscard]] constexpr REL::Version GetPluginVersion() const noexcept { return REL::Version::unpack(pluginVersion); } - constexpr void PluginName(std::string_view a_plugin) noexcept { SetCharBuffer(a_plugin, std::span{ pluginName }); } + constexpr void PluginName(const std::string_view a_plugin) noexcept { SetCharBuffer(a_plugin, std::span{ pluginName }); } [[nodiscard]] constexpr std::string_view GetPluginName() const noexcept { return std::string_view{ pluginName }; } - constexpr void AuthorName(std::string_view a_name) noexcept { SetCharBuffer(a_name, std::span{ author }); } + constexpr void AuthorName(const std::string_view a_name) noexcept { SetCharBuffer(a_name, std::span{ author }); } [[nodiscard]] constexpr std::string_view GetAuthorName() const noexcept { return std::string_view{ author }; } - constexpr void UsesSigScanning(bool a_value) noexcept { SetOrClearBit(addressIndependence, 1 << 0, a_value); } + constexpr void UsesSigScanning(const bool a_value) noexcept { SetOrClearBit(addressIndependence, 1 << 0, a_value); } - constexpr void UsesAddressLibrary(bool a_value) noexcept { SetOrClearBit(addressIndependence, 1 << 1, a_value); } + constexpr void UsesAddressLibrary(const bool a_value) noexcept { SetOrClearBit(addressIndependence, 1 << 1, a_value); } - constexpr void HasNoStructUse(bool a_value) noexcept { SetOrClearBit(structureCompatibility, 1 << 0, a_value); } + constexpr void HasNoStructUse(const bool a_value) noexcept { SetOrClearBit(structureCompatibility, 1 << 0, a_value); } - constexpr void IsLayoutDependent(bool a_value) noexcept { SetOrClearBit(structureCompatibility, 1 << 1, a_value); } + constexpr void IsLayoutDependent(const bool a_value) noexcept { SetOrClearBit(structureCompatibility, 1 << 1, a_value); } constexpr void CompatibleVersions(std::initializer_list a_versions) noexcept { @@ -158,7 +158,7 @@ namespace SFSE }); } - constexpr void MinimumRequiredXSEVersion(REL::Version a_version) noexcept { xseMinimum = a_version.pack(); } + constexpr void MinimumRequiredXSEVersion(const REL::Version a_version) noexcept { xseMinimum = a_version.pack(); } [[nodiscard]] static const PluginVersionData* GetSingleton() noexcept; @@ -181,7 +181,7 @@ namespace SFSE std::ranges::copy(a_src, a_dst.begin()); } - static constexpr void SetOrClearBit(std::uint32_t& a_data, std::uint32_t a_bit, bool a_set) noexcept + static constexpr void SetOrClearBit(std::uint32_t& a_data, const std::uint32_t a_bit, const bool a_set) noexcept { if (a_set) a_data |= a_bit; diff --git a/CommonLibSF/include/SFSE/Trampoline.h b/CommonLibSF/include/SFSE/Trampoline.h index db3617c2..14a4dba3 100644 --- a/CommonLibSF/include/SFSE/Trampoline.h +++ b/CommonLibSF/include/SFSE/Trampoline.h @@ -11,7 +11,7 @@ namespace SFSE { namespace detail { - [[nodiscard]] constexpr std::size_t roundup(std::size_t a_number, std::size_t a_multiple) noexcept + [[nodiscard]] constexpr std::size_t roundup(const std::size_t a_number, const std::size_t a_multiple) noexcept { if (a_multiple == 0) { return 0; @@ -21,7 +21,7 @@ namespace SFSE return remainder == 0 ? a_number : a_number + a_multiple - remainder; } - [[nodiscard]] constexpr std::size_t rounddown(std::size_t a_number, std::size_t a_multiple) noexcept + [[nodiscard]] constexpr std::size_t rounddown(const std::size_t a_number, const std::size_t a_multiple) noexcept { if (a_multiple == 0) { return 0; @@ -42,7 +42,7 @@ namespace SFSE Trampoline(Trampoline&& a_rhs) { move_from(std::move(a_rhs)); } - explicit Trampoline(std::string_view a_name) : + explicit Trampoline(const std::string_view a_name) : _name(a_name) {} ~Trampoline() { release(); } @@ -57,9 +57,9 @@ namespace SFSE return *this; } - void create(std::size_t a_size) { return create(a_size, nullptr); } + void create(const std::size_t a_size) { return create(a_size, nullptr); } - void create(std::size_t a_size, void* a_module) + void create(const std::size_t a_size, void* a_module) { if (a_size == 0) { stl::report_and_fail("cannot create a trampoline with a zero size"sv); @@ -70,7 +70,7 @@ namespace SFSE a_module = text.pointer() + text.size(); } - auto mem = do_create(a_size, reinterpret_cast(a_module)); + const auto mem = do_create(a_size, reinterpret_cast(a_module)); if (!mem) { stl::report_and_fail("failed to create trampoline"sv); } @@ -78,11 +78,11 @@ namespace SFSE set_trampoline(mem, a_size, [](void* a_mem, std::size_t) { WinAPI::VirtualFree(a_mem, 0, WinAPI::MEM_RELEASE); }); } - void set_trampoline(void* a_trampoline, std::size_t a_size) { set_trampoline(a_trampoline, a_size, {}); } + void set_trampoline(void* a_trampoline, const std::size_t a_size) { set_trampoline(a_trampoline, a_size, {}); } - void set_trampoline(void* a_trampoline, std::size_t a_size, deleter_type a_deleter) + void set_trampoline(void* a_trampoline, const std::size_t a_size, deleter_type a_deleter) { - auto trampoline = static_cast(a_trampoline); + const auto trampoline = static_cast(a_trampoline); if (trampoline) { constexpr auto INT3 = static_cast(0xCC); std::memset(trampoline, INT3, a_size); @@ -98,9 +98,9 @@ namespace SFSE log_stats(); } - [[nodiscard]] void* allocate(std::size_t a_size) + [[nodiscard]] void* allocate(const std::size_t a_size) { - auto result = do_allocate(a_size); + const auto result = do_allocate(a_size); log_stats(); return result; } @@ -124,7 +124,7 @@ namespace SFSE [[nodiscard]] constexpr std::size_t free_size() const noexcept { return _capacity - _size; } template - std::uintptr_t write_branch(std::uintptr_t a_src, std::uintptr_t a_dst) + std::uintptr_t write_branch(const std::uintptr_t a_src, const std::uintptr_t a_dst) { std::uint8_t data = 0; if constexpr (N == 5) { @@ -143,13 +143,13 @@ namespace SFSE } template - std::uintptr_t write_branch(std::uintptr_t a_src, F a_dst) + std::uintptr_t write_branch(const std::uintptr_t a_src, F a_dst) { return write_branch(a_src, stl::unrestricted_cast(a_dst)); } template - std::uintptr_t write_call(std::uintptr_t a_src, std::uintptr_t a_dst) + std::uintptr_t write_call(const std::uintptr_t a_src, const std::uintptr_t a_dst) { std::uint8_t data = 0; if constexpr (N == 5) { @@ -168,7 +168,7 @@ namespace SFSE } template - std::uintptr_t write_call(std::uintptr_t a_src, F a_dst) + std::uintptr_t write_call(const std::uintptr_t a_src, F a_dst) { return write_call(a_src, stl::unrestricted_cast(a_dst)); } @@ -176,19 +176,19 @@ namespace SFSE private: [[nodiscard]] void* do_create(std::size_t a_size, std::uintptr_t a_address); - [[nodiscard]] void* do_allocate(std::size_t a_size) + [[nodiscard]] void* do_allocate(const std::size_t a_size) { if (a_size > free_size()) { stl::report_and_fail("Failed to handle allocation request"sv); } - auto mem = _data + _size; + const auto mem = _data + _size; _size += a_size; return mem; } - void write_5branch(std::uintptr_t a_src, std::uintptr_t a_dst, std::uint8_t a_opcode) + void write_5branch(const std::uintptr_t a_src, std::uintptr_t a_dst, const std::uint8_t a_opcode) { #pragma pack(push, 1) @@ -245,7 +245,7 @@ namespace SFSE mem->addr = static_cast(a_dst); } - void write_6branch(std::uintptr_t a_src, std::uintptr_t a_dst, std::uint8_t a_modrm) + void write_6branch(const std::uintptr_t a_src, std::uintptr_t a_dst, const std::uint8_t a_modrm) { #pragma pack(push, 1) @@ -286,7 +286,7 @@ namespace SFSE } template - [[nodiscard]] std::uintptr_t write_branch(std::uintptr_t a_src, std::uintptr_t a_dst, std::uint8_t a_data) + [[nodiscard]] std::uintptr_t write_branch(const std::uintptr_t a_src, const std::uintptr_t a_dst, const std::uint8_t a_data) { const auto disp = reinterpret_cast(a_src + N - 4); const auto nextOp = a_src + N; @@ -323,7 +323,7 @@ namespace SFSE void log_stats() const; - [[nodiscard]] bool in_range(std::ptrdiff_t a_disp) const + [[nodiscard]] bool in_range(const std::ptrdiff_t a_disp) const { constexpr auto min = (std::numeric_limits::min)(); constexpr auto max = (std::numeric_limits::max)(); diff --git a/CommonLibSF/src/REL/ID.cpp b/CommonLibSF/src/REL/ID.cpp index 37f11fb4..001ee540 100644 --- a/CommonLibSF/src/REL/ID.cpp +++ b/CommonLibSF/src/REL/ID.cpp @@ -28,7 +28,7 @@ namespace REL return it->id; } - bool memory_map::open(stl::zwstring a_name, std::size_t a_size) + bool memory_map::open(const stl::zwstring a_name, const std::size_t a_size) { close(); @@ -60,7 +60,7 @@ namespace REL return true; } - bool memory_map::create(stl::zwstring a_name, std::size_t a_size) + bool memory_map::create(const stl::zwstring a_name, const std::size_t a_size) { close(); @@ -203,7 +203,7 @@ namespace REL load_file(file, version, true); } - bool IDDatabase::load_file(stl::zwstring a_filename, Version a_version, bool a_failOnError) + bool IDDatabase::load_file(const stl::zwstring a_filename, const Version a_version, const bool a_failOnError) { try { database::istream_t in(a_filename.data(), std::ios::in | std::ios::binary); @@ -264,7 +264,7 @@ namespace REL return true; } - bool IDDatabase::unpack_file(database::istream_t& a_in, database::header_t a_header, bool a_failOnError) + bool IDDatabase::unpack_file(database::istream_t& a_in, database::header_t a_header, const bool a_failOnError) { std::uint8_t type = 0; std::uint64_t id = 0; diff --git a/CommonLibSF/src/REL/Module.cpp b/CommonLibSF/src/REL/Module.cpp index 68cb388d..0fd1b87f 100644 --- a/CommonLibSF/src/REL/Module.cpp +++ b/CommonLibSF/src/REL/Module.cpp @@ -2,14 +2,14 @@ namespace REL { - Module::Module(std::uintptr_t a_base) + Module::Module(const std::uintptr_t a_base) { stl_assert(a_base, "failed to initializing module info with null module base"); _base = a_base; - auto dosHeader = reinterpret_cast(_base); - auto ntHeader = stl::adjust_pointer(dosHeader, dosHeader->lfanew); + 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 size = std::min(ntHeader->fileHeader.sectionCount, _segments.size()); @@ -52,7 +52,7 @@ namespace REL return managed.at(base); } - [[nodiscard]] Module& Module::get(std::string_view a_filePath) noexcept + [[nodiscard]] Module& 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())); return get(base); diff --git a/CommonLibSF/src/REL/Version.cpp b/CommonLibSF/src/REL/Version.cpp index a7e088b1..c7fd3f66 100644 --- a/CommonLibSF/src/REL/Version.cpp +++ b/CommonLibSF/src/REL/Version.cpp @@ -2,7 +2,7 @@ namespace REL { - constexpr Version::Version(std::string_view a_version) + constexpr Version::Version(const std::string_view a_version) { std::array powers{ 1, 1, 1, 1 }; std::size_t position = 0; @@ -28,7 +28,7 @@ namespace REL } } - [[nodiscard]] std::optional get_file_version(stl::zwstring a_filename) + [[nodiscard]] std::optional get_file_version(const stl::zwstring a_filename) { std::uint32_t dummy{ 0 }; std::vector buf(WinAPI::GetFileVersionInfoSize(a_filename.data(), std::addressof(dummy))); diff --git a/CommonLibSF/src/SFSE/API.cpp b/CommonLibSF/src/SFSE/API.cpp index b89d35e0..bdb3914e 100644 --- a/CommonLibSF/src/SFSE/API.cpp +++ b/CommonLibSF/src/SFSE/API.cpp @@ -36,7 +36,7 @@ namespace SFSE }; template - T* QueryInterface(const LoadInterface* a_intfc, std::uint32_t a_id) + T* QueryInterface(const LoadInterface* a_intfc, const std::uint32_t a_id) { auto result = static_cast(a_intfc->QueryInterface(a_id)); if (result && result->Version() > T::kVersion) { @@ -46,7 +46,7 @@ namespace SFSE } } - void Init(const LoadInterface* a_intfc, bool a_log) noexcept + void Init(const LoadInterface* a_intfc, const bool a_log) noexcept { stl_assert(a_intfc, "interface is null"sv); @@ -76,7 +76,7 @@ namespace SFSE } } - void RegisterForAPIInitEvent(std::function a_fn) + void RegisterForAPIInitEvent(const std::function& a_fn) { { auto& storage = detail::APIStorage::get(); @@ -116,11 +116,11 @@ namespace SFSE return trampoline; } - void AllocTrampoline(std::size_t a_size, bool a_trySFSEReserve) + void AllocTrampoline(const std::size_t a_size, const bool a_trySFSEReserve) { auto& trampoline = GetTrampoline(); - if (auto intfc = GetTrampolineInterface(); intfc && a_trySFSEReserve) { - auto memory = intfc->AllocateFromBranchPool(a_size); + if (const auto intfc = GetTrampolineInterface(); intfc && a_trySFSEReserve) { + const auto memory = intfc->AllocateFromBranchPool(a_size); if (memory) { trampoline.set_trampoline(memory, a_size); return; diff --git a/CommonLibSF/src/SFSE/IAT.cpp b/CommonLibSF/src/SFSE/IAT.cpp index 39cca617..4084432d 100644 --- a/CommonLibSF/src/SFSE/IAT.cpp +++ b/CommonLibSF/src/SFSE/IAT.cpp @@ -23,29 +23,29 @@ namespace SFSE void* GetIATPtr(void* a_module, std::string_view a_dll, std::string_view a_function) { assert(a_module); - auto dosHeader = static_cast(a_module); + const auto dosHeader = static_cast(a_module); if (dosHeader->magic != WinAPI::IMAGE_DOS_SIGNATURE) { log::error("Invalid DOS header"); return nullptr; } - auto ntHeader = stl::adjust_pointer(dosHeader, dosHeader->lfanew); - auto& dataDir = ntHeader->optionalHeader.dataDirectory[WinAPI::IMAGE_DIRECTORY_ENTRY_IMPORT]; - auto importDesc = stl::adjust_pointer(dosHeader, dataDir.virtualAddress); + 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); for (auto import = importDesc; import->characteristics != 0; ++import) { - auto name = stl::adjust_pointer(dosHeader, import->name); + const auto name = stl::adjust_pointer(dosHeader, import->name); if (a_dll.size() == strlen(name) && _strnicmp(a_dll.data(), name, a_dll.size()) != 0) { continue; } - 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)) { continue; } - 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; } @@ -56,11 +56,11 @@ namespace SFSE return nullptr; } - std::uintptr_t PatchIAT(std::uintptr_t a_newFunc, std::string_view a_dll, std::string_view a_function) + std::uintptr_t PatchIAT(const std::uintptr_t a_newFunc, std::string_view a_dll, std::string_view a_function) { std::uintptr_t origAddr = 0; - auto oldFunc = GetIATAddr(a_dll, a_function); + const auto oldFunc = GetIATAddr(a_dll, a_function); if (oldFunc) { origAddr = *reinterpret_cast(oldFunc); REL::safe_write(oldFunc, a_newFunc); diff --git a/CommonLibSF/src/SFSE/InputMap.cpp b/CommonLibSF/src/SFSE/InputMap.cpp index 35de7dba..a128589c 100644 --- a/CommonLibSF/src/SFSE/InputMap.cpp +++ b/CommonLibSF/src/SFSE/InputMap.cpp @@ -4,7 +4,7 @@ namespace SFSE { - std::uint32_t InputMap::GamepadMaskToKeycode(std::uint32_t keyMask) + std::uint32_t InputMap::GamepadMaskToKeycode(const std::uint32_t keyMask) { using XInputButton = RE::XInput::XInputButton; switch (keyMask) { @@ -45,7 +45,7 @@ namespace SFSE } } - std::uint32_t InputMap::GamepadKeycodeToMask(std::uint32_t keyCode) + std::uint32_t InputMap::GamepadKeycodeToMask(const std::uint32_t keyCode) { using XInputButton = RE::XInput::XInputButton; @@ -87,7 +87,7 @@ namespace SFSE } } - std::string InputMap::GetKeyName(std::uint32_t a_keyCode) + std::string InputMap::GetKeyName(const std::uint32_t a_keyCode) { if (a_keyCode >= kMacro_MouseButtonOffset && a_keyCode < kMacro_GamepadOffset) { return GetMouseButtonName(a_keyCode); @@ -98,7 +98,7 @@ namespace SFSE } } - std::string InputMap::GetKeyboardKeyName(std::uint32_t a_keyCode) + std::string InputMap::GetKeyboardKeyName(const std::uint32_t a_keyCode) { std::int32_t scancode = static_cast(a_keyCode & 0xFF); @@ -155,14 +155,14 @@ namespace SFSE lParam |= (0x1 << 24); } - wchar_t buffer[WinAPI::MAX_PATH]; - auto length = WinAPI::GetKeyNameText(lParam, buffer, WinAPI::MAX_PATH); - std::wstring keyNameW{ buffer, static_cast(length) }; + wchar_t buffer[WinAPI::MAX_PATH]; + const auto length = WinAPI::GetKeyNameText(lParam, buffer, WinAPI::MAX_PATH); + const std::wstring keyNameW{ buffer, static_cast(length) }; return stl::utf16_to_utf8(keyNameW).value_or(""s); } - std::string InputMap::GetMouseButtonName(std::uint32_t a_keyCode) + std::string InputMap::GetMouseButtonName(const std::uint32_t a_keyCode) { switch (a_keyCode) { case 256: @@ -190,7 +190,7 @@ namespace SFSE } } - std::string InputMap::GetGamepadButtonName(std::uint32_t a_keyCode) + std::string InputMap::GetGamepadButtonName(const std::uint32_t a_keyCode) { switch (a_keyCode) { case kGamepadButtonOffset_DPAD_UP: diff --git a/CommonLibSF/src/SFSE/Interfaces.cpp b/CommonLibSF/src/SFSE/Interfaces.cpp index 19dbd177..407d8017 100644 --- a/CommonLibSF/src/SFSE/Interfaces.cpp +++ b/CommonLibSF/src/SFSE/Interfaces.cpp @@ -35,7 +35,7 @@ namespace SFSE return static_cast(GetProxy()->GetPluginInfo(a_name)); } - void* LoadInterface::QueryInterface(std::uint32_t a_id) const + void* LoadInterface::QueryInterface(const std::uint32_t a_id) const { return GetProxy()->QueryInterface(a_id); } @@ -45,9 +45,9 @@ namespace SFSE return GetProxy()->interfaceVersion; } - bool MessagingInterface::Dispatch(std::uint32_t a_messageType, void* a_data, std::uint32_t a_dataLen, const char* a_receiver) const + bool MessagingInterface::Dispatch(const std::uint32_t a_messageType, void* a_data, const std::uint32_t a_dataLen, const char* a_receiver) const { - auto result = GetProxy()->Dispatch(GetPluginHandle(), a_messageType, a_data, a_dataLen, a_receiver); + const auto result = GetProxy()->Dispatch(GetPluginHandle(), a_messageType, a_data, a_dataLen, a_receiver); if (!result) { log::error("Failed to dispatch message to {}", (a_receiver ? a_receiver : "all listeners")); } @@ -55,14 +55,14 @@ namespace SFSE return result; } - bool MessagingInterface::RegisterListener(EventCallback a_callback) const + bool MessagingInterface::RegisterListener(const EventCallback a_callback) const { return RegisterListener("SFSE", a_callback); } - bool MessagingInterface::RegisterListener(const char* a_sender, EventCallback a_callback) const + bool MessagingInterface::RegisterListener(const char* a_sender, const EventCallback a_callback) const { - auto result = GetProxy()->RegisterListener(GetPluginHandle(), a_sender, std::bit_cast(a_callback)); + const auto result = GetProxy()->RegisterListener(GetPluginHandle(), a_sender, std::bit_cast(a_callback)); if (!result) { log::error("Failed to register messaging listener for {}", a_sender); } @@ -80,12 +80,12 @@ namespace SFSE return GetProxy()->interfaceVersion; } - void* TrampolineInterface::AllocateFromBranchPool(std::size_t a_size) const + void* TrampolineInterface::AllocateFromBranchPool(const std::size_t a_size) const { return GetProxy()->AllocateFromBranchPool(GetPluginHandle(), a_size); } - void* TrampolineInterface::AllocateFromLocalPool(std::size_t a_size) const + void* TrampolineInterface::AllocateFromLocalPool(const std::size_t a_size) const { return GetProxy()->AllocateFromLocalPool(GetPluginHandle(), a_size); } diff --git a/CommonLibSF/src/SFSE/Logger.cpp b/CommonLibSF/src/SFSE/Logger.cpp index 36fa460e..05e85522 100644 --- a/CommonLibSF/src/SFSE/Logger.cpp +++ b/CommonLibSF/src/SFSE/Logger.cpp @@ -10,9 +10,9 @@ namespace SFSE { std::optional log_directory() { - wchar_t* buffer{ nullptr }; - const auto result = WinAPI::SHGetKnownFolderPath(WinAPI::FOLDERID_DOCUMENTS, WinAPI::KF_FLAG_DEFAULT, nullptr, std::addressof(buffer)); - std::unique_ptr knownPath(buffer, WinAPI::CoTaskMemFree); + wchar_t* buffer{ nullptr }; + 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) { error("failed to get known folder path"sv); return std::nullopt; diff --git a/CommonLibSF/src/SFSE/Trampoline.cpp b/CommonLibSF/src/SFSE/Trampoline.cpp index 4c06af48..abdc0cfe 100644 --- a/CommonLibSF/src/SFSE/Trampoline.cpp +++ b/CommonLibSF/src/SFSE/Trampoline.cpp @@ -25,7 +25,7 @@ namespace SFSE #endif // https://stackoverflow.com/a/54732489 - void* Trampoline::do_create(std::size_t a_size, std::uintptr_t a_address) + void* Trampoline::do_create(const std::size_t a_size, const std::uintptr_t a_address) { constexpr std::size_t gigabyte = static_cast(1) << 30; constexpr std::size_t minRange = gigabyte * 2; @@ -33,7 +33,7 @@ namespace SFSE WinAPI::SYSTEM_INFO si; WinAPI::GetSystemInfo(&si); - std::uint32_t granularity = si.allocationGranularity; + 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; @@ -46,7 +46,7 @@ namespace SFSE return nullptr; } - auto baseAddr = reinterpret_cast(mbi.baseAddress); + const auto baseAddr = reinterpret_cast(mbi.baseAddress); min = baseAddr + mbi.regionSize; if (mbi.state == WinAPI::MEM_FREE) { @@ -54,7 +54,7 @@ namespace SFSE // if rounding didn't advance us into the next region and the region is the required size if (addr < min && (min - addr) >= a_size) { - auto mem = WinAPI::VirtualAlloc(reinterpret_cast(addr), a_size, WinAPI::MEM_COMMIT | WinAPI::MEM_RESERVE, WinAPI::PAGE_EXECUTE_READWRITE); + 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 {