|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
mg_01 Cheater Reputation: 0
Joined: 28 Jan 2018 Posts: 41
|
Posted: Sun Jan 28, 2018 11:03 am Post subject: How to print values to CSV file? |
|
|
Hello,
I wanted to have Cheat Engine write a CSV file that contains the values from a set of addresses which get updated every frame.
I'm using an emulator called PCSX2-RR and I'm trying to create a custom HUD, and I need the values from a replay file I've saved.
The idea is to create a custom HUD from values updated every frame. I just need the values that Cheat Engine shows while a replay file is playing.
Thank you.
|
|
Back to top |
|
|
mg_01 Cheater Reputation: 0
Joined: 28 Jan 2018 Posts: 41
|
Posted: Wed Jan 31, 2018 9:34 pm Post subject: |
|
|
I've only been able to figure out that I need to use IO write to make a csv file, and that I need to hook it to Cheat Engine's "GetAddressfromDescription". I just dont know how to have it update itself every frame as the game goes on.
My ghetto solution has been to capture my desktop at 3fps so that Cheat Engine updates itself in accordance with PCSX2-RR's values, then I speed the video up so that it's 60fps.
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Wed Jan 31, 2018 10:04 pm Post subject: |
|
|
hm, you can use a timer to repeat something eg.
Code: | mytimer = createTimer()
-- timer does not automatically keep track of total time elapsed or a time to stop
-- but we can use variables to implement it ourselves
mytimer_elapsed = 0
mytimer_timelimit = 60*1000 -- 1 minute
mytimer.Interval = 1000 / 60 -- run OnTimer function 60 times a second
mytimer.OnTimer = function(mytimer) -- function to run after intverval
mytimer_elapsed = mytimer_elapsed + mytimer.Interval -- increase elapsed time
if mytimer_timelimit > 0 and mytimer_elapsed > mytimer_timelimit then -- check limit
mytimer.destroy() -- stop and free timer
return -- don't continue this function
end
writeToCSV(1,2,3) -- call the writeToCSV function with arguments 1, 2, 3
end
--mytimer.enabled = false -- stop timer (temporarily, until enabled again) |
can't say for sure that writing to disk would be able to keep up, but if not it's possible that you could instead store all the values in a table, and then after whatever time period you'd use that stored data to write the csv.
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Thu Feb 01, 2018 9:17 am Post subject: |
|
|
I wrote data from a table to csv file using this :
Code: | function csvWrite(path, data, sep)
sep = sep or ','
local file = assert(io.open(path, "w"))
file:write('Address' .. "," .. 'Value')
file:write('\n')
for k, v in pairs(data) do
file:write(v["add"] .. "," .. v["val"])
file:write('\n')
end
file:close()
end
----- to use
local myTable = {}
myTable[1001] = {val= 1000,
add = "foo"}
myTable[1002] = {val = 1500,
add = "bar"}
csvWrite("D:\\csv\\testcsv.csv", myTable, sep) |
Quote: | but if not it's possible that you could instead store all the values in a table, and then after whatever time period you'd use that stored data to write the csv. |
so, like FreeER said, use a table to store data and then write all to a csv file. Now, what you need is collect/data(s) from running process and construct a table according to data types to store all data(s). FreeER provided it already + getAddressList() + addresslist_getMemoryRecord() + memoryrecord_getValue(), etc
EDIT :
I try get address and value using Windows Solitaire Game. So I got one address with value always change, here is script i tried :
Code: | mr=addresslist_getMemoryRecord(al,0)
lastAddress=memoryrecord_getAddress(mr)
lastValue=memoryrecord_getValue(mr)
--print(lastAddress.." / "..lastValue)
--make function to add result to table....
function b(...)
for i = 1, select('#',...) do
t[#t+1] = select(i,...)
end
end
--create table and add first record found
local t = {}
b(lastAddress,lastValue)
function readValueTimer(t)
local currentAddress=memoryrecord_getAddress(mr)
local currentValue=memoryrecord_getValue(mr)
if currentValue ~= lastValue then
--print(currentAddress.." / "..currentValue)
lastAddress = currentAddress
lastValue = currentValue
b(lastAddress,lastValue)
k = lastAddress
t[k] = lastValue
print(t[lastAddress])
end
end
t1=createTimer(nil)
timer_setInterval(t1,100)
timer_onTimer(t1,readValueTimer) |
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
mg_01 Cheater Reputation: 0
Joined: 28 Jan 2018 Posts: 41
|
Posted: Sat Feb 03, 2018 4:18 pm Post subject: |
|
|
This is a working script that my friend wrote for me. He said that FreeER and Corroder's scripts helped in creating it 'cause he doesn't have much LUA knowledge.
Anyway, thank you everyone for helping. I personally don't know much about coding, so it was difficult to understand this stuff. Just the same, thanks a lot!
Code: |
openProcess('PCSX2.exe')
filthyglobal = false
function csvWrite(path, data, sep)
sep = sep or ','
local file = assert(io.open(path, "a"))
local string = ''
if filthyglobal ~= true then
for i = 0, #data, 1 do
if i < #data then
string = string .. data[i]["desc"] .. ','
else
string = string .. data[i]["desc"]
end
end
file:write(string)
file:write('\n')
filthyglobal = true
string = ''
end
for i = 0, #data, 1 do
if i < #data then
string = string .. data[i]["val"] .. ','
else
string = string .. data[i]["val"]
end
end
file:write(string)
file:write('\n')
file:close()
end
addresslist = getAddressList()
v0 = addresslist.getMemoryRecordByDescription('Total Frames')
v1 = addresslist.getMemoryRecordByDescription('frameskip')
v0_prev = v0.Value
local datatable = {}
local t = createTimer(getMainForm())
t.Interval = (1000 / 60)
t.OnTimer = function(timer)
if (v0_prev ~= v0.Value) then
datatable[0] = {desc = v0.Description, val = v0.Value}
datatable[1] = {desc = v1.Description, val = v1.Value}
csvWrite("D:\\Data.csv", datatable)
end
v0_prev = v0.Value
end
|
The script uses the replay's Total Frame counter to update and write the values.
To what FreeER said, yeah the script won't get written in real time. My (ghetto) solution is using a simple macro to press 'Spacebar' every second so that it has time to update.
|
|
Back to top |
|
|
mg_01 Cheater Reputation: 0
Joined: 28 Jan 2018 Posts: 41
|
Posted: Tue Feb 06, 2018 5:52 am Post subject: |
|
|
Unfortunately, the script still drops inputs in the CSV. Even though it's updating at every Frame Change, there are still missed rows.
My friends said that it might be a limitation of cheat engine -- I've tried hitting space every full second, but it still ends up with dropped inputs.
|
|
Back to top |
|
|
FreeER Grandmaster Cheater Supreme Reputation: 53
Joined: 09 Aug 2013 Posts: 1091
|
Posted: Tue Feb 06, 2018 6:31 am Post subject: |
|
|
any time you have to manually do something is going to cause imperfections.
Try writing a script to press spacebar for you eg.
Code: | t = createTimer()
t.Interval = 1000
dostop = false
t.OnTimer = function(t)
-- stop when dostop variable is not false
-- alternatively destroy t yourself or set t.Enabled = false to pause
if dostop then t.destroy() end
-- only press space in the game
if getForegroundProcess() ~= getOpenedProcessID() then return end
doKeyPress(VK_SPACE)
end
-- t.onTimer(t) -- does not immediately run
|
If that doesn't work you can try keyDown(VK_SPACE) sleep(100) keyUp(VK_SPACE). But this won't work for some games since those functions use Window's window messages from my understanding and not all games get keyboard events from those.
|
|
Back to top |
|
|
mg_01 Cheater Reputation: 0
Joined: 28 Jan 2018 Posts: 41
|
Posted: Tue Feb 06, 2018 6:56 am Post subject: |
|
|
Yeah. I tried doing something with AHK, but it didn't work. So then I just used the Logitech Macro software and set it to press spacebar, then wait for a bit, and repeat; it still didn't work, though.
My friend who made the script had at one point set it to always-run -- thus it printed duplicate entries into the CSV.
I think reverting back to that method instead of using the Total Frame counter might work -- it'll just produce huge CSVs with duplicates. But I think it's possible to have Excel remove the duplicates in accordance to the Total Frame column -- to keep it continuous.
*Edit* While it doesn't drop any inputs, it has other problems. Where, although the Total Frames counter is duplicated, the other columns' values change -- that causes more problems than the first method. I'll go back to using my Water-Drinking-Toy-Duck to press Spacebar
|
|
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
|
|