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 help with the CE script

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

Joined: 24 Jun 2023
Posts: 2

PostPosted: Sat Jun 24, 2023 10:10 am    Post subject: need help with the CE script Reply with quote

Hello all, need help with the CE script. I need the script works only when one of these buttons ( up , down , left , right) and if these buttons are not pressed the script is not activated, how do I do it?
Code:
{ Game   : FreeStyle2.exe
  Version:
  Date   : 2023-03-20
  Author : nanim

  This script does blah blah blah
}

[ENABLE]

aobscanmodule(INJECT,GameApp.dll,D9 41 2C C3 CC) // should be unique
alloc(newmem,$1000)

label(code)
label(return)

newmem:

code:
mov [ecx+2C],(float)500
  fld dword ptr [ecx+2C]
  mov [ecx+2C],(float)500
  ret
  int 3
  jmp return

INJECT:
  jmp newmem
return:
registersymbol(INJECT)

[DISABLE]

INJECT:
  db D9 41 2C C3 CC

unregistersymbol(INJECT)
dealloc(newmem)

{
// ORIGINAL CODE - INJECTION POINT: GameApp.dll+1E4220

GameApp.dll+1E4216: C3        - ret
GameApp.dll+1E4217: CC        - int 3
GameApp.dll+1E4218: CC        - int 3
GameApp.dll+1E4219: CC        - int 3
GameApp.dll+1E421A: CC        - int 3
GameApp.dll+1E421B: CC        - int 3
GameApp.dll+1E421C: CC        - int 3
GameApp.dll+1E421D: CC        - int 3
GameApp.dll+1E421E: CC        - int 3
GameApp.dll+1E421F: CC        - int 3
// ---------- INJECTING HERE ----------
GameApp.dll+1E4220: D9 41 2C  - fld dword ptr [ecx+2C]
// ---------- DONE INJECTING  ----------
GameApp.dll+1E4223: C3        - ret
GameApp.dll+1E4224: CC        - int 3
GameApp.dll+1E4225: CC        - int 3
GameApp.dll+1E4226: CC        - int 3
GameApp.dll+1E4227: CC        - int 3
GameApp.dll+1E4228: CC        - int 3
GameApp.dll+1E4229: CC        - int 3
GameApp.dll+1E422A: CC        - int 3
GameApp.dll+1E422B: CC        - int 3
GameApp.dll+1E422C: CC        - int 3
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1069
Location: 0x90

PostPosted: Sat Jun 24, 2023 1:06 pm    Post subject: Reply with quote

It's likely to be that the function is only called when the button is pressed.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1516

PostPosted: Sat Jun 24, 2023 2:35 pm    Post subject: Reply with quote

Give your script a name and write it in the code below (yourScriptDesc).

1) Put the code below in a script and activate it.

2) Click F8 to turn the key reading timer on and off.

3) Click the arrow keys and test the results.

Code:
[ENABLE]

{$lua}

if checkTmr then checkTmr.Destroy() checkTmr=nil end   
checkTmr=createTimer() checkTmr.Interval=20 checkTmr.Enabled=false

checkTmr.OnTimer=function()
  if isKeyPressed(VK_LEFT) then
    sleep(150)
    --getAddressList().getMemoryRecordByDescription("yourScriptDesc?").Active=true
    print(1,"left click")
  elseif isKeyPressed(VK_UP) then
    sleep(150)
    print(2,"up click")
  elseif isKeyPressed(VK_RIGHT) then
    sleep(150)
    print(3,"right click")
  elseif isKeyPressed(VK_DOWN) then
    sleep(150)
    print(4,"down click")
  else
    --sleep(150)
    --getAddressList().getMemoryRecordByDescription("yourScriptDesc?").Active=false
    --print("no key!")
  end
end

if checkKey then checkKey.Destroy() checkKey=nil end

checkKey = createHotkey((function()
                     sleep(200)
                     if checkTmr.Enabled==false then
                        checkTmr.Enabled=true
                     else
                        checkTmr.Enabled=false
                     end
                  end), VK_F8)

{$asm}
[DISABLE]

{$lua}
if checkKey then checkKey.Destroy() checkKey=nil end
if checkTmr then checkTmr.Destroy() checkTmr=nil end 
   

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Slame12
How do I cheat?
Reputation: 0

Joined: 24 Jun 2023
Posts: 2

PostPosted: Sat Jun 24, 2023 3:14 pm    Post subject: Reply with quote

error : not all code is injectable
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Sat Jun 24, 2023 9:27 pm    Post subject: Reply with quote

