I want keytoggle changed to keypress but I don't know how.

Anything Cheat Engine related, bugs, suggestions, helping others, etc..
Post Reply
User avatar
MadeUpName_0098
Noobzor
Noobzor
Posts: 11
Joined: Sat May 04, 2019 1:20 am
Reputation: 1

I want keytoggle changed to keypress but I don't know how.

Post by MadeUpName_0098 »

I found the "simple tutorial" on doing this but I can't make any sense of it. I'm pretty much totally ignorant when it comes to LUA scripting.

I have this script for "Borderlands 2 Third Person Mode". (I got it from Nexus mods) It works fine but I want it to be 3rd person while the key is pressed and go back to normal when the key is released.

Currently it toggles on and off. Push G, it changes to 3rd person. Push G again it goes back to normal.

Can someone please make these changes for me?

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<CheatTable CheatEngineTableVersion="14">
  <CheatEntries>
    <CheatEntry>
      <ID>3656</ID>
      <Description>"Third Person Mode v3.2 (press G to toggle)"</Description>
      <Options moHideChildren="1"/>
      <Color>80000008</Color>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
aobscan(thirdpersonsubAOB1,F6 81 AC 0A 00 00 14 75 ** B8)
label(thirdpersonsubAOB1_jmp)
registersymbol(thirdpersonsubAOB1_jmp)
aobscan(thirdpersonsubAOB2,55 8b ec 83 ec 14 53 56 8b f1 8b 9e 94)
label(thirdpersonsubAOB2_jmp)
registersymbol(thirdpersonsubAOB2_jmp)
globalalloc(pCamera,4)
globalalloc(bToggleKeyPressed,4)
globalalloc(bScriptEnabled,4)
globalalloc(vCameraSet,4)
globalalloc(vCamreaMode,4)

///
pCamera:
dd 0
bToggleKeyPressed:
dd 0
bScriptEnabled:
dd 0
vCameraSet:
dd 0
vCamreaMode:
dd 000C0008
///

alloc(newmem,2048) //2kb should be enough
label(returnhere)
label(originalcode)
label(exit)
label(togglescript)
label(checktoggle)
label(thirdpersonmodestart)
label(setfirstperson)
label(setthirdpsrson)
label(dochangecamera)

newmem: //this is allocated memory, you have read,write,execute access
//place your code here
cmp dword ptr [ecx+00000190],0
je originalcode

mov [pCamera],ecx

pushad
push 'G' //key G, change to 0x74 for key F5
call GetAsyncKeyState
shr ax,#15
cmp ax,1
popad
je togglescript
mov [bToggleKeyPressed],0
jmp checktoggle

togglescript:
cmp [bToggleKeyPressed],1
je originalcode
mov [bToggleKeyPressed],1
xor [bScriptEnabled],1
jmp checktoggle

checktoggle:
cmp [bScriptEnabled],1
je thirdpersonmodestart
jmp setfirstperson

thirdpersonmodestart:
pushad
push 02 //key mouse right
call GetAsyncKeyState
shr ax,#15
cmp ax,1
popad
je setfirstperson
jmp setthirdpsrson

setfirstperson:
cmp [vCameraSet],0
je dochangecamera
jmp originalcode

setthirdpsrson:
cmp [vCameraSet],1
je dochangecamera
jmp originalcode

dochangecamera:
pushad
mov esi,ecx
mov ecx,[vCameraSet]
mov ecx,[vCamreaMode+ecx*2]      //get new camera value
mov byte ptr [esi+00000AAC],cl   //assign new camera value
mov dword ptr [esi+00000694],0   //unknown
mov ecx,esi
mov eax,dword ptr [esi+00000190] //data
push eax
call thirdpersonsubAOB2_jmp
popad
xor [vCameraSet],1
jmp originalcode

originalcode:
test byte ptr [ecx+00000AAC],14

exit:
jmp returnhere

thirdpersonsubAOB1: //"Borderlands2.exe"+61F640:
thirdpersonsubAOB1_jmp:
jmp newmem
nop
nop
returnhere:

thirdpersonsubAOB2: //?
thirdpersonsubAOB2_jmp:
 
 
[DISABLE]
//code from here till the end of the code will be used to disable the cheat
dealloc(newmem)
thirdpersonsubAOB1_jmp: //"Borderlands2.exe"+61F640:
db F6 81 AC 0A 00 00 14
//Alt: test byte ptr [ecx+00000AAC],14
thirdpersonsubAOB2_jmp: //?
//

