Exemplo n.º 1
0
        public static CNC_File Read(byte[] rawBytes)
        {
            //Validation
            if (BitConverter.ToInt32(rawBytes, 0) != CNC_SIGNATURE)
            {
                throw new InvalidDataException("CNC_SIGNATURE not found at offset 0x0. Parse failed.");
            }

            int count  = BitConverter.ToUInt16(rawBytes, 6);
            int offset = BitConverter.ToInt32(rawBytes, 8);

            //Parse file
            CNC_File cncFile = new CNC_File()
            {
                CncEntries = new List <CNC_Entry>()
            };

            for (int i = 0; i < count; i++)
            {
                cncFile.CncEntries.Add(CNC_Entry.Read(rawBytes, offset));
                offset += 12;
            }

            return(cncFile);
        }
Exemplo n.º 2
0
        public static List <byte> Write(CNC_Entry cncEntry)
        {
            List <byte> bytes = new List <byte>();

            bytes.AddRange(BitConverter.GetBytes(ushort.Parse(cncEntry.I_00)));
            bytes.AddRange(BitConverter.GetBytes(cncEntry.I_02));
            bytes.AddRange(BitConverter.GetBytes(cncEntry.I_04));
            bytes.AddRange(BitConverter.GetBytes(ushort.Parse(cncEntry.I_06)));
            bytes.AddRange(BitConverter.GetBytes(ushort.Parse(cncEntry.I_08)));
            bytes.AddRange(BitConverter.GetBytes(ushort.Parse(cncEntry.I_10)));
            return(bytes);
        }
Exemplo n.º 3
0
        public byte[] SaveToBytes()
        {
            List <byte> bytes = new List <byte>();

            //Header
            bytes.AddRange(BitConverter.GetBytes(CNC_SIGNATURE));
            bytes.AddRange(BitConverter.GetBytes((UInt16)65534));
            bytes.AddRange(BitConverter.GetBytes((UInt16)CncEntries.Count));
            bytes.AddRange(BitConverter.GetBytes((UInt32)12));

            //Entries
            for (int i = 0; i < CncEntries.Count; i++)
            {
                bytes.AddRange(CNC_Entry.Write(CncEntries[i]));
            }

            return(bytes.ToArray());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a CncEntry to the file. If an entry with the same IDs exist then it will overwrite that one.
        /// </summary>
        /// <param name="cncEntry"></param>
        public void AddEntry(CNC_Entry cncEntry)
        {
            int charaId     = int.Parse(cncEntry.I_00);
            int costume     = cncEntry.I_02;
            int modelPreset = cncEntry.I_04;

            for (int i = 0; i < CncEntries.Count; i++)
            {
                if (int.Parse(CncEntries[i].I_00) == charaId && CncEntries[i].I_02 == costume && CncEntries[i].I_04 == modelPreset)
                {
                    CncEntries[i] = cncEntry;
                    return;
                }
            }

            //Entry didn't already exist, so add it as a new entry.
            CncEntries.Add(cncEntry);
        }