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 


Change Specific Float Values From txt File List

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
makataurugami
How do I cheat?
Reputation: 0

Joined: 21 Apr 2017
Posts: 7

PostPosted: Mon Feb 05, 2018 6:24 pm    Post subject: Change Specific Float Values From txt File List Reply with quote

Hello, my problem is:
I need to change adresses in the same byte pattern.
For example, a group of coordinates, containing x, y and z respectively.
The x,y and z values are float values.
The first 12 bytes is the all (x,y,z) bytes, and I have 28 that I cannot change.
But, I have a list with x,z,y in this order, every value at line after line.
Ex:
x
z
y
x
z
y...
The first adress for change the first X I know, and after that have y, z and anothers 28 "restricted" values that I cannot change.
Any idea for a script that write x,y and z correctly with cheat engine reading txt file line by line?
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Mon Feb 05, 2018 7:19 pm    Post subject: Reply with quote

Not sure what are trying to do but here are some functions I use for my teleporter.

Code:

function I2CETeleporter.writeSavesToFile(fileName)
   local del = I2CETeleporter.DataDelimiter
   local le = I2CETeleporter.LineEnd
   if type(fileName) ~= 'string' then
      fileName =  I2CETeleporter.SavesFileName or 'I2CETeleporterSaves.txt'
   end
   if I2CETeleporter.Saves == nil then
      local msg = 'writeSavesToFile: no saves to write'
      Logger.error(msg)
      return
   end
   local fileStr = strE
   for k, v in pairs(I2CETeleporter.Saves) do
      fileStr = fileStr .. k:gsub('\r', strE):gsub('\n', strE) .. del .. v.X .. del .. v.Y .. del .. v.Z .. le
   end
   if I2CETeleporter.SavesFileAsTableFile then
      local tableFile = findTableFile(fileName)
      if tableFile == nil then
         tableFile = createTableFile(fileName)
      end
      if tableFile == nil then
         local msg = format('writeSavesToFile: Error opening table file, "%s"', fileName)
         Logger.error(msg)
         return
      end
      local stream = tableFile.getData()
      local bytes = { string.byte(fileStr, 1, -1) }
      stream.write(bytes)
      Logger.infof('writeSavesToFile: table file saved, "%s"', fileName)
   else
      local f, err = io.open(I2CETeleporter.SavesFileName, 'w')
      if err then
         Logger.errorf('writeSavesToFile: the local file could not be opened, "%s"', fileName)
      elseif f and not err then
         f:write(fileStr)
         f:close()
      end
   end
   return fileName
end

function I2CETeleporter.readSavesFromFile(fileName)
   local del = I2CETeleporter.DataDelimiter
   if type(fileName) ~= 'string' then
      fileName =  I2CETeleporter.SavesFileName or 'I2CETeleporterSaves.txt'
   end
   local fileStr = nil
   local f, err = io.open(I2CETeleporter.SavesFileName, 'r')
   if err then
      --Logger.debugf('readSavesFromFile: the local file could not be opened, "%s"', fileName)
      local tableFile = findTableFile(fileName)
      if tableFile == nil then
         --Logger.warnf('readSavesFromFile: the local file could not be opened, "%s"', fileName)
         Logger.warnf('readSavesFromFile: table file not found, "%s"', fileName)
         return
      end
      local stream = tableFile.getData()
      local bytes = stream.read(stream.Size)
      for i = 1, #bytes do
         if fileStr == nil then
            fileStr = strE
         end
         fileStr = fileStr .. string.char(bytes[i])
      end
   elseif f and not err then
      fileStr = f:read('*all')
      f:close()
   end
   if fileStr == nil then
      return
   end
   if I2CETeleporter.Saves == nil then
      I2CETeleporter.Saves = {}
   end
   fileStr = fileStr:gsub('\r\n', '\n'):gsub('\r', '\n')
   local lines = split(fileStr, '\n')
   local lastSave = nil
   for i, line in ipairs(lines) do
      if line ~= nil then
         local save = split(line, del)
         if save ~= nil and save[1] ~= nil and save[2] ~= nil and save[3] ~= nil and save[4] ~= nil then
            I2CETeleporter.Saves[save[1]] = {
               Name = save[1],
               X = tonumber(save[2]),
               Y = tonumber(save[3]),
               Z = tonumber(save[4]),
            }
            lastSave = save[1]
            Logger.debugf('readSavesFromFile: loading save: %s, %s, %s, %s', save[1], save[2], save[3], save[4])
         end
      end
   end
   if lastSave ~= nil then
      local bytes = { string.byte(lastSave, 1, -1) }
      bytes[#bytes + 1] = 0x00
      writeBytes(I2CETeleporter.SaveNameStringSymbol, bytes)
   end
   Logger.infof('readSavesFromFile: table file loaded, "%s"', fileName)
   return I2CETeleporter.Saves
end

_________________
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 Lua Scripting 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