unregistersymbol(thirdpersonsubAOB1_jmp)
unregistersymbol(thirdpersonsubAOB2_jmp)
dealloc(pCamera)
dealloc(bToggleKeyPressed)
dealloc(bScriptEnabled)
dealloc(vCameraSet)
dealloc(vCamreaMode)
</AssemblerScript>
      <CheatEntries>
        <CheatEntry>
          <ID>3675</ID>
          <Description>"First Person Value"</Description>
          <ShowAsHex>1</ShowAsHex>
          <Color>80000008</Color>
          <VariableType>Byte</VariableType>
          <Address>vCamreaMode</Address>
        </CheatEntry>
        <CheatEntry>
          <ID>3676</ID>
          <Description>"Third Person Value"</Description>
          <ShowAsHex>1</ShowAsHex>
          <Color>80000008</Color>
          <VariableType>Byte</VariableType>
          <Address>vCamreaMode+2</Address>
        </CheatEntry>
        <CheatEntry>
          <ID>3694</ID>
          <Description>"[some values]"</Description>
          <Color>80000008</Color>
          <GroupHeader>1</GroupHeader>
          <CheatEntries>
            <CheatEntry>
              <ID>3657</ID>
              <Description>"aac"</Description>
              <ShowAsHex>1</ShowAsHex>
              <Color>80000008</Color>
              <VariableType>Byte</VariableType>
              <Address>pCamera</Address>
              <Offsets>
                <Offset>AAC</Offset>
              </Offsets>
            </CheatEntry>
            <CheatEntry>
              <ID>3661</ID>
              <Description>"ae0 character's"</Description>
              <Color>80000008</Color>
              <VariableType>Float</VariableType>
              <Address>pCamera</Address>
              <Offsets>
                <Offset>AE0</Offset>
              </Offsets>
            </CheatEntry>
            <CheatEntry>
              <ID>3663</ID>
              <Description>"ae4 character's"</Description>
              <Color>80000008</Color>
              <VariableType>Float</VariableType>
              <Address>pCamera</Address>
              <Offsets>
                <Offset>AE4</Offset>
              </Offsets>
            </CheatEntry>
            <CheatEntry>
              <ID>3662</ID>
              <Description>"ae8 character's"</Description>
              <Color>80000008</Color>
              <VariableType>Float</VariableType>
              <Address>pCamera</Address>
              <Offsets>
                <Offset>AE8</Offset>
              </Offsets>
            </CheatEntry>
            <CheatEntry>
              <ID>3658</ID>
              <Description>"af0 camera's"</Description>
              <Color>80000008</Color>
              <VariableType>Float</VariableType>
              <Address>pCamera</Address>
              <Offsets>
                <Offset>AF0</Offset>
              </Offsets>
            </CheatEntry>
            <CheatEntry>
              <ID>3660</ID>
              <Description>"af4 camera's"</Description>
              <Color>80000008</Color>
              <VariableType>Float</VariableType>
              <Address>pCamera</Address>
              <Offsets>
                <Offset>AF4</Offset>
              </Offsets>
            </CheatEntry>
            <CheatEntry>
              <ID>3659</ID>
              <Description>"af8 camera's"</Description>
              <Color>80000008</Color>
              <VariableType>Float</VariableType>
              <Address>pCamera</Address>
              <Offsets>
                <Offset>AF8</Offset>
              </Offsets>
            </CheatEntry>
            <CheatEntry>
              <ID>3687</ID>
              <Description>"afc aim?"</Description>
              <ShowAsSigned>1</ShowAsSigned>
              <Color>80000008</Color>
              <VariableType>4 Bytes</VariableType>
              <Address>pCamera</Address>
              <Offsets>
                <Offset>AFC</Offset>
              </Offsets>
            </CheatEntry>
            <CheatEntry>
              <ID>3689</ID>
              <Description>"afe aim?"</Description>
              <ShowAsSigned>1</ShowAsSigned>
              <Color>80000008</Color>
              <VariableType>2 Bytes</VariableType>
              <Address>pCamera</Address>
              <Offsets>
                <Offset>AFE</Offset>
              </Offsets>
            </CheatEntry>
            <CheatEntry>
              <ID>3688</ID>
              <Description>"b00 aim?"</Description>
              <ShowAsSigned>1</ShowAsSigned>
              <Color>80000008</Color>
              <VariableType>4 Bytes</VariableType>
              <Address>pCamera</Address>
              <Offsets>
                <Offset>B00</Offset>
              </Offsets>
            </CheatEntry>
            <CheatEntry>
              <ID>3690</ID>
              <Description>"b02 aim?"</Description>
              <ShowAsSigned>1</ShowAsSigned>
              <Color>80000008</Color>
              <VariableType>2 Bytes</VariableType>
              <Address>pCamera</Address>
              <Offsets>
                <Offset>B02</Offset>
              </Offsets>
            </CheatEntry>
          </CheatEntries>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
  <UserdefinedSymbols/>
</CheatTable>

TimFun13
Expert Cheater
Expert Cheater
Posts: 1353
Joined: Fri Mar 03, 2017 12:31 am
Reputation: 7

Re: I want keytoggle changed to keypress but I don't know how.

Post by TimFun13 »

Topic moved, this is Auto Assembler (well XML with an assembler script) not Lua.

But give this a try:

Code: Select all

[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
aobscan(thirdpersonsubAOB1,F6 81 AC 0A 00 00 14 75 ** B8)
label(thirdpersonsubAOB1_jmp)
registersymbol(thirdpersonsubAOB1_jmp)
aobscan(thirdpersonsubAOB2,55 8b ec 83 ec 14 53 56 8b f1 8b 9e 94)
label(thirdpersonsubAOB2_jmp)
registersymbol(thirdpersonsubAOB2_jmp)
globalalloc(pCamera,4)
globalalloc(bToggleKeyPressed,4)
globalalloc(bScriptEnabled,4)
globalalloc(vCameraSet,4)
globalalloc(vCamreaMode,4)

///
pCamera:
dd 0
bToggleKeyPressed:
dd 0
bScriptEnabled:
dd 0
vCameraSet:
dd 0
vCamreaMode:
dd 000C0008
///

alloc(newmem,2048) //2kb should be enough
label(returnhere)
label(originalcode)
label(exit)
label(togglescript)
label(checktoggle)
label(thirdpersonmodestart)
label(setfirstperson)
label(setthirdpsrson)
label(dochangecamera)

newmem: //this is allocated memory, you have read,write,execute access
//place your code here
cmp dword ptr [ecx+00000190],0
je originalcode

mov [pCamera],ecx

pushad
push 'G' //key G, change to 0x74 for key F5
call GetAsyncKeyState
shr ax,#15
cmp ax,1
popad
//-------------------------------------------
// je togglescript
// mov [bToggleKeyPressed],0
// jmp checktoggle
je setthirdpsrson
jmp setfirstperson
//-------------------------------------------

togglescript:
cmp [bToggleKeyPressed],1
je originalcode
mov [bToggleKeyPressed],1
xor [bScriptEnabled],1
jmp checktoggle

checktoggle:
cmp [bScriptEnabled],1
je thirdpersonmodestart
jmp setfirstperson

thirdpersonmodestart:
pushad
push 02 //key mouse right
call GetAsyncKeyState
shr ax,#15
cmp ax,1
popad
je setfirstperson
jmp setthirdpsrson

setfirstperson:
cmp [vCameraSet],0
je dochangecamera
jmp originalcode

setthirdpsrson:
cmp [vCameraSet],1
je dochangecamera
jmp originalcode

dochangecamera:
pushad
mov esi,ecx
mov ecx,[vCameraSet]
mov ecx,[vCamreaMode+ecx*2]      //get new camera value
mov byte ptr [esi+00000AAC],cl   //assign new camera value
mov dword ptr [esi+00000694],0   //unknown
mov ecx,esi
mov eax,dword ptr [esi+00000190] //data
push eax
call thirdpersonsubAOB2_jmp
popad
xor [vCameraSet],1
jmp originalcode

originalcode:
test byte ptr [ecx+00000AAC],14

exit:
jmp returnhere

thirdpersonsubAOB1: //"Borderlands2.exe"+61F640:
thirdpersonsubAOB1_jmp:
jmp newmem
nop
nop
returnhere:

thirdpersonsubAOB2: //?
thirdpersonsubAOB2_jmp:
 
 
[DISABLE]
//code from here till the end of the code will be used to disable the cheat
dealloc(newmem)
thirdpersonsubAOB1_jmp: //"Borderlands2.exe"+61F640:
db F6 81 AC 0A 00 00 14
//Alt: test byte ptr [ecx+00000AAC],14
thirdpersonsubAOB2_jmp: //?
//

unregistersymbol(thirdpersonsubAOB1_jmp)
unregistersymbol(thirdpersonsubAOB2_jmp)
dealloc(pCamera)
dealloc(bToggleKeyPressed)
dealloc(bScriptEnabled)
dealloc(vCameraSet)
dealloc(vCamreaMode)

User avatar
MadeUpName_0098
Noobzor
Noobzor
Posts: 11
Joined: Sat May 04, 2019 1:20 am
Reputation: 1

Re: I want keytoggle changed to keypress but I don't know how.

Post by MadeUpName_0098 »

Thank you, ShyTwig16

CE threw an error when I pasted this in, but I hit yes and it works fine.
Not all code is injectable,
(error in line 9 (globalalloc(pCamera,4)) :Error allocating memory)
Are you sure you want to edit it to this

User avatar
MadeUpName_0098
Noobzor
Noobzor
Posts: 11
Joined: Sat May 04, 2019 1:20 am
Reputation: 1

Re: I want keytoggle changed to keypress but I don't know how.

Post by MadeUpName_0098 »

@ShyTwig16

I wanted to Thank you once more for your assistance.

I compared the original CT with the one you edited for me and was able to figure out what you did. This was enough for me to figure out how to edit the CT I downloaded for 'Borderlands The Pre Sequel" and make it work the same way, momentary instead of toggle.

Post Reply

Who is online

Users browsing this forum: No registered users