public static byte[] GetBytes(string String, int maxSize = 0) { if (Save_Type == SaveType.Animal_Crossing) { byte[] returnedString = new byte[maxSize > 0 ? maxSize : String.Length]; TextElementEnumerator t = StringInfo.GetTextElementEnumerator(String); int i = 0; while (t.MoveNext() && i < returnedString.Length) { if (Char_Dictionary.ContainsValue((string)t.Current)) { returnedString[i] = Char_Dictionary.FirstOrDefault(o => o.Value == (string)t.Current).Key; } else { returnedString[i] = Encoding.UTF8.GetBytes(new char[1] { String[t.ElementIndex] })[0]; } i++; } for (int x = 0; x < returnedString.Length; x++) { if (returnedString[x] == 0) { returnedString[x] = 0x20; } } return(returnedString); } else if (Save_Type == SaveType.Doubutsu_no_Mori || Save_Type == SaveType.Doubutsu_no_Mori_Plus || Save_Type == SaveType.Doubutsu_no_Mori_e_Plus) { byte[] String_Bytes = new byte[maxSize > 0 ? maxSize : String.Length]; for (int i = 0; i < String.Length; i++) { if (i >= String_Bytes.Length) { break; } if (StringUtility.Doubutsu_no_Mori_e_Plus_Char_Map.ContainsValue(String[i].ToString())) { String_Bytes[i] = StringUtility.Doubutsu_no_Mori_e_Plus_Char_Map.First(o => o.Value == String[i].ToString()).Key; } else { String_Bytes[i] = Encoding.ASCII.GetBytes(new char[1] { String[i] })[0]; } } if (maxSize > 0 && String.Length < maxSize) { for (int i = String.Length; i < maxSize; i++) { String_Bytes[i] = 0x20; } } return(String_Bytes); } else if (Save_Type == SaveType.Wild_World) { byte[] String_Buffer = StringUtility.To_Wild_World_String(Encoding.UTF8.GetBytes(String)); if (maxSize > 0) { Array.Resize(ref String_Buffer, maxSize); } return(String_Buffer); } else if (Save_Type == SaveType.City_Folk) { byte[] String_Buffer = new byte[maxSize > 0 ? maxSize : String.Length * 2]; //Characters are now unicode byte[] String_Bytes = Encoding.Unicode.GetBytes(String); for (int i = 0; i < String_Bytes.Length; i += 2) { Buffer.BlockCopy(String_Bytes.Skip(i).Take(2).Reverse().ToArray(), 0, String_Buffer, i, 2); } return(String_Buffer); } else if (Save_Type == SaveType.New_Leaf || Save_Type == SaveType.Welcome_Amiibo) { byte[] String_Buffer = Encoding.Unicode.GetBytes(String); if (maxSize > 0) { Array.Resize(ref String_Buffer, maxSize); } return(String_Buffer); } else { MainForm.Debug_Manager.WriteLine(string.Format("StringUtil was passed an unknown SaveType enum. Received Type: {0}", Save_Type.ToString()), DebugLevel.Error); return(null); } }
public ACString(byte[] stringBuffer, SaveType saveType) { Save_Type = saveType; String_Bytes = stringBuffer; switch (saveType) { case SaveType.Doubutsu_no_Mori: case SaveType.Doubutsu_no_Mori_Plus: case SaveType.Doubutsu_no_Mori_e_Plus: Char_Dictionary = StringUtility.Doubutsu_no_Mori_e_Plus_Char_Map; break; case SaveType.Animal_Crossing: Char_Dictionary = StringUtility.AC_CharacterDictionary; break; case SaveType.Wild_World: Char_Dictionary = StringUtility.WW_CharacterDictionary; break; default: Char_Dictionary = null; break; } if ((saveType == SaveType.Doubutsu_no_Mori || saveType == SaveType.Doubutsu_no_Mori_Plus || saveType == SaveType.Animal_Crossing || saveType == SaveType.Doubutsu_no_Mori_e_Plus || saveType == SaveType.Wild_World) && Char_Dictionary != null) { foreach (byte b in stringBuffer) { if (Char_Dictionary.ContainsKey(b)) { String += Char_Dictionary[b]; } else { String += Encoding.UTF8.GetString(saveType == SaveType.Wild_World ? StringUtility.Fix_Wild_World_String(new byte[1] { b }) : new byte[1] { b }); } } } else if (saveType == SaveType.City_Folk) { for (int i = 0; i < stringBuffer.Length; i += 2) { String += Encoding.Unicode.GetString(stringBuffer.Skip(i).Take(2).Reverse().ToArray()); } } else if (saveType == SaveType.New_Leaf || saveType == SaveType.Welcome_Amiibo) { String = Encoding.Unicode.GetString(stringBuffer); } }