Skip to content

Commit

Permalink
Update Example Plugin shared headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Archie-osu committed Dec 30, 2023
1 parent 4620f4f commit a10fd25
Show file tree
Hide file tree
Showing 2 changed files with 258 additions and 5 deletions.
172 changes: 170 additions & 2 deletions ExamplePlugin/include/YYToolkit/Shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,69 @@
using namespace Aurie;
using namespace YYTK;

static YYTKInterface* GetYYTKInterface()
{
static YYTKInterface* module_interface = nullptr;

// Try getting the interface
// If we error, we return nullptr.
if (!module_interface)
{
ObGetInterface(
"YYTK_Main",
reinterpret_cast<AurieInterfaceBase*&>(module_interface)
);
}

return module_interface;
}

RValue::RValue()
{
this->m_Real = 0;
this->m_Flags = 0;
this->m_Kind = VALUE_UNSET;
this->m_Kind = VALUE_UNDEFINED;
}

YYTK::RValue::RValue(
IN std::initializer_list<RValue> Values
)
{
// Initialize to undefined
*this = RValue();

if (!GetYYTKInterface())
return;

if (!GetYYTKInterface()->GetRunnerInterface().YYCreateArray)
return;

// Create a dummy array with the size of Values.size(), and initialize all members to 0
std::vector<double> dummy_array(Values.size(), 0.0);

// Initialize this RValue as an array
GetYYTKInterface()->GetRunnerInterface().YYCreateArray(
this,
static_cast<int>(dummy_array.size()),
dummy_array.data()
);

// Use direct object manipulation to set the actual values
for (size_t index = 0; index < Values.size(); index++)
{
RValue* member_value = nullptr;
AurieStatus last_status = GetYYTKInterface()->GetArrayEntry(
*this,
index,
member_value
);

// Make sure we got a valid pointer
if (!AurieSuccess(last_status))
continue;

*member_value = std::data(Values)[index];
}
}

