My C# Menu Class

PollDo you think this will work?
4 votes
Posts 1–11 of 11 · Page 1 of 1
My C# Menu Class
Hey guys, I attempted to get a menu working on my C# hack but I couldn't get the d3d device so I just gave up. I'ma just give up here after a few hours of googling, there seems to be no simple solution I could use. If anyone manages to get it, please help me out. Otherwise here is my menu code... It might not work as I can't test it without getting the device.

This is a basic port of Void's menu, Void also helped me out on a lot of the menu...

To C&P'ers, theres no point as this code will not work without a device.

Note: This code supports display numeral values as well as On/Off, the number can only go up to 10, but you can easily change that.

[PHP]//User1's C# Menu Class, ported from Void's menu class.
//Please give credits when used.
//This code might catastrophically fail as I never tried this...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;


namespace CombatArmsHack
{
class Menu
{
//Please tell me you understand the below code...
[DllImport("user32.dll")]
static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);

private System.Drawing.Font menuFont = new System.Drawing.Font("Comic Sans MS", 15); //The font to set the D3D Font to...

private Device m_Device; //D3D Device, if you can get this Managed or Unmanaged, please contact me.
private Font m_Font; //D3D Font
public List<MenuItem> MenuItems = new List<MenuItem>();


//Creates the font and sets the device
public Menu(Device device)
{
m_Device = device;
m_Font = new Font(m_Device,menuFont);
}
//Add a new Item to the Menu.
public void AddItem(string Text, int State, bool Logic)
{
MenuItem NewItem = new MenuItem();
NewItem.Text = Text;
NewItem.State = State;
NewItem.Logic = Logic;

MenuItems.Add(NewItem);
}
//Draws menu.
public void RenderMenu()
{
//Rectangle where one of the menu items will be rendered
System.Drawing.Rectangle CurRect = new System.Drawing.Rectangle(20,20,150,20);

for(int i = 0; i < MenuItems.Count;i++)
{
bool Selected = MenuItems[i].Selected;
int State = MenuItems[i].State;
bool Logic = MenuItems[i].Logic;
string Text = MenuItems[i].Text;


if(Selected)
{//Item is Selected
m_Font.DrawText(null,Text,CurRect,DrawTextFormat.L eft,System.Drawing.Color.Lime);
if(Logic)
{//Item is On/Off
if(State == 0)
{//Item Off
m_Font.DrawText(null,"Off",CurRect,DrawTextFormat. Right,System.Drawing.Color.Red);
}
else
{//Item On
m_Font.DrawText(null,"On",CurRect,DrawTextFormat.R ight,System.Drawing.Color.White);
}
}
else
{//If Not boolean, draw value
m_Font.DrawText(null,State.ToString(),CurRect,Draw TextFormat.Right,System.Drawing.Color.White);
}
}
else
{//Normal Item
m_Font.DrawText(null,Text,CurRect,DrawTextFormat.L eft,System.Drawing.Color.CornflowerBlue);
if(Logic)
{//Item is On/Off
if(State == 0)
{//Item Off
m_Font.DrawText(null,"Off",CurRect,DrawTextFormat. Right,System.Drawing.Color.Red);
}
else
{//Item On
m_Font.DrawText(null,"On",CurRect,DrawTextFormat.R ight,System.Drawing.Color.White);
}
}
else
{//Draw Number
m_Font.DrawText(null,State.ToString(),CurRect,Draw TextFormat.Right,System.Drawing.Color.White);
}
}
CurRect.Y += 17; //Shift rectangle down so the text does not get clipped.
}
}
//Takes care of which menu item is selected, and if it is on or off.
public void Controls()
{
int CurIndex = 0;
if(GetAsyncKeyState(System.Windows.Forms.Keys.Down ) != 0)
{
CurIndex++;
if (CurIndex > MenuItems.Count - 1)
{
CurIndex = MenuItems.Count - 1;
}
MenuItems[CurIndex].Selected = true;
try
{
MenuItems[CurIndex - 1].Selected = false;
}
catch (Exception) { }
}
if (GetAsyncKeyState(System.Windows.Forms.Keys.Up) != 0)
{
CurIndex--;
if (CurIndex < 0)
{
CurIndex = 0;
}
MenuItems[CurIndex].Selected = true;
try
{
MenuItems[CurIndex + 1].Selected = false;
}
catch (Exception) { }
}
if (GetAsyncKeyState(System.Windows.Forms.Keys.Right) != 0)
{
int CurState = MenuItems[CurIndex].State;
if (MenuItems[CurState].Logic)
{//If Boolean
if (CurState == 0)
{
CurState++;
}
else
{
CurState = 0;
}
}
else
{//Numeral Value
CurState++;
if (CurState > 10)
{
CurState = 10;
}
}
}
if (GetAsyncKeyState(System.Windows.Forms.Keys.Left) != 0)
{
int CurState = MenuItems[CurIndex].State;
if (MenuItems[CurState].Logic)
{//If Boolean
if (CurState == 0)
{
CurState = 1;
}
else
{
CurState = 0;
}
}
else
{//Numeral Value
CurState--;
if (CurState < 0)
{
CurState = 0;
}
}
}
}

public void Release()
{//Release Unmanaged memory.
m_Font.Dispose();
m_Device.Dispose();
}
}

//Menu Items
class MenuItem
{
public string Text; //Text to Display
public bool Selected; //Highlight?
public int State; //On/Off/Number
//If Logic is true, 0 = Off, 1 = On. Else it is a number
public bool Logic; //State is Bool or Num?
//If Logic = True, then the menu will display the State as On/Off.
}
}
[/PHP]

I hope one day someone can put this to good use, and again please help me get the D3D Device if possible...

Yes I know this code might be an epic fail as well, I'm not at all experienced with DX, or MDX.
NICE RELEASE BUT ITS A MISTAKE RELEASING IT!!! ALL YOUR HARD WORK
This looks real hard man
Thanks For Sharing Mate...
NP, a days work released into public domain... Not bad.
Yup, after the whole day of him spamming me for help, he just gives up. |:
Quote Originally Posted by Void View Post
Yup, after the whole day of him spamming me for help, he just gives up. |:
Wana help me out and show me how to get the device?
this is why u dont do C#
Lol, now you need another C++ DLL to activate the CLR runtime and host your C# DLL in it.
Quote Originally Posted by freedompeace View Post
Lol, now you need another C++ DLL to activate the CLR runtime and host your C# DLL in it.
Done long time ago... Thats the whole base of my project LOL
DUDE NICE CODING MAN!!! I SEE NOW WHAT you were working on...
Posts 1–11 of 11 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us