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 


Is there a way to change a found PTR value within CE script?

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

Joined: 17 Jan 2024
Posts: 3
Location: CA

PostPosted: Wed Jan 17, 2024 6:42 pm    Post subject: Is there a way to change a found PTR value within CE script? Reply with quote

So I have this as part of my script code and script works:

Code:

         <CheatEntry>
         <ID>26233</ID>
         <Description>"TimeSpeed"</Description>
         <ShowAsSigned>0</ShowAsSigned>
         <VariableType>Float</VariableType>
         <Address>[myworld]+170</Address>
         <Offsets>
            <Offset>248</Offset>
            <Offset>290</Offset>
         </Offsets>
         </CheatEntry>


This will show 20 and rarely change unless I manually change it in the running script and at some point it'll change back again.

I need something that checks the "20" value and change it, if so, and also check that "myworld" is valid (suppose it'll show "nil" if not - in script it shows ?? until I manually activate" "myworld".

Some easy way? - {$lua}, {$asm} or do I need code injection?

The more somewhat similar examples I look at the more confused I get (easy to do) -ha ha.
[/code]
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4719

PostPosted: Wed Jan 17, 2024 8:06 pm    Post subject: Reply with quote

Why put the first offset in the address field and the next two as manual offsets?

Here's some Lua code (Table -> Show Cheat Table Lua Script):
Code:
if mytimer then mytimer.destroy(); mytimer = nil end

mytimer = createTimer()
mytimer.Interval = 100
mytimer.OnTimer = function(t)
  local addr = getAddressSafe'[[[myworld]+170]+290]+248'
  if not addr then return end

  if (readInteger(addr) ~= 20) then
    writeInteger(addr, 20)
  end
end
This is more or less the same as freezing the memory record and setting the value to 20.

You could also do a code injection on whatever instruction is changing the value.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
nr1dane
How do I cheat?
Reputation: 0

Joined: 17 Jan 2024
Posts: 3
Location: CA

PostPosted: Wed Jan 17, 2024 8:54 pm    Post subject: Reply with quote

ParkourPenguin wrote:
Why put the first offset in the address field and the next two as manual offsets?

Here's some Lua code (Table -> Show Cheat Table Lua Script):
Code:
if mytimer then mytimer.destroy(); mytimer = nil end

mytimer = createTimer()
mytimer.Interval = 100
mytimer.OnTimer = function(t)
  local addr = getAddressSafe'[[[myworld]+170]+290]+248'
  if not addr then return end

  if (readInteger(addr) ~= 20) then
    writeInteger(addr, 20)
  end
end
This is more or less the same as freezing the memory record and setting the value to 20.

You could also do a code injection on whatever instruction is changing the value.



I appreciate your help a lot.

Well, the first offset within the address field - I used CakeSan's UE Dumper Tool to generate the found values, that's how it came out. Didn't think much of it until now.

Second, color me stupid or blonde - which I am - uh - was, more gray now.
Not sure how to implement the lua code into the CE script within the example CheatEntry code I posted. I have more values I want to set as well but that's the same senario. I just need it to check the value(s) at regular intervals in the runnig CE script.

In the running CE script I can freeze the value and/or change the value as well, but at some point it does revert back if not checked and frozen.
In other words - I kinda want to automate the value change without me setting manually.

I haven't tried code injection yet since I'm trying to keep it simple. But the lua is where I screw up. Tried somewhat same coding as you showed, but of course - total screwup.
I don't want to step out of the running script to run lua, that's redundant since the script I have works by freezing and/or setting values manually.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4719

PostPosted: Thu Jan 18, 2024 1:06 am    Post subject: Reply with quote

"CE script" isn't a thing. There are AA scripts and the main Lua script- that's pretty much it. You can run Lua code in an AA script w/ {$lua}, and the Lua Engine can be used to test Lua code in a bit more of a REPL-style interface.
AA scripts and the main Lua script don't run continuously. They do what's instructed and exit pretty much immediately in most cases. If you want something to run periodically, use a timer.

nr1dane wrote:
Not sure how to implement the lua code into the CE script within the example CheatEntry code I posted.
That memory record ("CheatEntry" xml node) is just an address. There is no "CE script" within it. Memory records are either addresses or AA scripts- not both. (for organization, there are headers with or without address support, but they have no relation to AA scripts)

Open the main Lua script window. Main CE window, top bar, "Table", "Show Cheat Table Lua Script"
Copy + paste that code in there
Run the script
The created timer will periodically set the value of the address to something.

If you want an AA script you can toggle on and off:
Code:
{$lua}
if syntaxcheck then return end

if mytimer then mytimer.destroy(); mytimer = nil end

[ENABLE]

mytimer = createTimer()
mytimer.Interval = 100
mytimer.OnTimer = function(t)
  local addr = getAddressSafe'[[[myworld]+170]+290]+248'
  if not addr then return end

  if (readInteger(addr) ~= 20) then
    writeInteger(addr, 20)
  end
end

[DISABLE]

nr1dane wrote:
Tried somewhat same coding as you showed, but of course - total screwup.
Other people might be able to help if you posted what you tried.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
nr1dane
How do I cheat?
Reputation: 0

Joined: 17 Jan 2024
Posts: 3
Location: CA

PostPosted: Thu Jan 18, 2024 8:03 pm    Post subject: Reply with quote

I understand now - thank you for hammering it into my little pea brain.
Been a while since I tinkered with CE and lua.

Much, much appreciated.

The "Show Cheat Table Lua Script" kinda stunned me since I have a somewhat complex lua script already that automatically connects to the wanted process and sets up the Mainform controls. I couldn't quite find a way to insert the wanted code for the situation without another one of my famous screwups.

I did, however, come up with a suitable solution - a keypress toggle (I know, not pretty, I need to clean it up a bit):

Code:

       <CheatEntry>
          <ID>26295</ID>
          <Description>"; = Toggle TimeSpeed (20/5) Sunrise (6/5), Sunset (18/20)"</Description>
          <Color>008000</Color>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>{$lua}
if syntaxcheck then return end
{$asm}
[ENABLE]
{$lua}
memrec.OnActivate = function(memrec, preState, curState)
  if (not preState) and curState then
    local t = createTimer()
    t.Interval = 1000
    t.OnTimer = function(t)
   
     local addr1 = getAddressSafe('[[[myworld]+170]+290]+248') -- TimeSpeed
     local addr2 = getAddressSafe('[[[myworld]+170]+290]+314') -- Sunrise
     local addr3 = getAddressSafe('[[[myworld]+170]+290]+318') -- Sunset
     if (readFloat(addr1) == 20) then
         writeFloat(addr1,5)
       writeFloat(addr2,5)
       writeFloat(addr3,20)
     else
         writeFloat(addr1,20)
        writeFloat(addr2,6)
        writeFloat(addr3,18)
     end

      t.destroy()
      memrec.Active = false
   end  -- function OnTimer
  end  -- not preState
  return true
end  -- function memrec

{$asm}
[DISABLE]
{$lua}
</AssemblerScript>
          <Hotkeys>
            <Hotkey>
              <Action>Toggle Activation</Action>
              <Keys/>
              <ID>0</ID>
            </Hotkey>
            <Hotkey>
              <Action>Toggle Activation</Action>
              <Keys>
                <Key>186</Key>
              </Keys>
              <ID>1</ID>
              <ActivateSound>Activate</ActivateSound>
              <DeactivateSound>Deactivate</DeactivateSound>
            </Hotkey>
          </Hotkeys>
        </CheatEntry>


And that did the trick.

Thank you again for all your help .
Cheers! Very Happy
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