May try this,
1. copy following text, which is clipboard of some ce memory record items;
2. click ce memory record panel or select an memory record, paste the text, some memory records should be created;
3. There should be 4 records corresponding to 4 hotkey setting, <CTRL+SHIFT>+LEFT/RIGHT/UP/DOWN (CTRL+SHIFT is to not easily activate it, you may need to make your setup in actual application);
3.1 each hot key toggle a different bit (0 <-> 1) of the same address of different bit position (0/1/2/3);
3.2 the setting need newer ce which has the option 'restore to original on release';
3.3 With suitable address setting, your AA can read the address to respond on what key is pressing;

Code:

<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>337</ID>
      <Description>"Key_Addr_Base"</Description>
      <Options moHideChildren="1"/>
      <ShowAsSigned>1</ShowAsSigned>
      <GroupHeader>1</GroupHeader>
      <Address>___</Address>
      <CheatEntries>
        <CheatEntry>
          <ID>338</ID>
          <Description>"LEFT"</Description>
          <ShowAsSigned>0</ShowAsSigned>
          <VariableType>Binary</VariableType>
          <BitStart>0</BitStart>
          <BitLength>1</BitLength>
          <ShowAsBinary>0</ShowAsBinary>
          <Address>+00</Address>
          <Hotkeys>
            <Hotkey OnlyWhileDown="1">
              <Action>Set Value</Action>
              <Keys>
                <Key>16</Key>
                <Key>17</Key>
                <Key>37</Key>
              </Keys>
              <Value>1</Value>
              <ID>0</ID>
            </Hotkey>
          </Hotkeys>
        </CheatEntry>
        <CheatEntry>
          <ID>340</ID>
          <Description>"RIGHT"</Description>
          <ShowAsSigned>0</ShowAsSigned>
          <VariableType>Binary</VariableType>
          <BitStart>1</BitStart>
          <BitLength>1</BitLength>
          <ShowAsBinary>0</ShowAsBinary>
          <Address>+00</Address>
          <Hotkeys>
            <Hotkey OnlyWhileDown="1">
              <Action>Set Value</Action>
              <Keys>
                <Key>16</Key>
                <Key>17</Key>
                <Key>39</Key>
              </Keys>
              <Value>1</Value>
              <ID>0</ID>
            </Hotkey>
          </Hotkeys>
        </CheatEntry>
        <CheatEntry>
          <ID>341</ID>
          <Description>"UP"</Description>
          <ShowAsSigned>0</ShowAsSigned>
          <VariableType>Binary</VariableType>
          <BitStart>2</BitStart>
          <BitLength>1</BitLength>
          <ShowAsBinary>0</ShowAsBinary>
          <Address>+00</Address>
          <Hotkeys>
            <Hotkey OnlyWhileDown="1">
              <Action>Set Value</Action>
              <Keys>
                <Key>16</Key>
                <Key>17</Key>
                <Key>38</Key>
              </Keys>
              <Value>1</Value>
              <ID>0</ID>
            </Hotkey>
          </Hotkeys>
        </CheatEntry>
        <CheatEntry>
          <ID>339</ID>
          <Description>"DOWN"</Description>
          <ShowAsSigned>0</ShowAsSigned>
          <VariableType>Binary</VariableType>
          <BitStart>3</BitStart>
          <BitLength>1</BitLength>
          <ShowAsBinary>0</ShowAsBinary>
          <Address>+00</Address>
          <Hotkeys>
            <Hotkey OnlyWhileDown="1">
              <Action>Set Value</Action>
              <Keys>
                <Key>16</Key>
                <Key>17</Key>
                <Key>40</Key>
              </Keys>
              <Value>1</Value>
              <ID>0</ID>
            </Hotkey>
          </Hotkeys>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
</CheatTable>


For older ce without the option 'restore to original on release', you need to reset/clear the address AFTER reading the value; eg.

Code:

...
mov         al,[KEY_ADDRESS]
mov         byte ptr[KEY_ADDRESS],0  //// reset
cmp         al,1  /// LEFT KEY and ONLY LEFT KEY PRESSING
je          do_left_key
cmp         al,5 /// LEFT AND UP KEY, and ONLY LEFT AND UP KEY PRESSING
je          do_left_up_key
...

Hope you get the idea


NOTE:
Some emulator may have such game-pad-address (ie. use a bit to repressing button pressing). In this case, try found the address so your AA can respond directly to player input without such memory record setting.

_________________
- Retarded.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1516

PostPosted: Sun Jun 25, 2023 9:21 am    Post subject: Reply with quote

Slame12 wrote:
error : not all code is injectable



I just tested its working.

But I recommend you to turn to @panraven code and warnings.

While my suggestion is superficial, @panraven's suggestion will take you and your knowledge further.



Ek1.PNG
 Description:
 Filesize:  43.47 KB
 Viewed:  1476 Time(s)

Ek1.PNG



_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
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