示例#1
0
        public static CharacterFile Load(byte[] rawData, bool issave = true)
        {
            try
            {
                int dataIdentifier = (rawData.Length < 3015)
                    ? 0
                    : BitConverter.ToInt32(rawData, rawData.Length - 4);

                const int cardOffset = 0;
                const int dataLenght = 3011;

                int dataOffset  = rawData.Length - dataIdentifier;
                int thumbOffset = dataOffset + dataLenght + 4;

                int cardLenght  = dataOffset;
                int thumbLenght = BitConverter.ToInt32(rawData, thumbOffset - 4);

                int rawOffset = thumbOffset + thumbLenght;
                int rawLength = rawData.Length - 4 - rawOffset;

                CharacterFile file = new CharacterFile();

                file.CardBytes = new byte[cardLenght];
                Buffer.BlockCopy(rawData, cardOffset, file.CardBytes, 0, file.CardBytes.Length);

                file.ThumbBytes = new byte[thumbLenght];
                Buffer.BlockCopy(rawData, thumbOffset, file.ThumbBytes, 0, file.ThumbBytes.Length);

                file.DataBytes = new byte[dataLenght];
                Buffer.BlockCopy(rawData, dataOffset, file.DataBytes, 0, file.DataBytes.Length);

                if (!issave)
                {
                    file.RawBytes = new byte[rawLength];
                    if (rawLength > 0)
                    {
                        Buffer.BlockCopy(rawData, rawOffset, file.RawBytes, 0, file.RawBytes.Length);
                    }
                }

                int version = BitConverter.ToInt32(file.DataBytes, 16);

                bool thousand = version <= 101;
                return(thousand
                    ? null
                    : file);
            }
            catch
            {
                return(null);
            }
        }
示例#2
0
 public static CharacterFile Load(string path)
 {
     try
     {
         FileStream    fs = new FileStream(path, FileMode.Open);
         CharacterFile cf = Load(fs);
         fs.Close();
         return(cf);
     }
     catch
     {
         return(null);
     }
 }