Skip to content

Commit

Permalink
Merge pull request #21 from qudix/dev
Browse files Browse the repository at this point in the history
feat: misc
  • Loading branch information
shad0wshayd3 authored Jun 10, 2024
2 parents 68478cf + d7ba6fe commit cc0444b
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 25 deletions.
39 changes: 39 additions & 0 deletions CommonLibF4/include/F4SE/Interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,49 @@ namespace F4SE
bool WriteRecord(std::uint32_t a_type, std::uint32_t a_version, const void* a_buf, std::uint32_t a_length) const;
bool OpenRecord(std::uint32_t a_type, std::uint32_t a_version) const;
bool WriteRecordData(const void* a_buf, std::uint32_t a_length) const;

template <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
bool WriteRecordData(const T& a_buf) const
{
return WriteRecordData(std::addressof(a_buf), sizeof(T));
}

template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
bool WriteRecordData(const T (&a_buf)[N]) const
{
return WriteRecordData(std::addressof(a_buf), sizeof(T) * N);
}

bool GetNextRecordInfo(std::uint32_t& a_type, std::uint32_t& a_version, std::uint32_t& a_length) const;

std::uint32_t ReadRecordData(void* a_buf, std::uint32_t a_length) const;

template <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
std::uint32_t ReadRecordData(T& a_buf) const
{
return ReadRecordData(std::addressof(a_buf), sizeof(T));
}

template <class T, std::enable_if_t<std::negation_v<std::is_pointer<T>>, int> = 0>
std::uint32_t ReadRecordDataEx(std::uint32_t& a_length, T& a_buf) const
{
a_length -= sizeof(T);
return ReadRecordData(std::addressof(a_buf), sizeof(T));
}

template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
std::uint32_t ReadRecordData(T (&a_buf)[N]) const
{
return ReadRecordData(std::addressof(a_buf), sizeof(T) * N);
}

template <class T, std::size_t N, std::enable_if_t<std::is_array_v<T>, int> = 0>
std::uint32_t ReadRecordDataEx(std::uint32_t& a_length, T (&a_buf)[N]) const
{
a_length -= sizeof(T);
return ReadRecordData(std::addressof(a_buf), sizeof(T) * N);
}

[[nodiscard]] std::optional<std::uint64_t> ResolveHandle(std::uint64_t a_handle) const
{
std::uint64_t result{ 0 };
Expand Down
7 changes: 7 additions & 0 deletions CommonLibF4/include/RE/Bethesda/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,13 @@ namespace RE
return func(this);
}

bool IsSneaking()
{
using func_t = decltype(&Actor::IsSneaking);
static REL::Relocation<func_t> func{ REL::ID(2207655) };
return func(this);
}

bool IsVisible() const
{
constexpr auto all = std::to_underlying(ACTOR_VISIBILITY_MASK::kAll);
Expand Down
2 changes: 1 addition & 1 deletion CommonLibF4/include/RE/Bethesda/BSScript/Stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace RE
[[nodiscard]] Variable& GetStackFrameVariable(const StackFrame* a_frame, std::uint32_t a_index, std::uint32_t a_pageHint)
{
using func_t = decltype(&Stack::GetStackFrameVariable);
static REL::Relocation<func_t> func{ REL::ID(897539) };
static REL::Relocation<func_t> func{ REL::ID(2314681) };
return func(this, a_frame, a_index, a_pageHint);
}

Expand Down
12 changes: 6 additions & 6 deletions CommonLibF4/include/RE/Bethesda/ControlMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace RE

[[nodiscard]] static ControlMap* GetSingleton()
{
static REL::Relocation<ControlMap**> singleton{ REL::ID(325206) };
static REL::Relocation<ControlMap**> singleton{ REL::ID(2692014) };
return *singleton;
}

Expand All @@ -87,35 +87,35 @@ namespace RE
bool PopInputContext(UserEvents::INPUT_CONTEXT_ID a_context)
{
using func_t = decltype(&ControlMap::PopInputContext);
static REL::Relocation<func_t> func{ REL::ID(74587) };
static REL::Relocation<func_t> func{ REL::ID(2268336) };
return func(this, a_context);
}

void PushInputContext(UserEvents::INPUT_CONTEXT_ID a_context)
{
using func_t = decltype(&ControlMap::PushInputContext);
static REL::Relocation<func_t> func{ REL::ID(1404410) };
static REL::Relocation<func_t> func{ REL::ID(2268335) };
return func(this, a_context);
}

bool RemapButton(BSFixedString const& a_id, INPUT_DEVICE a_device, std::int32_t a_buttonID)
{
using func_t = decltype(&ControlMap::RemapButton);
static REL::Relocation<func_t> func{ REL::ID(11351) };
static REL::Relocation<func_t> func{ REL::ID(0) };
return func(this, a_id, a_device, a_buttonID);
}

void SaveRemappings()
{
using func_t = decltype(&ControlMap::SaveRemappings);
static REL::Relocation<func_t> func{ REL::ID(1141541) };
static REL::Relocation<func_t> func{ REL::ID(0) };
return func(this);
}

void SetTextEntryMode(bool a_enable)
{
using func_t = decltype(&ControlMap::SetTextEntryMode);
static REL::Relocation<func_t> func{ REL::ID(1270079) };
static REL::Relocation<func_t> func{ REL::ID(0) };
return func(this, a_enable);
}

Expand Down
18 changes: 14 additions & 4 deletions CommonLibF4/include/RE/Bethesda/Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,18 +593,25 @@ namespace RE
};
static_assert(sizeof(TESDeathEvent) == 0x18);

