# Converts a string to a UTF16-encoded byte array. This looks like ASCII characters separated by 0x00 in most cases.
$nameBytes = ConvertTo-StringBytes -Input $NewPlayerAlias -Utf16 1
$output = ([byte[]]@( 0xFF, 0xFE ))
$output += $nameBytes
Set-Content -Out "$InstallDirectory\HomeWorldRM\Bin\Profiles\Profile1\name.dat" -Value $output -Encoding Byte
Set-Content -Out "$InstallDirectory\Homeworld2Classic\Bin\Profiles\Profile1\name.dat" -Value $output -Encoding Byte
#HomeworldRM\Bin\Profiles\Profile1\name.dat requires hexedit for name game truncates name automatically
#Homeworld2Classic\Bin\Profiles\Profile1\name.dat requires hexedit for name game truncates name automatically
Write-ReplaceContentInFile -Pattern '^ chatname = (.+)' -Substitution " chatname = ""$NewPlayerAlias""," -FilePath "$InstallDirectory\HomeworldRM\Bin\Profiles\Profile1\PLAYERCFG.LUA"
Write-ReplaceContentInFile -Pattern '^ chatname = (.+)' -Substitution " chatname = ""$NewPlayerAlias""," -FilePath "$InstallDirectory\Homeworld2Classic\Bin\Profiles\Profile1\PLAYERCFG.LUA"
Write-ReplaceContentInFile -Pattern '^PlayerName (.+)' -Substitution "PlayerName $NewPlayerAlias" -FilePath "$InstallDirectory\Homeworld1Classic\exe\Homeworld.cfg"