-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,29 @@ | ||
$QuickEditCodeSnippet=@" | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Runtime.InteropServices; | ||
|
||
public static class DisableConsoleQuickEdit | ||
{ | ||
const uint ENABLE_QUICK_EDIT = 0x0040; | ||
const int STD_INPUT_HANDLE = -10; | ||
[DllImport("kernel32.dll", SetLastError = true)] | ||
static extern IntPtr GetStdHandle(int nStdHandle); | ||
[DllImport("kernel32.dll")] | ||
static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode); | ||
[DllImport("kernel32.dll")] | ||
static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode); | ||
public static bool SetQuickEdit(bool reset) | ||
{ | ||
IntPtr consoleHandle = GetStdHandle(STD_INPUT_HANDLE); | ||
uint consoleMode; | ||
if (!GetConsoleMode(consoleHandle, out consoleMode)) | ||
{ | ||
return false; | ||
} | ||
if (reset) | ||
{ | ||
consoleMode &= ~ENABLE_QUICK_EDIT; | ||
} | ||
else | ||
{ | ||
consoleMode |= ENABLE_QUICK_EDIT; | ||
} | ||
if (!SetConsoleMode(consoleHandle, consoleMode)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
$Config = @{ | ||
# 自行指定游戏根目录和游戏启动命令示例: | ||
# GameRootDirectory = "C:\Users\Silver\Games\Tiancity\csol\"; | ||
# LaunchGameCmd = '"C:\Program Files (x86)\TCGame\tcgame.exe" cso'; | ||
MaxWaitTimeInRoom = 600; | ||
} | ||
"@ | ||
|
||
$QuickEditMode = Add-Type -TypeDefinition $QuickEditCodeSnippet -Language CSharp | ||
$Parameters = @() | ||
|
||
function Set-QuickEdit() | ||
foreach ($key in $Config.Keys) | ||
{ | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(Mandatory=$False, HelpMessage="This switch will disable Console QuickEdit mode.")] | ||
[switch]$DisableQuickEdit=$False | ||
) | ||
if([DisableConsoleQuickEdit]::SetQuickEdit($DisableQuickEdit)) | ||
{ | ||
Write-Output "[MESSAGE] Console Quick-Edit Mode disabled successfully." | ||
} | ||
else | ||
{ | ||
Write-Output "[ERROR] Attempt to disable Console Quick-Edit Mode failed." | ||
} | ||
$val = $Config[$key] | ||
if ($val -ne $Null -and $val.Length -gt 0) | ||
{ | ||
$Parameters += "--$key" | ||
$Parameters += "$val" | ||
} | ||
} | ||
|
||
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) | ||
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) | ||
{ | ||
$location = (Get-Location).ToString() | ||
Start-Process -FilePath powershell -Verb RunAs -ArgumentList "-NoExit -Command `"& {Set-Location `'$location`'; .\Controller.ps1}`"" | ||
Start-Process -FilePath powershell -Verb RunAs -ArgumentList "-NoExit -Command `"& { Set-Location `'$PSScriptRoot`'; .\Controller.ps1 }`"" | ||
} | ||
else | ||
{ | ||
Set-QuickEdit -DisableQuickEdit | ||
.\Controller.exe | ||
} | ||
.\Controller.exe $Parameters | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters