Advertisement
Mhmd_FVC

Lighnat0r's no mouse sens reset fix code (edited/commented by me)

Apr 20th, 2023 (edited)
2,256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance force
  2. OnExit, ExitSequence
  3. SplitPath, A_ScriptName,,,,ProgramNameNoExt
  4. menu, tray, tip, %ProgramNameNoExt%
  5. menu, tray, NoStandard
  6. menu, tray, Add, Restart Program, RestartSequence
  7. menu, tray, Add, Exit, ExitSequence
  8. RefreshRate = 20
  9. TrayTip, GTA VC No Mouse Sensitivity Reset, The script will prevent the game from resetting the mouse sensitivity on reset. To close the script right click on the tray icon here and select exit. The effect will last until the game is closed. `n`nMade by Lighnat0r,20,
  10.  
  11. If (IsLabel("DebugFunctions") AND A_IsCompiled != 1)
  12.   gosub DebugFunctions
  13. goto MainScript
  14.  
  15. MainScript:
  16.  WindowClass := "Grand theft auto 3"
  17.   WindowName := "GTA: Vice City"
  18.   WinWait ahk_class %WindowClass%
  19.   WinGetTitle, CurrentWindowName
  20.   If (CurrentWindowName != WindowName)
  21.     goto MainScript
  22.   WinGet, PID, PID
  23.   Memory(1, PID)
  24.   Process, Exist, %PID%
  25.   if ErrorLevel != 0
  26.     VersionOffset := GameVersionCheck()
  27.   else
  28.     goto MainScript
  29.  
  30.   GameRunningAddress := 0x00400000
  31.  
  32.   if VersionOffset = -4088
  33.     MouseSensitivity := 0x0046F5D1  ; Steam
  34.   Else if VersionOffset = -12280
  35.     MouseSensitivity := 0x0046F823  ; JP
  36.   Else
  37.     MouseSensitivity := 0x0046F4B1  ; Retail
  38.  
  39.   Target := 0x90 ; 144. This magic number seems to fix the mouse sens being reset on new games for some reason.
  40.   While Memory(3, GameRunningAddress, 1) != "Fail"
  41.   {
  42.     sleep %RefreshRate%
  43.     ;  If memory read from mouse sens address is not equal to the Target,
  44.     ;  write 144 to the mouse sens address and two addresses past it.
  45.     if Memory(3, MouseSensitivity, 1) != Target
  46.     {                                          
  47.       loop 3 ; For VC JP, default values of the address range are 1) 216, 2) 171, 3) 148
  48.       {
  49.         Address := MouseSensitivity + A_Index - 1
  50.         Memory(4, Address, Target, 1)
  51.       }
  52.     }
  53.   }
  54.   sleep 5000
  55.   goto MainScript
  56.  
  57. ExitSequence:
  58.  exitapp
  59.  
  60. RestartSequence:
  61.  reload
  62.   sleep 1000
  63.   return
  64.  
  65. DebugFunctions:
  66.  Hotkey, F7, DebugListvars, On
  67.   return
  68.  
  69. DebugListvars:
  70.  Listvars
  71.   return
  72.  
  73. Memory(Type=3,Param1=0,Param2=0,Param3=0,Param4=0)
  74. {
  75.   Static ProcessHandle
  76.   If Type = 1
  77.   {
  78.     ProcessHandle := DllCall("OpenProcess","Int",2035711,"Int", 0,"UInt",Param1)
  79.     If ProcessHandle = 0
  80.     {
  81.       Error := GetLastErrorMessage()
  82.       outputdebug Open process error`: %Error%
  83.       Return % DllCall("GetLastError")
  84.     }
  85.     Else
  86.       Return 0
  87.   }
  88.   Else If Type = 2
  89.     DllCall("CloseHandle","UInt",ProcessHandle)
  90.   Else If Type = 3 ; Read memory value
  91.   {
  92.     Param2 := ((!Param2) ? 4 : Param2)
  93.     VarSetCapacity(MVALUE,Param2,0)
  94.     If (Param3 = "Unicode" OR Param3 = "Ascii")
  95.     {
  96.       CharLength := ((Param3 = "Unicode") ? 2 : 1)
  97.       LoopAmount := Param2/CharLength
  98.       Loop %LoopAmount%
  99.       {
  100.         ReadAddress := Param1+((A_Index-1)*CharLength)
  101.         OutputChar%A_Index% := Memory(3, ReadAddress, CharLength)
  102.         OutputChar%A_Index% := Chr(OutputChar%A_Index%)
  103.         OutputString := OutputString . OutputChar%A_Index%
  104.       }
  105.       Return OutputString
  106.     }
  107.     If (ProcessHandle) && DllCall("ReadProcessMemory","UInt",ProcessHandle,"UInt",Param1,"Str",MVALUE,"UInt",Param2,"UInt",0)
  108.     {
  109.       Result = 0
  110.       Loop %Param2%
  111.       Result += *(&MVALUE + A_Index-1) << 8*(A_Index-1)
  112.       If (Param3 = "Float")
  113.         Result := HexToFloat(Result)
  114.       Return Result
  115.     }
  116.     Return !ProcessHandle ? "Handle Closed: " Closed : "Fail"
  117.   }
  118.   Else If Type = 4  ; Write memory value
  119.   {
  120.     If (Param4 = "Unicode" OR Param4 = "Ascii")
  121.     {
  122.       CharLength := ((Param4 = "Unicode") ? 2 : 1)
  123.       StringSplit, InputStringArray, Param2
  124.       Param3 := ((!Param3) ? InputStringArray0 : Param3)
  125.       Loop %Param3%
  126.       {
  127.         TextCharacter%A_Index%Address := Param1  + (A_Index-1) * CharLength
  128.         Memory(4, TextCharacter%A_Index%Address, 0, 1)
  129.       }
  130.       If (InputStringArray0 > Param3)
  131.         InputStringArray0 := Param3
  132.       Loop %InputStringArray0%
  133.       {
  134.         CurrentLetter := InputStringArray%A_Index%
  135.         If CurrentLetter = `%
  136.           CurrentLetter = 37
  137.         Else
  138.           CurrentLetter := Asc(CurrentLetter)
  139.         TextCharacter%A_Index%Address := Param1 + (A_Index-1) * CharLength
  140.         Memory(4, TextCharacter%A_Index%Address, CurrentLetter, 1)
  141.       }
  142.     }
  143.     Else
  144.     {
  145.       If (Param4 = "Float")
  146.         Param2 := FloatToHex(Param2)
  147.       Param3 := ((!Param3) ? 4 : Param3)
  148.       ;  WriteProcessMemory DLL call accepts 5 parameters (in order):
  149.       ;  Process handle, base address (Param1), buffer of data to be written (Param2), # of bytes to be written (always 1 in this program), and 0 (unused in this program).
  150.       If (ProcessHandle) && DllCall("WriteProcessMemory","UInt",ProcessHandle,"UInt",Param1,"Uint*",Param2,"Uint",Param3,"Uint",0)
  151.         Return "Success"
  152.       Return !ProcessHandle ? "Handle Closed: " closed : "Fail"
  153.     }
  154.   }
  155.   Else If Type = 5
  156.   {
  157.     Param1 := Memory(3, Param1)
  158.     If Param1 is not xdigit
  159.       Return Param1
  160.     Return Param1 + Param2
  161.   }
  162. }
  163.  
  164. GameVersionCheck()
  165. {
  166.   Value := Memory(3, 0x00608578, 1)
  167.   if Value = 0x5D
  168.     Return 0
  169.   if Value = 0x81
  170.     Return 8
  171.   if Value = 0x5B
  172.     Return -0xFF8
  173.   if Value = 0x44
  174.     Return -0x2FF8
  175.   Msgbox Error`: The script could not determine the version of GTA Vice City %Value%
  176. }
  177.  
  178. GetLastErrorMessage()
  179. {
  180.   ErrorCode := DllCall("GetLastError")
  181.   VarSetCapacity(ReturnedMessage, 2000)
  182.   ReturnValue := DllCall("FormatMessage", "UInt", 0x1000, "UInt", 0, "UInt", ErrorCode, "UInt", 0x800, "Str", ReturnedMessage, "UInt", 2000, "UInt", 0)
  183.   If ReturnValue = 0
  184.   {
  185.     ErrorCode := DllCall("GetLastError")
  186.     outputdebug Error getting error message`: %ErrorCode%
  187.   }
  188.   Else
  189.   {
  190.     Error = %ErrorCode%`: %ReturnedMessage%
  191.     return Error
  192.   }
  193. }
  194.  
  195. HexToFloat(x)
  196. {
  197.   Return (1-2*(x>>31)) * (2**((x>>23 & 255)-150)) * (0x800000 | x & 0x7FFFFF)
  198. }
  199.  
  200. FloatToHex(f)
  201. {
  202.   form := A_FormatInteger
  203.   SetFormat Integer, HEX
  204.   v := DllCall("MulDiv", Float,f, Int,1, Int,1, UInt)
  205.   SetFormat Integer, %form%
  206.   Return v
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement