Пример #1
0
        int SubStrCount(string str, string substr)
        {
            if (str == "" || substr == "")
            {
                return(0);
            }

            return(ByteHandling.CountBytes(Encoding.ASCII.GetBytes(str.ToCharArray()), Encoding.ASCII.GetBytes(substr.ToCharArray())));
        }
Пример #2
0
        //TODO: save and load set of prefixes to options.
        private void AddLocalizedStrings()
        {
            HashSet <string> hs;

            if (locStringsPrefixes.Length == 0)
            {
                hs = new HashSet <string>();
            }
            else
            {
                hs = new HashSet <string>(locStringsPrefixes.AsEnumerable());
            }

            bool setUpdated = false;

            foreach (RawFileData rawfile in rawFiles)
            {
                int offset = rawfile.Contents.IndexOf("&\"");
                while (offset != -1)
                {
                    if (rawfile.Contents[offset + 2] != '\"')
                    {
                        int    underlineOffset = rawfile.Contents.IndexOf("_", offset);
                        string s  = rawfile.Contents.Substring(offset + 2, underlineOffset - offset - 2);
                        string rn = rawfile.Name;
                        hs.Add(s);
                        setUpdated = true;
                    }
                    offset = rawfile.Contents.IndexOf("&\"", offset + 2);
                }
            }
            if (setUpdated)
            {
                locStringsPrefixes = hs.ToArray();
            }

            int locStringIndex = 0;

            foreach (string prefix in hs)
            {
                byte[] seek = Encoding.ASCII.GetBytes(string.Format(":{0}:", prefix));
                seek[0] = 0;
                seek[seek.Length - 1] = (byte)'_';
                int offset = ByteHandling.FindBytes(zd.DecompressedData, seek);
                while (offset != -1)
                {
                    int    startOfValueOffset = ByteHandling.FindByteBackward(zd.DecompressedData, 0xFF, offset) + 1;
                    int    endOfKeyOffset     = ByteHandling.FindByte(zd.DecompressedData, 0x00, offset + 1);
                    string value = ByteHandling.GetString(zd.DecompressedData, startOfValueOffset, offset);
                    string key   = ByteHandling.GetString(zd.DecompressedData, offset + 1, endOfKeyOffset);
                    locStrings.Add(new LocalizedStringData(locStringIndex, prefix, key, value, offset + 1, startOfValueOffset));
                    ++locStringIndex;
                    offset = ByteHandling.FindBytes(zd.DecompressedData, seek, offset + 1);
                }
            }
        }
Пример #3
0
        private void Parse_IW3_Unsigned(byte[] ff)
        {
            version        = ByteHandling.GetBytes(ff, 8, 12);
            compressedZone = ByteHandling.GetBytes(ff, 12);

            if (!version.SequenceEqual(HeaderIW3VersionUnsigned))
            {
                throw new Exception("Warning: fastfile version differs from default for this fastfile type."); //TODO: change exception type and message
            }
            ver = FastFileType.IW3_UNSIGNED;
        }
Пример #4
0
        //TODO: write localized strings asset
        private void WriteAssetData()
        {
            foreach (RawFileData rawFile in assetData.RawFiles)
            {
                if (!rawFile.Changed)
                {
                    continue;
                }

                if (rawFile.Size > rawFile.OriginalSize)
                {
                    throw new InternalBufferOverflowException("Attempting to overrun rawfile data: " + rawFile.Name);
                }

                zoneData.DecompressedData = ByteHandling.SetBytes(zoneData.DecompressedData, rawFile.ContentsOffset, rawFile.OriginalSize, 0x00);
                zoneData.DecompressedData = ByteHandling.ReplaceBytes(zoneData.DecompressedData, rawFile.ContentsOffset, Encoding.ASCII.GetBytes(rawFile.Contents));
            }
        }
Пример #5
0
        void AddRawFiles(byte[] extension)
        {
            int offset = ByteHandling.FindBytes(zd.DecompressedData, extension);

            while (offset != -1)
            {
                int    startOfNameOffset = ByteHandling.FindByteBackward(zd.DecompressedData, 0xFF, offset + 1) + 1;
                int    endOfNameOffset   = ByteHandling.FindByte(zd.DecompressedData, 0x00, offset + 1);
                int    assetSize         = ByteHandling.GetDword(zd.DecompressedData, startOfNameOffset - 8);
                string assetName         = ByteHandling.GetString(zd.DecompressedData, startOfNameOffset, endOfNameOffset);
                int    startOfContents   = endOfNameOffset + 1;
                int    endOfContents     = ByteHandling.FindByte(zd.DecompressedData, 0x00, startOfContents);
                string contents          = ByteHandling.GetString(zd.DecompressedData, startOfContents, endOfContents);

                rawFiles.Add(new RawFileData(rawfileIndex, assetName, startOfNameOffset, contents, assetSize, startOfContents));
                ++rawfileIndex;
                offset = ByteHandling.FindBytes(zd.DecompressedData, extension, offset + 1);
            }
        }
Пример #6
0
        public void ParseZoneHeader()
        {
            g_streamOutSize = ByteHandling.GetDword(decompressedData, 0);
            for (int i = 0; i < 9; ++i)
            {
                g_streamBlockSize[i] = ByteHandling.GetDword(decompressedData, 4 * (i + 1));
            }

            listStringCount  = ByteHandling.GetDword(decompressedData, 0x2C);
            assetsCount      = ByteHandling.GetDword(decompressedData, 0x34);
            listStringOffset = 0x3C + listStringCount * 4;
            listStrings      = new string[listStringCount];

            //Getting the strings from list
            int listStringStrStartOffset = listStringOffset;
            int listStringStrEndOffset   = listStringOffset;

            for (int i = 0; i < listStringCount; ++i)
            {
                if ((uint)ByteHandling.GetDword(decompressedData, 0x3C + 4 * i) == 0xFFFFFFFF)
                {
                    listStringStrEndOffset   = ByteHandling.FindByte(decompressedData, 0x00, listStringStrStartOffset);
                    listStrings[i]           = ByteHandling.GetString(decompressedData, listStringStrStartOffset, listStringStrEndOffset);
                    listStringStrStartOffset = listStringStrEndOffset + 1;
                }
            }

            assetsListOffset = listStringCount > 0 ? listStringStrEndOffset + 1 : listStringStrEndOffset;

            //Getting the assets' count from assets list
            for (int i = 0; i < assetsCount; ++i)
            {
                int assetType = ByteHandling.GetDword(decompressedData, assetsListOffset + 8 * i);
                assetsTypesCount[assetType]++;
            }

            assetsDataOffset = assetsListOffset + assetsCount * 8;
        }
Пример #7
0
        // Detects fastfile type and calls appropriate header parser.
        public void Parse()
        {
            byte[] ffContents;
            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                ffContents   = new byte[fs.Length];
                originalSize = fs.Read(ffContents, 0, (int)fs.Length);
            }

            originalSize = ffContents.Length;
            if (originalSize < 8)
            {
                throw new Exception("Not a fastfile"); //TODO: new exception and correct message.
            }
            byte[] ffHeader = ByteHandling.GetBytes(ffContents, 0, 8);
            if (ffHeader.SequenceEqual(HeaderIW3Unsigned))
            {
                Parse_IW3_Unsigned(ffContents);
            }
            else
            {
                throw new Exception("Unknown fastfile type"); //TODO: new exception and correct message.
            }
        }