Skip to content

Instantly share code, notes, and snippets.

@martonp96
Created October 22, 2022 12:24
Show Gist options
  • Save martonp96/bf93a51d07da27caf065cc5ea2e1a853 to your computer and use it in GitHub Desktop.
Save martonp96/bf93a51d07da27caf065cc5ea2e1a853 to your computer and use it in GitHub Desktop.
test
#include "stdafx.h"
#include "memory/CMemory.h"
#include <RED4ext/RED4ext.hpp>
#include <RED4ext/Scripting/Natives/Generated/Color.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/CompoundWidget.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/IWidgetController.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/TextWidget.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/Widget.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/EffectType.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/anim/Proxy.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/anim/Definition.hpp>
#include <RED4ext/Scripting/Natives/Generated/ink/anim/PlaybackOptions.hpp>
#include <RED4ext/Scripting/Natives/Generated/red/ResourceReferenceScriptToken.hpp>
#include <RED4ext/Scripting/Natives/Generated/text/TextParameterSet.hpp>
using namespace RED4ext;
class IScriptableWrapper
{
private:
IScriptable* instance;
RED4ext::Handle<IScriptable> handle;
protected:
IScriptableWrapper(const char* typeName) :
instance((IScriptable*)CRTTISystem::Get()->GetClass(typeName)->AllocInstance()),
handle(instance) {}
public:
template<class T = IScriptable>
inline T* GetInstance()
{
return (T*)instance;
}
};
class inkWidgetWrapper : public IScriptableWrapper
{
protected:
inkWidgetWrapper(const char* typeName) : IScriptableWrapper(typeName) {}
public:
inkWidgetWrapper() : IScriptableWrapper(ink::Widget::NAME) {}
inline void Reparent(WeakHandle<ink::CompoundWidget> newParent, int32_t index = -1)
{
GetInstance()->ExecuteFunction(__func__, newParent, index);
}
inline void SetAnchor(ink::EAnchor anchor)
{
GetInstance()->ExecuteFunction(__func__, anchor);
}
inline void SetAnchorPoint(Vector2 anchorPoint)
{
GetInstance()->ExecuteFunction(__func__, anchorPoint);
}
void SetTintColor(HDRColor color)
{
GetInstance()->ExecuteFunction(__func__, color);
}
};
class inkLeafWidgetWrapper : public inkWidgetWrapper
{
protected:
inkLeafWidgetWrapper(const char* typeName) : inkWidgetWrapper(typeName) {}
public:
inkLeafWidgetWrapper() : inkWidgetWrapper(ink::LeafWidget::NAME) {}
};
class inkTextWidgetWrapper : public inkLeafWidgetWrapper
{
protected:
inkTextWidgetWrapper(const char* typeName) : inkLeafWidgetWrapper(typeName) {}
public:
inkTextWidgetWrapper() : inkLeafWidgetWrapper(ink::TextWidget::NAME) {}
inline void SetText(CString displayText, Handle<text::TextParameterSet> textParams = {})
{
GetInstance()->ExecuteFunction(__func__, displayText, textParams);
}
inline void SetFontFamily(CString fontFamilyPath, CName fontStyle = {})
{
GetInstance()->ExecuteFunction(__func__, fontFamilyPath, fontStyle);
}
inline void SetFontStyle(CName fontStyle)
{
GetInstance()->ExecuteFunction(__func__, fontStyle);
}
inline void SetFontSize(int32_t textSize)
{
GetInstance()->ExecuteFunction(__func__, textSize);
}
};
CMemory::EDetour<void, ink::IWidgetController*, void*>
OnPlayerAttach("E8 ? ? ? ? 48 8B 9F ? ? ? ? 48 85 DB 74 25", 1,
[](ink::IWidgetController* widgetcontroller, void* player)
{
OnPlayerAttach(widgetcontroller, player);
if (widgetcontroller->GetType()->name == "gameuiRootHudGameController")
{
auto rootwidget = widgetcontroller->ExecuteFunction<WeakHandle<ink::CompoundWidget>>("GetRootCompoundWidget").value();
auto text = new inkTextWidgetWrapper();
text->SetText("test text");
text->SetFontFamily(R"(base\gameplay\gui\fonts\raj\raj.inkfontfamily)");
text->SetFontStyle("Bold");
text->SetFontSize(25);
text->SetAnchor(ink::EAnchor::BottomCenter);
text->SetAnchorPoint({ .5f, 1.f });
text->SetTintColor({ 1.1761f, .3809f, .3476f, 1.f });
text->Reparent(rootwidget);
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment