Autor Beitrag
Darkpara
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 61

Win XP

BeitragVerfasst: Mi 14.11.07 21:32 
Moin,

ich versuche ein kleines programm zu schreiben mit dem ich mir fps oder später vl. auch ma was anderes im spiel anzeigen lassen will.
vom prinzip gleich wie das teamspeak overlay oder fraps, die zeigen auch informationen in einem fullscreen spiel an.

hab bisel rumgelesen und bin auch hooks gestossen, mit welchen ich mich leider kaum auskenne.

so nun zur frage hier habe ich eine dll gefunden mit welcher es möglich sein soll texte in spielen auszugeben

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
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.


nur krig ich hier viele fehler:

[Pascal Error] directdll.dpr(23): E2003 Undeclared identifier: 'id3dxfont'
[Pascal Error] directdll.dpr(24): E2003 Undeclared identifier: 'td3dcolor'
[Pascal Error] directdll.dpr(37): E2066 Missing operator or semicolon
[Pascal Error] directdll.dpr(37): E2010 Incompatible types: 'HDC' and 'Pointer'
[Pascal Error] directdll.dpr(37): E2034 Too many actual parameters
[Pascal Error] directdll.dpr(45): E2003 Undeclared identifier: 'rect'
[Pascal Error] directdll.dpr(45): E2003 Undeclared identifier: 'y'
[Pascal Error] directdll.dpr(45): E2003 Undeclared identifier: 'x'
[Pascal Error] directdll.dpr(53): E2015 Operator not applicable to this operand type
[Pascal Error] directdll.dpr(55): E2003 Undeclared identifier: 'd3dxcreatefont'
[Pascal Error] directdll.dpr(55): E2003 Undeclared identifier: 'idirect3ddevice9'
[Pascal Error] directdll.dpr(67): E2003 Undeclared identifier: 'd3dcolor_rgba'
[Pascal Error] directdll.dpr(68): E2066 Missing operator or semicolon

wo genau muss ich den die variablen deklarieren in einer dll datei?
und die id3dxfont, td3color... ect, sollen mit nem header deklariert sein, wo krig ich so nen header her?

und nun die letzt frage, wenn ich die dll dann injecte wie use ich die funktionen dieser dll in meinem program?

danke schon mal im voraus..


Moderiert von user profile iconNarses: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Mi 14.11.2007 um 22:42
SAiBOT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: Mi 28.11.07 14:31 
-Du brauchst ein "DirectX SDK" (Software Development Kit), bzw Delphi Header such mal bei google!
-Und du brauchst die "madCollection" (Komponentensammlung von madsi) www.madshi.net/

Viel Erfolg!
Darkpara Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 61

Win XP

BeitragVerfasst: Do 29.11.07 00:09 
danke dir
konnte nun die dll fertig schreiben und hab auch was gefunden um die dll funktionen anzusprechen nur funktioniet das ned richtig :(
kennt sich wer mit dem madcomponenten aus? wär cool wenn irh ma schauen könnt was falsch is thx im voraus

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
library DrawText;

uses
  Windows,
  madCodeHook,
  DirectXGraphics in 'C:\Package\dx8\DirectXGraphics.pas',
  Direct3D9 in 'C:\Package\dx8\Direct3D9.pas',
  d3dx9 in 'C:\Package\dx8\d3dx9.pas';

{$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;
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;

procedure GetMsgFromDLL(name       : pchar;
                        messageBuf : pointer; messageLen : dword;
                        answerBuf  : pointer; answerLen  : dword); stdcall;
begin
  // this code has to be thread safe!
  boolean(answerBuf^) := MessageBox(0, pchar(messageBuf), 'question', MB_YESNO) = ID_YES;
end;

begin
  CreateIpcQueue('ShowText', GetMsgFromDLL);
  hookdirect3d9;
end.


hier is meine app. die auf die dll zugreiffen soll
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  UninjectLibrary(CURRENT_USER, 'DrawText.dll');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  InjectLibrary(CURRENT_USER, 'DrawText.dll');
end;


procedure TForm1.Timer1Timer(Sender: TObject);
begin
  SendIpcMessage('ShowText', pchar('test'), Length('test'));
end;
Der_Ventilator
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Di 26.02.08 01:53 
Hallo, hast du dein Programm fertig bekommen, ich versuch nämlich gerade das gleiche (Liedtitel meines Players in DirectX ausgeben) und könnte noch ein paar Tips gebrauchen
Tobi482
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135



BeitragVerfasst: Fr 07.03.08 17:24 
Hi,

ich kann dir da weiter helfen. Dazu muss ich aber erst wissen
um welches Spiel es sich handelt. Wie lange programmierst du
schon mit Delphi? Hast du schon mal mit Hooks gearbeitet?

Gruß Tobi