diff --git a/include/Mixin/Macros.hpp b/include/Mixin/Macros.hpp index 8ca3ec4..8d2e64d 100644 --- a/include/Mixin/Macros.hpp +++ b/include/Mixin/Macros.hpp @@ -128,36 +128,41 @@ } \ } _vl_field_put_typed_reg_##FieldPtr; -#define MIXIN_INVOKE_BEFORE_TYPED(MethodPtr, LAMBDA) \ - struct _VL_INVOKE_B_T_REG_##MethodPtr { \ - _VL_INVOKE_B_T_REG_##MethodPtr() { \ - using _Target = typename std::remove_pointer_t; \ - ::vl::mixin::InjectionSpec spec{ \ - ::vl::reflect::method_owner(), \ - ::vl::reflect::method_name(), \ - ::vl::reflect::method_desc(), \ - ::vl::mixin::At::INVOKE, ::vl::mixin::Side::Before, \ - ::vl::mixin::CallbackRegistry::add( \ - ::vl::mixin::make_typed_invoke_before(LAMBDA) \ - ) \ - }; \ - ::vl::mixin::Mixin<_Target>::add(spec); \ - } \ - } _vl_invoke_before_typed_reg_##MethodPtr; +#define MIXIN_INVOKE_BEFORE_TYPED(MethodPtr, InvokeTargetPtr, LAMBDA) \ + struct _VL_INVOKE_B_T_REG_##MethodPtr##_##InvokeTargetPtr { \ + _VL_INVOKE_B_T_REG_##MethodPtr##_##InvokeTargetPtr() { \ + using _Target = typename std::remove_pointer_t; \ + ::vl::mixin::InjectionSpec spec{}; \ + spec.owner = ::vl::reflect::method_owner(); \ + spec.methodName = ::vl::reflect::method_name(); \ + spec.methodDesc = ::vl::reflect::method_desc(); \ + spec.kind = ::vl::mixin::PointKind::Invoke; \ + spec.when = ::vl::mixin::Side::Before; \ + spec.cb = ::vl::mixin::CallbackRegistry::add( \ + ::vl::mixin::make_typed_invoke_before(LAMBDA)); \ + spec.invoke.owner = ::vl::reflect::method_owner(); \ + spec.invoke.name = ::vl::reflect::method_name(); \ + spec.invoke.desc = ::vl::reflect::method_desc(); \ + ::vl::mixin::Mixin<_Target>::add(spec); \ + } \ + } _vl_invoke_before_typed_reg_##MethodPtr##_##InvokeTargetPtr; -#define MIXIN_INVOKE_AFTER_TYPED(MethodPtr, LAMBDA) \ - struct _VL_INVOKE_A_T_REG_##MethodPtr { \ - _VL_INVOKE_A_T_REG_##MethodPtr() { \ - using _Target = typename std::remove_pointer_t; \ - ::vl::mixin::InjectionSpec spec{ \ - ::vl::reflect::method_owner(), \ - ::vl::reflect::method_name(), \ - ::vl::reflect::method_desc(), \ - ::vl::mixin::At::INVOKE, ::vl::mixin::Side::After, \ - ::vl::mixin::CallbackRegistry::add( \ - ::vl::mixin::make_typed_invoke_after(LAMBDA) \ - ) \ - }; \ - ::vl::mixin::Mixin<_Target>::add(spec); \ - } \ - } _vl_invoke_after_typed_reg_##MethodPtr; \ No newline at end of file +// After a specific invoke inside a method +#define MIXIN_INVOKE_AFTER_TYPED(MethodPtr, InvokeTargetPtr, LAMBDA) \ + struct _VL_INVOKE_A_T_REG_##MethodPtr##_##InvokeTargetPtr { \ + _VL_INVOKE_A_T_REG_##MethodPtr##_##InvokeTargetPtr() { \ + using _Target = typename std::remove_pointer_t; \ + ::vl::mixin::InjectionSpec spec{}; \ + spec.owner = ::vl::reflect::method_owner(); \ + spec.methodName = ::vl::reflect::method_name(); \ + spec.methodDesc = ::vl::reflect::method_desc(); \ + spec.kind = ::vl::mixin::PointKind::Invoke; \ + spec.when = ::vl::mixin::Side::After; \ + spec.cb = ::vl::mixin::CallbackRegistry::add( \ + ::vl::mixin::make_typed_invoke_after(LAMBDA)); \ + spec.invoke.owner = ::vl::reflect::method_owner(); \ + spec.invoke.name = ::vl::reflect::method_name(); \ + spec.invoke.desc = ::vl::reflect::method_desc(); \ + ::vl::mixin::Mixin<_Target>::add(spec); \ + } \ + } _vl_invoke_after_typed_reg_##MethodPtr##_##InvokeTargetPtr; \ No newline at end of file diff --git a/include/Mixin/Types.hpp b/include/Mixin/Types.hpp index ba59f7a..823573c 100644 --- a/include/Mixin/Types.hpp +++ b/include/Mixin/Types.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace vl::mixin { @@ -14,49 +15,72 @@ using CallbackId = std::size_t; // Erased ABI for callbacks: Core marshals args and provides a CallbackInfo*. using ErasedCallback = std::function; -struct InjectionSpec { - std::string_view owner; // internal name from generator - std::string_view methodName; // "tick" - std::string_view methodDesc; // "()V" - At at; - Side when{Side::Before}; - CallbackId cb{}; + +// --------------------------------------------------------------------- +// INVOKE sub-descriptor +// --------------------------------------------------------------------- +struct InvokeTarget { + std::string owner; // internal class name (e.g. net/minecraft/client/Minecraft) + 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 { - std::string_view owner; - std::string_view methodName; - std::string_view methodDesc; - CallbackId cb{}; + std::string owner; + std::string methodName; + std::string methodDesc; + CallbackId cb; }; struct ModifyConstSpec { - std::string_view owner; - std::string_view methodName; - std::string_view methodDesc; - enum { Int, Long, Float, Double, String } kind; - long long i64{}; - double fp{}; - std::string_view str{}; - CallbackId cb{}; // optional dynamic replacement + enum Kind { Int, Long, Float, Double, String } kind{}; + std::string owner; + std::string methodName; + std::string methodDesc; + CallbackId cb; + int64_t i64{}; + double fp{}; + std::string str; }; struct ModifyVarSpec { - std::string_view owner; - std::string_view methodName; - std::string_view methodDesc; - int varIndex{}; - CallbackId cb{}; + std::string owner; + std::string methodName; + std::string methodDesc; + CallbackId cb; + int varIndex{}; }; - +// Whole-class mixin description struct MixinSpec { - std::string_view owner; // target class internal name + std::string owner; std::vector injections; std::vector redirects; std::vector constants; std::vector vars; bool replaceWholeClass{false}; - CallbackId classBodyProvider{}; // if replaceWholeClass + CallbackId classBodyProvider{}; }; } // namespace vl::mixin