Share Pastebin
Guest
Public paste!

unasianazn

By: a guest | Dec 17th, 2009 | Syntax: Delphi | Size: 2.41 KB | Hits: 45 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. library UT_Hook;
  2.  
  3. uses
  4.   SysUtils,
  5.   Classes,
  6.   MagicApiHook,
  7.   dglOpenGL,
  8.   Windows;
  9.  
  10. var
  11.   oBindTexture : procedure(target : GLenum; texture: GLuint);  stdcall;
  12.   oDrawElements : procedure(mode: GLenum; count: GLsizei; _type: GLenum; indices: PGLvoid); stdcall;
  13.   oBegin : procedure(mode: GLenum); stdcall;
  14.   cTarget : Boolean; // Cham Target
  15.  
  16. {$R *.res}
  17.  
  18. procedure Colorize(r:Double; g:Double; b:Double);
  19. // Colorize the OpenGL Model for Chams
  20. var
  21.   color : array[0..5010] of Double;
  22.   d     : Integer;
  23. begin
  24.   d := 0;
  25.   while(d <= 5007) do
  26.   begin
  27.     color[d]   := r;
  28.     color[d+1] := g;
  29.     color[d+2] := b;
  30.     d := d+3;
  31.   end;
  32.   glColorPointer(3, GL_FLOAT, 0, @color);
  33. end;
  34.  
  35. procedure CheckTarget(c : PAnsiChar);
  36. begin
  37.   if(AnsiPos('player',c) > 0) then // This is part of the texture path
  38.     cTarget := True                //  that I logged. I will post my
  39.   else begin                       //  texture logger in the tutorial.
  40.     cTarget := False;              // Again, credz to Quicktime` for
  41.   end;                             //  idea. (Logger)
  42. end;
  43.  
  44. procedure hBindTexture(target : GLenum; texture: GLuint); stdcall;
  45. var
  46.   Shader : DWORD;
  47. begin
  48.   asm
  49.     mov Shader, esi             // MAJOR Credits to Quicktime`, this
  50.   end;                          // method is so easy for model rec.
  51.   if(Shader > 4096) then
  52.   begin
  53.     CheckTarget(Pointer(Shader));
  54.   end;
  55.  
  56.   oBindTexture(target, texture);
  57. end;
  58.  
  59. procedure hDrawElements(mode : GLenum; count : GLsizei; _type : GLenum; indices: PGLvoid); stdcall;
  60. begin
  61.   if(cTarget) then
  62.   begin
  63.     glDisable(GL_DEPTH_TEST);
  64.     Colorize(1, 0, 0); // Divide the rgb values by 255. This will be red when behind walls.
  65.     oDrawElements(mode, count, _type, indices); // Draw the model
  66.     //Colorize(0, 1, 0); // Green for visible
  67.     glEnable(GL_DEPTH_TEST);
  68.   end;
  69.  
  70.   oDrawElements(mode, count, _type, indices);
  71. end;
  72.  
  73. procedure hBegin(mode: GLenum); stdcall;
  74. begin
  75.   if(cTarget) then
  76.   begin
  77.     glDisable(GL_CULL_FACE);
  78.     glDisable(GL_FOG);
  79.   end;
  80.   oBegin(mode);
  81. end;
  82.  
  83. begin
  84.   // Hooking GL Functions
  85.   InitOpenGL();
  86.   ReadExtensions();
  87.   ReadImplementationProperties();
  88.   cTarget := false;
  89.  
  90.   ApiHook('opengl32.dll','glBindTexture',nil,@hBindTexture,@oBindTexture);
  91.   ApiHook('opengl32.dll','glDrawElements',nil,@hDrawElements,@oDrawElements);
  92.   ApiHook('opengl32.dll','glBegin',nil,@hBegin,@oBegin);
  93. end.