Results 1 to 1 of 1
  1. #1
    DatSik
    DatSik is offline
    New member DatSik's Avatar
    Join Date
    2012 Sep
    Location
    Oklahoma
    Posts
    24
    Thanks Thanks Given 
    1
    Thanks Thanks Received 
    9
    Thanked in
    1 Post
    Rep Power
    0

    Arrow D3D resources for Delphi

    Anyone have some good tutorials/Articles over this subject?

    Here is what i have found as far, im just looking for more is all. this is great and i dont take credit for it.

    Code:
    unit clsMenuEngine;
    
    interface
    
    uses  Windows, SysUtils, Variants, D3DX9, Direct3D9, DXTypes;
    
    type
     TItems = packed record
      strName: PAnsiChar;
      bOn    : Boolean;
      bShowCheck: Boolean;
    end;
    
    Type
     TMenuEngine = Class
      Private
       pD3Ddev:  Direct3D9.IDirect3DDevice9;
       fMenuFont: D3DX9.ID3DXFont;
    
       bVisable: Boolean;
       iMenuX, iMenuY, iMenuW, iMenuH, iMenuItems: Integer;
       dwMenuBgColor, dwMenuBorderColor, dwCrossHairColor, dwTextColor: Dword;
    
       Function GetDevice():IDirect3DDevice9;
       function GetFont(): ID3DXFont;
       procedure DrawRectangle(iXleft, iYtop, iWidth, iHight: Integer; Color: Dword);
       procedure DrawRectangleAlpha(iXleft, iYtop, iWidth, iHight: Integer; Color: Dword);
       procedure DrawBorder();
       procedure DrawBorderAlpha();
       procedure DrawCheck( Color: Dword; x,  y: Integer);
       procedure DrawDash( Color: Dword; x,  y: Integer);
       procedure DrawPlus(Color: Dword; x, y: Integer);
       procedure DrawBox();
       procedure DrawBoxAlpha();
       procedure DrawText(const iLeft, iTop: Integer; szText: PAnsiChar);
    
      Public
       aItems: Array of TItems;
       Constructor Create( Left, Top, Width, Hight, Items: Integer; BGColor, BDColor, TXTColor: Dword);
       Destructor Destroy(); Override;
       Procedure Render();
       Procedure Reset(Const pDevice: IDirect3DDevice9);
       procedure DrawXhair();
       procedure MenuItemAdd( iIndex: Integer; szText: PAnsiChar; bOnOff: Boolean; bShowOnOff: Boolean = True);
    
       Property Direct3DDevice: Direct3D9.IDirect3DDevice9 read pD3Ddev write pD3Ddev;
    
    
    
       Property MenuLeft: Integer read iMenuX write iMenuX;
       Property MenuTop: Integer read iMenuY write iMenuY;
       Property MenuWidth: Integer read iMenuW write iMenuW;
       Property MenuHight: Integer read iMenuH write iMenuH;
       Property MenuItems: Integer read iMenuItems write iMenuItems;
    
       Property BackGroundColor: Dword read dwMenuBgColor write dwMenuBgColor;
       Property BorderColor: Dword read dwMenuBorderColor write dwMenuBorderColor;
       Property TextColor: Dword read dwTextColor write dwTextColor;
    
       Property XHairColor: Dword read dwCrossHairColor write dwCrossHairColor;
    
       Property Menuvisable: Boolean read bVisable write bVisable;
    
    end;
    
    implementation
    
    { TMenuEngine }
    
    constructor TMenuEngine.Create( Left, Top,
      Width, Hight, Items: Integer; BGColor, BDColor, TXTColor: Dword);
    begin
       MenuLeft:= Left; MenuTop:= Top; MenuWidth:= Width; MenuHight:= Hight;
       BackGroundColor:= BGColor; BorderColor:= BDColor; TextColor:= TXTColor;
       MenuItems:= Items;
       SetLength(aItems,MenuItems);
    end;
    
    destructor TMenuEngine.Destroy;
    var
     i: Integer;
    begin
      inherited Destroy();
      pD3Ddev:= Nil;
      fMenuFont:= Nil;
    end;
    
    procedure TMenuEngine.DrawBorder;
    begin
       DrawRectangle(iMenuX, (iMenuY + iMenuH - 1), iMenuW, 1, dwMenuBorderColor);
       DrawRectangle(iMenuX, iMenuY, 1, iMenuH, dwMenuBorderColor);
       DrawRectangle(iMenuX, iMenuY, iMenuW, 1, dwMenuBorderColor);
       DrawRectangle((iMenuX + iMenuW - 1), iMenuY, 1, iMenuH, dwMenuBorderColor);
    end;
    
    procedure TMenuEngine.DrawBorderAlpha;
    begin
       DrawRectangleAlpha(iMenuX, (iMenuY + iMenuH - 1), iMenuW, 1, dwMenuBorderColor);
       DrawRectangleAlpha(iMenuX, iMenuY, 1, iMenuH, dwMenuBorderColor);
       DrawRectangleAlpha(iMenuX, iMenuY, iMenuW, 1, dwMenuBorderColor);
       DrawRectangleAlpha((iMenuX + iMenuW - 1), iMenuY, 1, iMenuH, dwMenuBorderColor);
    end;
    
    procedure TMenuEngine.DrawBox;
    begin
       DrawRectangle(iMenuX, iMenuY, iMenuW, iMenuH, dwMenuBgColor);
       DrawBorder;
    end;
    
    procedure TMenuEngine.DrawBoxAlpha;
    begin
       DrawRectangleAlpha(iMenuX, iMenuY, iMenuW, iMenuH, dwMenuBgColor);
       DrawBorderAlpha;
    end;
    
    procedure TMenuEngine.DrawCheck(Color: Dword; x, y: Integer);
    begin
      DrawRectangle( x,     y,     1, 3, Color );
    	DrawRectangle( x + 1, y + 1, 1, 3, Color );
    	DrawRectangle( x + 2, y + 2, 1, 3, Color );
    	DrawRectangle( x + 3, y + 1, 1, 3, Color );
    	DrawRectangle( x + 4, y,     1, 3, Color );
    	DrawRectangle( x + 5, y - 1, 1, 3, Color );
    	DrawRectangle( x + 6, y - 2, 1, 3, Color );
    	DrawRectangle( x + 7, y - 3, 1, 3, Color );
    end;
    
    procedure TMenuEngine.DrawDash(Color: Dword; x, y: Integer);
    begin
      DrawRectangle( x , y , 8, 3, Color );
    end;
    
    procedure TMenuEngine.DrawPlus(Color: Dword; x, y: Integer);
    begin
       DrawRectangle( x , y , 7, 1, Color );
       DrawRectangle( x + 3 , y - 3 , 1, 7, Color );
    end;
    
    procedure TMenuEngine.DrawRectangle(iXleft, iYtop, iWidth, iHight: Integer; Color: Dword);
    var
      d3dRectangle : D3DRECT;
    begin
    
       d3dRectangle.x1:= iXleft;
       d3dRectangle.y1:= iYtop;
       d3dRectangle.x2:= iXleft + iWidth;
       d3dRectangle.y2:= iYtop + iHight;
    
       Direct3DDevice.Clear(1,@d3dRectangle, D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER, Color, 0, 0);
    end;
    
    procedure TMenuEngine.DrawRectangleAlpha(iXleft, iYtop, iWidth, iHight: Integer; Color: Dword);
    type
      tStruct = packed record
        x, y, z, rhw: Single;
        Color: dWord;
    end;
    procedure AssignVertex(var Vertex: tStruct; x, y, z, rhw: Single; Color: Dword);
     begin
       Vertex.x:= x; Vertex.y:= y; Vertex.z:= z;
       Vertex.Color:= Color;
     end;
    var
      qV: array[0..3] of tStruct;
    begin
    
       AssignVertex(qV[0], iXLeft, iYtop + iHight, 0.0, 0.0, Color);
       AssignVertex(qV[1], iXLeft, iYtop, 0.0, 0.0, Color);
       AssignVertex(qV[2], iXLeft + iWidth, iYtop + iHight, 0.0, 0.0, Color);
       AssignVertex(qV[3], iXLeft + iWidth, iYtop, 0.0, 0.0, Color);
    
       Direct3DDevice.SetRenderState(D3DRS_ALPHABLENDENABLE,1);
       Direct3DDevice.SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
       Direct3DDevice.SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
       Direct3DDevice.SetRenderState(D3DRS_FOGENABLE, 0);
    
       Direct3DDevice.SetFVF(D3DFVF_XYZRHW or D3DFVF_DIFFUSE);
       Direct3DDevice.SetTexture(0, Nil);
       Direct3DDevice.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,qV,SizeOf(tStruct));
    
    end;
    
    procedure TMenuEngine.DrawText(const iLeft, iTop: Integer;
      szText: PAnsiChar);
    var
      d3dRectangle : D3DRECT;
    begin
      d3dRectangle.x1:= ileft;
      d3dRectangle.y1:= itop;
      d3dRectangle.x2:= ileft + 130;
      d3dRectangle.y2:= itop + 10;
    
      fMenuFont.DrawTextA(nil, szText, -1, @d3dRectangle, 0{( DT_CALCRECT or DT_NOCLIP )}, dwTextColor);
    
    end;
    
    procedure TMenuEngine.DrawXhair;
    var
      viewP: D3DVIEWPORT9;
      ScreenCenterX,ScreenCenterY: DWORD;
      d3dRectangle1,d3dRectangle2: D3DRECT;
    begin
      // Get screen
      Direct3DDevice.GetViewport(viewP);
      ScreenCenterX:= ((viewP.Width div 2) - 1);
      ScreenCenterY:= ((viewP.Height div 2) - 1);
      //Set xhair params
      d3dRectangle1.x1:= ScreenCenterX-10;
      d3dRectangle1.y1:= ScreenCenterY;
      d3dRectangle1.x2:= ScreenCenterX+ 10;
      d3dRectangle1.y2:= ScreenCenterY+1;
      d3dRectangle2.x1:= ScreenCenterX;
      d3dRectangle2.y1:= ScreenCenterY-10;
      d3dRectangle2.x2:= ScreenCenterX+ 1;
      d3dRectangle2.y2:= ScreenCenterY+10;
      //Draw crosshair
      Direct3DDevice.Clear(1, @d3dRectangle1, D3DCLEAR_TARGET, XHairColor, 0,  0);
      Direct3DDevice.Clear(1, @d3dRectangle2, D3DCLEAR_TARGET, XHairColor, 0,  0);
    end;
    
    function TMenuEngine.GetDevice: IDirect3DDevice9;
    begin
      Result:= Direct3DDevice;
    end;
    
    function TMenuEngine.GetFont: ID3DXFont;
    begin
      Result:= fMenuFont;
    end;
    
    procedure TMenuEngine.MenuItemAdd(iIndex: Integer; szText: PAnsiChar;
      bOnOff: Boolean; bShowOnOff : Boolean = True);
    begin
     aItems[pred(iIndex)].strName:= szText;
     aItems[pred(iIndex)].bOn:= bOnOff;
     aItems[pred(iIndex)].bShowCheck:= bShowOnOff;
    end;
    
    procedure TMenuEngine.Render;
    var
     i: integer;
    begin
       if MenuVisable then
        begin
         if MenuHight = 0 then
          MenuHight:= ((11 * MenuItems)+ 9);
         DrawBoxAlpha;
         for i:= 1 to MenuItems do
          begin
           If aItems[pred(i)].bShowCheck then
            begin
             TextColor:= $FF6746A3;
             DrawText(MenuLeft + 5,(MenuTop + 5 + (i*11) - 11)  , PChar(aItems[pred(i)].strName));
             if i = 2 then
              DrawPlus(XHairColor, (MenuLeft + MenuWidth) - 12 , (MenuTop + 5 + (i*11) - 11) + 2)
             else
             Case aItems[pred(i)].bOn of
              True: DrawCheck($EE00FF00, (MenuLeft + MenuWidth) - 12 , (MenuTop + 5 + (i*11) - 11) + 2);
              False: DrawDash($EEFF0000, (MenuLeft + MenuWidth) - 12 , (MenuTop + 5 + (i*11) - 11) + 2);
             end;
           end
           else
            begin
              TextColor:= $FFCB7018;
              DrawText(MenuLeft + 5,(MenuTop + 5 + (i*11) - 11)  , PChar(aItems[pred(i)].strName));
            end;
          end;
        end;
    end;
    
    procedure TMenuEngine.Reset(Const pDevice: IDirect3DDevice9);
    begin
       if Direct3DDevice <>  pDevice then
        begin
         Direct3DDevice:= pDevice;
         fMenuFont:= nil;
        if fMenuFont = nil then
         D3DXCreateFont(Direct3DDevice,10, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH or FF_DONTCARE, 'Terminal', fMenuFont);
       end;
    end;
    
    end.
    Usage:
    Code:
    MyMenu:= TMenuEngine.Create(20,20,100,18,1,$96000000,$FF000000,$FFCB7018);
    Arguments:
    Code:
    Create( Left, Top, Width, Hight, Items: Integer; BGColor, BDColor, TXTColor: Dword);
    o add Items to your menu:
    Code:
    MyMenu.MenuItemAdd(1,  'Your Menu Item Text',True, False);
    Arguments:
    PHP Code:
    MenuItemAddiIndexIntegerszTextPAnsiCharbOnOffBooleanbShowOnOffBoolean True); 
    To render your menu, just call it in a your hooked D3D9 function like this

    Code:
    if MyMenu.Direct3DDevice <> Self then
      MyMenu.Reset(Self);
    
    if MyMenu.Menuvisable then
      MyMenu.Render;

Similar Threads

  1. Replies: 148
    Last Post: 2022-07-04, 09:35 PM
  2. [Info] Warkeepers RESOURCES Unpack Script
    By h4x0r in forum Game Files
    Replies: 0
    Last Post: 2013-01-05, 07:06 PM
  3. [C++] Awesomenauts Resources Decrypting
    By h4x0r in forum C/C++
    Replies: 0
    Last Post: 2012-08-04, 12:12 AM
  4. [Delphi] Delphi elementclient inject
    By marcelo380 in forum Perfect World
    Replies: 0
    Last Post: 2012-06-08, 09:13 PM
  5. [Delphi] Delphi Training Video
    By Dwar in forum Programming Tutorials
    Replies: 0
    Last Post: 2010-11-29, 04:10 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •