Skip to content

Instantly share code, notes, and snippets.

@Bananasft
Last active September 7, 2016 12:44
Show Gist options
  • Save Bananasft/87672f0ed7ed540d10cb202d79b04ab1 to your computer and use it in GitHub Desktop.
Save Bananasft/87672f0ed7ed540d10cb202d79b04ab1 to your computer and use it in GitHub Desktop.
Searches for .mbin files inside a directory that match the given template type
function Get-MBinType
{
PARAM(
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[System.IO.FileInfo]$File
)
PROCESS
{
$start = 0x18
$end = 0x58
$b = ([char[]](Get-Content $File.FullName -Encoding Byte -TotalCount $end) -join '').Substring($start).Trim("`0")
$b = &{If($b[0] -eq 'c'){$b.Substring(1)}else{$b}}
return $b
}
}
function Find-FileByMbinType
{
PARAM(
[Parameter(Mandatory = $true)]
[string]$Path,
[Parameter(Mandatory = $true)]
[string]$Type,
[Parameter(Mandatory = $false)]
[switch]$Recurse
)
PROCESS
{
if(!(Test-Path $Path))
{
Write-Error "Path $Path doesn't exist!"
return
}
$Type = $Type.Trim([char]0x9D) # No idea why this is necessary
if($Recurse)
{$files = Get-ChildItem -Path $Path -Filter *.mbin -Recurse}
else
{$files = Get-ChildItem -Path $Path -Filter *.mbin}
$files | % {
$mbinType = Get-MBinType -File $_
if($mbinType -eq $Type)
{
Write-Output $_.FullName
}
}
}
}
# Change -Path "..." to the path the .mbin files are located in
# Change -Type "..." to the type that should be found
# If recursion is not wanted, omit the -Recurse parameter
Find-FileByMbinType -Path "C:\NMS\unpacked\" -Type "GcCreatureStupidNameTable" -Recurse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment