mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-13 11:27:42 +01:00
Initial commit
This commit is contained in:
commit
ac838687f8
157 changed files with 27905 additions and 0 deletions
48
Dalamud/Game/Internal/BaseAddressResolver.cs
Normal file
48
Dalamud/Game/Internal/BaseAddressResolver.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Dalamud.Game.Internal {
|
||||
public abstract class BaseAddressResolver {
|
||||
protected bool IsResolved { get; set; }
|
||||
|
||||
public void Setup(SigScanner scanner) {
|
||||
// Because C# don't allow to call virtual function while in ctor
|
||||
// we have to do this shit :\
|
||||
|
||||
if (IsResolved) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (scanner.Is32BitProcess) {
|
||||
Setup32Bit(scanner);
|
||||
} else {
|
||||
Setup64Bit(scanner);
|
||||
}
|
||||
SetupInternal(scanner);
|
||||
|
||||
IsResolved = true;
|
||||
}
|
||||
|
||||
protected virtual void Setup32Bit(SigScanner scanner) {
|
||||
throw new NotSupportedException("32 bit version is not supported.");
|
||||
}
|
||||
|
||||
protected virtual void Setup64Bit(SigScanner sig) {
|
||||
throw new NotSupportedException("64 bit version is not supported.");
|
||||
}
|
||||
|
||||
protected virtual void SetupInternal(SigScanner scanner) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
protected T GetVirtualFunction<T>(IntPtr address, int vtableOffset, int count) where T : class {
|
||||
// Get vtable
|
||||
var vtable = Marshal.ReadIntPtr(address, vtableOffset);
|
||||
|
||||
// Get an address to the function
|
||||
var functionAddress = Marshal.ReadIntPtr(vtable, IntPtr.Size * count);
|
||||
|
||||
return Marshal.GetDelegateForFunctionPointer<T>(functionAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue