Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Departure's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    818
    Reputation
    125
    Thanks
    1,785
    My Mood
    Doh

    Delphi Menu Class

    Decided to start making a class for a menu instead of just using standard functions and procedures, This allows multiple menus ect.. to be used. It is very configurable and can be configured on the fly with ease. And for some reason it actually gained FPS when using this class rather than calling functions(old menu), Anyway I hope it helps the Delphi users out

    P.s Dont try converting this to C++, It was built from scratch and is optimized for delphi..


    Credits:
    A couple of C++ functions That I converted to delphi (X-hair, DrawTriangleAlpha)

    [highlight=Delphi]
    (****************************
    Unit : clsMenuEngine
    Author : Departure
    ****************************)

    unit clsMenuEngine;

    interface

    uses Windows, SysUtils, Variants, D3DX9, Direct3D9, ***ypes;

    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_ALPHABLENDENAB LE,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
    //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.
    [/highlight]

    How to use:
    [highlight=Delphi]
    MyMenu:= TMenuEngine.Create(20,20,100,18,1,$96000000,$FF000 000,$FFCB7018);
    [/highlight]

    Arguments are.. Left,Top,Width,Hight,Number of Items,Backgound color, Border Color, Text Color

    All of these can be changed during running, Also the hight of the menu can be automatically calculated from the number of items(no need to set the high if you want to use the auto feature). there are many other cool features with this menu... once you have created your menu you can items like this...

    [highlight=Delphi]
    MyMenu.MenuItemAdd(1, '--{ DMHv0.3 }--',True, False);
    [/highlight]

    Arguments: Position of item, Text, Hack On/Off, Show CheckBox

    Hack on/off will determine if a tick or a dash gets showen next the item name, Show Checkbox is useful if you are adding a non hack item(example the title) otherwise if its a hack item this does not need to be set(Argument is True by default)...


    To render your menu you can do it like this in the hooked d3d function....

    [highlight=delphi]
    if MyMenu.Direct3DDevice <> Self then
    MyMenu.Reset(Self);

    if MyMenu.Menuvisable then
    MyMenu.Render;
    [/highlight]

    using the same way you can create as many menus as you want and can all be shown at the same time with different colours, settings, position, text ect.. ect.. without a big lose of FPS,
    Last edited by Departure; 05-31-2011 at 01:30 PM.

  2. The Following 7 Users Say Thank You to Departure For This Useful Post:

    [MPGH]AVGN (06-01-2011),freedompeace (05-31-2011),markoj (05-31-2011),NOOBJr (06-01-2011),OBrozz (06-10-2011),ParkII (06-11-2011),Stephen-Backup (06-11-2011)

  3. #2
    Fido Dido's Avatar
    Join Date
    May 2011
    Gender
    male
    Posts
    81
    Reputation
    22
    Thanks
    836
    Looks interesting.

  4. #3
    NOOBJr's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    in NOOB
    Posts
    1,426
    Reputation
    112
    Thanks
    693
    Nice Job Departure. This is cool I'm going to use it If I understand Delphi a little better.

  5. #4
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,035
    Reputation
    340
    Thanks
    2,784
    My Mood
    Sad
    Great work !

    Except... only like, one person in this entire section is proficient at Delphi: you. :/

  6. #5
    NOOBJr's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    in NOOB
    Posts
    1,426
    Reputation
    112
    Thanks
    693
    [SIZE="3"]
    Quote Originally Posted by freedompeace View Post
    Great work !

    Except... only like, one person in this entire section is proficient at Delphi./SIZE]


    Are you talking about me? LOL

  7. #6
    `Bobs Bees's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Posts
    930
    Reputation
    33
    Thanks
    183
    My Mood
    Relaxed
    Finally a working Delphi source, thanks.

    Anychance you have MsN that I could add you I need to ask you about some things.
    User CP -> Edit Signature -> Make less then one line.

  8. #7
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,035
    Reputation
    340
    Thanks
    2,784
    My Mood
    Sad
    Quote Originally Posted by Zane Slayman View Post


    Are you talking about me? LOL tehe
    If you hadn't modified my post, you would know who. :)

  9. The Following User Says Thank You to freedompeace For This Useful Post:

    NOOBJr (05-31-2011)

  10. #8
    Crash's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    JAville
    Posts
    2,889
    Reputation
    163
    Thanks
    3,289
    My Mood
    Sleepy
    Quote Originally Posted by freedompeace View Post


    If you hadn't modified my post, you would know who.
    I've never heard of anybody called you. ...

  11. #9
    NOOB's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Posts
    3,863
    Reputation
    425
    Thanks
    8,598
    Quote Originally Posted by Crash View Post
    I've never heard of anybody called you. ...
    let's call him

    @YOU

  12. The Following 2 Users Say Thank You to NOOB For This Useful Post:

    ++PashaAmd++ (05-31-2011),topblast (06-01-2011)

  13. #10
    tokairo's Avatar
    Join Date
    Nov 2008
    Gender
    male
    Location
    In a hole in Goiânia...
    Posts
    18
    Reputation
    10
    Thanks
    2
    My Mood
    Fine
    I'm very noob but I'm trying to evolve.
    I'm trying to test this code but is giving error:

    Direct3DDevice.Clear(1,@D3DRectangle, D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER, Color, 0, 0);

    Help me?

  14. #11
    markoj's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    s
    Posts
    1,067
    Reputation
    60
    Thanks
    407
    My Mood
    Bored
    Delphi looks like a pain, but it's a good alternative language for CA hacking. Great job
    Dont ban me

  15. The Following User Says Thank You to markoj For This Useful Post:

    NOOBJr (05-31-2011)

  16. #12
    Emote's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Posts
    202
    Reputation
    9
    Thanks
    18
    My Mood
    Inspired
    Good Job.

  17. #13
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    4,922
    My Mood
    Cool
    Quote Originally Posted by freedompeace View Post
    Great work !

    Except... only like, one person in this entire section is proficient at Delphi: you. :/
    Your wrong , For me to use Departure's Detours I would of have known Delphi to convert Them. I also know Delphi, how as much as him but I know enough
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  18. #14
    Emote's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Posts
    202
    Reputation
    9
    Thanks
    18
    My Mood
    Inspired
    Quote Originally Posted by markoj View Post
    Delphi looks like a pain, but it's a good alternative language for CA hacking. Great job
    yea man.........

  19. #15
    whit's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    7,170
    Reputation
    490
    Thanks
    2,252
    Quote Originally Posted by topblast View Post


    Your wrong , For me to use Departure's Detours I would of have known Delphi to convert Them. I also know Delphi, how as much as him but I know enough
    Its not hard to figure out the syntax

  20. The Following User Says Thank You to whit For This Useful Post:

    NOOBJr (06-01-2011)

Page 1 of 2 12 LastLast