Skip to content

Commit

Permalink
Refactored for clarity, updated docs, better error handling and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Apocrypher00 committed Jan 27, 2025
1 parent 1015218 commit 97bb978
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 61 deletions.
157 changes: 100 additions & 57 deletions KillPopper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,84 @@
Monitor for kills and notify the player.
.DESCRIPTION
This script monitors a temp folder where Nvidia stores "Player Killed" and "Player Downed" clips.
The creation of a temp clip indicates that the player died or killed another player in Hunt Showdown,
This script monitors a folder where Nvidia stores "Hunter killed" and "Player downed" clips.
The creation of a clip indicates that the player died or killed another player in Hunt Showdown,
but the game doesn't notify the player that they got a kill or that a clip was generated until after the match.
Therefore, we can leverage clip creation to confirm a player's kills.
.NOTES
Future versions may ignore "Player Downed", but I haven't figured out how to differentiate them yet.
.VERSION
1.2.1
1.2.2
.AUTHOR
Apocrypher00
#>

#### --- Imports --- ###################################################################################################

using namespace System.Windows.Forms
Add-Type -AssemblyName System.Windows.Forms

#### --- End Imports --- ###############################################################################################

#### --- Globals --- ###################################################################################################

# Current version of the script
$CurrentVersion = "1.2.2"

# Username for current user
$UserName = $Env:UserName
Write-Host "User is '$Username'"

# Path to user folder
$UserPath = "C:\Users\$UserName"

# Nvidia app path
$AppPath = "C:\Program Files\NVIDIA Corporation\NVIDIA app\CEF\NVIDIA app.exe"

# Temp Clip Path
$ClipPath = "C:\Users\$UserName\AppData\Local\Temp\Highlights\Hunt Showdown"
Write-Host "Highlights temp folder is '$ClipPath'"
$ClipPath = "$UserPath\AppData\Local\Temp\Highlights\Hunt Showdown"

# Gallery Path
$GalleryPath = "C:\Users\$UserName\Videos\Hunt Showdown"
Write-Host "Gallery folder is '$GalleryPath'"
$GalleryPath = "$UserPath\Videos\Hunt Showdown"

# Hunt splash screen path
$SplashPath = "C:\Program Files (x86)\Steam\steamapps\common\Hunt Showdown\EasyAntiCheat\SplashScreen.png"
Write-Host "Splash screen is at '$SplashPath'"

$CurrentVersion = "1.2.1"
# Version file URL
$RepoURL = "https://raw.githubusercontent.com/Apocrypher00/KillPopper/master"
# $ScriptURL = "$RepoURL/KillPopper.ps1"
$VersionFileURL = "$RepoURL/version.txt"

#### --- End Globals --- ###############################################################################################

#### --- Functions --- #################################################################################################

# Function to display a message box
function Show-MessageBox {
param (
[Parameter(Mandatory = $false, Position = 0)]
[string]
$Message = "",

[Parameter(Mandatory = $false, Position = 1)]
[string]
$Title = "",

[Parameter(Mandatory = $false, Position = 2)]
[MessageBoxButtons]
$Button = [MessageBoxButtons]::OK,

[Parameter(Mandatory = $false, Position = 3)]
[MessageBoxIcon]
$Icon = [MessageBoxIcon]::Information
)

return [MessageBox]::Show($Message, $Title, $Button, $Icon)
}

# Function to wait for user input before exiting
function Wait-Exit {
[CmdletBinding()]
param (
[Parameter(Mandatory = $false, Position = 0)]
[Parameter(Mandatory = $true, Position = 0)]
[string]
$Message,

Expand All @@ -62,16 +92,20 @@ function Wait-Exit {
if ($Message) { Write-Warning -Message $Message }
if ($ErrorRecord) { Write-Error -ErrorRecord $ErrorRecord }

Read-Host -Prompt "Press Enter to Exit"
try { Stop-Transcript | Out-Null } catch {}
exit
Show-MessageBox -Message $Message -Title "KillPopper" -Button OK -Icon Error | Out-Null
Stop-Transcript -ErrorAction SilentlyContinue | Out-Null
exit 1
}

# Function to display a notification
function Show-KillNotification {
New-BurntToastNotification -AppLogo $SplashPath -Text @("Hunt: Showdown 1896", "Kill Confirmed!")
}

#### --- End Functions --- #############################################################################################

#### --- Main Script --- ###############################################################################################

try {
# Set the window title
$host.UI.RawUI.WindowTitle = "KillPopper"
Expand All @@ -86,7 +120,35 @@ try {

Start-Transcript -Path ".\logs\$((Get-Date).ToString("yyyy-MM-dd_HH-mm-ss")).log" | Out-Null
} catch {
Wait-Exit "Failed to start transcript!"
Wait-Exit "Failed to start transcript!" $_
}

# Display the script information
Write-Host "Script version is: '$CurrentVersion'"
Write-Host "User is: '$Username'"
Write-Host "User folder is: '$UserPath'"
Write-Host "Highlights temp folder is: '$ClipPath'"
Write-Host "Gallery folder is: '$GalleryPath'"
Write-Host "Nvidia app is at: '$AppPath'"
Write-Host "Splash screen is at: '$SplashPath'"

# Check for updates
try {
$LatestVersion = Invoke-WebRequest -Uri $VersionFileURL -UseBasicParsing | Select-Object -ExpandProperty Content
$LatestVersion = $LatestVersion.Trim()

if ($LatestVersion -gt $CurrentVersion) {
Write-Host "New version available: $LatestVersion!" -ForegroundColor Green
Show-MessageBox `
-Message "New version available: $LatestVersion!" `
-Title "KillPopper" `
-Button OK `
-Icon Information | Out-Null
} else {
Write-Host "Script is up to date!" -ForegroundColor Green
}
} catch {
Write-Warning "Failed to check for updates!"
}

# Check if NuGet is installed
Expand Down Expand Up @@ -121,58 +183,37 @@ try {
Wait-Exit "Failed to import BurntToast!" $_
}

# Check for Clip Path
if (-not (Test-Path -Path $ClipPath)) {
try {
Write-Host "Temp folder missing. Creating now..."
New-Item -Path $ClipPath -ItemType Directory -Force
} catch {
Wait-Exit "Failed to create temp folder!" $_
}
}

# Check for splash screen
if (-not (Test-Path -Path $SplashPath)) {
Write-Warning "Splash screen not found! Switching to Default..."
$SplashPath = $null
}

# Check for updates
try {
$LatestVersion = Invoke-WebRequest -Uri $VersionFileURL -UseBasicParsing | Select-Object -ExpandProperty Content
$LatestVersion = $LatestVersion.Trim()

if ($LatestVersion -gt $CurrentVersion) {
Write-Warning "New version available: $LatestVersion!"
# Write-Host "Updating script..."

# # Download the latest script
# try {
# Invoke-WebRequest -Uri $ScriptURL -OutFile $MyInvocation.MyCommand.Path -UseBasicParsing
# Write-Host "Update successful! Restarting script..."
# Start-Process -FilePath "powershell.exe" -ArgumentList "-File `"$MyInvocation.MyCommand.Path`"" -WindowStyle Normal
# exit
# } catch {
# Write-Host "Failed to update script."
# exit 1
# }
} else {
Write-Host "Script is up to date (Version: $CurrentVersion)"
}
} catch {
Write-Warning "Failed to check for updates!"
}

# Check if the NVIDIA App is installed
# If so, we need to monitor the gallery instead of the temp folder
if (Test-Path -Path $AppPath) {
$ClipPath = $GalleryPath
Write-Host "NVIDIA App found. Monitoring Gallery instead of Temp folder."
$ClipPath = $GalleryPath
}

# Check for Clip Path
if (-not (Test-Path -Path $ClipPath)) {
try {
Write-Host "Temp folder missing. Creating now..."
New-Item -Path $ClipPath -ItemType Directory -Force
} catch {
Wait-Exit "Failed to create temp folder!" $_
}
}

# Event Handler: Action when a new clip is created
$ClipAction = {
$ClipEvent = $Event.SourceEventArgs
$FileName = $ClipEvent.Name
$FileName = $ClipEvent.Name

# Ignore "Player downed" clips
if ($FileName -like "*Player downed*") { return }

Write-Host "New clip created: $FileName"
Show-KillNotification
}
Expand Down Expand Up @@ -201,3 +242,5 @@ try {
} catch {
Wait-Exit "Unknown Error!" $_
}

#### --- End Main Script --- ###########################################################################################
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
# KillPopper

A PowerShell script that shows a Windows notification when you get a kill in Hunt: Showdown 1896

## Description

KillPopper is a PowerShell script that takes advantage of the NVIDIA highlights to let you know when you get a kill in Hunt Showdown.
Normally highlights aren't available until after the game, but they are still created as the kill (or down) happens.
This means that we can monitor the folder that the clips are generated in and show a notification in real-time.
This allows you to confirm every kill, even if you miss the sound cues or it happens very far away.
This is especially helpful when other players die to your traps on the other side of the map, although the highlight itself won't show the kill.

## Requirements

GeForce Experience (for v1.1+), or NVIDIA App (for v1.2+)
PowerShell 5+ (PowerShell 5 is pre-installed on Windows)
BurntToast PowerShell Module (should be installed the first time the script runs)
NuGet PowerShell Package Provider (should be installed the first time the script runs)
NuGet PowerShell Package Provider (should be installed the first time the script runs)
BurntToast PowerShell Module (should be installed the first time the script runs)

## Getting Started

Download the latest release and unzip the files to a new folder, then just double click the shortcut with the green arrow before playing.
The script will run in the background and monitor for new clips.
The script will tell you if any errors occurr by displaying them in the console and by logging everything to the logs folder.

Make sure that notifications are enabled and you don't have "Do Not Disturb" turned on while in-game.
The current version of KillPopper doesn't distinguish between kill clips and down clips, so you will have to disable "Player downed" highlights if you don't want notifications to appear when you die.
If you have GeForce Experience, KillPopper can't distinguish between kill clips and down clips, so you will have to disable "Player downed" highlights if you don't want notifications to appear when you die.
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.1
1.2.2

0 comments on commit 97bb978

Please sign in to comment.