Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $VERSION = "3.0";
- #
- #
- # VOLUME CHANGER SEGMENT
- #
- #
- Add-Type -AssemblyName PresentationFramework
- Add-Type -TypeDefinition @'
- using System.Runtime.InteropServices;
- [Guid("5CDF2C82-841E-4546-9722-0CF74078229A"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- interface IAudioEndpointVolume
- {
- // f(), g(), ... are unused COM method slots. Define these if you care
- int f(); int g(); int h(); int i();
- int SetMasterVolumeLevelScalar(float fLevel, System.Guid pguidEventContext);
- int j();
- int GetMasterVolumeLevelScalar(out float pfLevel);
- int k(); int l(); int m(); int n();
- int SetMute([MarshalAs(UnmanagedType.Bool)] bool bMute, System.Guid pguidEventContext);
- int GetMute(out bool pbMute);
- }
- [Guid("D666063F-1587-4E43-81F1-B948E807363F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- interface IMMDevice
- {
- int Activate(ref System.Guid id, int clsCtx, int activationParams, out IAudioEndpointVolume aev);
- }
- [Guid("A95664D2-9614-4F35-A746-DE8DB63617E6"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- interface IMMDeviceEnumerator
- {
- int f(); // Unused
- int GetDefaultAudioEndpoint(int dataFlow, int role, out IMMDevice endpoint);
- }
- [ComImport, Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")] class MMDeviceEnumeratorComObject { }
- public class Audio
- {
- static IAudioEndpointVolume Vol()
- {
- var enumerator = new MMDeviceEnumeratorComObject() as IMMDeviceEnumerator;
- IMMDevice dev = null;
- Marshal.ThrowExceptionForHR(enumerator.GetDefaultAudioEndpoint(/*eRender*/ 0, /*eMultimedia*/ 1, out dev));
- IAudioEndpointVolume epv = null;
- var epvid = typeof(IAudioEndpointVolume).GUID;
- Marshal.ThrowExceptionForHR(dev.Activate(ref epvid, /*CLSCTX_ALL*/ 23, 0, out epv));
- return epv;
- }
- public static float Volume
- {
- get { float v = -1; Marshal.ThrowExceptionForHR(Vol().GetMasterVolumeLevelScalar(out v)); return v; }
- set { Marshal.ThrowExceptionForHR(Vol().SetMasterVolumeLevelScalar(value, System.Guid.Empty)); }
- }
- public static bool Mute
- {
- get { bool mute; Marshal.ThrowExceptionForHR(Vol().GetMute(out mute)); return mute; }
- set { Marshal.ThrowExceptionForHR(Vol().SetMute(value, System.Guid.Empty)); }
- }
- }
- '@
- #
- #
- # VOLUME CHANGER SEGMENT END
- #
- #
- $count = [int]0;
- Get-WmiObject Win32_process -filter "name = 'powershell.exe'" | forEach {
- if($_.CommandLine -Match "TAManager.ps1") {
- $count++;
- }
- }
- if($count -ne 1) {
- Write-Output "TAM DETECTED IN ANOTHER WINDOW!"
- exit
- }
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
- # Set the size of your form
- $Form = New-Object System.Windows.Forms.Form
- $Form.width = 600
- $Form.height = 600
- $Form.Text = "TAManger Settings"
- # Set the font of the text to be used within the form
- $Font = New-Object System.Drawing.Font("Console",12)
- $Form.Font = $Font
- $MANAGE_PRIORITY = new-object System.Windows.Forms.checkbox
- $MANAGE_PRIORITY.Location = new-object System.Drawing.Size(30,25)
- $MANAGE_PRIORITY.Size = new-object System.Drawing.Size(250,50)
- $MANAGE_PRIORITY.Text = "High Priority"
- $MANAGE_PRIORITY.Checked = $true
- $Form.Controls.Add($MANAGE_PRIORITY)
- $MANAGE_APPS = new-object System.Windows.Forms.checkbox
- $MANAGE_APPS.Location = new-object System.Drawing.Size(30,75)
- $MANAGE_APPS.Size = new-object System.Drawing.Size(250,50)
- $MANAGE_APPS.Text = "Manage Apps"
- $MANAGE_APPS.Checked = $true
- $Form.Controls.Add($MANAGE_APPS)
- $MANAGE_KEYBINDS = new-object System.Windows.Forms.checkbox
- $MANAGE_KEYBINDS.Location = new-object System.Drawing.Size(30,125)
- $MANAGE_KEYBINDS.Size = new-object System.Drawing.Size(250,50)
- $MANAGE_KEYBINDS.Text = "Manage Keybinds"
- $MANAGE_KEYBINDS.Checked = $true
- $Form.Controls.Add($MANAGE_KEYBINDS)
- $MANAGE_VOLUME = new-object System.Windows.Forms.checkbox
- $MANAGE_VOLUME.Location = new-object System.Drawing.Size(30,175)
- $MANAGE_VOLUME.Size = new-object System.Drawing.Size(250,50)
- $MANAGE_VOLUME.Text = "Force Volume"
- $MANAGE_VOLUME.Checked = $true
- $Form.Controls.Add($MANAGE_VOLUME)
- $MANAGE_VOLUME_INPUT = new-object System.Windows.Forms.TextBox
- $MANAGE_VOLUME_INPUT.Location = new-object System.Drawing.Size(30,225)
- $MANAGE_VOLUME_INPUT.Size = new-object System.Drawing.Size(250,260)
- $MANAGE_VOLUME_INPUT.Text ="30";
- $Form.Controls.Add($MANAGE_VOLUME_INPUT)
- # Add an OK button
- $OKButton = new-object System.Windows.Forms.Button
- $OKButton.Location = new-object System.Drawing.Size(30,275)
- $OKButton.Size = new-object System.Drawing.Size(100,40)
- $OKButton.Text = "OK"
- $OKButton.Add_Click({$Form.Close()})
- $form.Controls.Add($OKButton)
- # Activate the form
- $Form.Add_Shown({$Form.Activate()})
- [void] $Form.ShowDialog()
- $managePriority = $MANAGE_PRIORITY.Checked;
- $manageApps = $MANAGE_APPS.Checked;
- $manageBinds = $MANAGE_KEYBINDS.Checked;
- $manageVolume = $MANAGE_VOLUME.Checked
- $manageVolumeText = $MANAGE_VOLUME_INPUT.Text;
- $goodGamesVolume = ([int]$MANAGE_VOLUME_INPUT.Text)/100;
- $currentVolume = 0;
- if($manageApps) {
- [string[]]$apps = Get-Content -Path 'applications.txt'
- } else {
- $apps = @();
- }
- [string[]]$games = Get-Content -Path 'games.txt'
- $gameStr = $games -join ", ";
- $appsStr = $apps -join ", ";
- function header {
- cls
- Write-Output "";
- Write-Output " Total Annihilation Manager v$VERSION, Made by Zombean#6280";
- Write-Output "";
- Write-Output " high priority enabled: $managePriority"
- Write-Output " app kill enabled: $manageApps ($appsStr)"
- Write-Output " use keybinds: $manageBinds"
- Write-Output " force volume: $manageVolume ($manageVolumeText)"
- Write-Output " Games: $gameStr";
- Write-Output "";
- Write-Output "";
- Write-Output $global:consoleBuffer[0..15];
- };
- $global:consoleBuffer = @();
- function console {
- Param (
- [string]$message,
- [int]$max
- )
- $global:consoleBuffer = ,$message + $global:consoleBuffer
- }
- function MLog{
- Param (
- $message
- )
- $date = (Get-Date -Format "HH:mm:ss");
- $ident = "TAM $VERSION"
- $out= " [$ident $date] $message"
- console($out);
- Add-Content -Path log\log.txt -Value $out
- header
- }
- function getProc {
- Param (
- $procName
- )
- return Get-WmiObject Win32_process -filter "name = '$procName.exe'";
- };
- function tap {
- param (
- $game
- )
- try {
- return (get-process -Name $game).priorityclass;
- } catch {
- }
- };
- function StartAHK {
- param (
- $AHKPath
- )
- Start-Process -FilePath "rebinds\AHK\AutoHotkeyU64.exe" -ArgumentList "rebinds\$AHKPath";
- }
- function AutoHotKeyManager {
- MLog("Checking for hotkey scripts");
- Get-ChildItem rebinds\* -Filter *.ahk | % {
- $tempName = $_.Name;
- MLog("starting script: $tempName");
- StartAHK($tempName)
- }
- }
- $global:appPaths = @();
- function appHandler {
- param (
- $appName
- )
- if((getProc($appName))) {
- if(((getProc($appName)).Path[1].length) -eq 1) {
- $appPath = ((getProc($appName)).Path);
- } else {
- $appPath= ((getProc($appName)).Path[1]);
- }
- MLog("closing: $appName")
- $global:appPaths += $appPath
- (Invoke-Expression "taskkill /IM $appName.exe > null 2>&1") | Out-Null
- (Invoke-Expression "taskkill /F /IM $appName.exe > null 2>&1") | Out-Null
- }
- }
- $lock_mode = 1;
- $activeGame = "";
- header
- While(1)
- {
- if($lock_mode) {
- forEach($game in $games) {
- if( (getProc($game)) -and $lock_mode) {
- $lock_mode = 0;
- $activeGame = $game;
- MLog("$activeGame detected");
- if($manageVolume) {
- $currentVolume = [audio]::Volume;
- [audio]::Volume = $goodGamesVolume;
- MLog("Changing volume from $currentVolume too $goodGamesVolume");
- }
- if($manageBinds) {
- AutoHotKeyManager;
- }
- if( ((tap($activeGame)) -ne 'High') -and ($managePriority)) {
- MLog("Setting high prorirty on $game.exe!");
- ((getProc($activeGame)).SetPriority(128)) | Out-Null;
- }
- ForEach ($app in $apps) {
- appHandler($app);
- }
- }
- }
- } else {
- if(!(getProc($activeGame)) -and ($lock_mode -eq 0)) {
- $date = (Get-Date -Format "HH:mm:ss");
- MLog("$activeGame.exe closed, Tidying Up!");
- if($manageVolume) {
- MLog("Changing volume from $goodGamesVolume too $currentVolume");
- [audio]::Volume = $currentVolume;
- }
- if($global:appPaths.count -ne 0) {
- MLog("Restarting apps");
- ForEach ($app in $global:appPaths) {
- Start-Process "$app" | Out-Null;
- }
- $global:appPaths = @()
- }
- $ahku = Get-WmiObject Win32_process -filter 'name = "AutoHotKeyU64.exe"';
- if($ahku) {
- MLog("closing autohotkey's");
- (taskkill /F /IM AutoHotKeyU64.exe) | Out-Null;
- }
- header;
- $lock_mode = 1;
- }
- }
- Start-Sleep -s 1
- }
Add Comment
Please, Sign In to add comment