Skip to content

Instantly share code, notes, and snippets.

@y-ack
Created March 19, 2017 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-ack/11b7d6c01b08c8edf10b2dcaae9ee290 to your computer and use it in GitHub Desktop.
Save y-ack/11b7d6c01b08c8edf10b2dcaae9ee290 to your computer and use it in GitHub Desktop.
Now I can edit map data in a text editor
#Use examples:
#Get-Content route1.blk | MapBytesToText -Width 10
#(Invoke-WebRequest https://raw.githubusercontent.com/pret/pokeyellow/master/maps/route1.blk).Content | MapBytesToText -Width 10
#Takes .blk files and outputs a table of tile block indexes I can actually work with
#The resulting format can be eaten by MapBytesToText to convert back into .blk
function MapBytesToText {
param([Parameter(Mandatory=$True,Position=1,ValueFromPipeline=$True)][String]$File,
[Parameter(Mandatory=$False)][Int]$Width)
$Width = $Width*4
$formattedbytes = ([System.Text.Encoding]::UTF8.GetBytes($File)) | Foreach-Object {$_.toString().PadLeft(3," ")}
$formattedbytes = $formattedbytes -join ','
if($Width) {$formattedbytes = $formattedbytes -replace "(.{$Width})","`$1`n"}
$formattedbytes
}
#Takes a formatted string of tile block indexes e.g.
# 10,78,86,86,86,77,
# 10,78,13,13,13,77
# as produced by MapBytesToText and converts for output to e.g. a .blk file
function MapStringToBytes {
param([Parameter(Mandatory=$True,Position=1,ValueFromPipeline=$True)][String]$In)
[System.Text.Encoding]::UTF8.GetString(($In -replace "[ `n]", "") -split ',')
}
#If there are no bugs, this flow should produce identical files.
#$mapdata = (Invoke-WebRequest https://raw.githubusercontent.com/pret/pokeyellow/master/maps/route1.blk).Content
#$mapdata | MapBytesToText -Width 10 | MapStringToBytes | Out-File route1.blk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment