forked from Aemony/CrossCode-IntegerScaling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUninstall-ScalingFix.ps1
More file actions
89 lines (78 loc) · 2.73 KB
/
Uninstall-ScalingFix.ps1
File metadata and controls
89 lines (78 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Functions
function Stop-Script {
[cmdletbinding()]
param([string]$Message = "")
Write-Warning $Message
Read-Host "Execution have terminated! Press Enter to close the window"
exit
}
Write-Host "Preparing patches..."
# Patches to apply
$Patches = @(
[PSCustomObject]@{
File = '.\assets\js\game.compiled.js'
Changes = @(
# `c` is the pixel scaling passed in the constructor of ig.System
# When initializing, set the canvas' renderingMode to pixelated
[PSCustomObject]@{
Original = 'this.height=b;if(this.imageSmoothingDisabled){'
Patched = 'this.height=b;this.canvas.style.imageRendering="pixelated";if(this.imageSmoothingDisabled){'
}
# Modify the "Double" scaling mode to instead be an integer scaling mode
[PSCustomObject]@{
Original = 'case sc.DISPLAY_TYPE.SCALE_X2:a=c*2;b=d*2;break;'
Patched = 'case sc.DISPLAY_TYPE.SCALE_X2:const m=Math.max(Math.min(Math.floor(b/c),Math.floor(i/d)),1);a=c*m;b=d*m;break;'
}
)
Content = $null
}
[PSCustomObject]@{
File = '.\assets\data\lang\sc\gui.en_US.json'
Changes = @(
# Rename the "Double" scaling mode to "Integer"
[PSCustomObject]@{
Original = '"display-type":{"name":"Display Type","group":["Original","Double","Fit","Stretch"]'
Patched = '"display-type":{"name":"Display Type","group":["Original","Integer","Fit","Stretch"]'
}
)
Content = $null
}
)
Write-Host "Verifying files..."
# Pre-patch checks...
ForEach ($Patch in $Patches)
{
If((Test-Path -Path $Patch.File) -eq $false)
{
Stop-Script "One or more of the required files were not found. Verify the script is being run in the game folder."
} else {
Write-Host "Reading file contents..."
$Patch.Content = Get-Content -Path $Patch.File -Raw
if($Patch.Content)
{
ForEach ($Change in $Patch.Changes)
{
$MatchesFound = ($Patch.Content -split $Change.Patched, 0, "simplematch" | Measure-Object | Select-Object -Exp Count) - 1
if($MatchesFound -ne 1)
{
Stop-Script "Expected 1 match but found $MatchesFound, in file '$($Patch.File)', for line:
$($Change.Patched)"
}
}
} else {
Stop-Script "The file was empty."
}
}
}
# Everything looks fine, let's patch the files!
ForEach ($Patch in $Patches)
{
Write-Host "Applying patches to " $Patch.File "..."
ForEach ($Change in $Patch.Changes)
{
$Patch.Content = $Patch.Content -replace [regex]::escape($Change.Patched), $Change.Original
}
$Patch.Content | Set-Content -Path $Patch.File
}
Write-Host "Patching is complete. Press Enter to exit the script."
Read-Host