[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)
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;
Verte*****lor:= 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 12:30 PM.
[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)
Nice Job Departure. This is cool I'm going to use it If I understand Delphi a little better.
Great work !
Except... only like, one person in this entire section is proficient at Delphi: you. :/
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.
NOOBJr (05-31-2011)
let's call him
@YOU
++PashaAmd++ (05-31-2011),topblast (06-01-2011)
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?
Delphi looks like a pain, but it's a good alternative language for CA hacking. Great job
Dont ban me
NOOBJr (05-31-2011)
I just like programming, that is all.
Current Stuff:
- GPU Programmer (Cuda)
- Client/Server (Cloud Server)
- Mobile App Development
NOOBJr (06-01-2011)