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 


Assembly Button

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
KalasDev
Master Cheater
Reputation: 1

Joined: 29 May 2016
Posts: 311

PostPosted: Sat Jul 08, 2017 4:45 am    Post subject: Assembly Button Reply with quote

I have this code:

Code:
local tag = sender.Tag;
   if (tag == 0) then
      sender.Tag = 1;
      autoAssemble([[//enable script]])
   else
      sender.Tag = 0
      autoAssemble([[//disable script]])
   end


I wonder how do I make it as button in Cheat Engine Trainer Generator?

What I did was placing a button, go to event and click on OnEnter, so for example in the code I posted I suppose to put my enable code in this part?:

([[//enable script]])

and my disable in the other one?

This is my Script I want to add as a button:

Code:
{ Game   : TheForest.exe
  Version:
  Date   : 2017-07-07
  Author : Kalas

  This script does blah blah blah
}

[ENABLE]

aobscan(PlayerStatsAOB,00 83 C4 10 D9 87 18 01 00 00)
alloc(newmem,$100,PlayerStatsAOB)

label(code)
label(return)

newmem:

code:
  fld dword ptr [edi+00000118]
  mov [edi+0000010C],(float)37 // BodyTemp
  mov [edi+00000110],(float)70 // HeartRate
  mov [edi+00000118],(float)100 // Stamina
  mov [edi+0000011C],(float)100 // Health
  mov [edi+00000124],(float)100 // Energy
  mov [edi+00000134],(float)100 // BatteryCharge
  mov [edi+00000150],(float)1 // Fullness
  mov [edi+00000154],(float)0 // Thirst
  mov [edi+00000231],0 // IsBloody
  mov [edi+00000232],0 // IsRed
  mov [edi+00000233],0 // IsCold
  jmp return

PlayerStatsAOB+04:
  jmp newmem
  nop
return:
registersymbol(PlayerStatsAOB)

[DISABLE]

PlayerStatsAOB+04:
  db D9 87 18 01 00 00

unregistersymbol(PlayerStatsAOB)
dealloc(newmem)
Back to top
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Sat Jul 08, 2017 8:20 am    Post subject: Re: Assembly Button Reply with quote

If I understand what you want, then this should work.
Code:
local tag = sender.Tag;
   if (tag == 0) then
      sender.Tag = 1;
      autoAssemble([[
        aobscan(PlayerStatsAOB,00 83 C4 10 D9 87 18 01 00 00)
        alloc(newmem,$100,PlayerStatsAOB)

        label(code)
        label(return)

        newmem:

        code:
          fld dword ptr [edi+00000118]
          mov [edi+0000010C],(float)37 // BodyTemp
          mov [edi+00000110],(float)70 // HeartRate
          mov [edi+00000118],(float)100 // Stamina
          mov [edi+0000011C],(float)100 // Health
          mov [edi+00000124],(float)100 // Energy
          mov [edi+00000134],(float)100 // BatteryCharge
          mov [edi+00000150],(float)1 // Fullness
          mov [edi+00000154],(float)0 // Thirst
          mov [edi+00000231],0 // IsBloody
          mov [edi+00000232],0 // IsRed
          mov [edi+00000233],0 // IsCold
          jmp return

        PlayerStatsAOB+04:
          jmp newmem
          nop
        return:
        registersymbol(PlayerStatsAOB)
      ]])
   else
      sender.Tag = 0
      autoAssemble([[
        PlayerStatsAOB+04:
        db D9 87 18 01 00 00

        unregistersymbol(PlayerStatsAOB)
        dealloc(newmem)
      ]])
   end

_________________
...
Back to top
View user's profile Send private message
KalasDev
Master Cheater
Reputation: 1

Joined: 29 May 2016
Posts: 311

PostPosted: Sat Jul 08, 2017 8:22 am    Post subject: Re: Assembly Button Reply with quote

Filipe_Br wrote:
If I understand what you want, then this should work.
Code:
local tag = sender.Tag;
   if (tag == 0) then
      sender.Tag = 1;
      autoAssemble([[
        aobscan(PlayerStatsAOB,00 83 C4 10 D9 87 18 01 00 00)
        alloc(newmem,$100,PlayerStatsAOB)

        label(code)
        label(return)

        newmem:

        code:
          fld dword ptr [edi+00000118]
          mov [edi+0000010C],(float)37 // BodyTemp
          mov [edi+00000110],(float)70 // HeartRate
          mov [edi+00000118],(float)100 // Stamina
          mov [edi+0000011C],(float)100 // Health
          mov [edi+00000124],(float)100 // Energy
          mov [edi+00000134],(float)100 // BatteryCharge
          mov [edi+00000150],(float)1 // Fullness
          mov [edi+00000154],(float)0 // Thirst
          mov [edi+00000231],0 // IsBloody
          mov [edi+00000232],0 // IsRed
          mov [edi+00000233],0 // IsCold
          jmp return

        PlayerStatsAOB+04:
          jmp newmem
          nop
        return:
        registersymbol(PlayerStatsAOB)
      ]])
   else
      sender.Tag = 0
      autoAssemble([[
        PlayerStatsAOB+04:
        db D9 87 18 01 00 00

        unregistersymbol(PlayerStatsAOB)
        dealloc(newmem)
      ]])
   end

Will it work if I do a new Button? Like shouldn't there be a unique function for each button?

What I want basically is a button to activate/deactivate my script Smile

How can I do in the code of the same button when I press it to enable It will say on / off, like this:

http://i64.tinypic.com/htclj4.png
Back to top
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Sat Jul 08, 2017 8:57 am    Post subject: Re: Assembly Button Reply with quote

Code:
form = createForm()

cb = createCheckBox(form)
cb.Caption = "HACK"

function cbOnChange()
    if cb.State == 1 then
        autoAssemble([[
          aobscan(PlayerStatsAOB,00 83 C4 10 D9 87 18 01 00 00)
          alloc(newmem,$100,PlayerStatsAOB)

          label(code)
          label(return)

          newmem:

          code:
            fld dword ptr [edi+00000118]
            mov [edi+0000010C],(float)37 // BodyTemp
            mov [edi+00000110],(float)70 // HeartRate
            mov [edi+00000118],(float)100 // Stamina
            mov [edi+0000011C],(float)100 // Health
            mov [edi+00000124],(float)100 // Energy
            mov [edi+00000134],(float)100 // BatteryCharge
            mov [edi+00000150],(float)1 // Fullness
            mov [edi+00000154],(float)0 // Thirst
            mov [edi+00000231],0 // IsBloody
            mov [edi+00000232],0 // IsRed
            mov [edi+00000233],0 // IsCold
            jmp return

          PlayerStatsAOB+04:
            jmp newmem
            nop
          return:
          registersymbol(PlayerStatsAOB)
        ]])
    else
        autoAssemble([[
          PlayerStatsAOB+04:
          db D9 87 18 01 00 00

          unregistersymbol(PlayerStatsAOB)
          dealloc(newmem)
        ]])
   end
end

cb.OnChange = cbOnChange

_________________
...
Back to top
View user's profile Send private message
KalasDev
Master Cheater
Reputation: 1

Joined: 29 May 2016
Posts: 311

PostPosted: Sat Jul 08, 2017 9:04 am    Post subject: Reply with quote

Last thing If you mind, how do I create a button and inside I can type my own message, like the about button!
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Sat Jul 08, 2017 1:15 pm    Post subject: Reply with quote

With newer Cheat Engine versions, the Lua exposed version of autoAssemble returns two values now. The first being if the function worked or not, the second being a disable handle that can be used to run the disable portion of a script.

For example, here is a function I made for a cheat to give infinite skill points on a specific game:

Code:
function cheat_InfiniteSkillPoints(enabled)
    -- Obtain the cheat pattern..
    local p = getPattern('skillpoints');
    if (p == nil) then return; end

    -- Build the cheat script..
    local script = string.format([[
[ENABLE]
alloc(newmem,1024,"CryGameSDK.dll")
label(rethere)

newmem:
    mov [rsi+00000160], 3E7
    jmp rethere

%X:
    jmp newmem
    nop
rethere:

[DISABLE]
dealloc(newmem);
    ]], p['r']);

    -- Toggle the cheat..
    if (enabled) then
        -- Backup the original code..
        cheatvars['skillpoints']['b'] = readBytes(p['r'], 6, true);

        -- Enable the cheat script..
        local a, b = autoAssemble(script, false);
        if (a) then
            cheatvars['skillpoints']['d'] = b;
        else
            dbgprintf('Error: Failed to assemble cheat script! (skillpoints)');
        end
    else
        -- Disable the script..
        autoAssemble(script, false, cheatvars['skillpoints']['d']);

        -- Restore the original code..
        writeBytes(p['r'], cheatvars['skillpoints']['b']);

        -- Clear the backup variables..
        cheatvars['skillpoints']['b'] = nil;
        cheatvars['skillpoints']['d'] = nil;
    end
end


The various tables that are not explained here are not really needed to demonstrate the use of autoAssemble's disables handle though. You just pass it the same script again then give it the extra parameter which is the disable handle returned when you first called the script to enable it.

_________________
- Retired.
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