[Solved] Read Memory Stream form findTableFile?

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
User avatar
TheyCallMeTim13
Cheater
Cheater
Posts: 31
Joined: Fri Mar 03, 2017 12:31 am
Reputation: 1

[Solved] Read Memory Stream form findTableFile?

Post by TheyCallMeTim13 » Fri Mar 03, 2017 9:29 pm

I'm am trying to read a table file, right now I just save it to disc then read file as normal, but how do I read the memory stream directly?
Last edited by TheyCallMeTim13 on Sat Mar 04, 2017 10:31 am, edited 1 time in total.
Code Happy, Code Freely, Be Awesome.

User avatar
TheyCallMeTim13
Cheater
Cheater
Posts: 31
Joined: Fri Mar 03, 2017 12:31 am
Reputation: 1

Re: Read Memory Stream form findTableFile?

Post by TheyCallMeTim13 » Sat Mar 04, 2017 1:02 am

So kinda figured it out

Code: Select all

local file = findTableFile('test.cea')

local lst = getPropertyList(file)
for i = 1, lst.Count - 1 do
	print(lst[i])
end

local stream = file.getData()
print(stream)

local bytes = stream.read(stream.Size)
for i = 1, #bytes do
	print(bytes[i], string.char(bytes[i]))
end
Gives me this output:

Code: Select all


stream 
0EBD9B90 
47 / 
47 / 
47 / 
47 / 
32   
67 C 
69 E 
65 A 
32   
116 t 
101 e 
115 s 
116 t 
32   
102 f 
105 i 
108 l 
101 e 
13 
 
10 
 
So I think this is the start of what I needed.
Code Happy, Code Freely, Be Awesome.

panraven
Noobzor
Noobzor
Posts: 11
Joined: Fri Mar 03, 2017 12:03 am
Reputation: 2

Re: Read Memory Stream form findTableFile?

Post by panraven » Sat Mar 04, 2017 7:29 am

The returned byte table can be convert to string with ce function byteTableToString
eg.

Code: Select all

local bytes = stream.read(stream.Size)
local str = byteTableToString(bytes)
or use a stringStream which need not create intermediate Lua byte table (for performance?).

Code: Select all

function GetTableFileAsString(tfName)
  local tf = findTableFile(tfName)
  if tf then
    local ss = createStringStream()
    ss.copyFrom(tf.Stream,tf.Stream.Size)
    local ret = ss.DataString
    ss.Destroy()
    return ret
  end
end
print(GetTableFileAsString("insert-table-file-name"))
ps: if DB make .DataString work with MemoryStream, it will be just a property instead of custom function.

bye~

User avatar
TheyCallMeTim13
Cheater
Cheater
Posts: 31
Joined: Fri Mar 03, 2017 12:31 am
Reputation: 1

Re: Read Memory Stream form findTableFile?

Post by TheyCallMeTim13 » Sat Mar 04, 2017 8:30 am

Thank you that's much nicer than what I had.
Code Happy, Code Freely, Be Awesome.

User avatar
TheyCallMeTim13
Cheater
Cheater
Posts: 31
Joined: Fri Mar 03, 2017 12:31 am
Reputation: 1

Re: Read Memory Stream form findTableFile?

Post by TheyCallMeTim13 » Sat Mar 04, 2017 8:34 am

hum..

This is what I had not sure which is cleaner..

Code: Select all

local stream = tableFile.getData()
local fileStr = nil
local bytes = stream.read(stream.Size)
for i = 1, #bytes do
	if fileStr == nil then
		fileStr = ''
	end
	fileStr = fileStr .. string.char(bytes[i])
end
EDIT:
Ended up using yours..

Code: Select all

if tableFile then
	local ss = createStringStream()
	ss.copyFrom(tableFile.Stream,tableFile.Stream.Size)
	local fileStr = ss.DataString
	ss.Destroy()
end
Definitely looks better!
Last edited by TheyCallMeTim13 on Sat Mar 04, 2017 8:44 am, edited 1 time in total.
Code Happy, Code Freely, Be Awesome.

User avatar
TheyCallMeTim13
Cheater
Cheater
Posts: 31
Joined: Fri Mar 03, 2017 12:31 am
Reputation: 1

Re: Read Memory Stream form findTableFile?

Post by TheyCallMeTim13 » Sat Mar 04, 2017 8:40 am

Though I think mine has places to fail.

Now Do I need to destroy the stream, I wouldn't think so, but if the stream is just some copy of the file memory then I mite need to?

I ask because of the destroy call on the return from createStringStream.
Code Happy, Code Freely, Be Awesome.

Eric
Hall of Famer
Hall of Famer
Posts: 33
Joined: Thu Mar 02, 2017 11:01 pm
Reputation: 9

Re: Read Memory Stream form findTableFile?

Post by Eric » Sat Mar 04, 2017 9:05 am

the stringstream is a different object than the tablefile. It just contains a copy after you made the copy, so you're free to destroy it

Post Reply

Who is online

Users browsing this forum: No registered users