 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Rectangle Advanced Cheater
Reputation: 1
Joined: 23 Feb 2013 Posts: 73
|
Posted: Thu May 16, 2013 8:35 am Post subject: D3D9 screenshot via lua (+Graphical issue)? |
|
|
Just wondering if there was a way to capture a frame using CE's built-in D3D hook functionality?
I have a strange graphical issue which I would like to bring to the forum's attention, and the screenshot must be made at a certain point during the execution of my current script...
So it would make more sense if I could just do this directly in LUA.
I checked main.lua but couldn't find any capture methods to aid me in this area, so I assume this is either an unsupported feature, or requires some external help?
If this isn't easily possible, then perhaps I could attempt to capture it in a regular screenshot and report it back here.
But I'd still be interested in such a feature...
UPDATE:
Well actually, I was able to capture it on my first try using MS Snipping Tool:
Notice the jagged outline around the text? Is this normal?
Here's the code I'm using:
| Code: | -- MAIN VARIABLES
local minCPU = tonumber("95") -- We won't display a warning unless
local minGPU = tonumber("95") -- temperatures exceed these values!
local processName = 'D1ablo III.exe' -- The target process (game.exe)
local windowTitle = "Lubbo's Fan Control - ver. 1.2.3" -- The monitor app's caption
local windowClass = "WindowsForms10.Window.8.app.0.2bf8098_r14_ad1" -- The monitor app's window class
-- WINAPI SETUP
require[[alien]]
local format = string.format
local user32 = alien.load("user32.dll")
local FindWindow = user32.FindWindowExA
local GetWindowText = user32.GetWindowTextA
local EnumChildWindows = user32.EnumChildWindows
FindWindow:types{ ret = 'long', abi = 'stdcall', 'long', 'long', 'string', 'string' }
GetWindowText:types{ ret = 'long', abi = 'stdcall', 'long', 'pointer', 'int' }
EnumChildWindows:types{ ret = 'int', abi = 'stdcall', 'long', 'callback', 'int' }
-- MONITORING VARIABLES
local parentWindow = 0
local windowProc = nil
local textCPU = "Unknown"
local textGPU = "Unknown"
local tempCPU = tonumber("100")
local tempGPU = tonumber("100")
-- CALLBACK WINDOW PROCEDURE
function EnumChildProc(handle, data)
-- Don't overprocess, if we already have what we want
if(textCPU ~= "" and textGPU ~= "") then
return 0
end
-- Get this window's caption
local buffer = alien.buffer(512)
GetWindowText(handle, buffer, 511)
local text = tostring(buffer):upper()
local token = text:sub(1, 3)
-- Update variables, if we've found a match
if(token == "CPU") then
textCPU = text:match("CPU +(.-) +")
textCPU = format("%3.3f", tonumber(textCPU))
tempCPU = tonumber(textCPU)
--print(format("CPU: %3.3f, Text: %s", tempCPU, textCPU))
elseif(token == "GPU") then
textGPU = text:match("GPU 2 +(.-) +")
textGPU = format("%3.3f", tonumber(textGPU))
tempGPU = tonumber(textGPU)
--print(format("GPU: %3.3f, Text: %s", tempGPU, textGPU))
end
return 1
end
-- UPDATES TEMPERATURE READOUTS, RETURNS
-- WHETHER OR NOT WE SHOULD BE WARNING THE USER
function updateTemperatures()
-- Step through parent windows to find the correct parent
parentWindow = FindWindow(0, 0, windowClass, windowTitle)
parentWindow = FindWindow(parentWindow, 0, windowClass, "")
parentWindow = FindWindow(parentWindow, 0, windowClass, "Sensors Monitor");
-- Initialize/reset variables
windowProc = alien.callback(EnumChildProc, "int", "long", "long")
textCPU = ""
textGPU = ""
tempCPU = 0.0
tempGPU = 0.0
-- Enumerate child controls
EnumChildWindows(parentWindow, windowProc, 0)
return (tempCPU > minCPU and tempGPU > minGPU)
end
-- D3D HOOK VARIABLES
local isD3dhook_initializeHook = false
local isTimerShowingMessageInGameMenu = false
local notificationTimer = nil
function OnCloseClick(sender)
--closeCE() -- Kind of annoying while debugging, lol =P
if(notificationTimer ~= nil) then
timer_setEnabled(notificationTimer, false)
object_destroy(notificationTimer)
notificationTimer = nil
end
return caFree
end
-- SET UP THE FORM WINDOW AND CONTROLS
trainerForm = createForm()
form_onClose(trainerForm, OnCloseClick)
control_setCaption(trainerForm, 'Temperature Hook')
control_setSize(trainerForm, 250, 150)
form_centerScreen(trainerForm)
exitBtn = createButton(trainerForm)
control_setCaption(exitBtn, 'E&xit')
control_onClick(exitBtn, OnCloseClick)
control_setSize(exitBtn, 230, 60)
control_setPosition(exitBtn, 10, 80)
labelCaption1 = createLabel(trainerForm)
local caption = format("[Target Process]: \"%s\"\n[Minimum CPU Threshold]: %3.3f\n[Minimum GPU Threshold]: %3.3f\n[Manual Display Hotkey]: CTRL+1", processName, minCPU, minGPU)
control_setCaption(labelCaption1, caption)
control_setPosition(labelCaption1, 10, 10)
form_show(trainerForm)
-- ATTACH TO TARGET PROCESS
autoAttachList = getAutoAttachList()
stringlist_add(autoAttachList, processName);
function onOpenProcess(processid)
if not isD3dhook_initializeHook then
reinitializeSymbolhandler()
d3dhook_initializeHook()
isD3dhook_initializeHook = true
ShowMessageInGame("[D3D Hook Enabled]", 300, 100, 2, 24, 10, 10)
createHotkey(OnKeyPressSomeActivate, VK_CONTROL, VK_1)
end
end
function OnTickTimerShowingMessageInGameMenu(senderTimer)
timer_setEnabled(senderTimer, false)
object_destroy(senderTimer)
object_destroy(displayedTextObject)
object_destroy(fontmap)
object_destroy(font)
isTimerShowingMessageInGameMenu = false
end
function ShowMessageInGame(stringMessage, fontWidthTextContainer, fontHeightTextContainer, timeShowing, fontSize, posX, posY)
font = createFont()
font_setName(font, "Trebuchet MS")
font_setSize(font, fontSize)
font_setColor(font, 0x0000ff)
fontmap = d3dhook_createFontmap(font)
displayedTextObject = d3dhook_createTextContainer(fontmap, fontWidthTextContainer, fontHeightTextContainer, stringMessage )
d3dhook_renderobject_setY(displayedTextObject, posX)
d3dhook_renderobject_setX(displayedTextObject, posY)
messageTimer = createTimer(nil, false)
timer_setInterval(messageTimer, timeShowing * 1000)
timer_onTimer(messageTimer, OnTickTimerShowingMessageInGameMenu)
timer_setEnabled(messageTimer, true)
isTimerShowingMessageInGameMenu = true
end
function OnKeyPressSomeActivate()
if not isTimerShowingMessageInGameMenu then
if updateTemperatures() then
local warningText = format("CPU: %3.3f\nGPU: %3.3f", tempCPU, tempGPU)
print(warningText)
ShowMessageInGame(warningText, 200, 100, 1, 24, 1, 1)
end
end
end
-- CREATE AN UPDATE TIMER FOR AUTOMATIC USER WARNINGS
notificationTimer = createTimer(nil, false)
timer_setInterval(notificationTimer, 999)
timer_onTimer(notificationTimer, OnKeyPressSomeActivate)
timer_setEnabled(notificationTimer, true) |
In order to make this code work (and reproduce the above) on your system, you will need several things:
- A MacBook Pro running Windows via bootcamp
- A game which utilizes D3D9
- Lubbo's MacBook Pro Fan Control
- Possibly an outdated graphics card
- Possibly some other stuff (like changes to window class names, etc)?
... So perhaps you'll be better off just reviewing the code itself =P
|
|
| Back to top |
|
 |
