procedure Test1(FD3DDevice: IDirect3DDevice9);stdcall;
var
Scrf:IDirect3DSurface9;
LOCKRECV:_D3DLOCKED_RECT;
Myread:DWORD;
begin //和其他读取显存的程序互拆
FD3DDevice.GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, Scrf);
if Scrf.LockRect(LOCKRECV,nil,D3DLOCK_READONLY)=0 then
begin
//显存大小为画面width*height*4=1024*768*4=3145728 因为是BGRA存储方式所以需要X4 //这样游戏显存就获取到memPic中了 然后把BGRA 转成RGB的 BMP的什么的
ReadProcessMemory($FFFFFFFF,LOCKRECV.pBits,MemPic,3145728,Myread);
end;
Scrf.UnlockRect;
end;
//------------------------------------------------------------------------------
function PresentCallback(const Self: IDirect3DDevice9;
const SourceRect, DestRect: PRect; const DestWindowOverride: HWND;
DirtyRegion: PRgnData): HResult; stdcall;
begin
Test1(Self);
Result :=TPresentNext(PresentNext)(Self, SourceRect, DestRect, DestWindowOverride, DirtyRegion);
end;
function CreateDeviceCallback(const Self: pointer; Adapter: longword;
DeviceType: TD3DDevType; hFocusWindow: HWND; BehaviorFlags: DWord;
pPresentationParameters: PD3DPresentParameters;
out ppReturnedDeviceInterface: IDirect3DDevice9): HResult; stdcall;
begin
Result := CreateDeviceNext(self, Adapter, DeviceType, hFocusWindow,
BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
if (Result = 0) and (@PresentNext = nil) then
hookcode(GetInterfaceMethod(ppReturnedDeviceInterface, 17),
@PresentCallback, @PresentNext);
end;
function Direct3DCreate9CallBack(SDKVersion: cardinal): Pointer; stdcall;
begin
Result := Direct3DCreate9next(SDKVersion);
if not (Result = nil) and (@CreateDeviceNext = nil) then
hookcode(GetPtrMethod(Result, 16), @CreateDeviceCallback,
@CreateDeviceNext);
end;
Procedure InstallHook();
begin
hookapi('d3d9.dll','Direct3DCreate9',@Direct3DCreate9CallBack,@Direct3DCreate9Next);
end;
end.