Advertisement
dragonbane

convertNameToOoTCharset

Mar 14th, 2021
1,497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1.  private byte[] convertNameToOoTCharset(string name)
  2.         {
  3.             char[] userName = name.ToCharArray();
  4.             byte[] convertedName = new byte[8];
  5.             byte nameIndex = 0;
  6.  
  7.             foreach (byte c in Encoding.ASCII.GetBytes(userName))
  8.             {
  9.                 byte adjustedChar = 0;
  10.  
  11.                 if (c >= Encoding.ASCII.GetBytes("0")[0] && c <= Encoding.ASCII.GetBytes("9")[0])
  12.                 {
  13.                     adjustedChar = (byte)(c - Encoding.ASCII.GetBytes("0")[0]);
  14.                 }
  15.                 else if (c >= Encoding.ASCII.GetBytes("A")[0] && c <= Encoding.ASCII.GetBytes("Z")[0])
  16.                 {
  17.                     adjustedChar = (byte)(c + 0x6A);
  18.                 }
  19.                 else if (c >= Encoding.ASCII.GetBytes("a")[0] && c <= Encoding.ASCII.GetBytes("z")[0])
  20.                 {
  21.                     adjustedChar = (byte)(c + 0x64);
  22.                 }
  23.                 else if (c == Encoding.ASCII.GetBytes(".")[0])
  24.                 {
  25.                     adjustedChar = 0xEA;
  26.                 }
  27.                 else if (c == Encoding.ASCII.GetBytes("-")[0])
  28.                 {
  29.                     adjustedChar = 0xE4;
  30.                 }
  31.                 else if (c == Encoding.ASCII.GetBytes(" ")[0])
  32.                 {
  33.                     adjustedChar = 0xDF;
  34.                 }
  35.                 else
  36.                 {
  37.                     continue;
  38.                 }
  39.  
  40.                 convertedName[nameIndex] = adjustedChar;
  41.  
  42.                 nameIndex++;
  43.  
  44.                 if (nameIndex >= 8)
  45.                     break;
  46.             }
  47.  
  48.             for (byte i = nameIndex; i < 8; i++) {
  49.                 convertedName[i] = 0xDF;
  50.             }
  51.  
  52.             return convertedName;
  53.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement