public void AddChitinKey(ref FileStruct.TSChitinKey tsChitinKey)
        {
            ChitinKey ckey = CreateChitinKey(ref tsChitinKey);

            if (ckey != null)
            {
                this.ckeyDictionary.Add(ckey.name, ckey, ckey.resourceType);
            }
        }
        public static bool ReadChitinKeyFile(ChitinIndex chitinIndex, string fileName)
        {
            FileStream fileStream = Utils.ReadFileStream(fileName);

            if (fileStream == null)
            {
                return(false);
            }

            buff = new byte[FileStruct.TSChitinHeaderSize];
            fileStream.Position = 0;

            FileStruct.TSChitinHeader chitinHead =
                (FileStruct.TSChitinHeader)ReadBuffer <FileStruct.TSChitinHeader>
                    (fileStream, buff, FileStruct.TSChitinHeaderSize);

            if (GlobalDefs.CHITINKEY_SIGNATURE != Utils.CharsToString(chitinHead.signature))
            {
                throw new ArgumentException("Warning: Invalid signature in *.key file.");
            }

            // Load up all the biffs into a collection
            buff = new byte[FileStruct.TSChitinBiffSize];
            fileStream.Position = chitinHead.biffOffset;

            chitinIndex.CbiffCollection.SetCapacity(chitinHead.biffCount + 30);

            for (int c = 0; c < chitinHead.biffCount; c++)
            {
                FileStruct.TSChitinBiff tsBiff =
                    (FileStruct.TSChitinBiff)ReadBuffer <FileStruct.TSChitinBiff>
                        (fileStream, buff, FileStruct.TSChitinBiffSize);

                string biffName = ReadOffsetStringBuffer(fileStream, tsBiff.biffNameOffset, tsBiff.biffNameSize);
                chitinIndex.AddChitinBiff(ref tsBiff, ref biffName);
            }

            // Load up the chitinkeys into the super dictionary
            buff = new byte[FileStruct.TSChitinKeySize];
            fileStream.Position = chitinHead.ckeyOffset;

            for (int c = 0; c < chitinHead.ckeyCount; c++)
            {
                FileStruct.TSChitinKey tsCkey =
                    (FileStruct.TSChitinKey)ReadBuffer <FileStruct.TSChitinKey>
                        (fileStream, buff, FileStruct.TSChitinKeySize);

                chitinIndex.AddChitinKey(ref tsCkey);
            }

            fileStream.Close();

            return(true);
        }
        private static ChitinKey CreateChitinKey(ref FileStruct.TSChitinKey tsChitinKey)
        {
            ChitinKey ckey = new ChitinKey();

            ckey.name = Utils.CharsToString(tsChitinKey.ckeyName).ToUpper();

            if (ckey.name == "")
            {
                return(null);
            }

            ckey.resourceType = ResourceStruct.ResourceFromCode(tsChitinKey.ckeyType);
            ckey.ckeyIndex    = (ushort)(tsChitinKey.ckeyIndex & 0x3FFF);
            ckey.tileIndex    = (ushort)(((tsChitinKey.ckeyIndex >> 14) | ((tsChitinKey.biffIndex & 0x0F) << 2)) - 1);
            ckey.biffIndex    = (ushort)(tsChitinKey.biffIndex >> 4);
            ckey.isBiffed     = true;

            return(ckey);
        } // false for override