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 


Multiple speedhack hotkeys with different variable speeds

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

Joined: 11 Sep 2019
Posts: 1

PostPosted: Wed Sep 11, 2019 7:17 am    Post subject: Multiple speedhack hotkeys with different variable speeds Reply with quote

So I'm creating a new topic as I've seen similar topics focused mainly on only one hotkey with one set speed, or a combo hotkey.

What I want is one page of code that allows me to create two sets of variables, one for one set of hotkeys and one for the other.

Ie. MouseX2+RightMouseButton sets the speedhack to .1, making for a really nice bullet time and slow aim, while LeftShift+MouseX2 would theoretically make for an additional speedy run.

So far all I've gotten in my attempts to edit the code from the closest I've found to what I want is errors...
Any hints here?

Big thanks to the folks over at FearlessRevolution for all this hard work and inspiration
The original to the code i'm editing can be found in the cheat engine table shown here:
fearlessrevolution DOT com viewtopic DOT php?t=10106
Can't post URL's as a new user, hope this is alright

Code:

[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat
alloc(slowmokeys,1024,RAGE2.exe)

label(dSlowMoKey1)
registersymbol(dSlowMoKey1)
label(dSlowMoKey2)
registersymbol(dSlowMoKey2)
label(dSlowMoKey3)
registersymbol(dSlowMoKey3)
label(dSlowMoKey4)
registersymbol(dSlowMoKey4)
label(dCustSpeedhackSpeed1)
registersymbol(dCustSpeedhackSpeed1)
label(dCustSpeedhackSpeed2)
registersymbol(dCustSpeedhackSpeed2)

///
slowmokeys:
bKeyCombMethod:
dd 1    //0: and, 1: or
dSlowMoKey1:
dd 14
dSlowMoKey2:
dd 02
dCustSpeedhackSpeed1:
dd (float)0.4
bKeyCombMethod:
dd 1    //0: and, 1: or
dSlowMoKey3:
dd 14
dSlowMoKey4:
dd 02
dCustSpeedhackSpeed2:
dd (float)2
///


{$lua}

lastSpeed=speedhack_getSpeed();
bSpeedKeyReleased=1;
local function slowmokeyLuaThread1(thread3)
   local addr = getAddressSafe('dCustSpeedhackSpeed1')
    local addrtimescale = readPointer(getAddressSafe('timeScale'))+0x380
   while SlowMokeyLuaThread1 do
      if addr then
            if ( (isKeyPressed(readInteger('dSlowMoKey1'))) and (isKeyPressed(readInteger('dSlowMoKey2'))) ) then

               if bSpeedKeyReleased == 1 then
                   if speedhack_getSpeed() ~= readFloat("dCustSpeedhackSpeed1") then
--                      print("pressing: ", lastSpeed)
                     lastSpeed=readFloat(addrtimescale)
                     writeFloat(addrtimescale,readFloat("dCustSpeedhackSpeed1"))
                     bSpeedKeyReleased=0
                   end
               end

            else

               if bSpeedKeyReleased == 0 then
                 bSpeedKeyReleased=1
--                 print(lastSpeed)
                 if readFloat(addrtimescale) ~= lastSpeed then
                   writeFloat(addrtimescale,lastSpeed)
                 end
               end

            end
      else
         addr = getAddressSafe('dCustSpeedhackSpeed1')
      end
   end
   thread3.terminate()
end
----------------------------------
if syntaxcheck then return end
SlowMokeyLuaThread1 = true
SlowMokeyLuaThread2 = true
createThread(slowmokeyLuaThread1,slowmokeyLuaThread2)
{$asm}
{$lua}
lastSpeed=speedhack_getSpeed();
bSpeedKeyReleased=1;
local function slowmokeyLuaThread2(thread4)
   local addr = getAddressSafe('dCustSpeedhackSpeed2')
    local addrtimescale = readPointer(getAddressSafe('timeScale'))+0x380
   while SlowMokeyLuaThread1 do
      if addr then
            if ( (isKeyPressed(readInteger('dSlowMoKey3'))) and (isKeyPressed(readInteger('dSlowMoKey4'))) ) then

               if bSpeedKeyReleased == 1 then
                   if speedhack_getSpeed() ~= readFloat("dCustSpeedhackSpeed2") then
--                      print("pressing: ", lastSpeed)
                     lastSpeed=readFloat(addrtimescale)
                     writeFloat(addrtimescale,readFloat("dCustSpeedhackSpeed2"))
                     bSpeedKeyReleased=0
                   end
               end

            else

               if bSpeedKeyReleased == 0 then
                 bSpeedKeyReleased=1
--                 print(lastSpeed)
                 if readFloat(addrtimescale) ~= lastSpeed then
                   writeFloat(addrtimescale,lastSpeed)
                 end
               end

            end
      else
         addr = getAddressSafe('dCustSpeedhackSpeed2')
      end
   end
   thread4.terminate()
end
----------------------------------
if syntaxcheck then return end
SlowMokeyLuaThread1 = true
SlowMokeyLuaThread2 = true
createThread(slowmokeyLuaThread1,slowmokeyLuaThread2)
{$asm}


[DISABLE]
//code from here till the end of the code will be used to disable the cheat
{$lua}
if syntaxcheck then return end
SlowMokeyLuaThread = false
{$asm}

///*****************************************///
dealloc(newmem)
unregistersymbol(dSlowMoKey1)
unregistersymbol(dSlowMoKey2)
unregistersymbol(dCustSpeedhackSpeed)
[/url]
_________________
~DashMGJ
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 42

Joined: 09 Aug 2013
Posts: 1089

PostPosted: Wed Sep 11, 2019 12:06 pm    Post subject: Reply with quote

so... take the code for one, change all the variable names to be
hotkey1_... then copy paste and change the 1 to 2? And use the hotkeys CE already gives you instead of making your own thread.

make an address in the table with the address of the timescale, something like ['timeScale'+0x380] with a name of "The Timescale"
If you're fine with not having to hold the key down the the code is pretty much this
Code:

local timescale = AddressList.getMemoryRecordByDescription("The Timescale")
hotkey1 = createHotkey(function()
  timescale.Value = timescale.Active and 1 or 0.4
  timescale.Active = not timescale.Active -- toggle freeze
end, VK_LSHIFT, VK_RBUTTON)
hotkey2 = createHotkey(function()
  timescale.Value = timescale.Active and 1 or 2
  timescale.Active = not timescale.Active -- toggle freeze
end, VK_LSHIFT, VK_XBUTTON2)


If you do want it to stop when you stop holding it down then add a couple values set to 0 inside the hotkey and create a timer that adds 1 to them, if they reach above 2 or something then they hotkey isn't setting them so must have been released and you can then unfreeze and reset the value. eg.

Code:

local timescale = AddressList.getMemoryRecordByDescription("The Timescale")
hotkey1var = 0
hotkey2var = 0
hotkey1 = createHotkey(function()
  hotkey1var = 0
  timescale.Value = 0.4
  timescale.Active = true
end, VK_LSHIFT, VK_RBUTTON)
hotkey2 = createHotkey(function()
  hotkey2var = 0
  timescale.Value = 2
  timescale.Active = true
end, VK_LSHIFT, VK_XBUTTON2)
hotkeytimer = createTimer()
hotkeytimer.Interval = 10
hotkeytimer.OnTimer = function()
  if hotkey1var > 1 or hotkey2var > 1 then
    tmescale.Active = false
    timescale.Value = 1
  end
  hotkey1var = hotkey1var + 1
  hotkey2var = hotkey2var + 1
end


alternatively you can set a hotkey via the gui to change the value and then use a script to add an OnPostHotkey function to it to change the value back to 1 and unfreeze (you'll need two with the same key to set and freeze though, for each value)

_________________
https://github.com/FreeER/ has a few CE related repos
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