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 


Disable activated cheat after game crash/close

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Sondio
Newbie cheater
Reputation: 1

Joined: 07 Mar 2019
Posts: 18

PostPosted: Thu Mar 07, 2019 10:52 pm    Post subject: Disable activated cheat after game crash/close Reply with quote

Hey there,
I'm new on this forum, I've been following you for some time and slowly I try to learn something new and fun;
from the information gathered here, I tried to create a trainer for minesweeper.exe, everything works fine but my problem is that:
 
if I close the game with the cheat activated, the trainer crashes and I have to close it from the PC task manager ...

What did I do wrong?

Sorry for my English
Thank you for your time
Minesweeper_Trainer+3.CT :
Code:
<?xml version="1.0" encoding="utf-8"?>
<CheatTable CheatEngineTableVersion="27">
  <Forms>
    <CETrainer Class="TTrainerForm" Encoding="Ascii85">#gxl#)=Ar49lMEd5oG{jBo,}i3W*]6,7%KKwlh@C)%6cpLUaN0/*j)anThN%ZQ*ILF/yW+;LcLz+4)PL8)4Y9IrIJJn/VFpEC_;,-fv=ZdxS!K%.K49p;nq}gb9}@G,TWj:Tk0yXh?jNC9Bc:L[$85ZUo)AaR}7sU@LO(K5=%T4zm-WspgXtLdlGLhpNiu+Ad8ypSXmcXDiE[bHZrrc}%I=CBPiwuVwU]!=qO;puCROi,z/W,ti9!0(,W8Jgf+jn$8u6C1e4WpUjyX!}oRF4nZs@+g{p,A:0cqGO%Ne(?lHCg.hOKsO[3YM9!)Kcu_pkPfH5,e0w1)3VGbn@C8mvHvWh^4-K:+*5/+YSsteqapK$hK3aXoFW[2tyf}v/EMl;.M10yqt}DMwcwmo}u.F(;-YphQCJ@v7Y;Nj_?OUe}mHo92U+?RS/%RqfWNT47$@:ymS3FoSWHpF-F!9oet0+M:GLH;QiPlb@%_P!#62zqHV]P^@q!k5G^uS(l736QuR3qTzo5vwkcFSe/S(]TbqA]S.J7t#zMAiCUvIsZXm7-[stk2-W(o+m/2U]V4n{Ur83#v4oK{;=q^*)k}hQ?XW4@IA%Xm[h9-xL*eFM6.dsvnOLIz#[Y@;CZ2@i$Y$l@+ZfU2*aM$VK;^s.b%F-b@]XR5wif6q}0Q,oM9cQ7OO3mG]Q-^AX!$nJhaytA^_-?L9[9.YorES/AQi]gVHlEDal[d;)9?UDB]elEuS1Ky_st*1;pRbJzT.kln4wn,o}rc5pd@-UE2$?4(dD#rHL?K5!rLs33Ol:x}#Gv[:$!zW</CETrainer>
  </Forms>
  <CheatEntries>
    <CheatEntry>
      <ID>13</ID>
      <Description>"LOADER"</Description>
      <LastState/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[ENABLE]

[DISABLE]
{$lua}
getAddressList().GetMemoryRecordByDescription('EN-TIME').Active=false
getAddressList().GetMemoryRecordByDescription('time').Active=false
getAddressList().GetMemoryRecordByDescription('EN-ZERO').Active=false
getAddressList().GetMemoryRecordByDescription('zero').Active=false
getAddressList().GetMemoryRecordByDescription('EN-HITZ').Active=false
getAddressList().GetMemoryRecordByDescription('hit').Active=false
CETrainer.CHEAT0.Activated=false
CETrainer.CHEAT1.Activated=false
CETrainer.CHEAT2.Activated=false
CETrainer.CHEAT3.Activated=false
{$asm}
</AssemblerScript>
      <CheatEntries>
        <CheatEntry>
          <ID>3</ID>
          <Description>"EN-TIME"</Description>
          <LastState/>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
getAddressList().GetMemoryRecordByDescription('EN-ZERO').Active=true
getAddressList().GetMemoryRecordByDescription('EN-HITZ').Active=true
{$asm}

alloc(newmem,2048,"Minesweeper.exe"+2B75B)
label(return)
label(code)
label(exit)
label(time)

newmem:
cmp [time],0
je code
movss xmm0,[rax+20]

code:
movss [rax+20],xmm0

time:
dd 0

exit:
jmp return

"Minesweeper.exe"+2B75B:
jmp newmem
return:

registersymbol(time)
 
[DISABLE]
"Minesweeper.exe"+2B75B:
db F3 0F 11 40 20
unregistersymbol(time)
dealloc(newmem)

{$lua}
getAddressList().GetMemoryRecordByDescription('time').Active=false
getAddressList().GetMemoryRecordByDescription('EN-ZERO').Active=false
getAddressList().GetMemoryRecordByDescription('zero').Active=false
getAddressList().GetMemoryRecordByDescription('EN-HITZ').Active=false
getAddressList().GetMemoryRecordByDescription('hit').Active=false
CETrainer.CHEAT1.Activated=false
CETrainer.CHEAT2.Activated=false
CETrainer.CHEAT3.Activated=false
{$asm}
</AssemblerScript>
          <Hotkeys>
            <Hotkey>
              <Action>Toggle Activation</Action>
              <Keys>
                <Key>36</Key>
              </Keys>
              <Description>ENABLE</Description>
              <ID>0</ID>
            </Hotkey>
          </Hotkeys>
          <CheatEntries>
            <CheatEntry>
              <ID>4</ID>
              <Description>"time"</Description>
              <LastState/>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
time:
dd 1
[DISABLE]
time:
dd 0
</AssemblerScript>
              <Hotkeys>
                <Hotkey>
                  <Action>Toggle Activation</Action>
                  <Keys>
                    <Key>97</Key>
                  </Keys>
                  <Description>FREEZE TIME</Description>
                  <ID>0</ID>
                </Hotkey>
              </Hotkeys>
            </CheatEntry>
          </CheatEntries>
        </CheatEntry>
        <CheatEntry>
          <ID>8</ID>
          <Description>"EN-ZERO"</Description>
          <LastState/>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
getAddressList().GetMemoryRecordByDescription('EN-TIME').Active=true
getAddressList().GetMemoryRecordByDescription('EN-HITZ').Active=true
{$asm}

alloc(newmem,2048,"Minesweeper.exe"+2B74E)
label(return)
label(code)
label(exit)
label(zero)

newmem:
cmp [zero],0
je code
movss [rax+20],xmm0

code:
movss xmm0,[rax+20]

zero:
dd 0

exit:
jmp return

"Minesweeper.exe"+2B74E:
jmp newmem

return:

registersymbol(zero)


[DISABLE]
"Minesweeper.exe"+2B74E:
db F3 0F 10 40 20
unregistersymbol(zero)
dealloc(newmem)

{$lua}
getAddressList().GetMemoryRecordByDescription('zero').Active=false
getAddressList().GetMemoryRecordByDescription('EN-TIME').Active=false
getAddressList().GetMemoryRecordByDescription('EN-HITZ').Active=false
{$asm}
</AssemblerScript>
          <CheatEntries>
            <CheatEntry>
              <ID>9</ID>
              <Description>"zero"</Description>
              <LastState/>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
getAddressList().GetMemoryRecordByDescription('time').Active=true
getAddressList().GetMemoryRecordByDescription('hit').Active=false
CETrainer.CHEAT1.Activated=true
CETrainer.CHEAT3.Activated=false
{$asm}

zero:
dd 1
[DISABLE]
zero:
dd 0

{$lua}
getAddressList().GetMemoryRecordByDescription('time').Active=false
CETrainer.CHEAT1.Activated=false
{$asm}
</AssemblerScript>
              <Hotkeys>
                <Hotkey>
                  <Action>Toggle Activation</Action>
                  <Keys>
                    <Key>96</Key>
                  </Keys>
                  <Description>ZERO TIME</Description>
                  <ID>0</ID>
                </Hotkey>
              </Hotkeys>
            </CheatEntry>
          </CheatEntries>
        </CheatEntry>
        <CheatEntry>
          <ID>11</ID>
          <Description>"EN-HITZ"</Description>
          <LastState/>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
{$lua}
getAddressList().GetMemoryRecordByDescription('EN-ZERO').Active=true
getAddressList().GetMemoryRecordByDescription('EN-TIME').Active=true
{$asm}


alloc(newmem,2048,"Minesweeper.exe"+32301)
label(return)
label(code)
label(exit)
label(hit)

newmem:
cmp [hit],0
je code
movss [rcx+20],xmm0

code:
movss xmm0,[rcx+20]

hit:
dd 0

exit:
jmp return

"Minesweeper.exe"+32301:
jmp newmem
return:

registersymbol(hit)

[DISABLE]
"Minesweeper.exe"+32301:
db F3 0F 10 41 20
unregistersymbol(hit)
dealloc(newmem)
{$lua}
getAddressList().GetMemoryRecordByDescription('hit').Active=false
getAddressList().GetMemoryRecordByDescription('EN-ZERO').Active=false
getAddressList().GetMemoryRecordByDescription('EN-TIME').Active=false
{$asm}

</AssemblerScript>
          <CheatEntries>
            <CheatEntry>
              <ID>12</ID>
              <Description>"hit"</Description>
              <LastState/>
              <VariableType>Auto Assembler Script</VariableType>
              <AssemblerScript>[ENABLE]
{$lua}
getAddressList().GetMemoryRecordByDescription('zero').Active=false
CETrainer.CHEAT2.Activated=false
{$asm}

hit:
dd 1
[DISABLE]
hit:
dd 0


</AssemblerScript>
              <Hotkeys>
                <Hotkey>
                  <Action>Toggle Activation</Action>
                  <Keys>
                    <Key>98</Key>
                  </Keys>
                  <Description>RESET TIME</Description>
                  <ID>0</ID>
                </Hotkey>
              </Hotkeys>
            </CheatEntry>
          </CheatEntries>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
  <UserdefinedSymbols/>
  <LuaScript>form_show(CETrainer)
local Trainer = { }
local getmr = getAddressList().GetMemoryRecordByDescription
local process_name = "Minesweeper.exe";
About=[[This trainer was made by : Cheat Engine 6.8]]
function Trainer.Main( )
 Trainer.process_checker = InitTimer(Trainer.main_panel,1000,false,process_checker)
 return true;
end
function InitTimer(owner,tickRate,status,func)
 timer = createTimer(owner)
 if timer == nil then
 return nil;
 end
 timer_setInterval(timer,tickRate)
 timer_onTimer(timer,func)
 timer_setEnabled(timer,status)
 return timer;
end
function process_checker(t)
 status = readInteger(process_name)
 local id = getOpenedProcessID()
 if status == nil then
 openProcess(process_name)
 getmr("LOADER").Active=false
 getmr("EN-TIME").Active=false
 getmr("time").Active=false
 getmr("EN-ZERO").Active=false
 getmr("zero").Active=false
 getmr("EN-HITZ").Active=false
 getmr("hit").Active=false
 CETrainer.CELabel3.Caption = "OFF"
 CETrainer.CELabel3.Font.Color = 0x0000FF
 CETrainer.CELabel4.Caption = "*****"
 CETrainer.CELabel4.Font.Color = 0x0000FF
 else
 getmr("LOADER").Active=true
 CETrainer.CELabel3.Caption = "ON"
 CETrainer.CELabel3.Font.Color = 0x00FF00
 CETrainer.CELabel4.Caption = id
 CETrainer.CELabel4.Font.Color = 0x00FF00
 end
end
function AboutClick()
 showMessage(About)
end
function onOpenProcess()
end
function closeCleanup(sender)
 closeCE()
 return caFree
end
Trainer.Main();
timer_setEnabled(Trainer.process_checker,true)
--TRAINERGENERATORSTART--
RequiredCEVersion=6.8
if (getCEVersion==nil) or (getCEVersion()&lt;RequiredCEVersion) then
  messageDialog('Please install Cheat Engine '..RequiredCEVersion, mtError, mbOK)
  closeCE()
