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 


Need Lua Script Help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Zephiles
Advanced Cheater
Reputation: 0

Joined: 04 Feb 2016
Posts: 56

PostPosted: Fri Aug 05, 2016 7:31 am    Post subject: Need Lua Script Help Reply with quote

I'm trying to modify a Lua script that Zanzer made, but I'm having some issues.

Code:
if timer1 then timer1.destroy() end
timer1 = createTimer()
timer1.Interval = 5
timer1.OnTimer = function(timer)
  local b = errorOnLookupFailure(false)
  local address = 86016
  local start = readInteger("7fff0000+418970")
  if start then
   local DynamicAddress = readInteger("start-ffd8")
   if DynamicAddress then
      if readInteger("DynamicAddress") == 0 then
         DynamicAddress = readInteger("start-ffc8")
      end
      address = DynamicAddress
   end
  end
  if address and (address > 86016) then
    if address ~= old_address then
      old_address = address
      address = string.format("%X", address)
      local reverse = ""
      for byte in string.gmatch(address, "..") do
        reverse = byte .. reverse
      end
      unregisterSymbol("Enemy1HPInScript")
      registerSymbol("Enemy1HPInScript", tonumber(reverse, 16))
    end
  else
     unregisterSymbol("Enemy1HPInScript")
      registerSymbol("Enemy1HPInScript", tonumber(86016))
  end
  errorOnLookupFailure(b)
end


What is supposed to happen is: (I also need to point out that these addresses are in Big Endian format)
The value at address 7fff0000+418970 is put into start. If the value stored there is not nil, then the value of the address start-ffd8 is put into DynamicAddress. If the value stored at DynamicAddress is not nil, then the value at DynamicAddress should be checked to see if it's 0 or not. If it's 0, then the value of address start-ffc8 (Which is also DynamicAddress-10) is put into DynamicAddress. Once this is done, address is assigned the value of DynamicAddress. Everything after "if address and (address > 86016) then" should work correctly, so the parts above it are the issue. Whenever I execute this script, the outputted value is always 86016, regardless of the other values.

I'll also provide an example of what is happening in the game:
The value at 7fff0000+418970 is 80CD9180, and is assigned to start. Next, the value at address 80CD9180-ffd8 is checked, which has a value of 0, and is assigned to DynamicAddress. Since the value is not nil but it is 0, the value at start-ffc8 is checked, which has a value of 810351C0, and is assigned to DynamicAddress.

I believe that since the addresses are in Big Endian format, then I need to make use of the code that reverses the byte order, but I'm not sure if I know how to properly implement this. So could anyone help me with this? And if that's not what needs to be done, can someone help me with what the real problem is?
Back to top
View user's profile Send private message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Fri Aug 05, 2016 3:03 pm    Post subject: Reply with quote

LUA
Code:
v=1008414272
print(string.format("%X",v))
print(string.format("%X",((v & 0xff) << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8 ) | (v >> 24)))


Code:
function SwapE(v)
  return(((v & 0xff) << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8 ) | (v >> 24))
end
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Aug 05, 2016 5:55 pm    Post subject: Reply with quote

Code:
readInteger(start - 0xffd8)
Back to top
View user's profile Send private message
Zephiles
Advanced Cheater
Reputation: 0

Joined: 04 Feb 2016
Posts: 56

PostPosted: Fri Aug 05, 2016 6:40 pm    Post subject: Reply with quote

So this is what I currently have:

Code:
function SwapE(v)
  return(((v & 0xff) << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8 ) | (v >> 24))
end

if timer1 then timer1.destroy() end
timer1 = createTimer()
timer1.Interval = 5
timer1.OnTimer = function(timer)
  local z = errorOnLookupFailure(false)
  local address = 86016
  local start = readInteger("7fff0000+418970")
  if start then
   start = SwapE(start)
   local DynamicAddress = readInteger(start-0xffd8)
   if DynamicAddress then
      if readInteger("DynamicAddress") == 0 then
         DynamicAddress = readInteger(start-0xffc8)
      end
      address = DynamicAddress
   end
  end
  if address and (address > 86016) then
    if address ~= old_address then
      old_address = address
      address = string.format("%X", address)
      local reverse = ""
      for byte in string.gmatch(address, "..") do
        reverse = byte .. reverse
      end
      unregisterSymbol("Enemy1HPInScript")
      registerSymbol("Enemy1HPInScript", tonumber(reverse, 16))
    end
  else
     unregisterSymbol("Enemy1HPInScript")
      registerSymbol("Enemy1HPInScript", tonumber(86016))
  end
  errorOnLookupFailure(z)
end


As of right now, this does not work correctly. Whenever I execute it, the value that is outputted is always 86016, regardless of what values are at the addresses above.

Can someone actually tell me how to fix this, instead of just putting blocks of code?
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Aug 05, 2016 7:04 pm    Post subject: Reply with quote

Code:
readInteger(DynamicAddress)
Back to top
View user's profile Send private message
Zephiles
Advanced Cheater
Reputation: 0

Joined: 04 Feb 2016
Posts: 56

PostPosted: Fri Aug 05, 2016 7:09 pm    Post subject: Reply with quote

Changing that made it work until the first DynamicPointer changed to 0. After that it stayed at 86016 again.
Back to top
View user's profile Send private message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Fri Aug 05, 2016 7:39 pm    Post subject: Reply with quote

Judiciously implement print() in your script. Debug line by line for what you expect to happen vs what does happen until you find your error. We cannot replicate your script without installing your game and trying ourselves.

print(string.format("%X",ADDRESS)) will print the hex version of address, use for any variables you want to see the hex of.
Back to top
View user's profile Send private message
Zephiles
Advanced Cheater
Reputation: 0

Joined: 04 Feb 2016
Posts: 56

PostPosted: Fri Aug 05, 2016 8:05 pm    Post subject: Reply with quote

OK I finally figured out the problem. The issue was this line:

Code:
if readInteger("DynamicAddress") == 0 then


Changing it to the following made the script work:

Code:
if DynamicAddress == 0 then
Back to top
View user's profile Send private message
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