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 issue finding GetFieldDefaultValue on 2021.3.23 #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal unsafe class Class_GetFieldDefaultValue_Hook : Hook<Class_GetFieldDefau
mask = "xxxxxxxxxxxxxx?xxxxxxxxxxxxx",
xref = false
},

// V Rising - Unity 2022.3.23 (x64)
new MemoryUtils.SignatureDefinition
{
Expand Down Expand Up @@ -71,6 +71,13 @@ internal unsafe class Class_GetFieldDefaultValue_Hook : Hook<Class_GetFieldDefau
mask = "xxxxxxxx????xxxxxxx",
xref = false
},
// Idle Slayer - Unity 2021.3.23 (x64)
new MemoryUtils.SignatureDefinition
{
pattern = "\x40\x53\x48\x83\xEC\x20\x48\x8B\xDA\xE8\xCC\xCC\xCC\xCC\x4C",
mask = "xxxxxxxxxx????x",
xref = false
}
};

private static nint FindClassGetFieldDefaultValueXref(bool forceICallMethod = false)
Expand Down Expand Up @@ -106,7 +113,16 @@ private static nint FindClassGetFieldDefaultValueXref(bool forceICallMethod = fa
var getStaticFieldValue = XrefScannerLowLevel.JumpTargets(getStaticFieldValueAPI).Single();
Logger.Instance.LogTrace("Field::StaticGetValue: 0x{GetStaticFieldValueAddress}", getStaticFieldValue.ToInt64().ToString("X2"));

var getStaticFieldValueInternal = XrefScannerLowLevel.JumpTargets(getStaticFieldValue).Last();
var getStaticFieldValueTargets = XrefScannerLowLevel.JumpTargets(getStaticFieldValue).ToList();

// Sometimes the compiler can do an optimization and omit 'retn' instruction,
// which then causes code following to grab wrong function pointer. A correct match should not contain more than 4 jumps
// This optimization also causes Field::StaticGetValueInternal method to be located right under Field::StaticGetValue method
// Example: https://discord.com/channels/623153565053222947/754333645199900723/1104817647171932283
if (getStaticFieldValueTargets.Count > 4)
return getStaticFieldValueTargets[^2];
limoka marked this conversation as resolved.
Show resolved Hide resolved

var getStaticFieldValueInternal = getStaticFieldValueTargets[^1];
Logger.Instance.LogTrace("Field::StaticGetValueInternal: 0x{GetStaticFieldValueInternalAddress}", getStaticFieldValueInternal.ToInt64().ToString("X2"));

var getStaticFieldValueInternalTargets = XrefScannerLowLevel.JumpTargets(getStaticFieldValueInternal).ToArray();
Expand Down
Loading