end
addresslist=getAddressList()
memrec3=addresslist.getMemoryRecordByID(3)
memrec4=addresslist.getMemoryRecordByID(4)
memrec9=addresslist.getMemoryRecordByID(9)
memrec12=addresslist.getMemoryRecordByID(12)
memrec3_hotkey0=memrec3.getHotkeyByID(0)
memrec4_hotkey0=memrec4.getHotkeyByID(0)
memrec9_hotkey0=memrec9.getHotkeyByID(0)
memrec12_hotkey0=memrec12.getHotkeyByID(0)
function onPostHotkey0(Hotkey)
 local memrec=Hotkey.Owner
 local isActive=memrec.Active
 CETrainer.CHEAT0.setActive(isActive)
 if gPlaySoundOnAction then
  if isActive then
  playSound(gActivateSound)
  else
  playSound(gDeactivateSound)
  end
 end
end
memrec3_hotkey0.onPostHotkey=onPostHotkey0
function onPostHotkey1(Hotkey)
 local memrec=Hotkey.Owner
 local isActive=memrec.Active
 CETrainer.CHEAT1.setActive(isActive)
 if gPlaySoundOnAction then
  if isActive then
  playSound(gActivateSound)
  else
  playSound(gDeactivateSound)
  end
 end
end
memrec4_hotkey0.onPostHotkey=onPostHotkey1
function onPostHotkey2(Hotkey)
 local memrec=Hotkey.Owner
 local isActive=memrec.Active
 CETrainer.CHEAT2.setActive(isActive)
 if gPlaySoundOnAction then
  if isActive then
  playSound(gActivateSound)
  else
  playSound(gDeactivateSound)
  end
 end
end
memrec9_hotkey0.onPostHotkey=onPostHotkey2
function onPostHotkey3(Hotkey)
 local memrec=Hotkey.Owner
 local isActive=memrec.Active
 CETrainer.CHEAT3.setActive(isActive)
 if gPlaySoundOnAction then
  if isActive then
  playSound(gActivateSound)
  else
  playSound(gDeactivateSound)
  end
 end
end
memrec12_hotkey0.onPostHotkey=onPostHotkey3
getAutoAttachList().add("Minesweeper.exe")
gPlaySoundOnAction=true
gActivateSound=findTableFile([[Activate]])
gDeactivateSound=findTableFile([[Deactivate]])
CETrainer.show()
--TRAINERGENERATORSTOP--
</LuaScript>
</CheatTable>
Back to top
View user's profile Send private message
Sondio
Newbie cheater
Reputation: 1

Joined: 07 Mar 2019
Posts: 18

PostPosted: Sun Mar 10, 2019 9:49 pm    Post subject: Reply with quote

wrong section?
wrong question ??
wrong ... what ???
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Sun Mar 10, 2019 10:47 pm    Post subject: Reply with quote

I am also new in this matter :

try to change this :

Code:
function closeCleanup(sender)
 getAddressList().GetMemoryRecordByDescription('time').Active=false
 getAddressList().GetMemoryRecordByDescription('EN-ZERO').Active=false
 getAddressList().GetMemoryRecordByDescription('zero').Active=false
 getAddressList().GetMemoryRecordByDescription('EN-HITZ').Active=false
 getAddressList().GetMemoryRecordByDescription('hit').Active=false
 CETrainer.CHEAT1.Activated=false
 CETrainer.CHEAT2.Activated=false
 CETrainer.CHEAT3.Activated=false
 
 --- try adding lines for deactivating all activated cheats before close the trainer

  closeCE()
 return caFree
end

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Sondio
Newbie cheater
Reputation: 1

Joined: 07 Mar 2019
Posts: 18

PostPosted: Sun Mar 10, 2019 11:16 pm    Post subject: Reply with quote

Corroder wrote:
I am also new in this matter :

try to change this :

Code:
function closeCleanup(sender)
 getAddressList().GetMemoryRecordByDescription('time').Active=false
 getAddressList().GetMemoryRecordByDescription('EN-ZERO').Active=false
 getAddressList().GetMemoryRecordByDescription('zero').Active=false
 getAddressList().GetMemoryRecordByDescription('EN-HITZ').Active=false
 getAddressList().GetMemoryRecordByDescription('hit').Active=false
 CETrainer.CHEAT1.Activated=false
 CETrainer.CHEAT2.Activated=false
 CETrainer.CHEAT3.Activated=false
 
 --- try adding lines for deactivating all activated cheats before close the trainer

  closeCE()
 return caFree
end


