27 Segment(
std::uintptr_t a_proxyBase,
std::uintptr_t a_address,
std::uintptr_t a_size) noexcept :
28 _proxyBase(a_proxyBase),
33 [[nodiscard]] std::uintptr_t
address() const noexcept {
return _address; }
34 [[nodiscard]] std::size_t
offset() const noexcept {
return address() - _proxyBase; }
35 [[nodiscard]] std::size_t
size() const noexcept {
return _size; }
37 [[nodiscard]]
void*
pointer() const noexcept {
return reinterpret_cast<void*
>(
address()); }
42 return static_cast<T*
>(
pointer());
46 std::uintptr_t _proxyBase{ 0 };
47 std::uintptr_t _address{ 0 };
48 std::size_t _size{ 0 };
60 [[nodiscard]] std::uintptr_t
base() const noexcept {
return _base; }
71 return static_cast<T*
>(
pointer());
77 const auto getFilename = [&]() {
81 static_cast<std::uint32_t
>(_filename.size()));
84 _filename.resize(getFilename());
85 if (
const auto result = getFilename();
86 result != _filename.size() - 1 ||
89 _filename = L
"SkyrimSE.exe"sv;
91 _filename = L
"SkyrimVR.exe"sv;
98 Module(
const Module&) =
delete;
99 Module(Module&&) =
delete;
101 ~Module() noexcept = default;
103 Module& operator=(const Module&) = delete;
104 Module& operator=(Module&&) = delete;
109 if (handle ==
nullptr) {
112 "Failed to obtain module handle for: \"{0}\".\n"
113 "You have likely renamed the executable to something unexpected. "
114 "Renaming the executable back to \"{0}\" may resolve the issue."sv,
117 _base =
reinterpret_cast<std::uintptr_t
>(handle);
123 void load_segments();
133 "Failed to obtain file version info for: {}\n"
134 "Please contact the author of this script extender plugin for further assistance."sv,
139 static constexpr std::array SEGMENTS{
141 std::make_pair(
".idata"sv, 0u),
142 std::make_pair(
".rdata"sv, 0u),
143 std::make_pair(
".data"sv, 0u),
144 std::make_pair(
".pdata"sv, 0u),
145 std::make_pair(
".tls"sv, 0u),
147 std::make_pair(
".gfids"sv, 0u)
150 static constexpr auto ENVIRONMENT = L
"SKSE_RUNTIME"sv;
152 std::wstring _filename;
153 std::array<Segment, Segment::total> _segments;
155 std::uintptr_t _base{ 0 };
Version version() const noexcept
Definition Module.h:62
T * pointer() const noexcept
Definition Module.h:69
std::uintptr_t base() const noexcept
Definition Module.h:60
stl::zwstring filename() const noexcept
Definition Module.h:61
REX::W32::HMODULE pointer() const noexcept
Definition Module.h:66
static Module & get()
Definition Module.h:54
Segment segment(Segment::Name a_segment) const noexcept
Definition Module.h:64
std::size_t size() const noexcept
Definition Module.h:35
Name
Definition Module.h:13
@ data
Definition Module.h:17
@ tls
Definition Module.h:19
@ textw
Definition Module.h:20
@ gfids
Definition Module.h:21
@ total
Definition Module.h:22
@ idata
Definition Module.h:15
@ textx
Definition Module.h:14
@ pdata
Definition Module.h:18
@ rdata
Definition Module.h:16
void * pointer() const noexcept
Definition Module.h:37
std::uintptr_t address() const noexcept
Definition Module.h:33
Segment() noexcept=default
std::size_t offset() const noexcept
Definition Module.h:34
T * pointer() const noexcept
Definition Module.h:40
std::optional< Version > GetFileVersion(stl::zwstring a_filename)
constexpr auto IMAGE_SCN_MEM_EXECUTE
Definition KERNEL32.h:96
constexpr auto IMAGE_SCN_MEM_WRITE
Definition KERNEL32.h:98
HINSTANCE HMODULE
Definition BASE.h:24
HMODULE GetModuleHandleW(const wchar_t *a_name) noexcept
std::uint32_t GetEnvironmentVariableW(const wchar_t *a_name, wchar_t *a_buf, std::uint32_t a_bufLen) noexcept
void report_and_fail(std::string_view a_msg, std::source_location a_loc=std::source_location::current())
Definition PCH.h:397
auto utf16_to_utf8(std::wstring_view a_in) noexcept -> std::optional< std::string >
Definition PCH.h:369
basic_zstring< wchar_t > zwstring
Definition PCH.h:83
Definition EffectArchetypes.h:65