| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- param(
- [Parameter(Mandatory = $true)][string]$UnityPath
- )
- $ErrorActionPreference = 'Stop'
- $taskPackage = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
- $taskCecil = Join-Path (Split-Path -Parent $UnityPath) 'Data/Managed/Unity.Cecil.dll'
- if (-not (Test-Path -LiteralPath $taskCecil)) { throw "Unity Cecil library not found: $taskCecil" }
- Add-Type -Path $taskCecil
- $taskRelativeDll = 'ThirdParty/GUPS/Obfuscator/Editor/Plugins/GUPS.Obfuscator.Editor.dll'
- $taskDll = Join-Path $taskPackage $taskRelativeDll
- $taskOldPrefix = 'Assets/GUPS/Obfuscator/Editor/Gui/Resources/'
- $taskNewPrefix = 'Packages/come.app.runtimes/ThirdParty/GUPS/Obfuscator/Editor/Gui/Resources/'
- $taskResources = Join-Path $taskPackage 'ThirdParty/GUPS/Obfuscator/Editor/Gui/Resources'
- function Get-InstructionSnapshot($Assembly) {
- foreach ($taskType in $Assembly.MainModule.GetTypes()) {
- foreach ($taskMethod in $taskType.Methods) {
- if (-not $taskMethod.HasBody) { continue }
- $taskMethod.FullName
- foreach ($taskInstruction in $taskMethod.Body.Instructions) { $taskInstruction.ToString() }
- }
- }
- }
- $taskReader = [Mono.Cecil.ReaderParameters]::new()
- $taskReader.ReadSymbols = $true
- $taskReader.InMemory = $true
- $taskAssembly = [Mono.Cecil.AssemblyDefinition]::ReadAssembly($taskDll, $taskReader)
- $taskStage = $null
- try {
- if ($taskAssembly.Name.HasPublicKey) { throw 'The vendor DLL is now signed; review the SDK update before patching.' }
- $taskBefore = (Get-InstructionSnapshot $taskAssembly) -join "`n"
- $taskChanged = 0
- $taskFound = [Collections.Generic.HashSet[string]]::new()
- foreach ($taskType in $taskAssembly.MainModule.GetTypes()) {
- foreach ($taskMethod in $taskType.Methods) {
- if (-not $taskMethod.HasBody) { continue }
- foreach ($taskInstruction in $taskMethod.Body.Instructions) {
- if ($taskInstruction.OpCode.Name -ne 'ldstr') { continue }
- $taskValue = [string]$taskInstruction.Operand
- if ($taskValue.StartsWith($taskOldPrefix, [StringComparison]::Ordinal)) {
- $taskValue = $taskNewPrefix + $taskValue.Substring($taskOldPrefix.Length)
- $taskInstruction.Operand = $taskValue
- $taskChanged++
- }
- if ($taskValue.StartsWith($taskNewPrefix, [StringComparison]::Ordinal)) {
- $taskResource = $taskValue.Substring($taskNewPrefix.Length)
- if (-not (Test-Path -LiteralPath (Join-Path $taskResources $taskResource) -PathType Leaf)) {
- throw "Missing GUPS GUI resource: $taskResource"
- }
- [void]$taskFound.Add($taskResource)
- }
- }
- }
- }
- if ($taskFound.Count -ne 14) { throw "Expected 14 GUI resources, found $($taskFound.Count). Review the SDK update." }
- if ($taskChanged -eq 0) { Write-Output 'PASS: all 14 GUPS GUI paths already target the package.'; return }
-
-
- $taskStage = Join-Path ([IO.Path]::GetTempPath()) ('GupsGuiPatch-' + [Guid]::NewGuid().ToString('N'))
- [IO.Directory]::CreateDirectory($taskStage) | Out-Null
- $taskStagedDll = Join-Path $taskStage 'GUPS.Obfuscator.Editor.dll'
- $taskWriter = [Mono.Cecil.WriterParameters]::new()
- $taskWriter.WriteSymbols = $true
- $taskAssembly.Write($taskStagedDll, $taskWriter)
- $taskCheck = [Mono.Cecil.AssemblyDefinition]::ReadAssembly($taskStagedDll, $taskReader)
- try {
- $taskAfter = (Get-InstructionSnapshot $taskCheck) -join "`n"
- if ($taskAfter -cne $taskBefore.Replace($taskOldPrefix, $taskNewPrefix)) { throw 'Unexpected IL changes in patched DLL.' }
- if (-not $taskCheck.MainModule.HasSymbols -or $taskCheck.MainModule.Mvid -ne $taskAssembly.MainModule.Mvid) {
- throw 'Debug symbols or module identity changed unexpectedly.'
- }
- } finally { $taskCheck.Dispose() }
- $taskAssembly.Dispose()
- [IO.File]::Copy($taskStagedDll, $taskDll, $true)
- [IO.File]::Copy([IO.Path]::ChangeExtension($taskStagedDll, '.pdb'), [IO.Path]::ChangeExtension($taskDll, '.pdb'), $true)
- Write-Output "PASS: patched $taskChanged GUI resource paths; other IL, module identity and symbols verified."
- } finally {
- $taskAssembly.Dispose()
- if ($taskStage) {
-
- foreach ($taskName in @('GUPS.Obfuscator.Editor.dll', 'GUPS.Obfuscator.Editor.pdb')) {
- $taskFile = Join-Path $taskStage $taskName
- if (Test-Path -LiteralPath $taskFile) { Remove-Item -LiteralPath $taskFile }
- }
- [IO.Directory]::Delete($taskStage, $false)
- }
- }
|