Skip to content

Commit

Permalink
Merge pull request #107 from qudix/upstream-po3-dev-pr
Browse files Browse the repository at this point in the history
Changes, Improvements, and XMake
  • Loading branch information
powerof3 authored Mar 4, 2024
2 parents 9a95e69 + bbdfa49 commit 6f144cc
Show file tree
Hide file tree
Showing 45 changed files with 661 additions and 301 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# dot folders
.vs/
.vs*/
.vscode/
.xmake/

# folders
build/
out/
build*/
out*/
vs*/

# files
*.zip
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ target_compile_definitions(
target_compile_features(
"${PROJECT_NAME}"
PUBLIC
cxx_std_20
cxx_std_23
)

if (MSVC)
Expand Down Expand Up @@ -135,6 +135,7 @@ install(
DIRECTORY
"include/RE"
"include/REL"
"include/REX"
"include/SKSE"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# `CommonLibSSE`
[![C++20](https://img.shields.io/static/v1?label=standard&message=C%2B%2B20&color=blue&logo=c%2B%2B&&logoColor=white&style=flat)](https://en.cppreference.com/w/cpp/compiler_support)
[![C++23](https://img.shields.io/static/v1?label=standard&message=C%2B%2B20&color=blue&logo=c%2B%2B&&logoColor=white&style=flat)](https://en.cppreference.com/w/cpp/compiler_support)
[![Platform](https://img.shields.io/static/v1?label=platform&message=windows&color=dimgray&style=flat)](#)
[![Main CI](https://github.com/dann1/CommonLibSSE/actions/workflows/main_ci.yml/badge.svg?branch=dev)](https://github.com/dann1/CommonLibSSE/actions/workflows/main_ci.yml?branch=dev)

Expand Down
2 changes: 2 additions & 0 deletions cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,8 @@ set(SOURCES
src/RE/Z/ZeroFunctionArguments.cpp
src/REL/ID.cpp
src/REL/Module.cpp
src/REL/Relocation.cpp
src/REL/Version.cpp
src/REX/W32/ADVAPI32.cpp
src/REX/W32/D3D11.cpp
src/REX/W32/D3DCOMPILER.cpp
Expand Down
2 changes: 1 addition & 1 deletion include/RE/A/ActorValueList.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace RE
// members
std::uint32_t unk00; // 00
std::uint32_t pad04; // 04
ActorValueInfo* actorValues[stl::to_underlying(ActorValue::kTotal)]; // 08
ActorValueInfo* actorValues[std::to_underlying(ActorValue::kTotal)]; // 08
};
}

Expand Down
6 changes: 3 additions & 3 deletions include/RE/B/BGSDefaultObjectManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,17 +442,17 @@ namespace RE
return func();
}

[[nodiscard]] TESForm* GetObject(DefaultObject a_object) const noexcept { return GetObject(stl::to_underlying(a_object)); }
[[nodiscard]] TESForm* GetObject(DefaultObject a_object) const noexcept { return GetObject(std::to_underlying(a_object)); }

template <class T>
[[nodiscard]] T* GetObject(DefaultObject a_object) const noexcept
{
return GetObject<T>(stl::to_underlying(a_object));
return GetObject<T>(std::to_underlying(a_object));
}

[[nodiscard]] TESForm* GetObject(std::size_t a_idx) const noexcept
{
assert(a_idx < stl::to_underlying(DefaultObject::kTotal));
assert(a_idx < std::to_underlying(DefaultObject::kTotal));
return objectInit[a_idx] ? objects[a_idx] : nullptr;
}

Expand Down
2 changes: 1 addition & 1 deletion include/RE/B/BGSEntryPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace RE
{
using func_t = decltype(&BGSEntryPoint::HandleEntryPoint<Args...>);
REL::Relocation<func_t> func{ RELOCATION_ID(23073, 23526) };
return func(a_entryPoint, a_perkOwner, a_args...);
func(a_entryPoint, a_perkOwner, a_args...);
}
};
}
4 changes: 2 additions & 2 deletions include/RE/B/BSStringPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ namespace RE
{
using func_t = decltype(&Entry::release8);
REL::Relocation<func_t> func{ RELOCATION_ID(67847, 69192) };
return func(a_entry);
func(a_entry);
}

static inline void release16(const wchar_t*& a_entry)
{
using func_t = decltype(&Entry::release16);
REL::Relocation<func_t> func{ RELOCATION_ID(67848, 69193) };
return func(a_entry);
func(a_entry);
}

inline void acquire()
Expand Down
2 changes: 1 addition & 1 deletion include/RE/G/GFxTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace RE

inline TaskId GetTaskType() const
{
return static_cast<TaskId>(stl::to_underlying(thisTaskId) & stl::to_underlying(TaskId::kType_Mask));
return static_cast<TaskId>(std::to_underlying(thisTaskId) & std::to_underlying(TaskId::kType_Mask));
}

inline TaskState GetTaskState() const
Expand Down
2 changes: 1 addition & 1 deletion include/RE/M/MiddleHighProcessData.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace RE
BSTArray<BGSPerkEntry*>& operator[](BGSEntryPoint::ENTRY_POINT a_pos)
{
assert(a_pos < BGSEntryPoint::ENTRY_POINT::kTotal);
return perkEntryArrays[stl::to_underlying(a_pos)];
return perkEntryArrays[std::to_underlying(a_pos)];
}

// members
Expand Down
2 changes: 1 addition & 1 deletion include/RE/Offsets.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "REL/Relocation.h"
#include "REL/ID.h"

namespace RE
{
Expand Down
2 changes: 1 addition & 1 deletion include/RE/Offsets_NiRTTI.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "REL/Relocation.h"
#include "REL/ID.h"

namespace RE
{
Expand Down
2 changes: 1 addition & 1 deletion include/RE/Offsets_RTTI.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "REL/Relocation.h"
#include "REL/ID.h"

namespace RE
{
Expand Down
2 changes: 1 addition & 1 deletion include/RE/Offsets_VTABLE.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "REL/Relocation.h"
#include "REL/ID.h"

namespace RE
{
Expand Down
2 changes: 1 addition & 1 deletion include/RE/T/TESDataHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace RE
std::uint16_t pad002; // 002
std::uint32_t pad004; // 004
TESObjectList* objectList; // 008
BSTArray<TESForm*> formArrays[stl::to_underlying(FormType::Max)]; // 010
BSTArray<TESForm*> formArrays[std::to_underlying(FormType::Max)]; // 010
TESRegionList* regionList; // D00
NiTPrimitiveArray<TESObjectCELL*> interiorCells; // D08
NiTPrimitiveArray<BGSAddonNode*> addonNodes; // D20
Expand Down
3 changes: 2 additions & 1 deletion include/RE/T/TESForm.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "RE/B/BSAtomic.h"
#include "RE/B/BSCoreTypes.h"
#include "RE/B/BSFixedString.h"
#include "RE/B/BSTArray.h"
#include "RE/B/BSTHashMap.h"
Expand Down Expand Up @@ -183,7 +184,7 @@ namespace RE
{
using func_t = decltype(&TESForm::AddCompileIndex);
REL::Relocation<func_t> func{ RELOCATION_ID(14509, 14667) };
return func(a_id, a_file);
func(a_id, a_file);
}

[[nodiscard]] static auto GetAllForms()
Expand Down
2 changes: 1 addition & 1 deletion include/RE/T/TESFullName.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace RE
{
using func_t = decltype(&TESFullName::SetFullName);
REL::Relocation<func_t> func{ RELOCATION_ID(22318, 22791) };
return func(this, a_name);
func(this, a_name);
}

// members
Expand Down
1 change: 1 addition & 0 deletions include/RE/T/TESObjectREFR.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ namespace RE
bool MoveToNode(TESObjectREFR* a_target, const BSFixedString& a_nodeName);
bool MoveToNode(TESObjectREFR* a_target, NiAVObject* a_node);
bool NameIncludes(std::string a_word);
void OpenContainer(std::int32_t a_openType) const;
NiPointer<TESObjectREFR> PlaceObjectAtMe(TESBoundObject* a_baseToPlace, bool a_forcePersist) const;
void PlayAnimation(stl::zstring a_from, stl::zstring a_to);
void PlayAnimation(NiControllerManager* a_manager, NiControllerSequence* a_toSeq, NiControllerSequence* a_fromSeq);
Expand Down
2 changes: 1 addition & 1 deletion include/REL/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace REL

void load_version()
{
const auto version = get_file_version(_filename);
const auto version = GetFileVersion(_filename);
if (version) {
_version = *version;
} else {
Expand Down
96 changes: 61 additions & 35 deletions include/REL/Relocation.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

#include "REX/W32/KERNEL32.h"
#include "REL/Module.h"

#include "SKSE/Trampoline.h"

#define REL_MAKE_MEMBER_FUNCTION_POD_TYPE_HELPER_IMPL(a_nopropQual, a_propQual, ...) \
template < \
Expand Down Expand Up @@ -187,19 +189,7 @@ namespace REL
}
}

inline void safe_write(std::uintptr_t a_dst, const void* a_src, std::size_t a_count)
{
std::uint32_t old{ 0 };
bool success = REX::W32::VirtualProtect(
reinterpret_cast<void*>(a_dst), a_count, REX::W32::PAGE_EXECUTE_READWRITE, std::addressof(old));
if (success) {
std::memcpy(reinterpret_cast<void*>(a_dst), a_src, a_count);
success = REX::W32::VirtualProtect(
reinterpret_cast<void*>(a_dst), a_count, old, std::addressof(old));
}

assert(success);
}
void safe_write(std::uintptr_t a_dst, const void* a_src, std::size_t a_count);

template <std::integral T>
void safe_write(std::uintptr_t a_dst, const T& a_data)
Expand All @@ -213,21 +203,9 @@ namespace REL
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)
{
std::uint32_t old{ 0 };
bool success = REX::W32::VirtualProtect(
reinterpret_cast<void*>(a_dst), a_count, REX::W32::PAGE_EXECUTE_READWRITE, std::addressof(old));
if (success) {
std::fill_n(reinterpret_cast<std::uint8_t*>(a_dst), a_count, a_value);
success = REX::W32::VirtualProtect(
reinterpret_cast<void*>(a_dst), a_count, old, std::addressof(old));
}
void safe_fill(std::uintptr_t a_dst, std::uint8_t a_value, std::size_t a_count);

assert(success);
}

template <class T>
template <class T = std::uintptr_t>
class Relocation
{
public:
Expand Down Expand Up @@ -274,22 +252,22 @@ namespace REL
}

template <class U = value_type>
[[nodiscard]] decltype(auto) operator*() const noexcept //
[[nodiscard]] decltype(auto) operator*() const noexcept
requires(std::is_pointer_v<U>)
{
return *get();
}

template <class U = value_type>
[[nodiscard]] auto operator->() const noexcept //
[[nodiscard]] auto operator->() const noexcept
requires(std::is_pointer_v<U>)
{
return get();
}

template <class... Args>
std::invoke_result_t<const value_type&, Args...> operator()(Args&&... a_args) const //
noexcept(std::is_nothrow_invocable_v<const value_type&, Args...>) //
std::invoke_result_t<const value_type&, Args...> operator()(Args&&... a_args) const
noexcept(std::is_nothrow_invocable_v<const value_type&, Args...>)
requires(std::invocable<const value_type&, Args...>)
{
return REL::invoke(get(), std::forward<Args>(a_args)...);
Expand All @@ -298,15 +276,63 @@ namespace REL
[[nodiscard]] constexpr std::uintptr_t address() const noexcept { return _impl; }
[[nodiscard]] std::size_t offset() const { return _impl - base(); }

[[nodiscard]] value_type get() const //
[[nodiscard]] value_type get() const
noexcept(std::is_nothrow_copy_constructible_v<value_type>)
{
assert(_impl != 0);
return stl::unrestricted_cast<value_type>(_impl);
}

template <std::integral U>
void write(const U& a_data)
requires(std::same_as<value_type, std::uintptr_t>)
{
safe_write(address(), std::addressof(a_data), sizeof(T));
}

template <class U>
void write(const std::span<U> a_data)
requires(std::same_as<value_type, std::uintptr_t>)
{
safe_write(address(), a_data.data(), a_data.size_bytes());
}

template <std::size_t N>
std::uintptr_t write_branch(const std::uintptr_t a_dst)
requires(std::same_as<value_type, std::uintptr_t>)
{
return SKSE::GetTrampoline().write_branch<N>(address(), a_dst);
}

template <std::size_t N, class F>
std::uintptr_t write_branch(const F a_dst)
requires(std::same_as<value_type, std::uintptr_t>)
{
return SKSE::GetTrampoline().write_branch<N>(address(), stl::unrestricted_cast<std::uintptr_t>(a_dst));
}

template <std::size_t N>
std::uintptr_t write_call(const std::uintptr_t a_dst)
requires(std::same_as<value_type, std::uintptr_t>)
{
return SKSE::GetTrampoline().write_call<N>(address(), a_dst);
}

template <std::size_t N, class F>
std::uintptr_t write_call(const F a_dst)
requires(std::same_as<value_type, std::uintptr_t>)
{
return SKSE::GetTrampoline().write_call<N>(address(), stl::unrestricted_cast<std::uintptr_t>(a_dst));
}

void write_fill(const std::uint8_t a_value, const std::size_t a_count)
requires(std::same_as<value_type, std::uintptr_t>)
{
safe_fill(address(), a_value, a_count);
}

template <class U = value_type>
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<U, std::uintptr_t>)
{
const auto addr = address() + (sizeof(void*) * a_idx);
Expand All @@ -316,7 +342,7 @@ namespace REL
}

template <class F>
std::uintptr_t write_vfunc(std::size_t a_idx, F a_newFunc) //
std::uintptr_t write_vfunc(const std::size_t a_idx, const F a_newFunc)
requires(std::same_as<value_type, std::uintptr_t>)
{
return write_vfunc(a_idx, stl::unrestricted_cast<std::uintptr_t>(a_newFunc));
Expand Down
Loading

0 comments on commit 6f144cc

Please sign in to comment.