struct TESEquipEvent
struct TESEnterSneakingEvent
{
public:
[[nodiscard]] static BSTEventSource<TESEquipEvent>* GetEventSource()
[[nodiscard]] static BSTEventSource<TESEnterSneakingEvent>* GetEventSource()
{
using func_t = decltype(&TESEquipEvent::GetEventSource);
using func_t = decltype(&TESEnterSneakingEvent::GetEventSource);
static REL::Relocation<func_t> func{ REL::ID(2201837) };
return func();
}

// members
NiPointer<TESObjectREFR> actor; // 00
};
static_assert(sizeof(TESEnterSneakingEvent) == 0x8);

struct TESEquipEvent
{
public:
// members
NiPointer<TESObjectREFR> actor; // 00
std::uint32_t baseObject; // 08
std::uint32_t originalRefr; // 0C
std::uint16_t uniqueID; // 10
Expand Down Expand Up @@ -643,6 +650,9 @@ namespace RE
return func();
}

[[nodiscard]] constexpr bool IsEnter() const noexcept { return type.all(FurnitureEventType::kEnter); }
[[nodiscard]] constexpr bool IsExit() const noexcept { return type.all(FurnitureEventType::kExit); }

// members
NiPointer<TESObjectREFR> actor; // 00
NiPointer<TESObjectREFR> targetFurniture; // 08
Expand Down
23 changes: 15 additions & 8 deletions CommonLibF4/include/RE/Bethesda/TESCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ namespace RE

[[nodiscard]] static PlayerCamera* GetSingleton()
{
static REL::Relocation<PlayerCamera**> singleton{ REL::ID(1171980) };
static REL::Relocation<PlayerCamera**> singleton{ REL::ID(2688801) };
return *singleton;
}

Expand All @@ -193,52 +193,59 @@ namespace RE
TESCameraState* PopState()
{
using func_t = decltype(&PlayerCamera::PopState);
static REL::Relocation<func_t> func{ REL::ID(120998) };
static REL::Relocation<func_t> func{ REL::ID(2248424) };
return func(this);
}

TESCameraState* PushState(CameraState a_state)
{
using func_t = decltype(&PlayerCamera::PushState);
static REL::Relocation<func_t> func{ REL::ID(746523) };
static REL::Relocation<func_t> func{ REL::ID(0) };
return func(this, a_state);
}

void ToggleFreeCameraMode(bool a_freezeTime)
{
using func_t = decltype(&PlayerCamera::ToggleFreeCameraMode);
static REL::Relocation<func_t> func{ REL::ID(224913) };
static REL::Relocation<func_t> func{ REL::ID(2248368) };
return func(this, a_freezeTime);
}

void SetState(TESCameraState* a_newstate) const
{
using func_t = decltype(&PlayerCamera::SetState);
static REL::Relocation<func_t> func{ REL::ID(858847) };
static REL::Relocation<func_t> func{ REL::ID(2214742) };
return func(this, a_newstate);
}

void StartFurnitureMode(TESObjectREFR* a_furniture)
{
using func_t = decltype(&PlayerCamera::StartFurnitureMode);
static REL::Relocation<func_t> func{ REL::ID(10202) };
static REL::Relocation<func_t> func{ REL::ID(0) };
return func(this, a_furniture);
}

void StartPipboyMode(bool a_forcePipboyModeCamera)
{
using func_t = decltype(&PlayerCamera::StartPipboyMode);
static REL::Relocation<func_t> func{ REL::ID(998069) };
static REL::Relocation<func_t> func{ REL::ID(2248358) };
return func(this, a_forcePipboyModeCamera);
}

void StopPipboyMode()
{
using func_t = decltype(&PlayerCamera::StopPipboyMode);
static REL::Relocation<func_t> func{ REL::ID(811954) };
static REL::Relocation<func_t> func{ REL::ID(2248359) };
return func(this);
}

bool QCameraEquals(CameraState a_state)
{
using func_t = decltype(&PlayerCamera::QCameraEquals);
static REL::Relocation<func_t> func{ REL::ID(2248421) };
return func(this, a_state);
}

// members
ActorHandle cameraTarget; // 064
BSTSmallArray<BSTSmartPointer<TESCameraState>, CameraStates::kTotal> tempReturnStates; // 068
Expand Down
7 changes: 1 addition & 6 deletions CommonLibF4/src/F4SE/Interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,10 @@ namespace F4SE

bool SerializationInterface::GetNextRecordInfo(std::uint32_t& a_type, std::uint32_t& a_version, std::uint32_t& a_length) const
{
const auto success =
GetProxy().GetNextRecordInfo(
return GetProxy().GetNextRecordInfo(
std::addressof(a_type),
std::addressof(a_version),
std::addressof(a_length));
if (!success) {
log::warn("failed to get next record info"sv);
}
return success;
}

std::uint32_t SerializationInterface::ReadRecordData(void* a_buf, std::uint32_t a_length) const
Expand Down

0 comments on commit cc0444b

Please sign in to comment.