From 7e18d270c67e5df20b124f0d8efae52c819199d6 Mon Sep 17 00:00:00 2001 From: Fexty Date: Mon, 29 Apr 2024 13:07:23 +0200 Subject: [PATCH] EffectEmitter class (wrapper around uMhEpv) --- Assets/Common/AddressRecords.json | 10 ++ SharpPluginLoader.Core/EffectEmitter.cs | 98 +++++++++++++++++++ .../SharpPluginLoader.Core.csproj | 3 + .../mhw-cs-plugin-loader.vcxproj | 1 + .../mhw-cs-plugin-loader.vcxproj.filters | 3 + 5 files changed, 115 insertions(+) create mode 100644 SharpPluginLoader.Core/EffectEmitter.cs diff --git a/Assets/Common/AddressRecords.json b/Assets/Common/AddressRecords.json index 7a2eef1..cb24b6d 100644 --- a/Assets/Common/AddressRecords.json +++ b/Assets/Common/AddressRecords.json @@ -423,5 +423,15 @@ "Name": "MtDti:Init", "Pattern": "48 89 5c 24 08 57 48 83 ec 20 81 61 30 00 00 80 1f", "Offset": 0 + }, + { + "Name": "EffectEmitter:SetEpv", + "Pattern": "48 8b d9 ff 90 c8 00 00 00 48 8b 8b 60 02 00 00 48 3b cf", + "Offset": -16 + }, + { + "Name": "EffectEmitter:SetConstraintModel", + "Pattern": "48 8b 81 70 02 00 00 48 8b f2 48 8b d9 48 3b c2 74 1e", + "Offset": -15 } ] \ No newline at end of file diff --git a/SharpPluginLoader.Core/EffectEmitter.cs b/SharpPluginLoader.Core/EffectEmitter.cs new file mode 100644 index 0000000..b126abf --- /dev/null +++ b/SharpPluginLoader.Core/EffectEmitter.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SharpPluginLoader.Core.Memory; +using SharpPluginLoader.Core.Models; +using SharpPluginLoader.Core.Resources; + +namespace SharpPluginLoader.Core; + +/// +/// Represents an instance of uMhEpv. This class has the capability to +/// emit effects +/// +public class EffectEmitter : Unit +{ + public EffectEmitter(nint instance) : base(instance) { } + public EffectEmitter() { } + + /// + /// The EPV that this effect emitter is using. Updating this value + /// will automatically call and update the property. + /// + public unsafe EffectProvider? EffectProvider + { + get => GetObject(0x260); + set => SetEpvFunc.Invoke(Instance, value?.Instance ?? 0); + } + + /// + /// The model that this effect emitter is constrained to. + /// + public unsafe Model? ConstraintModel + { + get => GetObject(0x270); + set => SetConstraintModelFunc.Invoke(Instance, value?.Instance ?? 0); + } + + /// + /// The EPV Group Id that this effect emitter is using. + /// + public ref int GroupId => ref GetRef(0x268); + + /// + /// The EPV Element Id that this effect emitter is using. + /// + public ref int ElementId => ref GetRef(0x26C); + + /// + /// Whether this effect emitter is playing. Do not modify this value, + /// use the and methods instead. + /// + public bool IsPlaying => GetRef(0x370); + + /// + /// How the effect referenced by this emitter is played. + /// Mostly unknown, 2 means the effect is looped infinitely. + /// + public ref int PlayType => ref GetRef(0x374); + + /// + /// The interval between each effect emission, if the effect is looped. + /// (See ) + /// + public ref float Interval => ref GetRef(0x378); + + /// + /// The EPVSP that this effect emitter is using. This is populated + /// automatically when you set the EPV. () + /// + public Resource? Epvsp => GetObject(0xA00); + + /// + /// Starts the emitter. + /// + public unsafe void Start() => StartFunction.Invoke(Instance); + + /// + /// Ends the emitter. + /// + public unsafe void Finish() => FinishFunction.Invoke(Instance); + + /// + /// Kills the emitter and all effects associated with it immediately. + /// + public unsafe void Kill() => KillFunction.Invoke(Instance); + + + private NativeAction StartFunction => new(GetVirtualFunction(38)); + private NativeAction FinishFunction => new(GetVirtualFunction(37)); + private NativeAction KillFunction => new(GetVirtualFunction(25)); + + private static readonly NativeAction SetEpvFunc + = new(AddressRepository.Get("EffectEmitter:SetEpv")); + private static readonly NativeAction SetConstraintModelFunc + = new(AddressRepository.Get("EffectEmitter:SetConstraintModel")); +} diff --git a/SharpPluginLoader.Core/SharpPluginLoader.Core.csproj b/SharpPluginLoader.Core/SharpPluginLoader.Core.csproj index 9eb909b..958a166 100644 --- a/SharpPluginLoader.Core/SharpPluginLoader.Core.csproj +++ b/SharpPluginLoader.Core/SharpPluginLoader.Core.csproj @@ -139,4 +139,7 @@ + + + diff --git a/mhw-cs-plugin-loader/mhw-cs-plugin-loader.vcxproj b/mhw-cs-plugin-loader/mhw-cs-plugin-loader.vcxproj index 91451cf..42a8b4b 100644 --- a/mhw-cs-plugin-loader/mhw-cs-plugin-loader.vcxproj +++ b/mhw-cs-plugin-loader/mhw-cs-plugin-loader.vcxproj @@ -217,6 +217,7 @@ + diff --git a/mhw-cs-plugin-loader/mhw-cs-plugin-loader.vcxproj.filters b/mhw-cs-plugin-loader/mhw-cs-plugin-loader.vcxproj.filters index 83b6a10..296310a 100644 --- a/mhw-cs-plugin-loader/mhw-cs-plugin-loader.vcxproj.filters +++ b/mhw-cs-plugin-loader/mhw-cs-plugin-loader.vcxproj.filters @@ -242,5 +242,8 @@ Resource Files\Shaders + + Resource Files + \ No newline at end of file