Updated default snippets

pull/33/head
Pat Hartl 2023-11-17 00:46:05 -06:00
parent 2cb7013120
commit aed9935b16
30 changed files with 24 additions and 91 deletions

View File

@ -1 +1 @@
Copy-Item -Path "$InstallDir\<Source Path>" -Destination "$InstallDir\<Destination Path>" -Recurse
Copy-Item -Path "$InstallDirectory\<Source Path>" -Destination "$InstallDirectory\<Destination Path>" -Recurse

View File

@ -1 +1 @@
New-Item -ItemType Directory -Force -Path "$InstallDir\<Path>"
New-Item -ItemType Directory -Force -Path "$InstallDirectory\<Path>"

View File

@ -1,2 +1,2 @@
# Writes byte[] to a file at an offset
Patch-Binary -FilePath "$InstallDir\<File Path>" -Offset 0x00 -Data $bytes
Patch-Binary -FilePath "$InstallDirectory\<File Path>" -Offset 0x00 -Data $bytes

View File

@ -1 +1 @@
Remove-Item "$InstallDir\<DirectoryPath>" -Recurse -ErrorAction Ignore
Remove-Item "$InstallDirectory\<DirectoryPath>" -Recurse -ErrorAction Ignore

View File

@ -1 +1 @@
Rename-Item -Path "$InstallDir\<FilePath>" -NewName "$InstallDir\<NewName>"
Rename-Item -Path "$InstallDirectory\<FilePath>" -NewName "$InstallDirectory\<NewName>"

View File

@ -1,2 +0,0 @@
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Regex '^game.setPlayerName "(.+)"' -Replacement "game.setPlayerName ""$NewName""" -FilePath "$InstallDir\<File Path>"

View File

@ -1,2 +0,0 @@
# Takes an input byte[] and separates it with 0x00 between each character
$bytes = Separate-AsciiBytes -Data $bytes

View File

@ -9,4 +9,4 @@
# WIN7RTM
# WIN8RTM
# See: https://ss64.com/nt/syntax-compatibility.html
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" -Name "$InstallDir\<Executable>" -Value "~ WINXPSP2 HIGHDPIAWARE" -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" -Name "$InstallDirectory\<Executable>" -Value "~ WINXPSP2 HIGHDPIAWARE" -Force

View File

@ -1,2 +0,0 @@
# Convert an input string to ASCII-encoded byte[]. Shorter strings will pad out to 12 bytes, longer strings will be trimmed.
$bytes = Get-AsciiBytes -InputString "Hello world!" -MaxLength 12

View File

@ -1,4 +1,4 @@
# Trim a string down to a specified amount of characters
if ($NewName.Length -gt 10) {
$NewName = $NewName.Substring(0, 10);
if ($NewPlayerAlias.Length -gt 10) {
$NewPlayerAlias = $NewPlayerAlias.Substring(0, 10);
}

View File

@ -1,2 +1,2 @@
# Write contents of a string to a file
Set-Content "$InstallDir\<File Path>" "Hello world!"
Set-Content "$InstallDirectory\<File Path>" "Hello world!"

View File

@ -0,0 +1,2 @@
# Bounds accessible via $Resolution.Height, $Resolution.Width
$Resolution = Convert-AspectRatio -Width 1280 -Height 800 -AspectRatio (4 / 3)

View File

@ -0,0 +1,2 @@
# Converts a string to a UTF16-encoded byte array. This looks like ASCII characters separated by 0x00 in most cases.
$bytes = ConvertTo-StringBytes -Input "Hello World!" -Utf16 1 -MaxLength 12

View File

@ -0,0 +1 @@
Edit-PatchBinary -FilePath "$InstallDirectory\<File Path>" -Offset 0x00 -Data $bytes

View File

@ -1,14 +0,0 @@
function Get-43Resolution([int]$Width, [int]$Height) {
$ratio = 4 / 3
if (($Width -gt $Height) -or ($Width -eq $Height)) {
return @{ Width = [math]::Round($ratio * $Height); Height = $Height }
}
if ($Width -lt $Height) {
return @{ Width = $Width; Height = [math]::Round($Width / $ratio) }
}
}
# Accessible via $Resolution.Height, $Resolution.Width
$Resolution = Get-43Resolution -Width 1280 -Height 800

View File

@ -1,30 +0,0 @@
function Get-AsciiBytes([string]$InputString, [int]$MaxLength)
{
if ($InputString.Length -gt $MaxLength)
{
$InputString = $InputString.Substring(0, $MaxLength)
}
$bytes = [System.Text.Encoding]::ASCII.GetBytes($InputString)
$array = @()
$count = 0
$extraPadding = $MaxLength - $bytes.Length
foreach ($byte in $bytes)
{
if ($count -lt $MaxLength)
{
$array += $byte
$count++
}
}
# Pad the end with 0x00 to meet our max length
for ($i = $count; $i -lt $MaxLength; $i++)
{
$array += 0x00
}
return $array
}

View File

@ -0,0 +1 @@
$manifest = Get-GameManifest "C:\\Games\\<Game Directory>"

View File

@ -0,0 +1,2 @@
# Bounds are accessible by $Resolution.Width and $Resolution.Height
$Resolution = Get-PrimaryDisplay

View File

@ -1,11 +0,0 @@
function Patch-Binary([byte[]]$Data, [int]$Offset, [string]$FilePath)
{
$bytes = [System.IO.File]::ReadAllBytes($FilePath)
for ($i = 0; $i -lt $Data.Length; $i++)
{
$bytes[$Offset + $i] = $Data[$i]
}
[System.IO.File]::WriteAllBytes($FilePath, $bytes)
}

View File

@ -1,12 +0,0 @@
function Separate-AsciiBytes([byte[]]$Data)
{
$array = @()
foreach ($byte in $Data)
{
$array += $byte
$array += 0x00
}
return $array
}

View File

@ -1,5 +1,2 @@
function Write-ReplaceContentInFile([string]$Regex, [string]$Replacement, [string]$FilePath)
{
$content = (Get-Content $FilePath) -replace $Regex, $Replacement
[IO.File]::WriteAllLines($FilePath, $content)
}
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Regex '^game.setPlayerName "(.+)"' -Replacement "game.setPlayerName ""$NewName""" -FilePath "$InstallDir\<File Path>"

View File

@ -0,0 +1 @@
$AllocatedKey

View File

@ -0,0 +1 @@
$DefaultInstallDirectory

View File

@ -1,3 +0,0 @@
# Accessible via $Display.Width and $Display.Height
Add-Type -AssemblyName System.Windows.Forms
$Display = ([System.Windows.Forms.Screen]::AllScreens | Where-Object Primary).Bounds

View File

@ -0,0 +1 @@
$OldPlayerAlias

View File

@ -0,0 +1 @@
$GameManifest

View File

@ -1 +0,0 @@
$InstallDir = $PSScriptRoot

View File

@ -0,0 +1 @@
$ServerAddress