library directdll;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
Windows,
madCodeHook;
{$R *.res}
var
direct3dcreate9next :
function (sdkversion : dword ) : dword;
stdcall =
nil;
createdevice9next :
function (self, adapter, devtype, wnd, flags, params, device: pointer) : dword;
stdcall =
nil;
presentnext :
function (self: pointer;
const sourcerect, destrect : prect;
const destwindowoverride : hwnd; dirtyregion : prgndata) : hresult;
stdcall =
nil;
font : id3dxfont;
mycolor : td3dcolor;
function getinterfacemethod(
const intf; methodindex: dword) : pointer;
begin
result := pointer(pointer(dword(pointer(intf)^) + methodindex * 4)^);
end;
procedure showtext(x,y: integer; s:
string; col: td3dcolor);
var
rect : trect;
begin
rect.top := y; rect.left := x;
rect.bottom := y+1; rect.right := x+1;
if @font <>
nil then
font.drawtexta(
nil,pchar(s),length(s),rect,dt_noclip,mycolor);
end;
function presentcallback(self : pointer;
const sourcerect, destrect : prect;
const destwindowoverride : hwnd; dirtyregion : prgndata) : hresult;
stdcall;
var
test : hwnd;
begin
result := presentnext(self,sourcerect,destrect,destwindowoverride,dirtyregion);
showtext(100,100,'
test',mycolor);
end;
function createdevice9callback(self, adapter, devtype, wnd, flags, params, device: pointer) : dword;
stdcall;
begin
font :=
nil;
result := createdevice9next(self, adapter, devtype, wnd, flags, params, device);
if font =
nil then
begin
d3dxcreatefont(idirect3ddevice9(device^),
20,
20,
0,
1,
false,
ansi_charset,
out_default_precis,
default_quality,
default_pitch,
'
Arial',
font);
mycolor := d3dcolor_rgba(255,0,0,255);
font.preloadcharacters(0,255);
end;
if result = 0
then begin
if @presentnext =
nil then
begin
hookcode(getinterfacemethod(device^, 17), @presentcallback, @presentnext)
end else
renewhook(@presentnext);
end;
end;
function direct3dcreate9callback(sdkversion: dword) : dword;
stdcall;
begin
font :=
nil;
result := direct3dcreate9next(sdkversion);
if result <> 0
then
if @createdevice9next =
nil then
hookcode(getinterfacemethod(result, 16), @createdevice9callback, @createdevice9next)
else
renewhook(@createdevice9next);
end;
function hookdirect3d9 : boolean;
begin
result := hookapi('
d3d9.dll', '
Direct3DCreate9', @direct3dcreate9callback, @direct3dcreate9next);
end;
begin
hookdirect3d9;
end.