-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathUtils.h
79 lines (61 loc) · 2.51 KB
/
Utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include <optional>
#include "VersionDb.h"
#include "World.h"
#define POINTER_SKYRIMSE(className, variableName, ...) static VersionDbPtr<className> variableName(__VA_ARGS__)
#define POINTER_SKYRIMSE_LEGACY(className, variableName, ...) static AutoPtr<decltype()> variableName(__VA_ARGS__)
// TODO: should this be debug only? I removed the check since debug is broken, can only use releasedbg
#define TP_ASSERT(Expr, Msg, ...) \
if (!(Expr)) \
{ \
Utils::Assert(#Expr, fmt::format(Msg, __VA_ARGS__).c_str()); \
}
struct TESForm;
namespace Utils
{
static void Assert(const char* apExpression, const char* apMessage)
{
spdlog::critical("Assertion failed ({}): {}", apExpression, apMessage);
if (IsDebuggerPresent())
__debugbreak();
}
std::optional<uint32_t> GetServerId(entt::entity aEntity) noexcept;
template <class T> T* GetByServerId(const uint32_t acServerId) noexcept
{
auto view = World::Get().view<FormIdComponent>();
for (entt::entity entity : view)
{
std::optional<uint32_t> serverIdRes = GetServerId(entity);
if (!serverIdRes.has_value())
continue;
uint32_t serverId = serverIdRes.value();
if (serverId == acServerId)
{
const auto& formIdComponent = view.get<FormIdComponent>(entity);
TESForm* pForm = TESForm::GetById(formIdComponent.Id);
if (pForm != nullptr)
{
return Cast<T>(pForm);
}
}
}
spdlog::warn("Form not found for server id {:X}", acServerId);
return nullptr;
}
void ShowHudMessage(const TiltedPhoques::String& acMessage);
} // namespace Utils
namespace TiltedPhoques
{
template <class TFunc, class TThis, class... TArgs> constexpr decltype(auto) ThisCall(TFunc* aFunction, VersionDbPtr<TThis>& aThis, TArgs&&... args) noexcept
{
return ThisCall(aFunction, aThis.Get(), args...);
}
template <class TFunc, class TThis, class... TArgs> constexpr decltype(auto) ThisCall(VersionDbPtr<TFunc>& aFunction, VersionDbPtr<TThis>& aThis, TArgs&&... args) noexcept
{
return ThisCall(aFunction.Get(), aThis.Get(), args...);
}
template <class TFunc, class TThis, class... TArgs> constexpr decltype(auto) ThisCall(VersionDbPtr<TFunc>& aFunction, TThis* apThis, TArgs&&... args) noexcept
{
return ThisCall(aFunction.Get(), apThis, args...);
}
} // namespace TiltedPhoques