Code:
Public Shared CNVRT As New PKMFontConverter
Public Shared Function PKMBytesToString(ByVal Byte_Array() As Byte) _
As String
PokemonLib.InitializeDictionaries()
If Byte_Array.Length = 1 Then
Dim buf As Byte = Byte_Array(0)
ReDim Byte_Array(1)
Byte_Array(0) = buf
End If
Dim strName As String = ""
For iCount As Integer = 0 To Byte_Array.Length - 1 Step 2
Dim iByte As UInt16 = BitConverter.ToUInt16(New Byte() {Byte_Array(iCount), Byte_Array(iCount + 1)}, 0)
If iByte >= 0 Then
If iByte <> &HFFFF Then strName &= Char.ConvertFromUtf32(CNVRT.PKMToUnicode(iByte))
End If
If Byte_Array(iCount + 0) = &HFF And Byte_Array(iCount + 1) = &HFF _
Then Return strName
Next
Return strName
End Function
Public Shared Function StringToPKMBytes(ByVal mString As String, Optional ByVal Terminator As Boolean = False) As Byte()
If mString = "" Then Return New Byte() {}
Dim Data((mString.Length * 2) + 1) As Byte
Dim strData As String = ""
For i As Integer = 0 To mString.Length - 1
Dim _i As Byte() = BitConverter.GetBytes(CNVRT.UnicodeToPKM(Char.ConvertToUtf32(mString, i)))
strData &= _i(0) & "," & _i(1) & ","
Next
strData = strData.Substring(0, strData.LastIndexOf(","))
Dim _strData() As String = strData.Split(",")
CNVRT.DictionaryInitialize()
For i As Integer = 0 To _strData.Length - 1
Try
Data(i) = Integer.Parse(_strData(i))
Catch ex As Exception
Console.WriteLine(Err.Number & ": " & ex.Message)
Stop
End Try
Next
If Terminator Then
If _strData.Length = Data.Length Then
Data(Data.Length - 2) = &HFF
Data(Data.Length - 1) = &HFF
Else
Data(_strData.Length) = &HFF
Data(_strData.Length + 1) = &HFF
End If
End If
strData = ""
For i As Integer = 0 To Data.Length - 1
strData &= Hex(Data(i)) & ", "
Next
If Terminator Then Return Data
Dim dataout(Data.Length - 3) As Byte
Array.Copy(Data, 0, dataout, 0, dataout.Length)
Return dataout
End Function
Bookmarks