Signed-off-by: Faumaray <faumaray@gmail.com>
This commit is contained in:
2 files changed
+88
-59
No files matched your search
+37
-32
@@ -128,36 +128,41 @@
|
|||||||
} \
|
} \
|
||||||
} _vl_field_put_typed_reg_##FieldPtr;
|
} _vl_field_put_typed_reg_##FieldPtr;
|
||||||
|
|
||||||
#define MIXIN_INVOKE_BEFORE_TYPED(MethodPtr, LAMBDA) \
|
#define MIXIN_INVOKE_BEFORE_TYPED(MethodPtr, InvokeTargetPtr, LAMBDA) \
|
||||||
struct _VL_INVOKE_B_T_REG_##MethodPtr { \
|
struct _VL_INVOKE_B_T_REG_##MethodPtr##_##InvokeTargetPtr { \
|
||||||
_VL_INVOKE_B_T_REG_##MethodPtr() { \
|
_VL_INVOKE_B_T_REG_##MethodPtr##_##InvokeTargetPtr() { \
|
||||||
using _Target = typename std::remove_pointer_t<decltype(MethodPtr)>; \
|
using _Target = typename std::remove_pointer_t<decltype(MethodPtr)>; \
|
||||||
::vl::mixin::InjectionSpec spec{ \
|
::vl::mixin::InjectionSpec spec{}; \
|
||||||
::vl::reflect::method_owner<MethodPtr>(), \
|
spec.owner = ::vl::reflect::method_owner<MethodPtr>(); \
|
||||||
::vl::reflect::method_name<MethodPtr>(), \
|
spec.methodName = ::vl::reflect::method_name<MethodPtr>(); \
|
||||||
::vl::reflect::method_desc<MethodPtr>(), \
|
spec.methodDesc = ::vl::reflect::method_desc<MethodPtr>(); \
|
||||||
::vl::mixin::At::INVOKE, ::vl::mixin::Side::Before, \
|
spec.kind = ::vl::mixin::PointKind::Invoke; \
|
||||||
::vl::mixin::CallbackRegistry::add( \
|
spec.when = ::vl::mixin::Side::Before; \
|
||||||
::vl::mixin::make_typed_invoke_before<MethodPtr>(LAMBDA) \
|
spec.cb = ::vl::mixin::CallbackRegistry::add( \
|
||||||
) \
|
::vl::mixin::make_typed_invoke_before<InvokeTargetPtr>(LAMBDA)); \
|
||||||
}; \
|
spec.invoke.owner = ::vl::reflect::method_owner<InvokeTargetPtr>(); \
|
||||||
::vl::mixin::Mixin<_Target>::add(spec); \
|
spec.invoke.name = ::vl::reflect::method_name<InvokeTargetPtr>(); \
|
||||||
} \
|
spec.invoke.desc = ::vl::reflect::method_desc<InvokeTargetPtr>(); \
|
||||||
} _vl_invoke_before_typed_reg_##MethodPtr;
|
::vl::mixin::Mixin<_Target>::add(spec); \
|
||||||
|
} \
|
||||||
|
} _vl_invoke_before_typed_reg_##MethodPtr##_##InvokeTargetPtr;
|
||||||
|
|
||||||
#define MIXIN_INVOKE_AFTER_TYPED(MethodPtr, LAMBDA) \
|
// After a specific invoke inside a method
|
||||||
struct _VL_INVOKE_A_T_REG_##MethodPtr { \
|
#define MIXIN_INVOKE_AFTER_TYPED(MethodPtr, InvokeTargetPtr, LAMBDA) \
|
||||||
_VL_INVOKE_A_T_REG_##MethodPtr() { \
|
struct _VL_INVOKE_A_T_REG_##MethodPtr##_##InvokeTargetPtr { \
|
||||||
using _Target = typename std::remove_pointer_t<decltype(MethodPtr)>; \
|
_VL_INVOKE_A_T_REG_##MethodPtr##_##InvokeTargetPtr() { \
|
||||||
::vl::mixin::InjectionSpec spec{ \
|
using _Target = typename std::remove_pointer_t<decltype(MethodPtr)>; \
|
||||||
::vl::reflect::method_owner<MethodPtr>(), \
|
::vl::mixin::InjectionSpec spec{}; \
|
||||||
::vl::reflect::method_name<MethodPtr>(), \
|
spec.owner = ::vl::reflect::method_owner<MethodPtr>(); \
|
||||||
::vl::reflect::method_desc<MethodPtr>(), \
|
spec.methodName = ::vl::reflect::method_name<MethodPtr>(); \
|
||||||
::vl::mixin::At::INVOKE, ::vl::mixin::Side::After, \
|
spec.methodDesc = ::vl::reflect::method_desc<MethodPtr>(); \
|
||||||
::vl::mixin::CallbackRegistry::add( \
|
spec.kind = ::vl::mixin::PointKind::Invoke; \
|
||||||
::vl::mixin::make_typed_invoke_after<MethodPtr>(LAMBDA) \
|
spec.when = ::vl::mixin::Side::After; \
|
||||||
) \
|
spec.cb = ::vl::mixin::CallbackRegistry::add( \
|
||||||
}; \
|
::vl::mixin::make_typed_invoke_after<InvokeTargetPtr>(LAMBDA)); \
|
||||||
::vl::mixin::Mixin<_Target>::add(spec); \
|
spec.invoke.owner = ::vl::reflect::method_owner<InvokeTargetPtr>(); \
|
||||||
} \
|
spec.invoke.name = ::vl::reflect::method_name<InvokeTargetPtr>(); \
|
||||||
} _vl_invoke_after_typed_reg_##MethodPtr;
|
spec.invoke.desc = ::vl::reflect::method_desc<InvokeTargetPtr>(); \
|
||||||
|
::vl::mixin::Mixin<_Target>::add(spec); \
|
||||||
|
} \
|
||||||
|
} _vl_invoke_after_typed_reg_##MethodPtr##_##InvokeTargetPtr;
|
||||||
+51
-27
@@ -3,6 +3,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace vl::mixin {
|
namespace vl::mixin {
|
||||||
|
|
||||||
@@ -14,49 +15,72 @@ using CallbackId = std::size_t;
|
|||||||
// Erased ABI for callbacks: Core marshals args and provides a CallbackInfo*.
|
// Erased ABI for callbacks: Core marshals args and provides a CallbackInfo*.
|
||||||
using ErasedCallback = std::function<void*(void** args, int argc, void* cbinfo)>;
|
using ErasedCallback = std::function<void*(void** args, int argc, void* cbinfo)>;
|
||||||
|
|
||||||
struct InjectionSpec {
|
|
||||||
std::string_view owner; // internal name from generator
|
// ---------------------------------------------------------------------
|
||||||
std::string_view methodName; // "tick"
|
// INVOKE sub-descriptor
|
||||||
std::string_view methodDesc; // "()V"
|
// ---------------------------------------------------------------------
|
||||||
At at;
|
struct InvokeTarget {
|
||||||
Side when{Side::Before};
|
std::string owner; // internal class name (e.g. net/minecraft/client/Minecraft)
|
||||||
CallbackId cb{};
|
std::string name; // method name to match (e.g. "doAttack")
|
||||||
|
std::string desc; // full JVM descriptor (e.g. "(I)Z")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Injection spec (for all @At types)
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
struct InjectionSpec {
|
||||||
|
std::string owner; // the target class where we inject
|
||||||
|
std::string methodName; // the method name where we inject
|
||||||
|
std::string methodDesc; // the method descriptor
|
||||||
|
At at; // HEAD / RETURN / INVOKE / FIELD_GET / FIELD_PUT
|
||||||
|
Side when; // Before / After (for INVOKE etc.)
|
||||||
|
CallbackId cb; // callback id
|
||||||
|
|
||||||
|
// For INVOKE / FIELD hooks, optional nested target to match the inside call or field
|
||||||
|
InvokeTarget invoke;
|
||||||
|
std::string fieldOwner;
|
||||||
|
std::string fieldName;
|
||||||
|
std::string fieldDesc;
|
||||||
|
};
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Other specs unchanged
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
struct RedirectSpec {
|
struct RedirectSpec {
|
||||||
std::string_view owner;
|
std::string owner;
|
||||||
std::string_view methodName;
|
std::string methodName;
|
||||||
std::string_view methodDesc;
|
std::string methodDesc;
|
||||||
CallbackId cb{};
|
CallbackId cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModifyConstSpec {
|
struct ModifyConstSpec {
|
||||||
std::string_view owner;
|
enum Kind { Int, Long, Float, Double, String } kind{};
|
||||||
std::string_view methodName;
|
std::string owner;
|
||||||
std::string_view methodDesc;
|
std::string methodName;
|
||||||
enum { Int, Long, Float, Double, String } kind;
|
std::string methodDesc;
|
||||||
long long i64{};
|
CallbackId cb;
|
||||||
double fp{};
|
int64_t i64{};
|
||||||
std::string_view str{};
|
double fp{};
|
||||||
CallbackId cb{}; // optional dynamic replacement
|
std::string str;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModifyVarSpec {
|
struct ModifyVarSpec {
|
||||||
std::string_view owner;
|
std::string owner;
|
||||||
std::string_view methodName;
|
std::string methodName;
|
||||||
std::string_view methodDesc;
|
std::string methodDesc;
|
||||||
int varIndex{};
|
CallbackId cb;
|
||||||
CallbackId cb{};
|
int varIndex{};
|
||||||
};
|
};
|
||||||
|
// Whole-class mixin description
|
||||||
struct MixinSpec {
|
struct MixinSpec {
|
||||||
std::string_view owner; // target class internal name
|
std::string owner;
|
||||||
std::vector<InjectionSpec> injections;
|
std::vector<InjectionSpec> injections;
|
||||||
std::vector<RedirectSpec> redirects;
|
std::vector<RedirectSpec> redirects;
|
||||||
std::vector<ModifyConstSpec> constants;
|
std::vector<ModifyConstSpec> constants;
|
||||||
std::vector<ModifyVarSpec> vars;
|
std::vector<ModifyVarSpec> vars;
|
||||||
bool replaceWholeClass{false};
|
bool replaceWholeClass{false};
|
||||||
CallbackId classBodyProvider{}; // if replaceWholeClass
|
CallbackId classBodyProvider{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace vl::mixin
|
} // namespace vl::mixin
|
||||||
Reference in new issue
Block a user