Код:
library dxtext;
uses
SysUtils,
Classes,
Windows,
Direct3D9,
D3DX9;
type
PDWORD=^DWORD;
var
D3DObj: IDirect3D9;
D3DDev: IDirect3DDevice9;
g_Font: ID3DXFont;
adr_Direct3DCreate9:DWORD;
adr_CreateDevice9:DWORD;
adr_EndScene9:DWORD;
function HookCode(target:pointer;new_adr,TrueAdr:PDWORD):BOOL;
var
op:DWORD;
begin
result:=false;
if ((VirtualProtect(target,5,PAGE_EXECUTE_READWRITE,@op)) and (DWORD(target)>0)) then
begin
BYTE(target^):=$E9;
DWORD(Pointer(DWORD(target)+1)^):=DWORD(new_adr) - DWORD(target) - DWORD(5);
TrueAdr^:=DWORD(target)+5;
result:=true;
end;
end;
function GetInterfaceMethod(const intf; methodIndex: dword) : pointer;
begin
result := pointer(pointer(dword(pointer(intf)^) + methodIndex * 4)^);
end;
function EndScene9Next(self: pointer): HResult;stdcall;
begin asm jmp [adr_EndScene9] end; end;
function CreateDevice9Next(self: Pointer; Adapter: LongWord; DeviceType: TD3DDevType; hFocusWindow: HWND; BehaviorFlags: DWord; pPresentationParameters: PD3DPresentParameters; out ppReturnedDeviceInterface: IDirect3DDevice9) : HRESULT;stdcall;
begin asm jmp [adr_CreateDevice9] end; end;
function Direct3DCreate9Next(SDKVersion: LongWord): DWORD;stdcall;
begin asm jmp [adr_Direct3DCreate9] end; end;
//РИСУЕМ ТУТ
function EndScene9Callback(self: pointer): HResult; stdcall;
var
TextRect: TRect;
begin
//мы все еще между begin и endscene, знач рисуем
TextRect := Rect(100,100,100,100);
g_Font.DrawTextA(nil,PChar('Хеллоу ворлд!!!'),-1,@TextRect,DT_LEFT or DT_NOCLIP,D3DCOLOR_RGBA($ff, $00, $00, $ff));
//а вот теперь вызоверем оригинальную endscene
Result:=EndScene9Next(self);
end;
//конец того где рисуем
function CreateDevice9Callback(self: pointer; Adapter: LongWord; DeviceType: TD3DDevType; hFocusWindow: HWND; BehaviorFlags: DWord; pPresentationParameters: PD3DPresentParameters; out ppReturnedDeviceInterface: IDirect3DDevice9) : HRESULT; stdcall;
var
A: Integer;
begin
result := CreateDevice9Next(self, adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
D3DDev := ppReturnedDeviceInterface;
if (result = 0) then
begin
A := D3DXCreateFont(
D3DDev, 14, 0, FW_NORMAL, 1,
false, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH or FF_DONTCARE,
PChar('Arial'),
g_Font
);
HookCode(GetInterfaceMethod(ppReturnedDeviceInterface{^}, 42), @EndScene9Callback, @adr_EndScene9);
end;
end;
function Direct3DCreate9Callback(SDKVersion: LongWord): DWORD; stdcall;
var
F: TStrings;
begin
Result:=Direct3DCreate9Next(SDKVersion);
D3DObj := IDirect3D9(Result);
if (Result <> 0) then
begin
HookCode(GetInterfaceMethod(result, 16), @CreateDevice9Callback, @adr_CreateDevice9);
end;
end;
begin
HookCode(GetProcAddress(LoadLibraryA('d3d9.dll'),'Direct3DCreate9'), @Direct3DCreate9Callback, @adr_Direct3DCreate9)
end.