RValue::RValue(
Expand Down Expand Up @@ -55,9 +113,35 @@ RValue::RValue(
this->m_Kind = VALUE_OBJECT;
}

YYTK::RValue::RValue(
IN const char* Value
)
{
// Init to empty
*this = std::string_view(Value);
}

RValue::RValue(
IN std::string_view Value
)
{
// Initialize it to just empty stuff
*this = RValue();

// Let's not crash on invalid interfaces provided
if (!GetYYTKInterface())
return;

// We can ignore this, because if it fails, we're just initialized to UNSET
GetYYTKInterface()->StringToRValue(
Value,
*this
);
}

RValue::RValue(
IN std::string_view Value,
IN YYTKInterface* Interface
IN class YYTKInterface* Interface
)
{
// Initialize it to just empty stuff
Expand Down Expand Up @@ -119,6 +203,19 @@ double RValue::AsReal() const
return 0.0;
}

std::string_view RValue::AsString()
{
// Let's not crash on invalid interfaces provided
if (!GetYYTKInterface())
return "";

if (!GetYYTKInterface()->GetRunnerInterface().YYGetString)
return "";

// Reason I don't use RValueToString is because that duplicates the string
return GetYYTKInterface()->GetRunnerInterface().YYGetString(this, 0);
}

std::string_view RValue::AsString(
IN YYTKInterface* Interface
)
Expand All @@ -132,3 +229,74 @@ std::string_view RValue::AsString(

return Interface->GetRunnerInterface().YYGetString(this, 0);
}

RValue& RValue::operator[](
IN size_t Index
)
{
if (!GetYYTKInterface())
return *this;

RValue* result = nullptr;
if (!AurieSuccess(GetYYTKInterface()->GetArrayEntry(
*this,
Index,
result
)))
{
return *this;
}

return *result;
}

RValue& RValue::operator[](
IN std::string_view Element
)
{
if (!GetYYTKInterface())
return *this;

RValue* instance_member = nullptr;
AurieStatus last_status = GetYYTKInterface()->GetInstanceMember(
*this,
Element.data(),
instance_member
);

// Prevents access violations, null references are undefined behavior in the C++ standard
if (!AurieSuccess(last_status) || !instance_member)
{
return *this;
}

return *instance_member;
}

RValue& RValue::at(
IN size_t Index
)
{
return this->operator[](Index);
}

RValue& RValue::at(
IN std::string_view Element
)
{
return this->operator[](Element);
}

RValue& CInstance::operator[](
IN std::string_view Element
)
{
return RValue(this).at(Element);
}

RValue& YYTK::CInstance::at(
IN std::string_view Element
)
{
return RValue(this).at(Element);
}
91 changes: 88 additions & 3 deletions ExamplePlugin/include/YYToolkit/Shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#ifndef YYTK_SHARED_H_
#define YYTK_SHARED_H_

#define YYTK_MAJOR 3
#define YYTK_MINOR 1
#define YYTK_PATCH 0

#include <Aurie/shared.hpp>
#include <FunctionWrapper/FunctionWrapper.hpp>
#include <d3d11.h>
Expand All @@ -19,6 +23,10 @@
#define UTEXT(x) ((const unsigned char*)(x))
#endif // UTEXT

#ifndef NULL_INDEX
#define NULL_INDEX INT_MIN
#endif

namespace YYTK
{
enum CmColor : uint8_t
Expand Down Expand Up @@ -91,6 +99,7 @@ namespace YYTK
struct YYRunnerInterface;
class YYTKInterface;
struct RValue;
struct RVariableRoutine;

struct YYGMLException
{
Expand All @@ -112,12 +121,12 @@ namespace YYTK

using PFUNC_RAW = void(*)();

using PFUNC_YYGMLScript = RValue * (*)(
using PFUNC_YYGMLScript = RValue & (*)(
IN CInstance* Self,
IN CInstance* Other,
OUT RValue* ReturnValue,
OUT RValue& Result,
IN int ArgumentCount,
IN RValue** Arguments
IN RValue** Arguments // Array of RValue pointers
);

#pragma pack(push, 4)
Expand All @@ -139,6 +148,10 @@ namespace YYTK
// Constructors
RValue();

RValue(
IN std::initializer_list<RValue> Values
);

RValue(
IN bool Value
);
Expand All @@ -159,18 +172,47 @@ namespace YYTK
IN CInstance* Object
);

RValue(
IN const char* Value
);

RValue(
IN std::string_view Value
);

RValue(
IN std::string_view Value,
IN YYTKInterface* Interface
);

// Custom getters
bool AsBool() const;

double AsReal() const;

std::string_view AsString();

std::string_view AsString(
IN YYTKInterface* Interface
);

// Overloaded operators
RValue& operator[](
IN size_t Index
);

RValue& operator[](
IN std::string_view Element
);

// STL-like access
RValue& at(
IN size_t Index
);

RValue& at(
IN std::string_view Element
);
};
#pragma pack(pop)

Expand Down Expand Up @@ -409,6 +451,19 @@ namespace YYTK
bool (*isRunningFromIDE)();
};

struct CInstance
{
// Overloaded operators
RValue& operator[](
IN std::string_view Element
);

// STL-like access
RValue& at(
IN std::string_view Element
);
};

// ExecuteIt
using FWCodeEvent = FunctionWrapper<bool(CInstance*, CInstance*, CCode*, int, RValue*)>;
// IDXGISwapChain::Present
Expand Down Expand Up @@ -525,6 +580,36 @@ namespace YYTK
IN int Index,
OUT CScript*& Script
) = 0;

virtual Aurie::AurieStatus GetBuiltinVariableIndex(
IN std::string_view Name,
OUT size_t& Index
) = 0;

virtual Aurie::AurieStatus GetBuiltinVariableInformation(
IN size_t Index,
OUT RVariableRoutine*& VariableInformation
) = 0;

virtual Aurie::AurieStatus GetBuiltin(
IN std::string_view Name,
IN CInstance* TargetInstance,
OPTIONAL IN int ArrayIndex,
OUT RValue& Value
) = 0;

virtual Aurie::AurieStatus SetBuiltin(
IN std::string_view Name,
IN CInstance* TargetInstance,
OPTIONAL IN int ArrayIndex,
IN RValue& Value
) = 0;

virtual Aurie::AurieStatus GetArrayEntry(
IN RValue& Value,
IN size_t ArrayIndex,
OUT RValue*& ArrayElement
) = 0;
};
}

Expand Down

0 comments on commit a10fd25

Please sign in to comment.