diff --git a/cmake/sourcelist.cmake b/cmake/sourcelist.cmake index 62a9bad07..cdf51ff78 100644 --- a/cmake/sourcelist.cmake +++ b/cmake/sourcelist.cmake @@ -117,7 +117,6 @@ set(sources ${sources} include/RE/H/hkpBroadPhase.cpp include/RE/H/hkpCdBody.cpp include/RE/H/hkpCharacterProxyListener.cpp - include/RE/H/hkpCollidable.cpp include/RE/H/hkpMaterial.cpp include/RE/H/hkpWorldObject.cpp include/RE/H/hkReferencedObject.cpp diff --git a/include/RE/A/Array.cpp b/include/RE/A/Array.cpp index 22d8b411d..abab30b79 100644 --- a/include/RE/A/Array.cpp +++ b/include/RE/A/Array.cpp @@ -162,17 +162,17 @@ namespace RE [[nodiscard]] TypeInfo::RawType Array::type() const { - const auto typeID = _elementType.GetRawType(); - switch (typeID) { + const stl::enumeration typeID = _elementType.GetRawType(); + switch (*typeID) { case TypeInfo::RawType::kNone: case TypeInfo::RawType::kObject: case TypeInfo::RawType::kString: case TypeInfo::RawType::kInt: case TypeInfo::RawType::kFloat: case TypeInfo::RawType::kBool: - return typeID + TypeInfo::RawType::kNoneArray; + return *(typeID + TypeInfo::RawType::kNoneArray); default: - return typeID + TypeInfo::RawType::kObject; + return *(typeID + TypeInfo::RawType::kObject); } } } diff --git a/include/RE/B/BGSDefaultObjectManager.h b/include/RE/B/BGSDefaultObjectManager.h index 4dbff53d1..9c98d99a2 100644 --- a/include/RE/B/BGSDefaultObjectManager.h +++ b/include/RE/B/BGSDefaultObjectManager.h @@ -435,17 +435,17 @@ namespace RE return func(); } - [[nodiscard]] TESForm* GetObject(DefaultObject a_object) const noexcept { return GetObject(to_underlying(a_object)); } + [[nodiscard]] TESForm* GetObject(DefaultObject a_object) const noexcept { return GetObject(stl::to_underlying(a_object)); } template [[nodiscard]] T* GetObject(DefaultObject a_object) const noexcept { - return GetObject(to_underlying(a_object)); + return GetObject(stl::to_underlying(a_object)); } [[nodiscard]] TESForm* GetObject(std::size_t a_idx) const noexcept { - assert(a_idx < to_underlying(DefaultObject::kTotal)); + assert(a_idx < stl::to_underlying(DefaultObject::kTotal)); return objectInit[a_idx] ? objects[a_idx] : nullptr; } diff --git a/include/RE/B/BSAtomic.cpp b/include/RE/B/BSAtomic.cpp index 134f756a4..1be15fa3d 100644 --- a/include/RE/B/BSAtomic.cpp +++ b/include/RE/B/BSAtomic.cpp @@ -49,14 +49,14 @@ namespace RE BSSemaphoreBase::BSSemaphoreBase() : semaphore() { - memzero(&semaphore); + stl::memzero(&semaphore); semaphore = ::CreateSemaphoreA(nullptr, 0, 40, nullptr); } BSSemaphoreBase::~BSSemaphoreBase() { ::CloseHandle(semaphore); - memzero(&semaphore); + stl::memzero(&semaphore); } BSSpinLock::BSSpinLock() : diff --git a/include/RE/B/BSInputDeviceManager.cpp b/include/RE/B/BSInputDeviceManager.cpp index b7298c293..38520d97e 100644 --- a/include/RE/B/BSInputDeviceManager.cpp +++ b/include/RE/B/BSInputDeviceManager.cpp @@ -22,22 +22,22 @@ namespace RE BSPCGamepadDeviceHandler* BSInputDeviceManager::GetGamepadHandler() { - return static_cast(devices[to_underlying(INPUT_DEVICE::kGamepad)]); + return static_cast(devices[stl::to_underlying(INPUT_DEVICE::kGamepad)]); } BSWin32KeyboardDevice* BSInputDeviceManager::GetKeyboard() { - return static_cast(devices[to_underlying(INPUT_DEVICE::kKeyboard)]); + return static_cast(devices[stl::to_underlying(INPUT_DEVICE::kKeyboard)]); } BSWin32MouseDevice* BSInputDeviceManager::GetMouse() { - return static_cast(devices[to_underlying(INPUT_DEVICE::kMouse)]); + return static_cast(devices[stl::to_underlying(INPUT_DEVICE::kMouse)]); } BSWin32VirtualKeyboardDevice* BSInputDeviceManager::GetVirtualKeyboard() { - return static_cast(devices[to_underlying(INPUT_DEVICE::kVirtualKeyboard)]); + return static_cast(devices[stl::to_underlying(INPUT_DEVICE::kVirtualKeyboard)]); } bool BSInputDeviceManager::IsGamepadConnected() diff --git a/include/RE/B/BSIntrusiveRefCounted.h b/include/RE/B/BSIntrusiveRefCounted.h index 043e8485d..1e4719071 100644 --- a/include/RE/B/BSIntrusiveRefCounted.h +++ b/include/RE/B/BSIntrusiveRefCounted.h @@ -26,7 +26,7 @@ namespace RE protected: // members - volatile std::uint32_t _refCount{ 0 }; // 0 + mutable volatile std::uint32_t _refCount{ 0 }; // 0 }; static_assert(sizeof(BSIntrusiveRefCounted) == 0x4); } diff --git a/include/RE/B/BSScaleformManager.cpp b/include/RE/B/BSScaleformManager.cpp index 95751a8dd..f293aae73 100644 --- a/include/RE/B/BSScaleformManager.cpp +++ b/include/RE/B/BSScaleformManager.cpp @@ -45,7 +45,8 @@ namespace RE return false; } - const auto def = loader->CreateMovie(filePath->c_str(), LoadConstants::kLoadKeepBindData | LoadConstants::kLoadWaitFrame1); + const stl::enumeration loadFlags{ LoadConstants::kLoadKeepBindData, LoadConstants::kLoadWaitFrame1 }; + const auto def = loader->CreateMovie(filePath->c_str(), *loadFlags); if (!def) { return false; } @@ -104,7 +105,8 @@ namespace RE return false; } - const auto def = loader->CreateMovie(filePath->c_str(), LoadConstants::kLoadKeepBindData | LoadConstants::kLoadWaitFrame1); + const stl::enumeration loadFlags{ LoadConstants::kLoadKeepBindData, LoadConstants::kLoadWaitFrame1 }; + const auto def = loader->CreateMovie(filePath->c_str(), *loadFlags); if (!def) { return false; } diff --git a/include/RE/B/BSTArray.cpp b/include/RE/B/BSTArray.cpp index f70e2ba84..d76a99b30 100644 --- a/include/RE/B/BSTArray.cpp +++ b/include/RE/B/BSTArray.cpp @@ -9,7 +9,7 @@ namespace RE if (_data) { deallocate(_data); } - memzero(this); + stl::memzero(this); } void* BSScrapArrayAllocator::allocate(std::size_t a_size) diff --git a/include/RE/B/BSTList.h b/include/RE/B/BSTList.h index 203842d33..86406a9e8 100644 --- a/include/RE/B/BSTList.h +++ b/include/RE/B/BSTList.h @@ -75,7 +75,7 @@ namespace RE // members value_type item; // 00 - observer next; // ?? + stl::observer next; // ?? }; template @@ -164,7 +164,7 @@ namespace RE } private: - observer _cur; + stl::observer _cur; }; using iterator = iterator_base; diff --git a/include/RE/B/BSXFlags.cpp b/include/RE/B/BSXFlags.cpp index f168517ce..1d6377951 100644 --- a/include/RE/B/BSXFlags.cpp +++ b/include/RE/B/BSXFlags.cpp @@ -10,6 +10,6 @@ namespace RE void BSXFlags::SetFlags(Flag a_flags) { - value = to_underlying(a_flags); + value = stl::to_underlying(a_flags); } } diff --git a/include/RE/B/BipedAnim.cpp b/include/RE/B/BipedAnim.cpp index 4a91d2390..f3d859924 100644 --- a/include/RE/B/BipedAnim.cpp +++ b/include/RE/B/BipedAnim.cpp @@ -7,7 +7,7 @@ namespace RE BipedAnim::~BipedAnim() { Dtor(); - memzero(this); + stl::memzero(this); } void BipedAnim::RemoveAllParts() diff --git a/include/RE/G/GFxResource.cpp b/include/RE/G/GFxResource.cpp index 246f353e1..5d3ea16f3 100644 --- a/include/RE/G/GFxResource.cpp +++ b/include/RE/G/GFxResource.cpp @@ -56,16 +56,21 @@ namespace RE GFxResource::ResourceType GFxResource::GetResourceType() const { - return (static_cast(GetResourceTypeCode()) & ResourceType::kTypeCode_Mask) >> ResourceType::kTypeCode_Shift; + return static_cast( + stl::to_underlying(GetResourceUse()) >> + stl::to_underlying(ResourceType::kTypeCode_Shift)); } GFxResource::ResourceUse GFxResource::GetResourceUse() const { - return static_cast(GetResourceTypeCode()) & ResourceUse::kTypeCode_Mask; + return static_cast( + GetResourceTypeCode() & + stl::to_underlying(ResourceUse::kTypeCode_Mask)); } std::uint32_t GFxResource::MakeTypeCode(ResourceType a_resourceType, ResourceUse a_resourceUse) { - return to_underlying(static_cast(a_resourceType << ResourceType::kTypeCode_Shift) | a_resourceUse); + return (stl::to_underlying(a_resourceType) << stl::to_underlying(ResourceType::kTypeCode_Shift)) | + stl::to_underlying(a_resourceUse); } } diff --git a/include/RE/G/GFxTranslator.cpp b/include/RE/G/GFxTranslator.cpp index 9f5bdd8a4..1eca0e351 100644 --- a/include/RE/G/GFxTranslator.cpp +++ b/include/RE/G/GFxTranslator.cpp @@ -100,12 +100,12 @@ namespace RE bool GFxTranslator::CanReceiveHTML() const { - return (GetCaps() & TranslateCap::kReceiveHTML) != TranslateCap::kNone; + return (stl::enumeration{ GetCaps() } & TranslateCap::kReceiveHTML) != TranslateCap::kNone; } bool GFxTranslator::NeedStripNewLines() const { - return (GetCaps() & TranslateCap::kStripTrailingNewLines) != TranslateCap::kNone; + return (stl::enumeration{ GetCaps() } & TranslateCap::kStripTrailingNewLines) != TranslateCap::kNone; } bool GFxTranslator::HandlesCustomWordWrapping() const diff --git a/include/RE/G/GFxWWHelper.cpp b/include/RE/G/GFxWWHelper.cpp index 71efa6044..397dda294 100644 --- a/include/RE/G/GFxWWHelper.cpp +++ b/include/RE/G/GFxWWHelper.cpp @@ -6,7 +6,8 @@ namespace RE { bool GFxWWHelper::FindCharWithFlags(WordWrappingType a_wwMode, wchar_t a_ch, BreakInfoFlags a_charBreakFlags) { - if ((a_wwMode & WordWrappingType::kProhibition) == WordWrappingType::kNone) { + const stl::enumeration wwMode{ a_wwMode }; + if ((wwMode & WordWrappingType::kProhibition) == WordWrappingType::kNone) { return false; } @@ -28,7 +29,8 @@ namespace RE bool GFxWWHelper::IsAsianChar(WordWrappingType a_wwMode, wchar_t a_ch) { - if ((a_wwMode & WordWrappingType::kNoHangulWrap) != WordWrappingType::kNone) { + const stl::enumeration wwMode{ a_wwMode }; + if ((wwMode & WordWrappingType::kNoHangulWrap) != WordWrappingType::kNone) { if ((a_ch >= 0x1100 && a_ch <= 0x11FF) || (a_ch >= 0x3130 && a_ch <= 0x318F) || (a_ch >= 0xAC00 && a_ch <= 0xD7A3)) { return false; } @@ -128,7 +130,9 @@ namespace RE UPInt GFxWWHelper::FindWordWrapPos(WordWrappingType a_wwMode, [[maybe_unused]] UPInt a_wordWrapPos, const wchar_t* a_paraText, UPInt a_paraLen, UPInt a_lineStartPos, UPInt a_lineLen) { assert(a_paraText); - if ((a_wwMode & WordWrappingType::kAll) == WordWrappingType::kNone || a_lineLen == 0) { + + const stl::enumeration wwMode{ a_wwMode }; + if ((wwMode & WordWrappingType::kAll) == WordWrappingType::kNone || a_lineLen == 0) { return UPINT_MAX; } @@ -147,7 +151,7 @@ namespace RE pos = prev + 1; } - if (IsLineBreakOpportunityAt(a_wwMode, lineText, pos)) { + if (IsLineBreakOpportunityAt(*wwMode, lineText, pos)) { break; } diff --git a/include/RE/H/HeapBlock.cpp b/include/RE/H/HeapBlock.cpp index 1b8122a37..715f687ee 100644 --- a/include/RE/H/HeapBlock.cpp +++ b/include/RE/H/HeapBlock.cpp @@ -4,16 +4,16 @@ namespace RE { std::uint32_t HeapBlock::Used::GetCheckPoint() const { - return static_cast(pun_bits(memContext1, memContext2, memContext3, memContext4, memContext5, memContext6, memContext7, memContext8)); + return static_cast(stl::pun_bits(memContext1, memContext2, memContext3, memContext4, memContext5, memContext6, memContext7, memContext8)); } std::uint32_t HeapBlock::Used::GetMemContext() const { - return static_cast(pun_bits(stackTrace1, stackTrace2, stackTrace3, stackTrace4, stackTrace5, stackTrace6, stackTrace7, stackTrace8, stackTrace9, stackTrace10, stackTrace11, stackTrace12, stackTrace13, stackTrace14, stackTrace15, stackTrace16, stackTrace17, stackTrace18, stackTrace19, stackTrace20, stackTrace21, stackTrace22)); + return static_cast(stl::pun_bits(stackTrace1, stackTrace2, stackTrace3, stackTrace4, stackTrace5, stackTrace6, stackTrace7, stackTrace8, stackTrace9, stackTrace10, stackTrace11, stackTrace12, stackTrace13, stackTrace14, stackTrace15, stackTrace16, stackTrace17, stackTrace18, stackTrace19, stackTrace20, stackTrace21, stackTrace22)); } std::uint32_t HeapBlock::Used::GetStackTrace() const { - return static_cast(pun_bits(checkPoint1, checkPoint2)); + return static_cast(stl::pun_bits(checkPoint1, checkPoint2)); } } diff --git a/include/RE/H/hkpCollidable.cpp b/include/RE/H/hkpCollidable.cpp deleted file mode 100644 index b307f3c46..000000000 --- a/include/RE/H/hkpCollidable.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "RE/H/hkpCollidable.h" - -namespace RE -{ - void* hkpCollidable::GetOwner() const - { - return const_cast(adjust_pointer(this, ownerOffset)); - } -} diff --git a/include/RE/H/hkpCollidable.h b/include/RE/H/hkpCollidable.h index c4f0099eb..531c26618 100644 --- a/include/RE/H/hkpCollidable.h +++ b/include/RE/H/hkpCollidable.h @@ -37,7 +37,11 @@ namespace RE }; static_assert(sizeof(BoundingVolumeData) == 0x38); - void* GetOwner() const; + [[nodiscard]] void* GetOwner() const + { + return const_cast(stl::adjust_pointer(this, ownerOffset)); + } + template T* GetOwner() const { diff --git a/include/RE/I/IFormFactory.cpp b/include/RE/I/IFormFactory.cpp index 58100db4f..21121e8be 100644 --- a/include/RE/I/IFormFactory.cpp +++ b/include/RE/I/IFormFactory.cpp @@ -6,7 +6,7 @@ namespace RE { struct Factories { - IFormFactory* data[to_underlying(FormType::Max)]; + IFormFactory* data[stl::to_underlying(FormType::Max)]; }; REL::Relocation formFactories{ REL::ID(514355) }; diff --git a/include/RE/I/InventoryChanges.cpp b/include/RE/I/InventoryChanges.cpp index 5851522b7..3e4517f1a 100644 --- a/include/RE/I/InventoryChanges.cpp +++ b/include/RE/I/InventoryChanges.cpp @@ -14,7 +14,7 @@ namespace RE InventoryChanges::~InventoryChanges() { Dtor(); - memzero(this); + stl::memzero(this); } void InventoryChanges::AddEntryData(InventoryEntryData* a_entry) diff --git a/include/RE/M/MemoryPage.cpp b/include/RE/M/MemoryPage.cpp index 4357f2f8d..8900c3836 100644 --- a/include/RE/M/MemoryPage.cpp +++ b/include/RE/M/MemoryPage.cpp @@ -11,7 +11,7 @@ namespace RE void* MemoryPage::GetTail() { - return adjust_pointer(GetHead(), pageSize); + return stl::adjust_pointer(GetHead(), pageSize); } bool MemoryPage::IsInRange(const void* a_ptr) diff --git a/include/RE/M/MiddleHighProcessData.h b/include/RE/M/MiddleHighProcessData.h index 6511919d1..e483c3770 100644 --- a/include/RE/M/MiddleHighProcessData.h +++ b/include/RE/M/MiddleHighProcessData.h @@ -181,7 +181,7 @@ namespace RE BSTArray& operator[](BGSEntryPoint::ENTRY_POINT a_pos) { assert(a_pos < BGSEntryPoint::ENTRY_POINT::kTotal); - return perkEntryArrays[to_underlying(a_pos)]; + return perkEntryArrays[stl::to_underlying(a_pos)]; } // members diff --git a/include/RE/N/NiTCollection.h b/include/RE/N/NiTCollection.h index dfaa98717..98b826105 100644 --- a/include/RE/N/NiTCollection.h +++ b/include/RE/N/NiTCollection.h @@ -58,7 +58,7 @@ namespace RE inline static void Deallocate(T* a_array) { if (a_array) { - auto head = adjust_pointer(a_array, -ssizeof_v); + auto head = stl::adjust_pointer(a_array, -stl::ssizeof_v); for (std::size_t i = 0; i < *head; ++i) { a_array[i].~T(); } diff --git a/include/RE/O/Object.cpp b/include/RE/O/Object.cpp index 9a8281303..3483e2c32 100644 --- a/include/RE/O/Object.cpp +++ b/include/RE/O/Object.cpp @@ -11,7 +11,7 @@ namespace RE Object::~Object() { Dtor(); - memzero(this); + stl::memzero(this); } VMHandle Object::GetHandle() const diff --git a/include/RE/O/ObjectTypeInfo.cpp b/include/RE/O/ObjectTypeInfo.cpp index 4ae02fd7f..859feba85 100644 --- a/include/RE/O/ObjectTypeInfo.cpp +++ b/include/RE/O/ObjectTypeInfo.cpp @@ -44,7 +44,7 @@ namespace RE TypeInfo::RawType ObjectTypeInfo::GetRawType() const { - return unrestricted_cast(this); + return stl::unrestricted_cast(this); } auto ObjectTypeInfo::GetUnlinkedFunctionIter() diff --git a/include/RE/S/ShadowSceneNode.h b/include/RE/S/ShadowSceneNode.h index dbe2cfc48..962a82e40 100644 --- a/include/RE/S/ShadowSceneNode.h +++ b/include/RE/S/ShadowSceneNode.h @@ -50,11 +50,11 @@ namespace RE std::uint64_t unk1F0; // 1F0 std::uint64_t unk1F8; // 1F8 - owner unk200; // 200 - smart ptr + stl::owner unk200; // 200 - smart ptr std::uint64_t unk208; // 208 - owner unk210; // 210 - smart ptr + stl::owner unk210; // 210 - smart ptr std::uint64_t unk218; // 218 - owner unk220; // 220 - smart ptr + stl::owner unk220; // 220 - smart ptr std::uint64_t unk228; // 228 BSTArray unk230; // 230 std::uint64_t unk248; // 248 diff --git a/include/RE/S/Stack.cpp b/include/RE/S/Stack.cpp index 17427420c..888fa4db8 100644 --- a/include/RE/S/Stack.cpp +++ b/include/RE/S/Stack.cpp @@ -10,7 +10,7 @@ namespace RE Stack::~Stack() { Dtor(); - memzero(this); + stl::memzero(this); } std::uint32_t Stack::GetPageForFrame(const StackFrame* a_frame) const diff --git a/include/RE/T/TESAIForm.cpp b/include/RE/T/TESAIForm.cpp index 313befbe3..3e78ae453 100644 --- a/include/RE/T/TESAIForm.cpp +++ b/include/RE/T/TESAIForm.cpp @@ -9,32 +9,32 @@ namespace RE ACTOR_AGGRESSION TESAIForm::GetAggressionLevel() const { - return static_cast(pun_bits(aiData.aggression1, aiData.aggression2)); + return static_cast(stl::pun_bits(aiData.aggression1, aiData.aggression2)); } ACTOR_ASSISTANCE TESAIForm::GetAssistanceLevel() const { - return static_cast(pun_bits(aiData.assistance1, aiData.assistance2)); + return static_cast(stl::pun_bits(aiData.assistance1, aiData.assistance2)); } ACTOR_CONFIDENCE TESAIForm::GetConfidenceLevel() const { - return static_cast(pun_bits(aiData.confidence1, aiData.confidence2, aiData.confidence3)); + return static_cast(stl::pun_bits(aiData.confidence1, aiData.confidence2, aiData.confidence3)); } std::uint8_t TESAIForm::GetEnergyLevel() const { - return static_cast(pun_bits(aiData.energyLevel1, aiData.energyLevel2, aiData.energyLevel3, aiData.energyLevel4, aiData.energyLevel5, aiData.energyLevel6, aiData.energyLevel7, aiData.energyLevel8)); + return static_cast(stl::pun_bits(aiData.energyLevel1, aiData.energyLevel2, aiData.energyLevel3, aiData.energyLevel4, aiData.energyLevel5, aiData.energyLevel6, aiData.energyLevel7, aiData.energyLevel8)); } ACTOR_MOOD TESAIForm::GetMoodLevel() const { - return static_cast(pun_bits(aiData.mood1, aiData.mood2, aiData.mood3)); + return static_cast(stl::pun_bits(aiData.mood1, aiData.mood2, aiData.mood3)); } ACTOR_MORALITY TESAIForm::GetMoralityLevel() const { - return static_cast(pun_bits(aiData.morality1, aiData.morality1)); + return static_cast(stl::pun_bits(aiData.morality1, aiData.morality1)); } bool TESAIForm::NoSlowApproach() const diff --git a/include/RE/T/TESDataHandler.cpp b/include/RE/T/TESDataHandler.cpp index 7d40e5042..3265c0279 100644 --- a/include/RE/T/TESDataHandler.cpp +++ b/include/RE/T/TESDataHandler.cpp @@ -107,6 +107,6 @@ namespace RE BSTArray& TESDataHandler::GetFormArray(FormType a_formType) { - return formArrays[to_underlying(a_formType)]; + return formArrays[stl::to_underlying(a_formType)]; } } diff --git a/include/RE/T/TESDataHandler.h b/include/RE/T/TESDataHandler.h index 89bf9dfa3..fed306307 100644 --- a/include/RE/T/TESDataHandler.h +++ b/include/RE/T/TESDataHandler.h @@ -63,7 +63,7 @@ namespace RE std::uint16_t pad002; // 002 std::uint32_t pad004; // 004 TESObjectList* objectList; // 008 - BSTArray formArrays[to_underlying(FormType::Max)]; // 010 + BSTArray formArrays[stl::to_underlying(FormType::Max)]; // 010 TESRegionList* regionList; // D00 NiTPrimitiveArray interiorCells; // D08 NiTPrimitiveArray addonNodes; // D20 diff --git a/include/RE/T/TypeInfo.cpp b/include/RE/T/TypeInfo.cpp index f8c8919cc..8c49b2ab0 100644 --- a/include/RE/T/TypeInfo.cpp +++ b/include/RE/T/TypeInfo.cpp @@ -80,7 +80,7 @@ namespace RE ObjectTypeInfo* TypeInfo::GetTypeInfo() const { assert(IsObject()); - return reinterpret_cast(GetRawType() & ~RawType::kObject); + return reinterpret_cast(stl::to_underlying(GetRawType()) & ~stl::to_underlying(RawType::kObject)); } auto TypeInfo::GetUnmangledRawType() const diff --git a/include/RE/V/Variable.cpp b/include/RE/V/Variable.cpp index a10c23f00..1eaa4fbcd 100644 --- a/include/RE/V/Variable.cpp +++ b/include/RE/V/Variable.cpp @@ -43,7 +43,7 @@ namespace RE Variable::~Variable() { Cleanup(); - memzero(this); + stl::memzero(this); } Variable& Variable::operator=(const Variable& a_rhs) diff --git a/include/REL/Relocation.cpp b/include/REL/Relocation.cpp index c7194dac7..bef39375e 100644 --- a/include/REL/Relocation.cpp +++ b/include/REL/Relocation.cpp @@ -132,7 +132,7 @@ namespace REL void Module::load_segments() { auto dosHeader = reinterpret_cast(_base); - auto ntHeader = adjust_pointer(dosHeader, dosHeader->e_lfanew); + auto ntHeader = stl::adjust_pointer(dosHeader, dosHeader->e_lfanew); const auto* sections = IMAGE_FIRST_SECTION(ntHeader); const auto size = std::min(ntHeader->FileHeader.NumberOfSections, _segments.size()); for (std::size_t i = 0; i < size; ++i) { diff --git a/include/REL/Relocation.h b/include/REL/Relocation.h index 48ef34671..5a75c374f 100644 --- a/include/REL/Relocation.h +++ b/include/REL/Relocation.h @@ -187,7 +187,7 @@ namespace REL std::aligned_storage_t result; using func_t = member_function_non_pod_type_t; - auto func = unrestricted_cast(std::forward(a_func)); + auto func = stl::unrestricted_cast(std::forward(a_func)); return func(std::forward(a_first), std::addressof(result), std::forward(a_rest)...); } @@ -205,7 +205,7 @@ namespace REL if constexpr (std::is_member_function_pointer_v>) { if constexpr (detail::is_x64_pod_v>) { // member functions == free functions in x64 using func_t = detail::member_function_pod_type_t>; - auto func = unrestricted_cast(std::forward(a_func)); + auto func = stl::unrestricted_cast(std::forward(a_func)); return func(std::forward(a_args)...); } else { // shift args to insert result return detail::invoke_member_function_non_pod(std::forward(a_func), std::forward(a_args)...); @@ -894,7 +894,7 @@ namespace REL noexcept(std::is_nothrow_copy_constructible_v) { assert(_impl != 0); - return unrestricted_cast(_impl); + return stl::unrestricted_cast(_impl); } template @@ -911,7 +911,7 @@ namespace REL std::uintptr_t write_vfunc(std::size_t a_idx, F a_newFunc) // requires(std::same_as) { - return write_vfunc(a_idx, unrestricted_cast(a_newFunc)); + return write_vfunc(a_idx, stl::unrestricted_cast(a_newFunc)); } private : diff --git a/include/SKSE/IAT.cpp b/include/SKSE/IAT.cpp index c7d6feda5..abebed10c 100644 --- a/include/SKSE/IAT.cpp +++ b/include/SKSE/IAT.cpp @@ -73,25 +73,25 @@ namespace SKSE return nullptr; } - auto ntHeader = adjust_pointer<::IMAGE_NT_HEADERS>(dosHeader, dosHeader->e_lfanew); + auto ntHeader = stl::adjust_pointer<::IMAGE_NT_HEADERS>(dosHeader, dosHeader->e_lfanew); auto& dataDir = ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]; - auto importDesc = adjust_pointer<::IMAGE_IMPORT_DESCRIPTOR>(dosHeader, dataDir.VirtualAddress); + auto importDesc = stl::adjust_pointer<::IMAGE_IMPORT_DESCRIPTOR>(dosHeader, dataDir.VirtualAddress); for (auto import = importDesc; import->Characteristics != 0; ++import) { - auto name = adjust_pointer(dosHeader, import->Name); + auto name = stl::adjust_pointer(dosHeader, import->Name); if (_stricmp(a_dll.data(), name) != 0) { continue; } - auto thunk = adjust_pointer<::IMAGE_THUNK_DATA>(dosHeader, import->OriginalFirstThunk); + auto thunk = stl::adjust_pointer<::IMAGE_THUNK_DATA>(dosHeader, import->OriginalFirstThunk); for (std::size_t i = 0; thunk[i].u1.Ordinal; ++i) { if (IMAGE_SNAP_BY_ORDINAL(thunk[i].u1.Ordinal)) { continue; } - auto importByName = adjust_pointer(dosHeader, thunk[i].u1.AddressOfData); + auto importByName = stl::adjust_pointer(dosHeader, thunk[i].u1.AddressOfData); if (_stricmp(a_function.data(), importByName->Name) == 0) { - return adjust_pointer<::IMAGE_THUNK_DATA>(dosHeader, import->FirstThunk) + i; + return stl::adjust_pointer<::IMAGE_THUNK_DATA>(dosHeader, import->FirstThunk) + i; } } } diff --git a/include/SKSE/IAT.h b/include/SKSE/IAT.h index 568cc1037..27a89e8a1 100644 --- a/include/SKSE/IAT.h +++ b/include/SKSE/IAT.h @@ -26,6 +26,6 @@ namespace SKSE template inline std::uintptr_t PatchIAT(F a_newFunc, std::string_view a_dll, std::string_view a_function) { - return PatchIAT(unrestricted_cast(a_newFunc), a_dll, a_function); + return PatchIAT(stl::unrestricted_cast(a_newFunc), a_dll, a_function); } } diff --git a/include/SKSE/Impl/PCH.h b/include/SKSE/Impl/PCH.h index 5e4af2af5..e1c34290e 100644 --- a/include/SKSE/Impl/PCH.h +++ b/include/SKSE/Impl/PCH.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -33,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -71,110 +73,26 @@ namespace SKSE using zstring = basic_zstring; using zwstring = basic_zstring; - struct source_location - { - public: - constexpr source_location() noexcept = default; - constexpr source_location(const source_location&) noexcept = default; - constexpr source_location(source_location&&) noexcept = default; - - ~source_location() noexcept = default; - - constexpr source_location& operator=(const source_location&) noexcept = default; - constexpr source_location& operator=(source_location&&) noexcept = default; - - [[nodiscard]] static constexpr source_location current( - std::uint_least32_t a_line = __builtin_LINE(), - std::uint_least32_t a_column = __builtin_COLUMN(), - const char* a_fileName = __builtin_FILE(), - const char* a_functionName = __builtin_FUNCTION()) noexcept { return { a_line, a_column, a_fileName, a_functionName }; } - - [[nodiscard]] constexpr std::uint_least32_t line() const noexcept { return _line; } - [[nodiscard]] constexpr std::uint_least32_t column() const noexcept { return _column; } - [[nodiscard]] constexpr const char* file_name() const noexcept { return _fileName; } - [[nodiscard]] constexpr const char* function_name() const noexcept { return _functionName; } - - protected: - constexpr source_location( - std::uint_least32_t a_line, - std::uint_least32_t a_column, - const char* a_fileName, - const char* a_functionName) noexcept : - _line(a_line), - _column(a_column), - _fileName(a_fileName), - _functionName(a_functionName) - {} - - private: - std::uint_least32_t _line{ 0 }; - std::uint_least32_t _column{ 0 }; - const char* _fileName{ "" }; - const char* _functionName{ "" }; - }; - - [[noreturn]] inline void report_and_fail(std::string_view a_msg, source_location a_loc = source_location::current()) - { - const auto body = [&]() { - constexpr std::array directories{ - "include/"sv, - "src/"sv, - }; - - const std::filesystem::path p = a_loc.file_name(); - const auto filename = p.generic_string(); - std::string_view fileview = filename; - - constexpr auto npos = std::string::npos; - std::size_t pos = npos; - std::size_t off = 0; - for (const auto& dir : directories) { - pos = fileview.find(dir); - if (pos != npos) { - off = dir.length(); - break; - } - } - - if (pos != npos) { - fileview = fileview.substr(pos + off); - } - - return fmt::format(FMT_STRING("{}({}): {}"), fileview, a_loc.line(), a_msg); - }(); - - const auto caption = []() -> std::string { - const auto maxPath = WinAPI::GetMaxPath(); - std::vector buf; - buf.reserve(maxPath); - buf.resize(maxPath / 2); - std::uint32_t result = 0; - do { - buf.resize(buf.size() * 2); - result = WinAPI::GetModuleFileName( - WinAPI::GetCurrentModule(), - buf.data(), - static_cast(buf.size())); - } while (result && result == buf.size() && buf.size() <= std::numeric_limits::max()); + // owning pointer + template < + class T, + class = std::enable_if_t< + std::is_pointer_v>> + using owner = T; - if (result && result != buf.size()) { - std::filesystem::path p(buf.begin(), buf.begin() + result); - return p.filename().string(); - } else { - return {}; - } - }(); + // non-owning pointer + template < + class T, + class = std::enable_if_t< + std::is_pointer_v>> + using observer = T; - spdlog::log( - spdlog::source_loc{ - a_loc.file_name(), - static_cast(a_loc.line()), - a_loc.function_name() }, - spdlog::level::critical, - a_msg); - WinAPI::MessageBox(nullptr, body.c_str(), (caption.empty() ? nullptr : caption.c_str()), 0); - WinAPI::TerminateProcess(WinAPI::GetCurrentProcess(), EXIT_FAILURE); - } + // non-null pointer + template < + class T, + class = std::enable_if_t< + std::is_pointer_v>> + using not_null = T; template // requires(std::invocable>) // @@ -258,7 +176,7 @@ namespace SKSE constexpr enumeration(enumeration&&) noexcept = default; - template + template // NOLINTNEXTLINE(google-explicit-constructor) constexpr enumeration(enumeration a_rhs) noexcept : _impl(static_cast(a_rhs.get())) {} @@ -341,45 +259,28 @@ namespace SKSE } } -#define SKSE_MAKE_LOGICAL_OP(a_op) \ - template < \ - class E, \ - class U1, \ - class U2> \ - [[nodiscard]] constexpr bool operator a_op(enumeration a_lhs, enumeration a_rhs) noexcept \ - { \ - return a_lhs.get() a_op a_rhs.get(); \ - } \ - \ - template < \ - class E, \ - class U> \ - [[nodiscard]] constexpr bool operator a_op(enumeration a_lhs, E a_rhs) noexcept \ - { \ - return a_lhs.get() a_op a_rhs; \ - } \ - \ - template < \ - class E, \ - class U> \ - [[nodiscard]] constexpr bool operator a_op(E a_lhs, enumeration a_rhs) noexcept \ - { \ - return a_lhs a_op a_rhs.get(); \ +#define SKSE_MAKE_LOGICAL_OP(a_op, a_result) \ + template \ + [[nodiscard]] constexpr a_result operator a_op(enumeration a_lhs, enumeration a_rhs) noexcept \ + { \ + return a_lhs.get() a_op a_rhs.get(); \ + } \ + \ + template \ + [[nodiscard]] constexpr a_result operator a_op(enumeration a_lhs, E a_rhs) noexcept \ + { \ + return a_lhs.get() a_op a_rhs; \ } #define SKSE_MAKE_ARITHMETIC_OP(a_op) \ - template < \ - class E, \ - class U> \ + template \ [[nodiscard]] constexpr auto operator a_op(enumeration a_enum, U a_shift) noexcept \ ->enumeration \ { \ return static_cast(static_cast(a_enum.get()) a_op a_shift); \ } \ \ - template < \ - class E, \ - class U> \ + template \ constexpr auto operator a_op##=(enumeration& a_enum, U a_shift) noexcept \ ->enumeration& \ { \ @@ -387,56 +288,42 @@ namespace SKSE } #define SKSE_MAKE_ENUMERATION_OP(a_op) \ - template < \ - class E, \ - class U1, \ - class U2> \ + template \ [[nodiscard]] constexpr auto operator a_op(enumeration a_lhs, enumeration a_rhs) noexcept \ ->enumeration> \ { \ return static_cast(static_cast(a_lhs.get()) a_op static_cast(a_rhs.get())); \ } \ \ - template < \ - class E, \ - class U> \ + template \ [[nodiscard]] constexpr auto operator a_op(enumeration a_lhs, E a_rhs) noexcept \ ->enumeration \ { \ return static_cast(static_cast(a_lhs.get()) a_op static_cast(a_rhs)); \ } \ \ - template < \ - class E, \ - class U> \ + template \ [[nodiscard]] constexpr auto operator a_op(E a_lhs, enumeration a_rhs) noexcept \ ->enumeration \ { \ return static_cast(static_cast(a_lhs) a_op static_cast(a_rhs.get())); \ } \ \ - template < \ - class E, \ - class U1, \ - class U2> \ + template \ constexpr auto operator a_op##=(enumeration& a_lhs, enumeration a_rhs) noexcept \ ->enumeration& \ { \ return a_lhs = a_lhs a_op a_rhs; \ } \ \ - template < \ - class E, \ - class U> \ + template \ constexpr auto operator a_op##=(enumeration& a_lhs, E a_rhs) noexcept \ ->enumeration& \ { \ return a_lhs = a_lhs a_op a_rhs; \ } \ \ - template < \ - class E, \ - class U> \ + template \ constexpr auto operator a_op##=(E& a_lhs, enumeration a_rhs) noexcept \ ->E& \ { \ @@ -444,18 +331,14 @@ namespace SKSE } #define SKSE_MAKE_INCREMENTER_OP(a_op) \ - template < \ - class E, \ - class U> \ + template \ constexpr auto operator a_op##a_op(enumeration& a_lhs) noexcept \ ->enumeration& \ { \ return a_lhs a_op## = static_cast(1); \ } \ \ - template < \ - class E, \ - class U> \ + template \ [[nodiscard]] constexpr auto operator a_op##a_op(enumeration& a_lhs, int) noexcept \ ->enumeration \ { \ @@ -477,12 +360,8 @@ namespace SKSE return static_cast(~static_cast(a_enum.get())); } - SKSE_MAKE_LOGICAL_OP(==); - SKSE_MAKE_LOGICAL_OP(!=); - SKSE_MAKE_LOGICAL_OP(<); - SKSE_MAKE_LOGICAL_OP(<=); - SKSE_MAKE_LOGICAL_OP(>); - SKSE_MAKE_LOGICAL_OP(>=); + SKSE_MAKE_LOGICAL_OP(==, bool); + SKSE_MAKE_LOGICAL_OP(<=>, std::strong_ordering); SKSE_MAKE_ARITHMETIC_OP(<<); SKSE_MAKE_ENUMERATION_OP(<<); @@ -501,15 +380,15 @@ namespace SKSE template class atomic_ref : - public std::atomic_ref> + public std::atomic_ref { private: - using super = std::atomic_ref>; + using super = std::atomic_ref; public: using value_type = typename super::value_type; - explicit atomic_ref(T& a_obj) noexcept(std::is_nothrow_constructible_v) : + explicit atomic_ref(volatile T& a_obj) noexcept(std::is_nothrow_constructible_v) : super(const_cast(a_obj)) {} @@ -518,7 +397,7 @@ namespace SKSE }; template - atomic_ref(T&) -> atomic_ref; + atomic_ref(volatile T&) -> atomic_ref; template class atomic_ref; template class atomic_ref; @@ -537,30 +416,6 @@ namespace SKSE static_assert(atomic_ref::is_always_lock_free); static_assert(atomic_ref::is_always_lock_free); static_assert(atomic_ref::is_always_lock_free); - } - - inline namespace util - { - // owning pointer - template < - class T, - class = std::enable_if_t< - std::is_pointer_v>> - using owner = T; - - // non-owning pointer - template < - class T, - class = std::enable_if_t< - std::is_pointer_v>> - using observer = T; - - // non-null pointer - template < - class T, - class = std::enable_if_t< - std::is_pointer_v>> - using not_null = T; template struct ssizeof @@ -575,285 +430,116 @@ namespace SKSE template inline constexpr auto ssizeof_v = ssizeof::value; - // + operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - [[nodiscard]] constexpr Enum operator+(Enum a_lhs, Enum a_rhs) noexcept - { - using underlying_type_t = std::underlying_type_t; - return static_cast( - static_cast(a_lhs) + - static_cast(a_rhs)); - } - - // += operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - constexpr Enum& operator+=(Enum& a_lhs, Enum a_rhs) noexcept - { - return a_lhs = a_lhs + a_rhs; - } - - // - operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - [[nodiscard]] constexpr Enum operator-(Enum a_lhs, Enum a_rhs) noexcept - { - using underlying_type_t = std::underlying_type_t; - return static_cast( - static_cast(a_lhs) - - static_cast(a_rhs)); - } - - // -= operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - constexpr Enum& operator-=(Enum& a_lhs, Enum a_rhs) noexcept - { - return a_lhs = a_lhs - a_rhs; - } - - // ~ operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - [[nodiscard]] constexpr Enum operator~(Enum a_val) noexcept - { - using underlying_type_t = std::underlying_type_t; - return static_cast(~static_cast(a_val)); - } - - // & operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - [[nodiscard]] constexpr Enum operator&(Enum a_lhs, Enum a_rhs) noexcept - { - using underlying_type_t = std::underlying_type_t; - return static_cast( - static_cast(a_lhs) & - static_cast(a_rhs)); - } - - // &= operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - constexpr Enum& operator&=(Enum& a_lhs, Enum a_rhs) noexcept - { - return a_lhs = a_lhs & a_rhs; - } - - // | operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - [[nodiscard]] constexpr Enum operator|(Enum a_lhs, Enum a_rhs) noexcept + template + [[nodiscard]] auto adjust_pointer(U* a_ptr, std::ptrdiff_t a_adjust) noexcept { - using underlying_type_t = std::underlying_type_t; - return static_cast( - static_cast(a_lhs) | - static_cast(a_rhs)); + auto addr = a_ptr ? reinterpret_cast(a_ptr) + a_adjust : 0; + if constexpr (std::is_const_v && std::is_volatile_v) { + return reinterpret_cast*>(addr); + } else if constexpr (std::is_const_v) { + return reinterpret_cast*>(addr); + } else if constexpr (std::is_volatile_v) { + return reinterpret_cast*>(addr); + } else { + return reinterpret_cast(addr); + } } - // |= operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - constexpr Enum& operator|=(Enum& a_lhs, Enum a_rhs) noexcept + template + void memzero(volatile T* a_ptr, std::size_t a_size = sizeof(T)) { - return a_lhs = a_lhs | a_rhs; + const auto begin = reinterpret_cast(a_ptr); + constexpr char val{ 0 }; + std::fill_n(begin, a_size, val); } - // ^ operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - [[nodiscard]] constexpr Enum operator^(Enum a_lhs, Enum a_rhs) noexcept + template + [[nodiscard]] inline auto pun_bits(Args... a_args) // + requires(std::same_as, bool>&&...) { - using underlying_type_t = std::underlying_type_t; - return static_cast( - static_cast(a_lhs) ^ - static_cast(a_rhs)); - } + constexpr auto ARGC = sizeof...(Args); - // ^= operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - constexpr Enum& operator^=(Enum& a_lhs, Enum a_rhs) noexcept - { - return a_lhs = a_lhs ^ a_rhs; - } + std::bitset bits; + std::size_t i = 0; + ((bits[i++] = a_args), ...); - // << operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - [[nodiscard]] constexpr Enum operator<<(Enum a_lhs, Enum a_rhs) noexcept - { - using underlying_type_t = std::underlying_type_t; - return static_cast( - static_cast(a_lhs) - << static_cast(a_rhs)); + if constexpr (ARGC <= std::numeric_limits::digits) { + return bits.to_ulong(); + } else if constexpr (ARGC <= std::numeric_limits::digits) { + return bits.to_ullong(); + } else { + static_assert(false && sizeof...(Args)); + } } - // <<= operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - constexpr Enum& operator<<=(Enum& a_lhs, Enum a_rhs) noexcept + [[noreturn]] inline void report_and_fail(std::string_view a_msg, std::source_location a_loc = std::source_location::current()) { - return a_lhs = a_lhs << a_rhs; - } + const auto body = [&]() { + constexpr std::array directories{ + "include/"sv, + "src/"sv, + }; - // >> operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - [[nodiscard]] constexpr Enum operator>>(Enum a_lhs, Enum a_rhs) noexcept - { - using underlying_type_t = std::underlying_type_t; - return static_cast( - static_cast(a_lhs) >> - static_cast(a_rhs)); - } + const std::filesystem::path p = a_loc.file_name(); + const auto filename = p.generic_string(); + std::string_view fileview = filename; - // >>= operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - constexpr Enum& operator>>=(Enum& a_lhs, Enum a_rhs) noexcept - { - return a_lhs = a_lhs >> a_rhs; - } + constexpr auto npos = std::string::npos; + std::size_t pos = npos; + std::size_t off = 0; + for (const auto& dir : directories) { + pos = fileview.find(dir); + if (pos != npos) { + off = dir.length(); + break; + } + } - // prefix ++ operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - constexpr Enum& operator++(Enum& a_this) noexcept - { - return a_this += static_cast(1); - } + if (pos != npos) { + fileview = fileview.substr(pos + off); + } - // postfix ++ operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - [[nodiscard]] constexpr Enum operator++(Enum& a_this, int) noexcept - { - auto tmp = a_this; - ++a_this; - return tmp; - } + return fmt::format(FMT_STRING("{}({}): {}"), fileview, a_loc.line(), a_msg); + }(); - // prefix -- operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - constexpr Enum& operator--(Enum& a_this) noexcept - { - return a_this -= static_cast(1); - } + const auto caption = []() -> std::string { + const auto maxPath = WinAPI::GetMaxPath(); + std::vector buf; + buf.reserve(maxPath); + buf.resize(maxPath / 2); + std::uint32_t result = 0; + do { + buf.resize(buf.size() * 2); + result = WinAPI::GetModuleFileName( + WinAPI::GetCurrentModule(), + buf.data(), + static_cast(buf.size())); + } while (result && result == buf.size() && buf.size() <= std::numeric_limits::max()); - // postfix ++ operator - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - [[nodiscard]] constexpr Enum operator--(Enum& a_this, int) noexcept - { - auto tmp = a_this; - --a_this; - return tmp; - } + if (result && result != buf.size()) { + std::filesystem::path p(buf.begin(), buf.begin() + result); + return p.filename().string(); + } else { + return {}; + } + }(); - template < - class Enum, - std::enable_if_t< - std::is_enum_v< - Enum>, - int> = 0> - [[nodiscard]] constexpr auto to_underlying(Enum a_val) noexcept - { - using underlying_type_t = std::underlying_type_t; - return static_cast(a_val); + spdlog::log( + spdlog::source_loc{ + a_loc.file_name(), + static_cast(a_loc.line()), + a_loc.function_name() }, + spdlog::level::critical, + a_msg); + WinAPI::MessageBox(nullptr, body.c_str(), (caption.empty() ? nullptr : caption.c_str()), 0); + WinAPI::TerminateProcess(WinAPI::GetCurrentProcess(), EXIT_FAILURE); } - template - [[nodiscard]] auto adjust_pointer(U* a_ptr, std::ptrdiff_t a_adjust) noexcept + template + [[nodiscard]] constexpr auto to_underlying(Enum a_val) noexcept // + requires(std::is_enum_v) { - auto addr = a_ptr ? reinterpret_cast(a_ptr) + a_adjust : 0; - if constexpr (std::is_const_v && std::is_volatile_v) { - return reinterpret_cast*>(addr); - } else if constexpr (std::is_const_v) { - return reinterpret_cast*>(addr); - } else if constexpr (std::is_volatile_v) { - return reinterpret_cast*>(addr); - } else { - return reinterpret_cast(addr); - } + return static_cast>(a_val); } template @@ -866,11 +552,11 @@ namespace SKSE // From != To } else if constexpr (std::is_reference_v) { - return unrestricted_cast(std::addressof(a_from)); + return stl::unrestricted_cast(std::addressof(a_from)); // From: NOT reference } else if constexpr (std::is_reference_v) { - return *unrestricted_cast< + return *stl::unrestricted_cast< std::add_pointer_t< std::remove_reference_t>>(a_from); @@ -894,40 +580,6 @@ namespace SKSE return to; } } - - template - void memzero(volatile T* a_ptr, std::size_t a_size = sizeof(T)) - { - const auto begin = reinterpret_cast(a_ptr); - constexpr char val{ 0 }; - std::fill_n(begin, a_size, val); - } - - template < - class... Args, - std::enable_if_t< - std::conjunction_v< - std::is_same< - bool, - std::remove_cv_t< - Args>>...>, - int> = 0> - [[nodiscard]] inline auto pun_bits(Args... a_args) - { - constexpr auto ARGC = sizeof...(Args); - - std::bitset bits; - std::size_t i = 0; - ((bits[i++] = a_args), ...); - - if constexpr (ARGC <= std::numeric_limits::digits) { - return bits.to_ulong(); - } else if constexpr (ARGC <= std::numeric_limits::digits) { - return bits.to_ullong(); - } else { - static_assert(false && sizeof...(Args)); - } - } } } @@ -938,18 +590,16 @@ namespace SKSE namespace RE { - using namespace ::std::literals; - using namespace ::SKSE::util; - namespace stl = ::SKSE::stl; - namespace WinAPI = ::SKSE::WinAPI; + using namespace std::literals; + namespace stl = SKSE::stl; + namespace WinAPI = SKSE::WinAPI; } namespace REL { - using namespace ::std::literals; - using namespace ::SKSE::util; - namespace stl = ::SKSE::stl; - namespace WinAPI = ::SKSE::WinAPI; + using namespace std::literals; + namespace stl = SKSE::stl; + namespace WinAPI = SKSE::WinAPI; } #include "REL/Relocation.h" diff --git a/include/SKSE/Logger.h b/include/SKSE/Logger.h index a3098b125..9bd62def3 100644 --- a/include/SKSE/Logger.h +++ b/include/SKSE/Logger.h @@ -3,20 +3,18 @@ #include "RE/B/BSTEvent.h" #include "RE/L/LogEvent.h" -// clang format chokes hard on classes with attributes -#define SKSE_MAYBE_UNUSED [[maybe_unused]] #define SKSE_MAKE_SOURCE_LOGGER(a_func, a_type) \ \ template \ - struct SKSE_MAYBE_UNUSED a_func \ + struct [[maybe_unused]] a_func \ { \ a_func() = delete; \ \ template \ - a_func( \ + explicit a_func( \ T&& a_fmt, \ Args&&... a_args, \ - stl::source_location a_loc = stl::source_location::current()) \ + std::source_location a_loc = std::source_location::current()) \ { \ spdlog::log( \ spdlog::source_loc{ \ @@ -32,37 +30,19 @@ template \ a_func(T&&, Args&&...) -> a_func; -namespace SKSE +namespace SKSE::log { - namespace log - { - SKSE_MAKE_SOURCE_LOGGER(trace, trace); - SKSE_MAKE_SOURCE_LOGGER(debug, debug); - SKSE_MAKE_SOURCE_LOGGER(info, info); - SKSE_MAKE_SOURCE_LOGGER(warn, warn); - SKSE_MAKE_SOURCE_LOGGER(error, err); - SKSE_MAKE_SOURCE_LOGGER(critical, critical); + SKSE_MAKE_SOURCE_LOGGER(trace, trace); + SKSE_MAKE_SOURCE_LOGGER(debug, debug); + SKSE_MAKE_SOURCE_LOGGER(info, info); + SKSE_MAKE_SOURCE_LOGGER(warn, warn); + SKSE_MAKE_SOURCE_LOGGER(error, err); + SKSE_MAKE_SOURCE_LOGGER(critical, critical); - [[nodiscard]] std::optional log_directory(); - } + [[nodiscard]] std::optional log_directory(); void add_papyrus_sink(std::regex a_filter); void remove_papyrus_sink(); } #undef SKSE_MAKE_SOURCE_LOGGER -#undef SKSE_MAYBE_UNUSED - -#define _DMESSAGE(a_fmt, ...) -#define _VMESSAGE(a_fmt, ...) -#define _MESSAGE(a_fmt, ...) -#define _WARNING(a_fmt, ...) -#define _ERROR(a_fmt, ...) -#define _FATALERROR(a_fmt, ...) - -#pragma deprecated("_DMESSAGE") -#pragma deprecated("_VMESSAGE") -#pragma deprecated("_MESSAGE") -#pragma deprecated("_WARNING") -#pragma deprecated("_ERROR") -#pragma deprecated("_FATALERROR") diff --git a/include/SKSE/Trampoline.h b/include/SKSE/Trampoline.h index 472cf6148..e17b712f0 100644 --- a/include/SKSE/Trampoline.h +++ b/include/SKSE/Trampoline.h @@ -150,7 +150,7 @@ namespace SKSE template std::uintptr_t write_branch(std::uintptr_t a_src, F a_dst) { - return write_branch(a_src, unrestricted_cast(a_dst)); + return write_branch(a_src, stl::unrestricted_cast(a_dst)); } template @@ -175,7 +175,7 @@ namespace SKSE template std::uintptr_t write_call(std::uintptr_t a_src, F a_dst) { - return write_call(a_src, unrestricted_cast(a_dst)); + return write_call(a_src, stl::unrestricted_cast(a_dst)); } private: