Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to show an ingame menu in d3d games

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials
View previous topic :: View next topic  
Author Message
Dark Byte
Site Admin
Reputation: 338

Joined: 09 May 2003
Posts: 19893
Location: The netherlands

PostPosted: Sat May 19, 2012 8:27 pm    Post subject: How to show an ingame menu in d3d games Reply with quote

the following code is an example of how to enable the d3dhook, creating the textures, sprites and textcontainers, and displaying them inside the game.

The result should be a blue window in the topcenter of the screen with 3 menu options.
Those menu options can be clicked to toggle, but the keyboard can also be used to navigate the menu. Enter toggles the option

Code:

--create a background image (in this case, just a simple 1 pixel color stretched)
background=createPicture()
bmp=picture_getBitmap(background);

graphic_setHeight(bmp,1)
graphic_setWidth(bmp,1)
c=rasterimage_getCanvas(bmp)

canvas_setPixel(c,0,0,0xff0000)

highlighter=createPicture()
bmp=picture_getBitmap(highlighter);

graphic_setHeight(bmp,1)
graphic_setWidth(bmp,1)
c=rasterimage_getCanvas(bmp)

canvas_setPixel(c,0,0,0x0000ff)



d3dhook_initializeHook()
bgtexture=d3dhook_createTexture(background)

bgsprite=d3dhook_createSprite(bgtexture);
d3dhook_renderobject_setX(bgsprite, -1) --center it horizontally
d3dhook_sprite_setWidth(bgsprite,200)
d3dhook_sprite_setHeight(bgsprite,200)

highlightertexture=d3dhook_createTexture(highlighter)
hlsprite=d3dhook_createSprite(highlightertexture)
d3dhook_renderobject_setVisible(hlsprite, false) --don't show it just yet
d3dhook_renderobject_setX(hlsprite, -1) --center (so matches with the background)
d3dhook_sprite_setWidth(hlsprite,200)



font=createFont()
fontmap=d3dhook_createFontmap(font)

lineheight=d3dhook_texture_getHeight(fontmap) --fontmap inherits from texture so this can be used

d3dhook_sprite_setHeight(hlsprite,lineheight) --make the highlightr the same height as a textline

Option1=d3dhook_createTextContainer(fontmap,-1,50,'Option 1: OFF')
Option2=d3dhook_createTextContainer(fontmap,-1,50+lineheight,'Option 2: OFF')
Option3=d3dhook_createTextContainer(fontmap,-1,50+lineheight*2,'Option 3: OFF')
Option1State=false
Option2State=false
Option3State=false


selectedOption=1

function setHighlighterToSelectedOption()
  d3dhook_renderobject_setY(hlsprite, 50+lineheight*(selectedOption-1))
end


setHighlighterToSelectedOption()
d3dhook_renderobject_setVisible(hlsprite, true)

function ExecuteSelectedOption()
  local onoff="OFF";

  if (selectedOption==1) then
    Option1State=not Option1State
    if (Option1State) then
      onoff="ON"
    else
      onoff="OFF"
    end   
    d3dhook_textcontainer_setText(Option1,'Option 1: '..onoff);
  end

  if (selectedOption==2) then
    Option2State=not Option2State
    if (Option2State) then
      onoff="ON"
    else
      onoff="OFF"
    end
    d3dhook_textcontainer_setText(Option2,'Option 2: '..onoff);
  end

  if (selectedOption==3) then
    Option3State=not Option3State
    if (Option3State) then
      onoff="ON"
    else
      onoff="OFF"
    end
    d3dhook_textcontainer_setText(Option3,'Option 3: '..onoff);
  end

 
end

function objectclick(object, x, y)
  --bla=userDataToInteger(object)
  --print(string.format("click on %x",bla))


  if (object==Option1) then
    selectedOption=1
    ExecuteSelectedOption()
  end

  if (object==Option2) then
    selectedOption=2
    ExecuteSelectedOption()
  end

  if (object==Option3) then
    selectedOption=3
    ExecuteSelectedOption()
  end

  setHighlighterToSelectedOption()
end
d3dhook_onClick(objectclick)

function keydown(virtualkey,char)
  if (virtualkey==VK_DOWN) then
    --down arrow
    if (selectedOption<3) then
      selectedOption=selectedOption+1
    end
  end

  if (virtualkey==VK_UP) then
    --up arrow
    if (selectedOption>1) then
      selectedOption=selectedOption-1
    end
  end

  if (virtualkey==VK_RETURN) then
    ExecuteSelectedOption()
  end

  setHighlighterToSelectedOption()

  return true
end

d3dhook_onKey(keydown)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 148

Joined: 07 Nov 2008
Posts: 4173
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun May 20, 2012 5:02 am    Post subject: Reply with quote

Gr8.

Looks like d3dhook_onClick(objectclick) and d3dhook_onKey(keydown) does not work in XRay Engine. I must use memoryrecord with few hotkeys set, and few onHotkey functions.



Code:

-- commented out d3dhook_onKey(keydown)
-- commented out d3dhook_onClick(objectclick)

addresslist=getAddressList()
d3d_hotkeys_memrec=addresslist_getMemoryRecordByID(addresslist,5)

d3d_hotkeys_memrec_hotkey0=memoryrecord_getHotkeyByID(d3d_hotkeys_memrec,0)
d3d_hotkeys_memrec_hotkey1=memoryrecord_getHotkeyByID(d3d_hotkeys_memrec,1)
d3d_hotkeys_memrec_hotkey2=memoryrecord_getHotkeyByID(d3d_hotkeys_memrec,2)
d3d_hotkeys_memrec_hotkey3=memoryrecord_getHotkeyByID(d3d_hotkeys_memrec,3)
d3d_hotkeys_memrec_hotkey4=memoryrecord_getHotkeyByID(d3d_hotkeys_memrec,4)

function onHotkey0(Hotkey)
  keydown(VK_UP,'')
end
memoryrecordhotkey_onHotkey(d3d_hotkeys_memrec_hotkey0,onHotkey0)

function onHotkey1(Hotkey)
  keydown(VK_DOWN,'')
end
memoryrecordhotkey_onHotkey(d3d_hotkeys_memrec_hotkey1,onHotkey1)

function onHotkey234(Hotkey)
  keydown(VK_RETURN,'')
end
memoryrecordhotkey_onHotkey(d3d_hotkeys_memrec_hotkey2,onHotkey234)
memoryrecordhotkey_onHotkey(d3d_hotkeys_memrec_hotkey3,onHotkey234)
memoryrecordhotkey_onHotkey(d3d_hotkeys_memrec_hotkey4,onHotkey234)

_________________
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 338

Joined: 09 May 2003
Posts: 19893
Location: The netherlands

PostPosted: Sun May 20, 2012 8:37 am    Post subject: Reply with quote

Yes, it depends on the game and how it handles window messages. (and if it used directinput)
For example if it completely disregards all conventional windows messaging (like header, resize, moving, etc...) then the window hook won't be getting many messages to work with

If realtime keyboard and mouse control is necessary for what you wish to do, you could try an hook on PeekMessage/GetMessage and pass WM_MOUSEDOWN , WM_LBUTTONDOWN and WM_LBUTTONUP down to the window handler anyhow
Or a hook someplace else, as long as you end up sending a message to the window handler with these messages


Tip: createHotkey might be easier to work with

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
toanhung1
Newbie cheater
Reputation: 0

Joined: 07 Apr 2012
Posts: 11

PostPosted: Wed Aug 29, 2012 2:18 pm    Post subject: Reply with quote

question..

Any sample how to make it work when the option is change to on ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 338

Joined: 09 May 2003
Posts: 19893
Location: The netherlands

PostPosted: Wed Aug 29, 2012 3:11 pm    Post subject: Reply with quote

you basically just write your code at "if (Option1State) then "
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
toanhung1
Newbie cheater
Reputation: 0

Joined: 07 Apr 2012
Posts: 11

PostPosted: Thu Aug 30, 2012 11:42 am    Post subject: Reply with quote

thanks got that to work

1 more question

the background is on center , i can move to left or right , but how to i move to between left and center ,,, let say

======================== <--- screen
.......move here .............................



or center left instead on top center

thank for help
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 338

Joined: 09 May 2003
Posts: 19893
Location: The netherlands

PostPosted: Thu Aug 30, 2012 1:13 pm    Post subject: Reply with quote

In that case, instead of an x coordinate of -1 (-1=center on that axis) give the pixels exactly

Use d3dhook_getWidth() to find the center of the screen and go from there

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
toanhung1
Newbie cheater
Reputation: 0

Joined: 07 Apr 2012
Posts: 11

PostPosted: Fri Aug 31, 2012 9:09 am    Post subject: Reply with quote

got that!!! to work

1 more question dark b


let say when we create that menu, when we click on the menu area, it will only work for the menu instead send the actual click on game too?

because when it click the game start to move to that click

sorry for alot question
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 338

Joined: 09 May 2003
Posts: 19893
Location: The netherlands

PostPosted: Sat Sep 01, 2012 8:03 am    Post subject: Reply with quote

That's not possible in this version yet. But perhaps next one
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
sandaasu
How do I cheat?
Reputation: 0

Joined: 29 Dec 2012
Posts: 3

PostPosted: Sat Dec 29, 2012 12:12 pm    Post subject: Reply with quote

Hello everyone Very Happy

i am sorry for pulling that thread out of its grave but i wonder how exaclty to use this code in action.

I already tested it and the menu works for me but i DONT know how to
add a cheat table "function" like a moneyhack etc. to it.

Please help me out a bit Smile
Back to top
View user's profile Send private message AIM Address
abhijeet1001
Advanced Cheater
Reputation: 0

Joined: 10 Apr 2013
Posts: 87

PostPosted: Wed Dec 24, 2014 10:21 am    Post subject: Reply with quote

any way to delete erase the textures , sprites ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 338

Joined: 09 May 2003
Posts: 19893
Location: The netherlands

PostPosted: Wed Dec 24, 2014 10:42 am    Post subject: Reply with quote

first assign a new texture to the sprite, or destroy it.
then you can destroy the texture if you like

you can use object_destroy(sprite/texture) or the recommended sprite.destroy()

(this is very old code)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
iGuzmonJ
How do I cheat?
Reputation: 0

Joined: 24 Oct 2014
Posts: 9

PostPosted: Sun Feb 22, 2015 1:47 am    Post subject: Reply with quote

Is there a way to get the same effect without using d3d? The game i am trying it on doesn't use d3d.
Back to top
View user's profile Send private message
Peppe90
Newbie cheater
Reputation: 0

Joined: 19 Mar 2010
Posts: 24

PostPosted: Fri Jun 05, 2015 6:56 am    Post subject: Reply with quote

Is possible to show just the Value of the address?

Something like fraps that show fps, but I want see the value of the address that change when playing.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites