IMG

 
IMG
IMG   IMG
  Welcome to GTAForums! Be sure to check out the Grand Theft Auto V Forum.

You are not registered! (If you are, click here to login) Registering is fast, free and easy and allows you to instantly reply to any topic on GTAForums.
Why wait? Click here to register your own unique username and become part of the ever-growing community!


( Log In | Register | Revalidate Validation E-mail )
Quick Log-In:
  IMG
       
>
  Reply to this topicStart new topicStart Poll

 GTA IV Controls override

 
nightwalker83  
Posted: Wednesday, May 4 2011, 12:20
Quote Post


Don't mind me
Group Icon
Group: Members
Joined: Oct 10, 2004

au.gif

XXXXX



Hi,

I made this small application in Visual Basic 6.0 to automatically delete the stupid default settings that keep overriding and resetting the default controls in GTA IV. All you need to do is ad the code to a form and compile the project. After that place the execute file that is created in the GTA IV directory and run it.

CODE

'Description: checks the system for the default GTA IV settings files
'and deletes them so you can play the game using the controls you define.
'Date: 04/05/2011
'Author: Aaron Spehr
'Alias: Nightwalker83
'Website: http://aaronspehr.net/

Option Explicit
Private sUserName As String
     Private path As String
'Used to get the username of the currently logged in account
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'Used to get the operating system version
Private Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
   Private Type STARTUPINFO
     cb As Long
     lpReserved As String
     lpDesktop As String
     lpTitle As String
     dwX As Long
     dwY As Long
     dwXSize As Long
     dwYSize As Long
     dwXCountChars As Long
     dwYCountChars As Long
     dwFillAttribute As Long
     dwFlags As Long
     wShowWindow As Integer
     cbReserved2 As Integer
     lpReserved2 As Long
     hStdInput As Long
     hStdOutput As Long
     hStdError As Long
  End Type

  Private Type PROCESS_INFORMATION
     hProcess As Long
     hThread As Long
     dwProcessId As Long
     dwThreadID As Long
  End Type
 
  Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
     hHandle As Long, ByVal dwMilliseconds As Long) As Long
'API Constants
Const SMTO_BLOCK = &H1
Const SMTO_ABORTIFHUNG = &H2
Const WM_NULL = &H0
Const WM_CLOSE = &H10
Const PROCESS_ALL_ACCESS = &H1F0FFF
'API functions
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, _
lpdwProcessId As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" _
(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As _
Long, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long

Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long

  Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
     lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
     lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
     ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
     ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
     lpStartupInfo As STARTUPINFO, lpProcessInformation As _
     PROCESS_INFORMATION) As Long

  Private Declare Function CloseHandle Lib "kernel32" _
     (ByVal hObject As Long) As Long

  Private Declare Function GetExitCodeProcess Lib "kernel32" _
     (ByVal hProcess As Long, lpExitCode As Long) As Long

  Private Const NORMAL_PRIORITY_CLASS = &H20&
  Private Const INFINITE = -1&
     Dim proc As PROCESS_INFORMATION
     Dim start As STARTUPINFO
     Dim ret&
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

  Public Function ExecCmd(cmdline$)
 
     ' Initialize the STARTUPINFO structure:
     start.cb = Len(start)

     ' Start the shelled application:
     ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
        NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

     ' Wait for the shelled application to finish:
        ret& = WaitForSingleObject(proc.hProcess, INFINITE)
        Call GetExitCodeProcess(proc.hProcess, ret&)
        Call CloseHandle(proc.hThread)
        Call CloseHandle(proc.hProcess)
        ExecCmd = ret&
  End Function
 
Private Sub Form_Activate()
   Dim retval As Long
   Dim lngResult As Long
   Dim lngReturnValue As Long
      CurrentUser
      WinVersion
     Me.Visible = False
   'Replace the path and app.name.type with that of the application you want to use
     retval = ExecCmd("GTAIV.exe")
   'Hide  the form from the user
     
       lngReturnValue = SendMessageTimeout(0, WM_NULL, 0&, 0&, SMTO_ABORTIFHUNG And SMTO_BLOCK, 1000, lngResult)
   DoEvents
   If Not lngReturnValue Then
   'Close the host and the client if the client does not respond
       Call GetExitCodeProcess(proc.hProcess, ret&)
       Call CloseHandle(proc.hThread)
       Call CloseHandle(proc.hProcess)
      Unload Me
   End If
End Sub


Private Sub WinVersion()
'Retrive the current operating system and set the settings path accordingly
'http://social.msdn.microsoft.com/Forums/en/vbide/thread/395b12fd-ccfc-4281-b1b3-4c69b56f8b85
   Dim osinfo As OSVERSIONINFO
   Dim retvalue As Integer
 
   osinfo.dwOSVersionInfoSize = 148
   osinfo.szCSDVersion = Space$(128)
   retvalue = GetVersionExA(osinfo)
   If osinfo.dwMajorVersion = 7 Then 'Windows 7
   path = "C:\Users\" + sUserName + "\AppData\Local\Rockstar Games\GTA IV\Settings\"
   ElseIf osinfo.dwMajorVersion = 6 Then 'Vista
   path = "C:\Users\" + sUserName + "\AppData\Local\Rockstar Games\GTA IV\Settings\"
   'MsgBox (path)
   ElseIf osinfo.dwMajorVersion = 5 Then 'XP
   path = "C:\Documents and Settings\" + sUserName + "\Local Settings\Application Data\Rockstar Games\GTA IV\Settings\"
   'ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc.
   Else
   End If
   Call Delete(path)
End Sub

Public Function CurrentUser() As String
'*********************************************************
'* Function to get the current logged on user in windows *
'*********************************************************
'http://www.vbforums.com/showthread.php?t=357723
Dim strBuff As String * 255
Dim X As Long

CurrentUser = ""
X = GetUserName(strBuff, Len(strBuff) - 1)
If X > 0 Then
'Look for Null Character, usually included
X = InStr(strBuff, vbNullChar)
'Trim off buffered spaces too
If X > 0 Then
CurrentUser = UCase(Left$(strBuff, X - 1)) 'UCase is optional;)
Else
CurrentUser = UCase(Left$(strBuff, X))
End If
End If
sUserName = CurrentUser
End Function

Private Function Delete(path As String)
Dim sNextFile As String
sNextFile = Dir$(path + "*.*", vbNormal + vbHidden + vbReadOnly)
'MsgBox (sNextFile)
Do While sNextFile <> ""
    SetAttr path & sNextFile, vbNormal
    Kill (path & sNextFile)
    sNextFile = Dir$
Loop
End Function


Any questions and comments are welcome,



Nightwalker

This post has been edited by nightwalker83 on Wednesday, May 4 2011, 16:28
Users WebsitePMMSN
  Top
 

 
LulzAllDay  
Posted: Thursday, May 5 2011, 16:45
Quote Post


Dead and gone.
Group Icon
Group: Members
Joined: Feb 12, 2011

cd.gif

XXXXX



If this is truly your code, you deserve an award. Props.


There's no need to quote the entire post. - Girish
Users WebsitePMMSNXbox LivePlayStation Network
  Top
 

 
nightwalker83  
Posted: Thursday, May 5 2011, 22:42
Quote Post


Don't mind me
Group Icon
Group: Members
Joined: Oct 10, 2004

au.gif

XXXXX



Well, I did do some research! I included the links back to the the original posts where I borrowed parts of the code from.
Users WebsitePMMSN
  Top
 

 
nightwalker83  
Posted: Saturday, May 7 2011, 01:18
Quote Post


Don't mind me
Group Icon
Group: Members
Joined: Oct 10, 2004

au.gif

XXXXX



I refined the above code so it doesn't need a form just a module.

CODE

'Description: checks the system for the default GTA IV settings files
'and deletes them so you can play the game using the controls you define.
'Date: 04/05/2011
'Update 07/04/2011 Refine the code to remove unnecessary code.
'                  Also, remove the need for a form the code only requires a module to run.
'Author: Aaron Spehr
'Alias: Nightwalker83
'Website: http://aaronspehr.net/

Option Explicit
Private sUserName As String
     Private path As String
'Used to get the username of the currently logged in account
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
'Used to get the operating system version
Private Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
   Private Type STARTUPINFO
     cb As Long
     lpReserved As String
     lpDesktop As String
     lpTitle As String
     dwX As Long
     dwY As Long
     dwXSize As Long
     dwYSize As Long
     dwXCountChars As Long
     dwYCountChars As Long
     dwFillAttribute As Long
     dwFlags As Long
     wShowWindow As Integer
     cbReserved2 As Integer
     lpReserved2 As Long
     hStdInput As Long
     hStdOutput As Long
     hStdError As Long
  End Type

  Private Type PROCESS_INFORMATION
     hProcess As Long
     hThread As Long
     dwProcessId As Long
     dwThreadID As Long
  End Type
 
  Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
     hHandle As Long, ByVal dwMilliseconds As Long) As Long
'API Constants
 Const SMTO_BLOCK = &H1
 Const SMTO_ABORTIFHUNG = &H2
 Const WM_NULL = &H0
 Const WM_CLOSE = &H10
 Const PROCESS_ALL_ACCESS = &H1F0FFF
'API functions

Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" _
(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As _
Long, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long

  Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
     lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
     lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
     ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
     ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
     lpStartupInfo As STARTUPINFO, lpProcessInformation As _
     PROCESS_INFORMATION) As Long

  Private Declare Function CloseHandle Lib "kernel32" _
     (ByVal hObject As Long) As Long

  Private Declare Function GetExitCodeProcess Lib "kernel32" _
     (ByVal hProcess As Long, lpExitCode As Long) As Long

  Private Const NORMAL_PRIORITY_CLASS = &H20&
     Private Const INFINITE = -1&
     Dim proc As PROCESS_INFORMATION
     Dim start As STARTUPINFO
     Dim ret&
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

  Public Function ExecCmd(cmdline$)
 
     ' Initialize the STARTUPINFO structure:
     start.cb = Len(start)

     ' Start the shelled application:
     ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
        NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)

     ' Wait for the shelled application to finish:
        ret& = WaitForSingleObject(proc.hProcess, INFINITE)
        Call GetExitCodeProcess(proc.hProcess, ret&)
        Call CloseHandle(proc.hThread)
        Call CloseHandle(proc.hProcess)
        ExecCmd = ret&
  End Function
 
Private Sub Main()
   Dim retval As Long
   Dim lngResult As Long
   Dim lngReturnValue As Long
      CurrentUser
      WinVersion
   'Replace the path and app.name.type with that of the application you want to use
     retval = ExecCmd("GTAIV.exe")
     
       lngReturnValue = SendMessageTimeout(0, WM_NULL, 0&, 0&, SMTO_ABORTIFHUNG And SMTO_BLOCK, 1000, lngResult)
   DoEvents
   If Not lngReturnValue Then
   'Close the host and the client if the client does not respond
       Call GetExitCodeProcess(proc.hProcess, ret&)
       Call CloseHandle(proc.hThread)
       Call CloseHandle(proc.hProcess)
      'Unload Me
   End If
End Sub


Private Sub WinVersion()
'Retrive the current operating system and set the settings path accordingly
'http://social.msdn.microsoft.com/Forums/en/vbide/thread/395b12fd-ccfc-4281-b1b3-4c69b56f8b85
   Dim osinfo As OSVERSIONINFO
   Dim retvalue As Integer
 
   osinfo.dwOSVersionInfoSize = 148
   osinfo.szCSDVersion = Space$(128)
   retvalue = GetVersionExA(osinfo)
   If osinfo.dwMajorVersion = 7 Then 'Windows 7
   path = "C:\Users\" + sUserName + "\AppData\Local\Rockstar Games\GTA IV\Settings\"
   ElseIf osinfo.dwMajorVersion = 6 Then 'Vista
   path = "C:\Users\" + sUserName + "\AppData\Local\Rockstar Games\GTA IV\Settings\"
   'MsgBox (path)
   ElseIf osinfo.dwMajorVersion = 5 Then 'XP
   path = "C:\Documents and Settings\" + sUserName + "\Local Settings\Application Data\Rockstar Games\GTA IV\Settings\"
   'ElseIf osinfo.dwMajorVersion = 4 Then 'Win2k etc.
   Else
   End If
   Call Delete(path)
End Sub

Public Function CurrentUser() As String
'*********************************************************
'* Function to get the current logged on user in windows *
'*********************************************************
'http://www.vbforums.com/showthread.php?t=357723
Dim strBuff As String * 255
Dim X As Long

CurrentUser = ""
X = GetUserName(strBuff, Len(strBuff) - 1)
If X > 0 Then
'Look for Null Character, usually included
X = InStr(strBuff, vbNullChar)
'Trim off buffered spaces too
If X > 0 Then
CurrentUser = UCase(Left$(strBuff, X - 1)) 'UCase is optional;)
Else
CurrentUser = UCase(Left$(strBuff, X))
End If
End If
sUserName = CurrentUser
End Function

Private Function Delete(path As String)
Dim sNextFile As String
sNextFile = Dir$(path + "*.*", vbNormal + vbHidden + vbReadOnly)
Do While sNextFile <> ""
    SetAttr path & sNextFile, vbNormal
    Kill (path & sNextFile)
    sNextFile = Dir$
Loop
End Function
Users WebsitePMMSN
  Top
 

 
goin-god  
Posted: Friday, Jul 22 2011, 03:26
Quote Post


High Roller
Group Icon
Group: $outh $ide Hoodz
Joined: Mar 18, 2007

ar.gif

Member Award




Why can't you give us the compiled version? Not everyone has VB.
Users WebsitePMMSNPlayStation Network
  Top
 

 
nightwalker83  
Posted: Friday, Jul 22 2011, 03:31
Quote Post


Don't mind me
Group Icon
Group: Members
Joined: Oct 10, 2004

au.gif

XXXXX



I didn't think of that when I posted originally but since you replied to the thread I just uploaded the new version you can download the new version in this thread.

Edit:

I have compiled the above code and submitted the file to gta garage the file will appear here when approved.

This post has been edited by nightwalker83 on Saturday, Jul 23 2011, 03:33
Users WebsitePMMSN
  Top
 

 
Girish  
Posted: Saturday, Jul 23 2011, 16:22
Quote Post



Group Icon
Group: Moderators
Joined: Apr 20, 2006

ia.gif

Member Award




Since this is GTA related and you've uploaded it on GTAG too, I'd recommend making a topic in the Mod Showroom. That way, you'll also be able to link the GTAG download with your topic here. smile.gif
Users WebsitePMMSN
  Top
 

 
nightwalker83  
Posted: Sunday, Jul 24 2011, 04:09
Quote Post


Don't mind me
Group Icon
Group: Members
Joined: Oct 10, 2004

au.gif

XXXXX



Yeah, I have now included a link back to the showroom topic back to this thread. I have also included links to both threads in my sig.
Users WebsitePMMSN
  Top
 

 

0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)

0 Members:

Topic Options Reply to this topicStart new topicStart Poll
Search topic for posted by (exact match)



 
IMG IMG