# Updates the scripts inside Fishing.rbxlx from src/ WITHOUT touching the map. # Studio must be closed. A backup is saved to backups\ first. # Run: powershell -ExecutionPolicy Bypass -File update-place.ps1 $ErrorActionPreference = 'Stop' $root = $PSScriptRoot $enc = New-Object System.Text.UTF8Encoding($false) $placePath = Join-Path $root 'Fishing.rbxlx' if (Test-Path "$placePath.lock") { throw "Roblox Studio has Fishing.rbxlx open. Close Studio first." } # src folder -> service class in the place $services = [ordered]@{ 'ReplicatedFirst' = 'ReplicatedFirst' 'ReplicatedStorage' = 'ReplicatedStorage' 'ServerScriptService' = 'ServerScriptService' 'StarterPlayer\StarterPlayerScripts' = 'StarterPlayerScripts' } $scripts = @() foreach ($rel in $services.Keys) { $dir = Join-Path "$root\src" $rel if (-not (Test-Path $dir)) { continue } Get-ChildItem $dir -File -Filter *.lua | ForEach-Object { $n = $_.Name if ($n -like '*.server.lua') { $class = 'Script'; $name = $n -replace '\.server\.lua$', '' } elseif ($n -like '*.client.lua') { $class = 'LocalScript'; $name = $n -replace '\.client\.lua$', '' } else { $class = 'ModuleScript'; $name = $n -replace '\.lua$', '' } $src = [System.IO.File]::ReadAllText($_.FullName, $enc) if ($src.Contains(']]>') -or $src.Contains('')) { throw "Unsupported text in $n" } $scripts += @{ Name = $name; Class = $class; Service = $services[$rel]; Source = $src } } } # backup $backupDir = Join-Path $root 'backups' New-Item -ItemType Directory -Force $backupDir | Out-Null $stamp = Get-Date -Format 'yyyyMMdd-HHmmss' Copy-Item $placePath (Join-Path $backupDir "Fishing-$stamp.rbxlx") $xml = [System.IO.File]::ReadAllText($placePath, $enc) foreach ($s in $scripts) { # all items of this class with this exact name $pattern = '\s*' $found = @() foreach ($m in [regex]::Matches($xml, $pattern)) { $propsEnd = $xml.IndexOf('', $m.Index) $seg = $xml.Substring($m.Index, $propsEnd - $m.Index) if ($seg -match '([^<]*)' -and $Matches[1] -eq $s.Name) { $found += @{ Start = $m.Index; PropsEnd = $propsEnd } } } if ($found.Count -gt 1) { throw "Several $($s.Class) named $($s.Name) in the place - not touching it." } $cdata = '' if ($found.Count -eq 1) { $f = $found[0] $seg = $xml.Substring($f.Start, $f.PropsEnd - $f.Start) $srcTag = [regex]::Match($seg, '[\s\S]*?') $newTag = '' + $cdata + '' if ($srcTag.Success) { $absStart = $f.Start + $srcTag.Index $xml = $xml.Substring(0, $absStart) + $newTag + $xml.Substring($absStart + $srcTag.Length) } else { $xml = $xml.Substring(0, $f.PropsEnd) + $newTag + $xml.Substring($f.PropsEnd) } Write-Host "updated $($s.Service)/$($s.Name)" } else { # new script: put it right after the service's own block $svc = [regex]::Match($xml, '\s*') if (-not $svc.Success) { throw "Service $($s.Service) not found in the place." } $insertAt = $xml.IndexOf('', $svc.Index) + ''.Length $ref = 'RBX' + ([guid]::NewGuid().ToString('N').ToUpper()) $item = "`n$($s.Name)$cdata" $xml = $xml.Substring(0, $insertAt) + $item + $xml.Substring($insertAt) Write-Host "added $($s.Service)/$($s.Name)" } } [System.IO.File]::WriteAllText($placePath, $xml, $enc) Write-Host "Done. Backup: backups\Fishing-$stamp.rbxlx"