Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Fexty12573 committed Apr 29, 2024
2 parents 729f686 + 7e18d27 commit ea62641
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Assets/Common/AddressRecords.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
98 changes: 98 additions & 0 deletions SharpPluginLoader.Core/EffectEmitter.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Represents an instance of uMhEpv. This class has the capability to
/// emit effects
/// </summary>
public class EffectEmitter : Unit
{
public EffectEmitter(nint instance) : base(instance) { }
public EffectEmitter() { }

/// <summary>
/// The EPV that this effect emitter is using. Updating this value
/// will automatically call <see cref="Kill"/> and update the <see cref="Epvsp"/> property.
/// </summary>
public unsafe EffectProvider? EffectProvider
{
get => GetObject<EffectProvider>(0x260);
set => SetEpvFunc.Invoke(Instance, value?.Instance ?? 0);
}

/// <summary>
/// The model that this effect emitter is constrained to.
/// </summary>
public unsafe Model? ConstraintModel
{
get => GetObject<Model>(0x270);
set => SetConstraintModelFunc.Invoke(Instance, value?.Instance ?? 0);
}

/// <summary>
/// The EPV Group Id that this effect emitter is using.
/// </summary>
public ref int GroupId => ref GetRef<int>(0x268);

/// <summary>
/// The EPV Element Id that this effect emitter is using.
/// </summary>
public ref int ElementId => ref GetRef<int>(0x26C);

/// <summary>
/// Whether this effect emitter is playing. Do not modify this value,
/// use the <see cref="Start"/> and <see cref="Finish"/> methods instead.
/// </summary>
public bool IsPlaying => GetRef<bool>(0x370);

/// <summary>
/// How the effect referenced by this emitter is played.
/// Mostly unknown, 2 means the effect is looped infinitely.
/// </summary>
public ref int PlayType => ref GetRef<int>(0x374);

/// <summary>
/// The interval between each effect emission, if the effect is looped.
/// (See <see cref="PlayType"/>)
/// </summary>
public ref float Interval => ref GetRef<float>(0x378);

/// <summary>
/// The EPVSP that this effect emitter is using. This is populated
/// automatically when you set the EPV. (<see cref="EffectProvider"/>)
/// </summary>
public Resource? Epvsp => GetObject<Resource>(0xA00);

/// <summary>
/// Starts the emitter.
/// </summary>
public unsafe void Start() => StartFunction.Invoke(Instance);

/// <summary>
/// Ends the emitter.
/// </summary>
public unsafe void Finish() => FinishFunction.Invoke(Instance);

/// <summary>
/// Kills the emitter and all effects associated with it immediately.
/// </summary>
public unsafe void Kill() => KillFunction.Invoke(Instance);


private NativeAction<nint> StartFunction => new(GetVirtualFunction(38));
private NativeAction<nint> FinishFunction => new(GetVirtualFunction(37));
private NativeAction<nint> KillFunction => new(GetVirtualFunction(25));

private static readonly NativeAction<nint, nint> SetEpvFunc
= new(AddressRepository.Get("EffectEmitter:SetEpv"));
private static readonly NativeAction<nint, nint> SetConstraintModelFunc
= new(AddressRepository.Get("EffectEmitter:SetConstraintModel"));
}
3 changes: 3 additions & 0 deletions SharpPluginLoader.Core/SharpPluginLoader.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,7 @@
<ItemGroup>
<NativeLibs Remove="UnitManager.cs" />
</ItemGroup>
<ItemGroup>
<NativeLibs Remove="EffectEmitter.cs" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions mhw-cs-plugin-loader/mhw-cs-plugin-loader.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
<ClInclude Include="Timeline.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\Assets\Common\AddressRecords.json" />
<None Include="..\README.md" />
<None Include="..\vcpkg.json" />
<None Include=".clang-tidy" />
Expand Down
3 changes: 3 additions & 0 deletions mhw-cs-plugin-loader/mhw-cs-plugin-loader.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,8 @@
<None Include="Shaders\LineRenderingGS.hlsl">
<Filter>Resource Files\Shaders</Filter>
</None>
<None Include="..\Assets\Common\AddressRecords.json">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
</Project>

0 comments on commit ea62641

Please sign in to comment.