public static string ToPonyCode(this PonyData data) { var bits = new BitArray(data.Name.Length * 6 + 276); var index = 0; bits.AddBits(ref index, data.Race, 2); bits.AddBits(ref index, data.HairColor0, 24); bits.AddBits(ref index, data.HairColor1, 24); bits.AddBits(ref index, data.BodyColor, 24); bits.AddBits(ref index, data.EyeColor, 24); bits.AddBits(ref index, data.HoofColor, 24); bits.AddBits(ref index, data.Mane, 8); bits.AddBits(ref index, data.Tail, 8); bits.AddBits(ref index, data.Eye, 8); bits.AddBits(ref index, data.Hoof, 5); bits.AddBits(ref index, data.CutieMark0, 10); bits.AddBits(ref index, data.CutieMark1, 10); bits.AddBits(ref index, data.CutieMark2, 10); bits.AddBits(ref index, data.Gender, 2); bits.AddBits(ref index, BitConverter.ToInt32(BitConverter.GetBytes(data.BodySize), 0), 32); bits.AddBits(ref index, BitConverter.ToInt32(BitConverter.GetBytes(data.HornSize), 0), 32); bits.AddBits(ref index, Math.Min(31, data.Name.Length - 1), 5); string name = data.Name; for (int i = 0; i < name.Length; i++) { char @char = name[i]; bits.AddBits(ref index, @char.EncodeChar(), 6); } bits.AddBits(ref index, data.HairColor2, 24); var buffer = new byte[(bits.Length + 7) >> 3]; bits.CopyTo(buffer, 0); return(Convert.ToBase64String(buffer)); }