Skip to content

Commit

Permalink
Merge pull request #30 from Kasuromi/metadata-29-detour-fix
Browse files Browse the repository at this point in the history
Support metadata v29 in injector detours
  • Loading branch information
ghorsington authored Apr 22, 2022
2 parents 493854d + 5167d62 commit e1f77fc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion UnhollowerBaseLib/Injection/InjectorHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,19 @@ private static d_GetTypeInfoFromTypeDefinitionIndex FindGetTypeInfoFromTypeDefin
var imageGetType = XrefScannerLowLevel.JumpTargets(imageGetClassAPI).Single();
LogSupport.Trace($"Image::GetType: 0x{imageGetType.ToInt64():X2}");

var getTypeInfoFromTypeDefinitionIndex = XrefScannerLowLevel.JumpTargets(imageGetType).Single();
var imageGetTypeXrefs = XrefScannerLowLevel.JumpTargets(imageGetType);
var getTypeInfoFromTypeDefinitionIndex = imageGetTypeXrefs.First();

if (imageGetTypeXrefs.Count() > 1) {
// (Kasuromi): metadata v29 introduces handles and adds extra calls, a check for unity versions might be necessary in the future

// Second call after obtaining handle, if there are any more calls in the future - correctly index into it if issues occur
var getTypeInfoFromHandle = imageGetTypeXrefs.Last();

// Two calls, second one (GetIndexForTypeDefinitionInternal) is inlined
getTypeInfoFromTypeDefinitionIndex = XrefScannerLowLevel.JumpTargets(getTypeInfoFromHandle).Single();
}

LogSupport.Trace($"MetadataCache::GetTypeInfoFromTypeDefinitionIndex: 0x{getTypeInfoFromTypeDefinitionIndex.ToInt64():X2}");

GetTypeInfoFromTypeDefinitionIndexOriginal = ClassInjector.Detour.Detour<d_GetTypeInfoFromTypeDefinitionIndex>(
Expand Down

0 comments on commit e1f77fc

Please sign in to comment.