Skip to content

Commit

Permalink
More DirectX Function delegates
Browse files Browse the repository at this point in the history
  • Loading branch information
MeFisto94 committed Apr 14, 2024
1 parent 600dbad commit 001547c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
46 changes: 46 additions & 0 deletions D3D9/D3D9Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ public enum Direct3DDevice9ExFunctionOrdinals : short
GetDisplayModeEx = 133,
}

public enum IDirect3DVertexBuffer9FunctionOrdinals : short
{
QueryInterface = 0,
AddRef = 1,
Release = 2,
GetDevice = 3,
SetPrivateData = 4,
GetPrivateData = 5,
FreePrivateData = 6,
SetPriority = 7,
GetPriority = 8,
PreLoad = 9,
GetType = 10,
Lock = 11,
Unlock = 12,
GetDesc = 13,
}

// Calling convention: DX9 methods are COM (combaseapi.h) and as such, since C-abi has no __thiscall, they are
// strictly stdcall and by-convention push "this" on the stack.

[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public delegate int Direct3D9Device_BeginSceneDelegate(IntPtr device);

Expand Down Expand Up @@ -178,11 +199,36 @@ public unsafe delegate int Direct3D9Device_PresentDelegate(IntPtr devicePtr, Rec
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe delegate int Direct3D9DeviceEx_PresentExDelegate(IntPtr devicePtr, Rectangle* pSourceRect,
Rectangle* pDestRect, IntPtr hDestWindowOverride, IntPtr pDirtyRegion, Present dwFlags);

[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe delegate int Direct3D9Device_CreateShader(IntPtr devicePtr, IntPtr pFunction, IntPtr ppShader);

[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public unsafe delegate int Direct3D9Device_CreateTexture(IntPtr devicePtr, uint width, uint height, uint levels, uint usage,
uint format, uint pool, IntPtr *ppTexture, IntPtr pSharedHandle);

[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public delegate int Direct3D9Device_SetShader(IntPtr devicePtr, IntPtr pShader);

[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public delegate int Direct3D9Device_DrawIndexedPrimitive(IntPtr devicePtr, uint primitiveType, int baseVertexIndex,
uint minVertexIndex, uint numVertices, uint startIndex, uint primCount);

[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public delegate int Direct3DVertexBuffer9_Lock(IntPtr pBuffer, uint offsetToLock, uint sizeToLock, IntPtr ppbData, int flags);

[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public delegate int Direct3DVertexBuffer9_Unlock(IntPtr pBuffer);

[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public delegate int Direct3D9Device_SetIndices(IntPtr devicePtr, IntPtr pIndexBuffer);

public static class Functions
{
public const int D3D9_DEVICE_METHOD_COUNT = 119;
public const int D3D9Ex_DEVICE_METHOD_COUNT = 15;
public const int D3D9_METHOD_COUNT = 17;
public const int D3D9_VERTEX_BUFFER_METHOD_COUNT = 14;

public static IntPtr[] GetVTblAddresses(IntPtr pointer, int numberOfMethods)
{
Expand Down
3 changes: 1 addition & 2 deletions D3D9/D3D9HookManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public void Load()
using (var d3d = new Direct3D())
{
using (var device = new Device(d3d, 0, DeviceType.NullReference, IntPtr.Zero,
CreateFlags.HardwareVertexProcessing,
new PresentParameters
CreateFlags.HardwareVertexProcessing, new PresentParameters
{ BackBufferWidth = 1, BackBufferHeight = 1, DeviceWindowHandle = WindowHandle }))
{
Logger.Debug("D3D9Hook: Device created");
Expand Down

0 comments on commit 001547c

Please sign in to comment.