library UT_Hook;
uses
SysUtils,
Classes,
MagicApiHook,
dglOpenGL,
Windows;
var
oBindTexture : procedure(target : GLenum; texture: GLuint); stdcall;
oDrawElements : procedure(mode: GLenum; count: GLsizei; _type: GLenum; indices: PGLvoid); stdcall;
oBegin : procedure(mode: GLenum); stdcall;
cTarget : Boolean; // Cham Target
{$R *.res}
procedure Colorize(r:Double; g:Double; b:Double);
// Colorize the OpenGL Model for Chams
var
color : array[0..5010] of Double;
d : Integer;
begin
d := 0;
while(d <= 5007) do
begin
color[d] := r;
color[d+1] := g;
color[d+2] := b;
d := d+3;
end;
glColorPointer(3, GL_FLOAT, 0, @color);
end;
procedure CheckTarget(c : PAnsiChar);
begin
if(AnsiPos('player',c) > 0) then // This is part of the texture path
cTarget := True // that I logged. I will post my
else begin // texture logger in the tutorial.
cTarget := False; // Again, credz to Quicktime` for
end; // idea. (Logger)
end;
procedure hBindTexture(target : GLenum; texture: GLuint); stdcall;
var
Shader : DWORD;
begin
asm
mov Shader, esi // MAJOR Credits to Quicktime`, this
end; // method is so easy for model rec.
if(Shader > 4096) then
begin
CheckTarget(Pointer(Shader));
end;
oBindTexture(target, texture);
end;
procedure hDrawElements(mode : GLenum; count : GLsizei; _type : GLenum; indices: PGLvoid); stdcall;
begin
if(cTarget) then
begin
glDisable(GL_DEPTH_TEST);
Colorize(1, 0, 0); // Divide the rgb values by 255. This will be red when behind walls.
oDrawElements(mode, count, _type, indices); // Draw the model
//Colorize(0, 1, 0); // Green for visible
glEnable(GL_DEPTH_TEST);
end;
oDrawElements(mode, count, _type, indices);
end;
procedure hBegin(mode: GLenum); stdcall;
begin
if(cTarget) then
begin
glDisable(GL_CULL_FACE);
glDisable(GL_FOG);
end;
oBegin(mode);
end;
begin
// Hooking GL Functions
InitOpenGL();
ReadExtensions();
ReadImplementationProperties();
cTarget := false;
ApiHook('opengl32.dll','glBindTexture',nil,@hBindTexture,@oBindTexture);
ApiHook('opengl32.dll','glDrawElements',nil,@hDrawElements,@oDrawElements);
ApiHook('opengl32.dll','glBegin',nil,@hBegin,@oBegin);
end.