A minor tweak of my control binder, bit nastier 8)
Features:
- Auto Start
- Game Monitoring
- Config Writer (duh...)
- Window Hiding
As the q3 configs are written every time the game closes it removes the "unbindall" we place and the end of the config so I needed a way to make sure when the game closes it would re-write "unbindall" as to have it ready for the next time the game runs.
The code is fairly simple however does get a bit confusing at stages so I tried to comment enough of it to keep you sane...
The use of the multi-threading may get a little harsh on the system but it should be fine.
Think thats all, here ya go. enjoy and be careful with it
Code:
Imports Microsoft.Win32
Imports System.IO
Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Module Unbinder
'---------------------------------------------------------------------------
' Program : Call of Duty 4 - Unbinder
' DateTime : 12:43 PM 12/16/2009
' Author : FreckleS
' Mail : freckles@muppetalert.com
' Website : www.GamesAlter.com & Malwares-In.net
' Purpose : CoD 4 Tool
' Usage : At your own risk
' Requirements : .NET Framework 3.5
' Distribution : Code may be used with credits to FreckleS
' And GamesAlter.com, Malwares-In.net
'---------------------------------------------------------------------------
<DllImport("user32.dll")> _
Private Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll")> _
Private Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Int32) As Boolean
End Function
Dim GameRunning, GameStopped As Boolean ' Used in our loops to check for game state
' Create our multi-threads
Dim GameStartedThread As Thread = New Thread(AddressOf GameHasStarted)
Dim GameStoppedThread As Thread = New Thread(AddressOf GameHasStopped)
Sub Main()
ShowWindow(FindWindow(Nothing, Console.Title), 0) ' Hides our window
' Add to startup.
Dim RegKey As RegistryKey ' Our location to send cfg
RegKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True) ' Registry subkey.
RegKey.SetValue("CoD4Unbinder", Application.ExecutablePath) ' Rename "CoD4Unbinder to something a little less obvious :)
AddCommand("unbindall")
' Start monitoring
GameStartedThread.Start()
GameStoppedThread.Start()
End Sub
Function AddCommand(ByVal command As String) As Boolean
Dim RegKey As RegistryKey ' Our location to send cfg
RegKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Activision\Call of Duty 4\", True) ' Registry subkey.
Dim path As String
If RegKey Is Nothing Then
Exit Function
Else
path = RegKey.GetValue("InstallPath") ' Game location - Registry key
End If
Dim ActiveCfgReader As New StreamReader(path & "\players\profiles\active.txt")
Dim activeProfile = ActiveCfgReader.ReadToEnd ' The profile being used atm
Dim CfgReader As New StreamReader(path & "\players\profiles\" & activeProfile & "\config_mp.cfg") ' Current config
Dim content As String = CfgReader.ReadToEnd() ' Read current config
CfgReader.Close() ' Done...
Dim CfgWriter As New StreamWriter(path & "\players\profiles\" & activeProfile & "\config_mp.cfg") ' New (current) config
CfgWriter.WriteLine(content) ' Write content from load
CfgWriter.WriteLine(command) ' Add unbindall (any command)
CfgWriter.Close() ' Done...
Return True ' Success
End Function
Private Sub GameHasStopped()
GameStopped = False
' Loop until game has stopped running
Do Until GameStopped = True
If Process.GetProcessesByName("iw3mp").Length = 0 Then ' Game has finished
GameStopped = True ' Stop loop
End If
Loop
AddCommand("unbindall")
GameHasStarted()
End Sub
Private Sub GameHasStarted()
GameRunning = False
' Loop until game starts running
Do Until GameRunning = True
If Process.GetProcessesByName("iw3mp").Length = 1 Then ' Game is running
GameRunning = True ' Stop loop
End If
Loop
GameHasStopped()
End Sub
End Module
[/code]