Guest User

P5S_Costume_Patch.ps1

a guest
Apr 14th, 2021
2,634
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Uncomment to make a seperate exe for the patched version. (Comment out the other option)
  2. $source = 'game.exe'
  3. $output = 'game_patched.exe'
  4.  
  5. #Uncomment to make a backup of the original exe and output to the original name
  6. #Make sure to delete 'game_original.exe' if they ever put out an update or it'll use the old version!
  7. #$source = 'game_original.exe'
  8. #$output = 'game.exe'
  9.  
  10.  
  11. Function SwapCostumes{
  12.     #Costume names
  13.     $script:costumes =@{
  14.         'Daily'='H050'
  15.         'Swim'='H052'
  16.         'Yukata'='H053'
  17.         'Towel'='H054'    
  18.         #Note: Sophie only supports Daily
  19.     }
  20.    
  21.     #if you want to use the original costume just comment out the line
  22.  
  23.     $JokerCostumeChanges=1  #use 2 for 'hotfix', 1 for latest.
  24.     $SophieCostumeChanges=2 #seems to require 2 replacements for both versions
  25.  
  26.  
  27.     for ($num = 1 ; $num -le $JokerCostumeChanges ; $num++)
  28.     {
  29.         SetCostume 'Joker' 'Daily'
  30.     }
  31.     SetCostume 'Skull' 'Daily'
  32.     SetCostume 'Panther' 'Daily'
  33.     SetCostume 'Fox' 'Daily'
  34.     SetCostume 'Queen' 'Swim'
  35.     SetCostume 'Noir' 'Swim'
  36.     SetCostume 'Navi' 'Swim'
  37.     for ($num = 1 ; $num -le $SophieCostumeChanges ; $num++){
  38.         SetCostume 'Sophie' 'Daily' #for some reason requires two changes
  39.     }
  40. }
  41.  
  42.  
  43. #Remaining of file is just logic
  44.  
  45. Function LoadFile{
  46.     #If the source file does not exist, but the destination does, make a backup of the destination and use that.
  47.     if (-not(Test-Path -Path $source -PathType Leaf) -and(Test-Path -Path $output -PathType Leaf)) {
  48.         try {
  49.             Copy-Item $output -Destination $source
  50.         }
  51.         catch {
  52.             throw $_.Exception.Message
  53.         }
  54.     }
  55.     Write-Host "Reading file"
  56.     $script:content = Get-Content -path $source -Raw
  57.     Write-Host "Finished Reading file"
  58. }
  59.  
  60.  
  61. Function Unicode {
  62.     Begin {
  63.         $output=[System.Text.StringBuilder]::new()
  64.     }
  65.     Process {
  66.         $output.Append($(
  67.             if ($_ -is [int]) { [char]::ConvertFromUtf32($_) }
  68.             else { [string]$_ }
  69.         )) | Out-Null
  70.     }
  71.     End { $output.ToString() }
  72. }
  73.  
  74.  function Pad{
  75.     param (
  76.         [string]$shortName
  77.     )
  78.     $longname='CE1MotorCharacterSetting', 0xEF, 0xBC, 0xBB, $shortName, 0xEF, 0xBC, 0xBD |Unicode
  79.     $length=$longname.Length
  80.     [int]$paddedLength=[Math]::floor($longname.length/8)
  81.     $paddedLength*=8
  82.     #if($longname.length%8 -ne 0)
  83.     #{
  84.         $paddedLength+=8
  85.  
  86.     #}
  87.    
  88.     $longname=$longname.PadRight($paddedLength,"`0")
  89.  
  90.     return $longname
  91.  
  92.  }
  93. function InnerSwap{
  94.     param (
  95.         [string]$original_short,
  96.         [string]$costume_short
  97.     )
  98.     $original=Pad $original_short
  99.     $costume=Pad $costume_short
  100.  
  101.     $index=$script:content.IndexOf($original)
  102.     $extratext = 'CE1MotorCharacterSetting'
  103.     if($index -ne -1){
  104.        
  105.  
  106.         if($original.Length -ne $costume.Length){
  107.             if($original.Length -le $costume.Length){
  108.                 $extraCount=$costume.Length-$original.Length
  109.                 $original+=$extratext.Substring(0,$extraCount)
  110.             }
  111.             if($original.Length -gt $costume.Length){
  112.                 $costume=$costume.PadRight($original.Length,"`0")
  113.             }
  114.  
  115.  
  116.  
  117.  
  118.         }
  119.         Write-Host "Swapping" $original_short "for" $costume_short
  120.         [regex]$pattern = $original
  121.         $script:content=$pattern.replace($script:content, $costume, 1)
  122.     }else {
  123.         Write-Host "Couldn't find " $original_short
  124.     }
  125.    
  126.  
  127. }
  128.  
  129. function SetCostume {
  130.     param (
  131.         [string]$original,
  132.         [string]$costume
  133.     )
  134.  
  135.     $names = @{
  136.         'Joker' = 'Hero', '0'
  137.         'Skull' = 'Ryuji', '1'
  138.         'Panther' = 'Ann', '3'
  139.         'Fox' = 'Yusuke', '4'
  140.         'Queen' = 'Makoto', '5'
  141.         'Noir' = 'Haru', '6'
  142.         'Navi' = 'Futaba', '7'
  143.         'Sophie' = 'Sophia', '8'
  144.       }
  145.  
  146.     $info=$names[$original]
  147.     $name=$info[0]
  148.     $num=$info[1]
  149.  
  150.     $costumenum=$script:costumes[$costume]
  151.     $originalfile='H000'+$num+'_'+$original
  152.     $replacement=$costumenum+$num+'_'+$name+'_'+$costume
  153.  
  154.     InnerSwap $originalfile $replacement
  155. }
  156. Function SaveFile{
  157.     Write-Host "Writing file"
  158.     Set-Content -Path $output -Value $script:content
  159.     Write-Host "Finished"
  160. }
  161.  
  162. LoadFile
  163. SwapCostumes
  164. SaveFile
Advertisement
Comments
Add Comment
Please, Sign In to add comment