Skip to content

Commit

Permalink
ActionCloner adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
Fexty12573 committed Oct 12, 2024
1 parent f0c4159 commit e4492ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
5 changes: 5 additions & 0 deletions Assets/Common/AddressRecords.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,10 @@
"Name": "Monster:GetActionTableCall",
"Pattern": "E8 ?? ?? ?? ?? 4C 8B C0 41 8B D6 48 85 FF 74 30",
"Offset": 0
},
{
"Name": "EmAction:VTableAssignment",
"Pattern": "C7 41 0C 89 88 88 3C 89 71 08 48 8D 05 ?? ?? ?? ?? 48 89 01",
"Offset": 13
}
]
16 changes: 6 additions & 10 deletions SharpPluginLoader.Core/Actions/ActionCloner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,13 @@ private unsafe ActionCloner()
_patch = new Patch(setActionSetFixup, [0xC3, 0xCC, 0xCC, 0xCC, 0xCC], true);
_hook = Hook.Create<SetActionSetDelegate>(AddressRepository.Get("Entity:SetActionSet"), SetActionSetHook);

// Obtain base action functions
var baseAction = MtDti.Find("cEmAction")?.CreateInstance<Action>();
if (baseAction is null)
{
throw new InvalidOperationException("Failed to create base action instance");
}
var vtableAssignment = AddressRepository.Get("EmAction:VTableAssignment");
var baseActionVft = (nint*)(MemoryUtil.Read<int>(vtableAssignment) + vtableAssignment + 4);

_baseOnInitialize = Marshal.GetDelegateForFunctionPointer<OnActionInitialize>(baseAction.GetVirtualFunction(5));
_baseOnExecute = Marshal.GetDelegateForFunctionPointer<OnActionExecute>(baseAction.GetVirtualFunction(6));
_baseOnUpdate = Marshal.GetDelegateForFunctionPointer<OnActionUpdate>(baseAction.GetVirtualFunction(7));
_baseOnEnd = Marshal.GetDelegateForFunctionPointer<OnActionEnd>(baseAction.GetVirtualFunction(8));
_baseOnInitialize = Marshal.GetDelegateForFunctionPointer<OnActionInitialize>(baseActionVft[5]);
_baseOnExecute = Marshal.GetDelegateForFunctionPointer<OnActionExecute>(baseActionVft[6]);
_baseOnUpdate = Marshal.GetDelegateForFunctionPointer<OnActionUpdate>(baseActionVft[7]);
_baseOnEnd = Marshal.GetDelegateForFunctionPointer<OnActionEnd>(baseActionVft[8]);

return;

Expand Down

0 comments on commit e4492ed

Please sign in to comment.