Skip to content

Commit

Permalink
Update shared lib
Browse files Browse the repository at this point in the history
  • Loading branch information
psiberx committed Aug 6, 2023
1 parent 73bf934 commit ac86029
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
8 changes: 6 additions & 2 deletions lib/Core/Foundation/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@ void Core::Application::Bootstrap()

m_booted = true;

OnStarting();

for (const auto& feature : GetRegistered())
{
feature->OnBootstrap();
}

OnBootstrap();
OnStarted();
}

void Core::Application::Shutdown()
{
if (!m_booted)
return;

OnShutdown();
OnStopping();

for (const auto& feature : GetRegistered())
{
feature->OnShutdown();
}

OnStopped();

m_booted = false;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/Core/Foundation/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ class Application : public Registry<Feature>
protected:
void OnRegistered(const Core::SharedPtr<Feature>& aFeature) override;

virtual void OnBootstrap() {};
virtual void OnShutdown() {};
virtual void OnStarting() {};
virtual void OnStarted() {};
virtual void OnStopping() {};
virtual void OnStopped() {};

private:
bool m_booted = false;
Expand Down
30 changes: 26 additions & 4 deletions lib/Core/Raw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ class RawFunc<A, R (C::*)(Args...)> : public RawFunc<A, R (*)(C*, Args...)>
using Base::Base;
};

template<uintptr_t A, typename T>
class RawVFunc {};

template<uintptr_t A, typename C, typename R, typename... Args>
class RawVFunc<A, R (C::*)(Args...)> : public RawBase
{
public:
using Type = R (*)(C*, Args...);
using Callable = Type;

static constexpr uintptr_t offset = A;

constexpr RawVFunc() = default;

R operator()(C* aContext, Args&&... aArgs) const
{
auto vft = *reinterpret_cast<uintptr_t*>(aContext);
auto callable = *reinterpret_cast<Callable*>(vft + offset);
return callable(aContext, std::forward<Args>(aArgs)...);
}
};

template<uintptr_t A, typename T>
class RawPtr : public RawBase
{
Expand Down Expand Up @@ -167,12 +189,12 @@ class OffsetPtr
static constexpr bool indirect = std::is_pointer_v<T>;

constexpr OffsetPtr(uintptr_t aBase)
: addr(aBase + offset)
: address(aBase + offset)
{
}

constexpr OffsetPtr(void* aBase)
: addr(reinterpret_cast<uintptr_t>(aBase) + offset)
: address(reinterpret_cast<uintptr_t>(aBase) + offset)
{
}

Expand Down Expand Up @@ -234,7 +256,7 @@ class OffsetPtr

[[nodiscard]] inline uintptr_t GetAddress() const noexcept
{
return addr;
return address;
}

inline static Type* Get(void* aBase)
Expand All @@ -247,6 +269,6 @@ class OffsetPtr
return OffsetPtr(aBase);
}

uintptr_t addr;
uintptr_t address;
};
}
24 changes: 22 additions & 2 deletions lib/Red/TypeInfo/Invocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ namespace Red
{
namespace Detail
{
constexpr auto TDBIDHelper = Red::CName("gamedataTDBIDHelper");

constexpr bool IsFakeStatic(Red::CName aTypeName)
{
return aTypeName == TDBIDHelper;
}

inline CBaseFunction* GetFunction(CClass* aType, CName aName)
{
if (aType)
Expand Down Expand Up @@ -39,6 +46,11 @@ inline CBaseFunction* GetStaticFunction(CClass* aType, CName aName)
}
}

if (IsFakeStatic(aType->name))
{
return GetFunction(aType, aName);
}

if (aType->parent)
{
return GetStaticFunction(aType->parent, aName);
Expand Down Expand Up @@ -73,8 +85,16 @@ inline bool CallFunction(CBaseFunction* aFunc, IScriptable* aContext, Args&&...
{
const auto& func = reinterpret_cast<Red::CClassFunction*>(aFunc);

if (!aContext || !aContext->GetType()->IsA(func->parent))
return false;
if (!IsFakeStatic(func->parent->name))
{
if (!aContext || !aContext->GetType()->IsA(func->parent))
return false;
}
else
{
static char s_dummyContext[sizeof(Red::IScriptable)]{};
aContext = reinterpret_cast<IScriptable*>(&s_dummyContext);
}
}

CStack stack(aContext);
Expand Down

0 comments on commit ac86029

Please sign in to comment.