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 


Script hangs CE and target app when activated multiple times

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

Joined: 22 Oct 2018
Posts: 5

PostPosted: Thu Aug 04, 2022 8:01 pm    Post subject: Script hangs CE and target app when activated multiple times Reply with quote

Grettings!

I've been trying to figure what's the issue with my script, what it does is to enable a simple "free camera mode". When enabled and disabled for the first time it will work normally, but problems arise when is enabled and disabled the third or fourth time. Both the CE and target application freeze and I have to kill both programs via the Task Manager because they become unresponsive.

Here's the code (it was stripped down since I believe the issue is very likely caused by the injection itself):

Code:

[ENABLE]
{$lua}

--//Set search AoB and code-disabling camera function

function gameplayCamControl(toggle)
   if toggle then -- Enable
      local s = [[
      GAMEPLAY_CAM_CONTROL + 0xC0:
      db 90 90 90
      luacall(playSound(findTableFile('Activate')))
      ]]
      autoAssemble(s)
   end

   if not toggle then -- Disable
      local s = [[
      GAMEPLAY_CAM_CONTROL + 0xC0:
      db 0F 29 11
      unregistersymbol(GAMEPLAY_CAM_CONTROL)
      luacall(playSound(findTableFile('Deactivate')))
      ]]
      autoAssemble(s)
   end
end

search_aob = [[
aobScanRegion(GAMEPLAY_CAM_CONTROL, target_application + 30000000, target_application + 40000000, 0F 28 32 0F 29 31 BA ?0 ?? ?? 0? 8B 0D ?0 A? ?? 0? 83 C1 60 83 E1 F0 89 C8 C1 E8 0C 8B 04 85 30 ?0 ?? ?? BB ?? ?? ?? 30 01 C1 0F 88 ?? ?? ?? D? 0F 28 39 0F 29 3A BA ?0 ?? ?? 0? 8B 0D ?0 A? ?? 0? 81 C1 90 00 00 00 83 E1 F0 89 C8 C1 E8 0C 8B 04 85 30 ?0 ?? ?? BB ?? ?? ?? 30 01 C1 0F 88 ?? ?? ?? D? 0F 28 02 0F 29 01 BA ?0 ?? ?? 0? 8B 0D ?0 ?? ?? 0? 83 E1 F0 89 C8 C1 E8 0C 8B 04 85 30 ?0 ?? ?? BB ?? ?? ?? 30 01 C1 0F 88 ?? ?? ?? D? 0F 28 09 0F 29 0A BA ?0 ?? ?? 0? 8B 0D ?0 ?? ?? 0? 83 E1 F0 89 C8 C1 E8 0C 8B 04 85 30 ?0 ?? ?? BB ?? ?? ?? 30 01 C1 0F 88 ?? ?? ?? D? 0F 28 12 0F 29 11 8B 0D ?0 ?? ?? 0? 81 C1 4E 01 00 00 89 C8 C1 E8 0C 8B 04 85 30 ?0 ?? ?? BB ?? ?? ?? 30 01 C1 0F 88 ?? ?? ?? D? 0F B6 01)

registersymbol(GAMEPLAY_CAM_CONTROL)
]]

--//Get process ID of target application then pause it

target_application = getOpenedProcessID()
pause(target_application)


if autoAssemble(search_aob) then
   
   -- do stuff
   
   unpause(target_application)

else

   --//If injection was a failure then print a error message and unpause the emulator
   
   print("Unable to run the script.")
   
   unpause(target_application)
   
end



{$asm}
[DISABLE]
{$lua}

pause(target_application)

gameplayCamControl(false) -- restore NOP'd bytes

unpause(target_application)

{$asm}


The "target application" in question is the PCSX2 emulator. The AoBScan injection is used only once and it's just to NOP the bytes relevant to the game's camera code. I also use aobScanRegion since it speeds up the activation time.


If anyone can give me a hand I'd appreciate it. Thanks in advance Very Happy.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Thu Aug 04, 2022 9:34 pm    Post subject: Reply with quote

You aren't using the syntaxcheck variable (like most other people... Sad )

Maybe it's the aobscan. Maybe it's whatever you omitted in place of the "do stuff" comment. Maybe there's a deadlock happening from your weird code.

Using the auto assembler recursively is almost always a bad idea (I don't even know if it's designed to be reentrant). That luacall just makes it even worse.

I wouldn't call autoAssemble at all and would instead do everything in Lua. Particularly limit the aobscan to only scan through executable regions.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
holaboludo
How do I cheat?
Reputation: 0

Joined: 22 Oct 2018
Posts: 5

PostPosted: Fri Aug 05, 2022 7:40 am    Post subject: Reply with quote

Thanks for the reply ParkourPenguin. The assembly part of CE is very difficult for me to understand and use but I'm gonna try to look up about it later.

I tried removing the luacall(playSound(findTableFile(''))) function and the issue seems to have been fixed now. EDIT: the problem still persists sadly.

Apologies for not sharing the full code before, it's pretty long. I apologize for the messiness of it, hopefully is readable enough.

Basically what it does is to run an AoBscan injection to disable the camera's control. If the AoBscan injection is successful then it will pause the emulator and run multiple simple smaller non-injection AoBscan searches to print the camera's coordinates, disable the HUD graphics, set the camera's control hotkeys and apply a small fix caused by disabling the camera's code then resume the emulation. Many of these addresses require AoBscans since their addresses are not dynamic and change every gameplay.

Code:

[ENABLE]

{$lua}

--//Set search AoB and code-disabling camera function

function gameplayCamControl(toggle)
   if toggle then
      local s = [[
      GAMEPLAY_CAM_CONTROL + 0xC0:
      db 90 90 90
      ]]
      autoAssemble(s)
   end

   if not toggle then
      local s = [[
      GAMEPLAY_CAM_CONTROL + 0xC0:
      db 0F 29 11
      unregistersymbol(GAMEPLAY_CAM_CONTROL)
      ]]
      autoAssemble(s)
   end
end



search_aob = [[
aobScanRegion(GAMEPLAY_CAM_CONTROL, pcsx2_emu_id + 30000000, pcsx2_emu_id + 40000000, 0F 28 32 0F 29 31 BA ?0 ?? ?? 0? 8B 0D ?0 A? ?? 0? 83 C1 60 83 E1 F0 89 C8 C1 E8 0C 8B 04 85 30 ?0 ?? ?? BB ?? ?? ?? 30 01 C1 0F 88 ?? ?? ?? D? 0F 28 39 0F 29 3A BA ?0 ?? ?? 0? 8B 0D ?0 A? ?? 0? 81 C1 90 00 00 00 83 E1 F0 89 C8 C1 E8 0C 8B 04 85 30 ?0 ?? ?? BB ?? ?? ?? 30 01 C1 0F 88 ?? ?? ?? D? 0F 28 02 0F 29 01 BA ?0 ?? ?? 0? 8B 0D ?0 ?? ?? 0? 83 E1 F0 89 C8 C1 E8 0C 8B 04 85 30 ?0 ?? ?? BB ?? ?? ?? 30 01 C1 0F 88 ?? ?? ?? D? 0F 28 09 0F 29 0A BA ?0 ?? ?? 0? 8B 0D ?0 ?? ?? 0? 83 E1 F0 89 C8 C1 E8 0C 8B 04 85 30 ?0 ?? ?? BB ?? ?? ?? 30 01 C1 0F 88 ?? ?? ?? D? 0F 28 12 0F 29 11 8B 0D ?0 ?? ?? 0? 81 C1 4E 01 00 00 89 C8 C1 E8 0C 8B 04 85 30 ?0 ?? ?? BB ?? ?? ?? 30 01 C1 0F 88 ?? ?? ?? D? 0F B6 01) // should be unique
registersymbol(GAMEPLAY_CAM_CONTROL)
]]



--//Get process ID of the active PCSX2 instance then pause it

pcsx2_emu_id = getOpenedProcessID()
pause(pcsx2_emu_id)

--//Run search AoB. If successful then:
--//run he camera code disabler
--//disable control input
--//set camera control speed rates
--//set hotkeys and store cam_values values so we can use them later
--//fix right-stick analog issue when disabling the script

if autoAssemble(search_aob) then

   --[[Toggle code]]
   gameplayCamControl(true)

   --[[Set global hotkey delay]]
   setGlobalKeyPollInterval(0)

   --[[Disable controller input]]
   writeBytes(0x203F70BC, 00, 00, 00 ,00)

   --[[Set Pause game flag]]
   writeBytes(0x207651E8, 05)

   --[[Disable HUD]]
   writeBytes(0x203FFBCF, 00)

   --[[
   Set movement rates here. The higher the value the faster the camera will move.
   This parameter uses floating point numbers only.
   ]]

   move_cam_rate = 5.5 --- X,Z,Y coordinates movement speed
   move_analog_cam_rate = 0.098125 --- PITCH/YAW/ROLL movement speed



   --[[Start search for the camera coordinates]]

   ms = createMemScan()
   ms.firstScan(soExactValue, vtByteArray, nil, "00 00 ?? 44 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 ?? ?? ?? 00 00 00 00 00 02 C0 01 00 00 80 3F FF FF 7F 4B 00 00 00 00 00 02 C0 01 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 3F ?? ?? ?? 43 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?? ?? ?? ?? 00 00 00 00 00 00 00 00 00 00 00 C5 00 00 00 C5 ?? ?? ?? ?? 00 00 80 BF 00 00 00 00 00 00 00 00 ?? ?? ?? ?? 00 00 00 00 ?? ?? ?? 3F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?? ?? ?? ?? 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?? ?? 80 BF 00 00 80 BF 00 00 00 00 00 00 00 00 ?? ?? ?? ?? 00 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 00 45 00 00 00 45 CD CC ?? ?? ?? ?? ?? 3F 03 00 00 00 ?? ?? ?? ?? 01 00 00 ?? ?? ?? ?? ?? 00 00 00 15 00 01 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 ?? 44 00 00 ?? ??" , nil, 0x20800000,0x21f00000,"",1,"4",true,nil,nil,nil)
   ms.waitTillDone()
   fl = createFoundList(ms)
   fl.initialize()
   
   

   --[[Process found results and create cheat table]]
   
   if (fl~=nil) then
      al = getAddressList()

      header3 = al.createMemoryRecord()

      header3.Description = "GAMEPLAY freecam script"
      header3.isGroupHeader = true

      for i = 1, 1 do

         base_address = getAddress(fl[0])

         cam_coord_header = al.createMemoryRecord()
         cam_coord_header.Description = "Camera coordinates"
         cam_coord_header.appendToEntry(header3)
         cam_coord_header.isGroupHeader = true

         tps_cam_xpos1 = al.createMemoryRecord() ---///third person view camera
         tps_cam_ypos1 = al.createMemoryRecord()
         tps_cam_zpos1 = al.createMemoryRecord()
         tps_cam_xpos2 = al.createMemoryRecord()
         tps_cam_ypos2 = al.createMemoryRecord()
         tps_cam_zpos2 = al.createMemoryRecord()

         as_cam_pitch = al.createMemoryRecord() ---///analog stick movement
         as_cam_yaw = al.createMemoryRecord()
         as_cam_roll = al.createMemoryRecord()

         p_state = al.createMemoryRecord()
         h_state = al.createMemoryRecord()

         third_person_view_camera_xpos1 = base_address + 0xB30
         third_person_view_camera_ypos1 = base_address + 0xB34
         third_person_view_camera_zpos1 = base_address + 0xB38
         third_person_view_camera_xpos2 = base_address + 0xB3C
         third_person_view_camera_ypos2 = base_address + 0xB40
         third_person_view_camera_zpos2 = base_address + 0xB44

         pause_state = 0x207651E8
         controller_state = 0x203F70BC
         hud_state = 0x203FFBCF

         analog_stick_camera_movement_pitch = base_address + 0xC20
         analog_stick_camera_movement_yaw = base_address + 0xC24
         analog_stick_camera_movement_roll = base_address + 0xC28

         third_person_view_camera_xpos1_old = readFloat(third_person_view_camera_xpos1)
         third_person_view_camera_ypos1_old = readFloat(third_person_view_camera_ypos1)
         third_person_view_camera_zpos1_old = readFloat(third_person_view_camera_zpos1)

         third_person_view_camera_xpos2_old = readFloat(third_person_view_camera_xpos2)
         third_person_view_camera_ypos2_old = readFloat(third_person_view_camera_ypos2)
         third_person_view_camera_zpos2_old = readFloat(third_person_view_camera_zpos2)

         tps_cam_xpos1.Description = "tpscam_player_axis_x"
         tps_cam_xpos1.setAddress(third_person_view_camera_xpos1)
         tps_cam_xpos1.Type = vtSingle
         tps_cam_xpos1.appendToEntry(cam_coord_header)

         tps_cam_ypos1.Description = "tpscam_player_axis_y"
         tps_cam_ypos1.setAddress(third_person_view_camera_ypos1)
         tps_cam_ypos1.Type = vtSingle
         tps_cam_ypos1.appendToEntry(cam_coord_header)

         tps_cam_zpos1.Description = "tpscam_player_axis_zoom"
         tps_cam_zpos1.setAddress(third_person_view_camera_zpos1)
         tps_cam_zpos1.Type = vtSingle
         tps_cam_zpos1.appendToEntry(cam_coord_header)

         tps_cam_xpos2.Description = "tpscam_camera_axis_x"
         tps_cam_xpos2.setAddress(third_person_view_camera_xpos2)
         tps_cam_xpos2.Type = vtSingle
         tps_cam_xpos2.appendToEntry(cam_coord_header)

         tps_cam_ypos2.Description = "tpscam_camera_axis_y"
         tps_cam_ypos2.setAddress(third_person_view_camera_ypos2)
         tps_cam_ypos2.Type = vtSingle
         tps_cam_ypos2.appendToEntry(cam_coord_header)

         tps_cam_zpos2.Description = "tpscam_camera_axis_zoom"
         tps_cam_zpos2.setAddress(third_person_view_camera_zpos2)
         tps_cam_zpos2.Type = vtSingle
         tps_cam_zpos2.appendToEntry(cam_coord_header)

         as_cam_pitch.Description = "Analog stick camera pitch"
         as_cam_pitch.setAddress(analog_stick_camera_movement_pitch)
         as_cam_pitch.Type = vtSingle
         as_cam_pitch.appendToEntry(cam_coord_header)

         as_cam_yaw.Description = "Analog stick camera yaw"
         as_cam_yaw.setAddress(analog_stick_camera_movement_yaw)
         as_cam_yaw.Type = vtSingle
         as_cam_yaw.appendToEntry(cam_coord_header)

         as_cam_roll.Description = "Analog stick camera roll"
         as_cam_roll.setAddress(analog_stick_camera_movement_roll)
         as_cam_roll.Type = vtSingle
         as_cam_roll.appendToEntry(cam_coord_header)


         cam_coord_misc = al.createMemoryRecord()
         cam_coord_misc.Description = "Camera coordinates misc"
         cam_coord_misc.appendToEntry(header3)
         cam_coord_misc.isGroupHeader = true


         p_state.Description = "Pause state"
         p_state.setAddress(pause_state)
         p_state.Type = vtByte
         p_state.appendToEntry(cam_coord_misc)

         h_state.Description = "HUD state"
         h_state.setAddress(hud_state)
         h_state.Type = vtByte
         h_state.appendToEntry(cam_coord_misc)
         
         

         --[[Set hotkeys]]

         mrhk_tps_cam_xpos1 = al.getMemoryRecordByDescription("tpscam_player_axis_x")
         mrhk_tps_cam_ypos1 = al.getMemoryRecordByDescription("tpscam_player_axis_y")
         mrhk_tps_cam_zpos1 = al.getMemoryRecordByDescription("tpscam_player_axis_zoom")

         mrhk_tps_cam_xpos2 = al.getMemoryRecordByDescription("tpscam_camera_axis_x")
         mrhk_tps_cam_ypos2 = al.getMemoryRecordByDescription("tpscam_camera_axis_y")
         mrhk_tps_cam_zpos2 = al.getMemoryRecordByDescription("tpscam_camera_axis_zoom")

         mrhk_as_cam_pitch = al.getMemoryRecordByDescription("Analog stick camera pitch")
         mrhk_as_cam_yaw = al.getMemoryRecordByDescription("Analog stick camera yaw")
         mrhk_as_cam_roll = al.getMemoryRecordByDescription("Analog stick camera roll")

         key1 = mrhk_tps_cam_xpos1.createHotkey({VK_A},mrhIncreaseValue,move_cam_rate,"tpscam_player_axis_x")
         key2 = mrhk_tps_cam_xpos1.createHotkey({VK_D},mrhDecreaseValue,move_cam_rate,"tpscam_player_axis_x")
         key1 = mrhk_tps_cam_ypos1.createHotkey({VK_S},mrhIncreaseValue,move_cam_rate,"tpscam_player_axis_y")
         key2 = mrhk_tps_cam_ypos1.createHotkey({VK_W},mrhDecreaseValue,move_cam_rate,"tpscam_player_axis_y")
         key1 = mrhk_tps_cam_zpos1.createHotkey({VK_E},mrhIncreaseValue,move_cam_rate,"tpscam_player_axis_zoom")
         key2 = mrhk_tps_cam_zpos1.createHotkey({VK_Q},mrhDecreaseValue,move_cam_rate,"tpscam_player_axis_zoom")

         key1 = mrhk_tps_cam_xpos2.createHotkey({VK_F},mrhIncreaseValue,move_cam_rate,"tpscam_camera_axis_x")
         key2 = mrhk_tps_cam_xpos2.createHotkey({VK_H},mrhDecreaseValue,move_cam_rate,"tpscam_camera_axis_x")
         key1 = mrhk_tps_cam_ypos2.createHotkey({VK_G},mrhIncreaseValue,move_cam_rate,"tpscam_camera_axis_y")
         key2 = mrhk_tps_cam_ypos2.createHotkey({VK_T},mrhDecreaseValue,move_cam_rate,"tpscam_camera_axis_y")
         key1 = mrhk_tps_cam_zpos2.createHotkey({VK_Y},mrhIncreaseValue,move_cam_rate,"tpscam_camera_axis_zoom")
         key2 = mrhk_tps_cam_zpos2.createHotkey({VK_R},mrhDecreaseValue,move_cam_rate,"tpscam_camera_axis_zoom")

         key1 = mrhk_as_cam_pitch.createHotkey({VK_K},mrhIncreaseValue,move_analog_cam_rate,"Analog stick camera pitch")
         key2 = mrhk_as_cam_pitch.createHotkey({VK_I},mrhDecreaseValue,move_analog_cam_rate,"Analog stick camera pitch")
         key1 = mrhk_as_cam_yaw.createHotkey({VK_L},mrhIncreaseValue,move_analog_cam_rate,"Analog stick camera yaw")
         key2 = mrhk_as_cam_yaw.createHotkey({VK_J},mrhDecreaseValue,move_analog_cam_rate,"Analog stick camera yaw")
         key1 = mrhk_as_cam_roll.createHotkey({VK_O},mrhIncreaseValue,move_analog_cam_rate,"Analog stick camera roll")
         key2 = mrhk_as_cam_roll.createHotkey({VK_U},mrhDecreaseValue,move_analog_cam_rate,"Analog stick camera roll")
         
         
         

         --[[Reset key]]

         key3 = mrhk_tps_cam_xpos1.createHotkey({VK_SPACE},mrhSetValue,third_person_view_camera_xpos1_old,"tpscam_player_axis_x")
         key3 = mrhk_tps_cam_ypos1.createHotkey({VK_SPACE},mrhSetValue,third_person_view_camera_ypos1_old,"tpscam_player_axis_y")
         key3 = mrhk_tps_cam_zpos1.createHotkey({VK_SPACE},mrhSetValue,third_person_view_camera_zpos1_old,"tpscam_player_axis_zoom")
         key3 = mrhk_tps_cam_xpos2.createHotkey({VK_SPACE},mrhSetValue,third_person_view_camera_xpos2_old,"tpscam_camera_axis_x")
         key3 = mrhk_tps_cam_ypos2.createHotkey({VK_SPACE},mrhSetValue,third_person_view_camera_ypos2_old,"tpscam_camera_axis_y")
         key3 = mrhk_tps_cam_zpos2.createHotkey({VK_SPACE},mrhSetValue,third_person_view_camera_zpos2_old,"tpscam_camera_axis_zoom")

         key3 = mrhk_as_cam_pitch.createHotkey({VK_SPACE},mrhSetValue,0,"Analog stick camera pitch")
         key3 = mrhk_as_cam_yaw.createHotkey({VK_SPACE},mrhSetValue,0,"Analog stick camera yaw")
         key3 = mrhk_as_cam_roll.createHotkey({VK_SPACE},mrhSetValue,0,"Analog stick camera roll")
         
      end
      fl.destroy()
      fl=nil
   else
      ms.destroy()
   end   
   ms.destroy()



   --[[Disable menu and HUD graphics]]
   
   --//Start search for the Pause menu transparency value

   ms = createMemScan()
   ms.firstScan(soExactValue, vtByteArray, nil, "B0 C5 3C 00 01 01 00 ??", nil, 0x20900000,0x21f00000,"",1,"4",true,nil,nil,nil)
   ms.waitTillDone()
   fl = createFoundList(ms)
   fl.initialize()

   --Process found results and create cheat table
   
   if (fl~=nil) then
      al = getAddressList()

      for i = 1, 1 do
         
         zaddress = getAddress(fl[0])

         mntrsnprncy = al.createMemoryRecord()

         menutransparency = zaddress + 0x4

         writeBytes(menutransparency, 00)

         mntrsnprncy.Description = "Pause menu transparency"
         mntrsnprncy.setAddress(menutransparency)
         mntrsnprncy.Type = vtByte
         mntrsnprncy.appendToEntry(cam_coord_misc)
      end
      fl.destroy()
      fl=nil
   else
      ms.destroy()
   end
   ms.destroy()



   --[[Right-stick analog fix]]
   
   --//This fixes an issue with the right-analog stick (the stick that controls the camera in-game)
   --//becoming unresponsive when disabling the free cam script

   ms = createMemScan()
   ms.firstScan(soExactValue, vtByteArray, nil, "3C 00 0? 0? ?? ?? FF FF 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ??" , nil, 0x20800000,0x21f00000,"",1,"4",true,nil,nil,nil)
   ms.waitTillDone()
   fl = createFoundList(ms)
   fl.initialize()
   
   if (fl~=nil) then
      
      al = getAddressList()
      
      for i = 1, 1 do
         
         xaddress = getAddress(fl[0])
         
         anlg_fix = al.createMemoryRecord()

         analogfix = xaddress + 0x3

         anlg_fix.Description = "Right-stick analog fix"
         anlg_fix.setAddress(analogfix)
         anlg_fix.Type = vtByte
         anlg_fix.appendToEntry(cam_coord_misc)

      end
      
      fl.destroy()
      fl=nil
      
   else
      
      ms.destroy()
      
   end
   ms.destroy()

   --//Unpause the emulator once the search is done, the values are set and the code was successfully injected
   
   unpause(pcsx2_emu_id)

else
   
   --//If search was a failure then print a error message and unpause the emulator
   
   print("Unable to run the script.")
   
   unpause(pcsx2_emu_id)
end

{$asm}

[DISABLE]

{$lua}

--//Restore pre-activation values

--[[Restore controller input]]
writeBytes(0x203F70BC, 192, 125, 105 ,0)

--[[Restore pause menu visibility]]
writeBytes(menutransparency, 01)

--[[Restore non-pause HUD visibility]]
writeBytes(0x203FFBCF, 01)

--[[Restore default camera position values]]
writeFloat(third_person_view_camera_xpos1, third_person_view_camera_xpos1_old)
writeFloat(third_person_view_camera_ypos1, third_person_view_camera_ypos1_old)
writeFloat(third_person_view_camera_zpos1, third_person_view_camera_zpos1_old)
writeFloat(third_person_view_camera_xpos2, third_person_view_camera_xpos2_old)
writeFloat(third_person_view_camera_ypos2, third_person_view_camera_ypos2_old)
writeFloat(third_person_view_camera_zpos2, third_person_view_camera_zpos2_old)

--[[Right-analog stick fix]]
writeBytes(analogfix, 04)

--[[Unpause game]]
writeBytes(0x207651E8, 04)

--Destroy entries
header3.destroy()

--restored previously NOP'd code
gameplayCamControl(false)

{$asm}



By the way, it is there an AA equivalent of running the Find what accesses this address option on an address then NOP'ing any opcode it might contain, then later restore it? but the address was returned by an AoBscan instead?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Fri Aug 05, 2022 11:31 am    Post subject: Reply with quote

  • Again, syntaxcheck
  • Again, I wouldn't use autoAssemble like that
  • pause / unpause don't take parameters
  • What is setGlobalKeyPollInterval doing there?
  • You sometimes use literal addresses. This is bad. If it's in the main exe, use game.exe+offset. e.g. `writeBytes('game.exe+1234', 5)`
  • Use local variables
  • Doing an aobscan for writable data is bad
  • I've had problems passing nil for certain parameters in memscan.firstScan sometimes
  • For simple cases like this you should probably be using AOBScan instead of memscans
  • Checking if the foundlist is nil does nothing. (you call initialize before that, so clearly it isn't nil)
  • If the foundlist ever was nil, you'd double free the memscan (memscan.destroy called twice). This would be very bad if CE wasn't smart enough to catch this
  • You access the first result of the foundlist without checking if it found anything first (fl.Count > 0). Also, it's not a bad idea to check if it found more than one and abort if so.
  • `for i = 1, 1 do...` is a weird way of setting i to 1- especially since you don't even use i
  • You're creating a bunch of memory records every time you enable the script. Create them once and access them.
  • memoryrecord.setAddress takes a string. You're lucky CE has a special case that converts numbers to hexadecimal strings in this function
  • Do you really have to pause / unpause the process?

CE logs some information using OutputDebugString. Maybe use DebugView (windows sysinternals) to get some idea of where CE freezes up
holaboludo wrote:
By the way, it is there an AA equivalent of running the Find what accesses this address option on an address then NOP'ing any opcode it might contain, then later restore it? but the address was returned by an AoBscan instead?
Yes, but that's incredibly unsafe and you should absolutely not do that. If you want to shoot yourself in the foot, look into debug_setBreakpoint, getPreviousOpcode, and getInstructionSize.
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Fri Aug 05, 2022 12:54 pm    Post subject: Reply with quote

Is the memoryrecord set to run asynchronous? If so, AddressList access is not thread safe
_________________
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
holaboludo
How do I cheat?
Reputation: 0

Joined: 22 Oct 2018
Posts: 5

PostPosted: Sat Aug 06, 2022 6:52 am    Post subject: Reply with quote

ParkourPenguin wrote:
  • Again, syntaxcheck
  • Again, I wouldn't use autoAssemble like that
  • pause / unpause don't take parameters
  • Use local variables
  • Doing an aobscan for writable data is bad
  • For simple cases like this you should probably be using AOBScan instead of memscans
  • Checking if the foundlist is nil does nothing. (you call initialize before that, so clearly it isn't nil)
  • If the foundlist ever was nil, you'd double free the memscan (memscan.destroy called twice). This would be very bad if CE wasn't smart enough to catch this
  • You access the first result of the foundlist without checking if it found anything first (fl.Count > 0). Also, it's not a bad idea to check if it found more than one and abort if so.
  • memoryrecord.setAddress takes a string. You're lucky CE has a special case that converts numbers to hexadecimal strings in this function


Noted.

ParkourPenguin wrote:
What is setGlobalKeyPollInterval doing there?


I used this because to "smooth" the camera movement because the original movement set for the hotkeys is a bit "choppy".

ParkourPenguin wrote:
You sometimes use literal addresses. This is bad. If it's in the main exe, use game.exe+offset. e.g. `writeBytes('game.exe+1234', 5)`


I'm using an emulator and PCSX2 always load the game's ELF file (or parts of it) and assets in the same memory region and remains there every time the game is run (which starts at offset (pcsx2.exe + 0x20000000, which is PCSX2's designed region for emulating the PS2 RAM, IIRC). AFAIK PCSX2's own executable remains untouched.

ParkourPenguin wrote:
You're creating a bunch of memory records every time you enable the script. Create them once and access them.


The reason for this is that I want to free up space on CE's GUI every time the user disables the script since there also other scripts running and create entries. I have no plans of creating a trainer at the moment.

ParkourPenguin wrote:
Do you really have to pause / unpause the process?


I thought this would speed up the AoB scan and the memoryrecord creation process a bit.

Dark Byte wrote:
Is the memoryrecord set to run asynchronous? If so, AddressList access is not thread safe


No idea of how to check this, but I did run the script with the "Execute asynchronous" option ticked and still had the same issue, not sure if that counts.




Most of the script code was adapted from other solutions posted on the forums and because I never had a problem with it until now never figured it'd be that bad. Also because I use CE as data/file research tool (since I'm a modder myself) than a cheating one most of these issues went over my head.

Thanks for the replies though, sadly this is way far more complex than I thought and my current knowledge of LUA and CE allows me to understand so I think I'll go back to square one. If anyone is willing to rewrite my code in a more "proper" way I'd really appreciate it. Not asking for a full rewrite but more in a pseudocode-esque way and how it'd look if it was written by a experienced user, so I can learn from it then take it from there.
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