Very Happy THANK YOU for your answer!!!!!!
but Sad does not work;

if the game is closed, the trainer is disabled and i can close CE; = OK
if the game is open, i actived trainer and i can close CE; = OK
if i close game, when cheat are actived , CE go stucks; = NOT OK

how i can auto disable/dealloc memory code cheat if game crash or if i close game before disable trainer?

Thank you for your time!

_________________
DaSpamer
I am the leader of the lazy and with the books I made filters !!!Cool
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Mon Mar 11, 2019 12:37 am    Post subject: Reply with quote

Quote:
if i close game, when cheat are actived , CE go stucks; = NOT OK


Then you need to check if game open or not and throw several conditions to handle it. in this case : if not found 'game_name.exe' on process list then disable all activated hacks or all hacks activating set to false.

Code:
cecheck_list = createStringlist()

function gamecheck()
  getProcesslist(cecheck_list)
  local count = 0
  for i=0,cecheck_list.count-1 do
    if cecheck_list[i]:find("Minesweeper") then
      count = count + 1
    end
  end
  if count > 1 then
    --- activated hack here
  else
    --- deactivating hack here
    check_t = false
    closeCE()
  end
  end
  cecheck_list.clear()
end

check_t=createTimer(nil)
timer_onTimer(check_t, gamecheck)
timer_setInterval(check_t, 200)
timer_setEnabled(check_t, true)

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25788
Location: The netherlands

PostPosted: Mon Mar 11, 2019 7:48 am    Post subject: Reply with quote

AddressList.disableAllWithoutExecute() will disable all <Script> entries

and use a timer where you read 'process' and if it returns nil it's gone
Code:

function (t)
if readinteger(process)==nil then
  disableeverything()
end
end

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Sondio
Newbie cheater
Reputation: 1

Joined: 07 Mar 2019
Posts: 18

PostPosted: Tue Mar 12, 2019 12:45 pm    Post subject: Reply with quote

Corroder wrote:

Code:
cecheck_list = createStringlist()

function gamecheck()
  getProcesslist(cecheck_list)
  local count = 0
  for i=0,cecheck_list.count-1 do
    if cecheck_list[i]:find("Minesweeper") then
      count = count + 1
    end
  end
  if count > 1 then
    --- activated hack here
  else
    --- deactivating hack here
    check_t = false
    closeCE()
  end
  end
  cecheck_list.clear()
end

check_t=createTimer(nil)
timer_onTimer(check_t, gamecheck)
timer_setInterval(check_t, 200)
timer_setEnabled(check_t, true)


Dark Byte wrote:
AddressList.disableAllWithoutExecute() will disable all <Script> entries

and use a timer where you read 'process' and if it returns nil it's gone


Very Happy THANK YOU SO MUCH!!! Very Happy

Code:
cecheck_list = createStringlist()
function gamecheck()
 status = readInteger(process_name)
 getProcesslist(cecheck_list)
 local count = 0
 for i=0,cecheck_list.count-1 do
  if cecheck_list[i]:find(process_name) then
  count = count + 1
  end
 end
 if count < 1 and status == nil then
 ----------------------------------------------------- deactivated hack here
 AddressList.disableAllWithoutExecute()
 CETrainer.CHEAT3.Activated=false
 CETrainer.CHEAT2.Activated=false
 CETrainer.CHEAT1.Activated=false
 CETrainer.CHEAT0.Activated=false
 CETrainer.CELabel3.Caption = "Lunch GAME..."
 CETrainer.CELabel3.Font.Color = 0xFF00FF
 check_t = false
 elseif count < 1 and status ~= nil then
 ----------------------------------------------------- deactivated hack here
 AddressList.disableAllWithoutExecute()
 CETrainer.CHEAT3.Activated=false
 CETrainer.CHEAT2.Activated=false
 CETrainer.CHEAT1.Activated=false
 CETrainer.CHEAT0.Activated=false
 else
 ----------------------------------------------------- activated hack here
 end
 cecheck_list.clear()
end
check_t=createTimer(nil)
timer_onTimer(check_t, gamecheck)
timer_setInterval(check_t, 500)
timer_setEnabled(check_t, true)

_________________
DaSpamer
I am the leader of the lazy and with the books I made filters !!!Cool
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 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