Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix in combat signature #253

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions OverlayPlugin.Core/MemoryProcessors/EnmityMemory61.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ public class EnmityMemory61 : EnmityMemory
private const string charmapSignature = "48c1ea0381faa9010000????8bc2488d0d";
private const string targetSignature = "83E901740832C04883C4205BC3488D0D";
private const string enmitySignature = "83f9ff7412448b048e8bd3488d0d";
private const string inCombatSignature = "4889742420574883ec200fb60233f68905";
private const string inCombatSignature = "803D????????000F95C04883C428";
private const string enmityHudSignature = "48895C246048897C2470488B3D";

// Offsets from the signature to find the correct address.
private const int charmapSignatureOffset = 0;
private const int targetSignatureOffset = 0;
private const int enmitySignatureOffset = -2608;
private const int aggroEnmityOffset = -2336;
private const int inCombatSignatureOffset = 0;
private const int inCombatSignatureOffset = -12;
private const int inCombatRIPOffset = 1;
private const int enmityHudSignatureOffset = 0;
private readonly int[] enmityHudPointerPath = new int[] { 0x30, 0x58, 0x98, 0x20 };

Expand Down Expand Up @@ -155,7 +156,7 @@ private bool GetPointerAddress()
}

/// IN COMBAT
list = memory.SigScan(inCombatSignature, inCombatSignatureOffset, bRIP);
list = memory.SigScan(inCombatSignature, inCombatSignatureOffset, bRIP, inCombatRIPOffset);

if (list != null && list.Count > 0)
{
Expand Down
12 changes: 6 additions & 6 deletions OverlayPlugin.Core/MemoryProcessors/FFXIVMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public IntPtr ReadIntPtr(IntPtr addr)
/// <param name="offset">The offset from the end of the found pattern to read a pointer from the process memory.</param>
/// <param name="rip_addressing">Uses x64 RIP relative addressing mode</param>
/// <returns>A list of pointers read relative to the end of strings in the process memory matching the |pattern|.</returns>
public List<IntPtr> SigScan(string pattern, int offset, bool rip_addressing)
public List<IntPtr> SigScan(string pattern, int pattern_offset, bool rip_addressing, int rip_offset = 0)
{
List<IntPtr> matches_list = new List<IntPtr>();

Expand Down Expand Up @@ -333,7 +333,7 @@ public List<IntPtr> SigScan(string pattern, int offset, bool rip_addressing)
IntPtr num_bytes_read = IntPtr.Zero;
if (NativeMethods.ReadProcessMemory(processHandle, read_start_addr, read_buffer, read_size, ref num_bytes_read))
{
int max_search_offset = num_bytes_read.ToInt32() - pattern_array.Length - Math.Max(0, offset);
int max_search_offset = num_bytes_read.ToInt32() - pattern_array.Length - Math.Max(0, pattern_offset);
// With RIP we will read a 4byte pointer at the |offset|, else we read an 8byte pointer. Either
// way we can't find a pattern such that the pointer we want to read is off the end of the buffer.
if (rip_addressing)
Expand All @@ -360,10 +360,10 @@ public List<IntPtr> SigScan(string pattern, int offset, bool rip_addressing)
IntPtr pointer;
if (rip_addressing)
{
Int32 rip_ptr_offset = BitConverter.ToInt32(read_buffer, search_offset + pattern_array.Length + offset);
Int32 rip_ptr_offset = BitConverter.ToInt32(read_buffer, search_offset + pattern_array.Length + pattern_offset);
Int64 pattern_start_game_addr = read_start_addr.ToInt64() + search_offset;
Int64 pointer_offset_from_pattern_start = pattern_array.Length + offset;
Int64 rip_ptr_base = pattern_start_game_addr + pointer_offset_from_pattern_start + 4;
Int64 pointer_offset_from_pattern_start = pattern_array.Length + pattern_offset;
Int64 rip_ptr_base = pattern_start_game_addr + pointer_offset_from_pattern_start + 4 + rip_offset;
// In RIP addressing, the pointer from the executable is 32bits which we stored as |rip_ptr_offset|. The pointer
// is then added to the address of the byte following the pointer, making it relative to that address, which we
// stored as |rip_ptr_base|.
Expand All @@ -372,7 +372,7 @@ public List<IntPtr> SigScan(string pattern, int offset, bool rip_addressing)
else
{
// In normal addressing, the 64bits found with the pattern are the absolute pointer.
pointer = new IntPtr(BitConverter.ToInt64(read_buffer, search_offset + pattern_array.Length + offset));
pointer = new IntPtr(BitConverter.ToInt64(read_buffer, search_offset + pattern_array.Length + pattern_offset));
}
matches_list.Add(pointer);
}
Expand Down