Rectangle Advanced Cheater
Reputation: 1
Joined: 23 Feb 2013 Posts: 73
|
Posted: Fri May 17, 2013 2:29 pm Post subject: |
|
|
| Can someone at least tell me if the rendered text issue is normal?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25856 Location: The netherlands
|
Posted: Fri May 17, 2013 2:36 pm Post subject: |
|
|
When creating the font, try adding this code:
| Code: |
setProperty(font, "Quality", "fqNonAntialiased")
|
That way the chosen font shouldn't have any extra half transparent bits around the character when drawn to a non transparent bmp for the fontmap
also, make sure the X and Y positions are whole numbers. It supports floating point values, but you will get pixel tearing then (seeing from the code it should be fine)
(also, printscreen + paste in mspaint should work too)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Rectangle Advanced Cheater
Reputation: 1
Joined: 23 Feb 2013 Posts: 73
|
Posted: Fri May 17, 2013 3:46 pm Post subject: |
|
|
Thanks!
| Dark Byte wrote: | | also, printscreen + paste in mspaint should work too |
Yeah but I'm using a MacBook Pro, so there is no print screen key. =P
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri May 17, 2013 4:30 pm Post subject: |
|
|
From Google:
- Command+Shift+3: takes a screenshot of the full screen (or screens if multiple monitors), and save it as a file to the desktop
- Command+Shift+4: brings up a selection box so you can specify an area to take a screenshot of, then save it as a file to the desktop
- Command+Shift+4, then spacebar, then click a window: takes a screenshot of a window only and saves it as a file to the desktop
_________________
- Retired. |
|
| Back to top |
|
 |
|
|
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 can download files in this forum
|
|