Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Join Halo CE servers conveniently.
- PS2EXE can be used to turn this script into an executabe :
- ps2exe ".\BHS.ps1" "BHS.exe" -noConsole -version "1.0.0.1" -title "BHS" -description "Join Halo CE servers conveniently" -iconFile ".\BHS.ico"
- MT can be used to enforced UAC as this tool will need to be run as Adminstrator if installed in HaloCE folder :
- mt.exe -manifest C:\Temp\MISC\BHS.manifest "-outputresource:C:\Temp\MISC\BHS.exe;#1"
- .NOTES
- This tool generates a configuration files and therefore must be installed somewhere it can write or else be run as Admnistrator.
- #>
- Add-Type -AssemblyName System.Windows.Forms
- Add-Type -AssemblyName System.Drawing
- $ScriptDirectory = If (-Not $PSScriptRoot) { Split-Path -Parent (Convert-Path ([environment]::GetCommandLineArgs()[0])) } Else { $PSScriptRoot }
- $serversListPath = "$ScriptDirectory\BHS_ServersList"
- $commandLineArgumentsPath = "$ScriptDirectory\BHS_CommandLineArguments"
- Function Help {
- $helpMessage = "`n Join Halo CE servers conveniently.`n
- This tool generates configuration files and therefore must be`n installed somewhere it can write or else be run as Admnistrator.`n`n"
- [void][System.Windows.Forms.MessageBox]::Show($helpMessage, "BHS Helper")
- }
- Function Get-CommandLineArguments {
- $commandlineArguments = ""
- If (Test-Path $commandLineArgumentsPath) {
- $commandlineArguments = Get-Content $commandLineArgumentsPath
- }
- Return $commandlineArguments
- }
- Function Start-Game {
- $joinOptions = Get-CommandLineArguments
- $IP = $serversDataGridView.CurrentRow.Cells["IP:PORT"].Value
- If (Select-String -InputObject $IP -Pattern "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{4,5}$") {
- $officialArguments = @("Nosound", "Novideo", "Nojoystick", "Nogamma", "Use20", "Use14", "Use11", "UseFF", "Safemode", "Window", "Width640", "Screenshot", "Timedemo", "Console", "Devmode")
- $BrokenGameArguments = $False
- $joinOptions.Split("-") | % {
- If (-Not [string]::IsNullOrEmpty($_)) {
- If ($officialArguments -notcontains $($_ -replace '\s','')) {
- [System.Windows.Forms.MessageBox]::Show("Command line arguments are incorrect.", "" , '0', 'Error')
- $BrokenGameArguments = $True
- }
- }
- }
- If (-Not $BrokenGameArguments) {
- $joinOptions = $joinOptions + " -Connect $IP"
- Start-Process -WorkingDirectory "C:\Program Files (x86)\Microsoft Games\Halo Custom Edition" -FilePath "C:\Program Files (x86)\Microsoft Games\Halo Custom Edition\haloce.exe" -Verb "RunAs" -ArgumentList $joinOptions
- }
- }
- Else {
- [System.Windows.Forms.MessageBox]::Show("IP:PORT format is incorrect.", "" , '0', 'Error')
- Return
- }
- }
- $BHSform = New-Object System.Windows.Forms.Form
- $BHSform.Size = New-Object System.Drawing.Size 280,289
- $BHSform.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
- $BHSform.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon("C:\Windows\System32\actioncentercpl.dll")
- $BHSform.BackColor = "DarkBlue"
- $BHSform.FormBorderStyle = "FixedDialog"
- $BHSform.MaximizeBox = $False
- $BHSform.Add_Closing({
- If ($serversDataGridView.RowCount -eq 0) { Return }
- #Test if program can write here
- $sw = New-Object System.IO.StreamWriter($serversListPath)
- $serversDataGridView.Rows | % {
- If ($_.Cells[0].Value.Length -gt 0 -And $_.Cells[1].Value.Length -gt 0) {
- $sw.WriteLine(($_.Cells | % { $_.Value }) -join ',')
- }
- }
- $sw.Close()
- })
- $helpMenu = New-Object System.Windows.Forms.ToolStripMenuItem
- $helpMenu.Size = New-Object System.Drawing.Size 35,20
- $helpMenu.Text = "&Help"
- $helpMenu.BackColor = "White"
- $helpMenu.Add_Click({Help})
- $signMenu = New-Object System.Windows.Forms.ToolStripMenuItem
- $signMenu.Size = New-Object System.Drawing.Size 35,20
- $signMenu.Text = "&?"
- $signMenu.BackColor = "White"
- $signMenu.DropDownItems.AddRange(@($helpMenu))
- $menu = New-Object System.Windows.Forms.MenuStrip
- $menu.Size = New-Object System.Drawing.Size 35,20
- $menu.Text = "&Help"
- $menu.TabIndex = 0
- $menu.Location = New-Object Drawing.Point 150,60
- $menu.Items.AddRange(@($signMenu))
- $menu.RightToLeft = 'Yes'
- $menu.BackColor = "DarkBlue"
- $serversLabel = New-Object Windows.Forms.Label
- $serversLabel.Location = New-Object Drawing.Point 10,10
- $serversLabel.Forecolor = 'White'
- $serversLabel.text = "Halo servers list :"
- $serversDataGridView = New-Object System.Windows.Forms.DataGridView
- $serversDataGridView.Size = New-Object System.Drawing.Size 268,159 #251,157
- $serversDataGridView.Location = New-Object Drawing.Point 10,38
- $serversDataGridView.DefaultCellStyle.SelectionBackColor = "DarkBlue"
- $serversDataGridView.AllowUserToAddRows = $True
- $serversDataGridView.MultiSelect = $False
- $serversDataGridView.EnableHeadersVisualStyles = $False;
- $serversDataGridView.BackgroundColor = "DarkBlue"
- $serversDataGridView.GridColor = "DarkBlue"
- $serversDataGridView.BorderStyle = "None"
- $serversDataGridView.ColumnCount = 2
- $serversDataGridView.Columns[0].Name = "Name"
- $serversDatagridview.Columns[0].Width = 80
- $serversDatagridview.Columns[0].HeaderCell.Style.Alignment = "MiddleCenter"
- $serversDatagridview.Columns[0].DefaultCellStyle.Alignment = "MiddleCenter"
- $serversDataGridView.Columns[1].Name = "IP:PORT"
- $serversDatagridview.Columns[1].Width = 128
- $serversDatagridview.Columns[1].HeaderCell.Style.Alignment = "MiddleCenter"
- $serversDatagridview.Columns[1].DefaultCellStyle.Alignment = "MiddleCenter"
- If (Test-Path $serversListPath) {
- $serversList = Get-content $serversListPath
- If (-Not [String]::IsNullOrWhiteSpace($serversList)) {
- $serversList | % {
- $serverListData = $_.Split(",")
- $serversDataGridView.Rows.Add($serverListData[0], $serverListData[1]) | Out-NUll
- }
- }
- }
- $joinoptionsButton = New-Object Windows.Forms.Button
- $joinoptionsButton.Size = New-Object System.Drawing.Size 80,40
- $joinoptionsButton.Location = New-Object Drawing.Point 10,208
- $joinoptionsButton.Forecolor = 'White'
- $joinoptionsButton.text = "Edit join options"
- $joinoptionsButton.Add_Click({
- $argumentTextBox.text = Get-CommandLineArguments
- $BHSChildform.ShowDialog() | Out-NUll
- })
- $joinButton = New-Object Windows.Forms.Button
- $joinButton.Size = New-Object System.Drawing.Size 164,40
- $joinButton.Location = New-Object Drawing.Point 97,208
- $joinButton.Forecolor = 'White'
- $joinButton.text = "Join server"
- $joinButton.Add_Click({Start-Game})
- $BHSChildform = New-Object System.Windows.Forms.Form
- $BHSChildform.Size = New-Object System.Drawing.Size 326,140
- $BHSChildform.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
- $BHSChildform.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon("C:\Windows\System32\actioncentercpl.dll")
- $BHSChildform.BackColor = "DarkBlue"
- $BHSChildform.FormBorderStyle = "FixedDialog"
- $BHSChildform.MaximizeBox = $False
- $joinargumentLabel = New-Object Windows.Forms.Label
- $joinargumentLabel.Location = New-Object Drawing.Point 10,10
- $joinargumentLabel.Forecolor = 'White'
- $joinargumentLabel.text = "Join arguments :"
- $argumentTextBox = New-Object Windows.Forms.TextBox
- $argumentTextBox.Size = New-Object System.Drawing.Size 300,30
- $argumentTextBox.Location = New-Object Drawing.Point 10,34
- $argumentTextBox.Forecolor = 'DarkBlue'
- $saveButton = New-Object Windows.Forms.Button
- $saveButton.Size = New-Object System.Drawing.Size 70,30
- $saveButton.Location = New-Object Drawing.Point 123,66
- $saveButton.Forecolor = 'White'
- $saveButton.text = "Save"
- $saveButton.Add_Click({
- Set-Content $commandlineArgumentsPath $($argumentTextBox.Text)
- $BHSChildform.Close()
- })
- $BHSChildform.Controls.Add($joinargumentLabel)
- $BHSChildform.Controls.Add($argumentTextBox)
- $BHSChildform.Controls.Add($saveButton)
- $BHSform.Controls.Add($menu)
- $BHSform.Controls.Add($serversLabel)
- $BHSform.Controls.Add($serversDataGridView)
- $BHSform.Controls.Add($joinoptionsButton)
- $BHSform.Controls.Add($joinButton)
- $BHSform.ShowDialog() | Out-NUll
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement