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 


String Stream Returning nil.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sat Mar 04, 2017 8:34 pm    Post subject: String Stream Returning nil. Reply with quote

So I made a lua extension that reads cea file local and if not found reads table files.

Extension:
link: http{://}forum{.}cheatengine{.}org/viewtopic{.}php?t=603440

I ended up coming up with this to read the table files.

Code:


local tableFile = findTableFile(ceaFile)
if tableFile == nil then
   Logger.error(format('I2CETH: getAutoAssembleFileSection: Error opening table file: "%s"', ceaFile), err)
   return nil
end
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


Which returns the file string with out problems.

but I got this from 'panraven' in the new forum, and it worked the first few times but now mostly (not every time) returns nil.

Code:

local tableFile = findTableFile(ceaFile)
if tableFile == nil then
   Logger.error(format('I2CETH: getAutoAssembleFileSection: Error opening table file: "%s"', ceaFile), err)
   return nil
end
-- START: Not Working
local stringStream = createStringStream()
stringStream.copyFrom(tableFile.Stream, tableFile.Stream.Size)
local fileStr = stringStream.DataString
stringStream.Destroy()
-- END: Not Working


Basically 'stringStream.DataString' keeps returning nil.

So I do have a work around but I was just trying to figure out why it, seemingly, randomly fails.

Not a big issue but still bugs me not knowing why.

_________________
Back to top
View user's profile Send private message Visit poster's website
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Sat Mar 04, 2017 10:32 pm    Post subject: Reply with quote

I tried c&p you code within a 100x for-loop to load a same 4M binary table file, and count its returned string sum. The result return correctly. So stringStream is ok to handle binary file.
It may be something outside the code to cause the inconsistency?
I've no idea why too~

btw, I also do an unrelated test where do above almost the same with 10000x of a 500k table file with or without destroy the stringStream explicitly and manually. (since there is a follow up at fearlessrevolution about destroying object)

If destroy, the CE memory usage is around 70~80M during the loop.

If not destroy, the CE memory usage grow to as large as 10G during the loop, but all released soon after the loop.

It seems CE will auto-destroy at least stringStream object, but only when CE has 'leisure time?', it may be better manually destroy that's manually created.

bye~

_________________
- Retarded.
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sun Mar 05, 2017 12:25 am    Post subject: Reply with quote

Yeah just weird how it worked fine for a while, then just kinda stopped, I feel like there has to be some thing I add that caused it, but just can't find it.

I'll keep playing with it.

Thanks again for the help though.

I think I have read a lot of your posts so this isn't first time you have helped me.

_________________
Back to top
View user's profile Send private message Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Sun Mar 05, 2017 6:23 am    Post subject: Re: String Stream Returning nil. Reply with quote

I also used copyFrom() method many times. I also had few problems. And this is my conclusion: always set Position property when using copyFrom.

Try this:
Code:
local tableFile = findTableFile(ceaFile)
if tableFile == nil then
   Logger.error(format('I2CETH: getAutoAssembleFileSection: Error opening table file: "%s"', ceaFile), err)
   return nil
end

local stringStream = createStringStream()
local tableFileStream = tableFile.Stream
tableFileStream.Position = 0
stringStream.copyFrom(tableFileStream, tableFileStream.Size)
local fileStr = stringStream.DataString
stringStream.destroy()

_________________
Back to top
View user's profile Send private message MSN Messenger
TheyCallMeTim13
Wiki Contributor
Reputation: 51

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sun Mar 05, 2017 12:11 pm    Post subject: Reply with quote

OK, That really make sense, I never told it where to read form, Kinda know it was some thing small but just could't see it.

I will have to give it a try, Thanks for the all the help.

_________________
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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 can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites