示例#1
0
    static List <ImportFile> ReadImportFile(IntPtr hMpq, string impFile)
    {
        List <ImportFile> result = null;

        IntPtr hFile;

        if (StormLib.SFileOpenFileEx(hMpq, impFile, 0u, out hFile))
        {
            var fSize = StormLib.SFileGetFileSize(hFile, 0u);
            if (fSize < 0xFFFFFFFFu)
            {
                var buffer = Marshal.AllocHGlobal((int)fSize);
                if (StormLib.SFileReadFile(hFile, buffer, fSize, 0u, IntPtr.Zero))
                {
                    int offset  = 0;
                    var version = Marshal.ReadInt32(buffer, offset);
                    if (version < 2)
                    {
                        offset += sizeof(int);
                        var fileCount = Marshal.ReadInt32(buffer, offset);
                        offset += sizeof(int);
                        result  = new List <ImportFile>(fileCount);
                        for (int i = 0; i < fileCount; i++)
                        {
                            var bt     = (version > 0) && ((Marshal.ReadByte(buffer, offset++) & 1) > 0);
                            var strLen = SeekStrLen(buffer, offset, fSize);
                            var data   = new byte[strLen];
                            Marshal.Copy(buffer + offset, data, 0, data.Length);
                            offset += strLen + 1;
                            result.Add(new ImportFile(Encoding.UTF8.GetString(data), bt));
                        }
                    }
                }
                Marshal.FreeHGlobal(buffer);
            }
            else
            {
                result = new List <ImportFile>();
            }
        }
        if (hFile != IntPtr.Zero)
        {
            StormLib.SFileCloseFile(hFile);
        }

        return(result);
    }
示例#2
0
    static string DetectImpFile(IntPtr hMpq)
    {
        string impFile = null;

        for (int i = 0; (i < archTypes.Length) && (impFile == null); i++)
        {
            var    archType = archTypes[i];
            IntPtr hFile;
            if (StormLib.SFileOpenFileEx(hMpq, archType.DetectFile, 0u, out hFile) && (StormLib.SFileGetFileSize(hFile, 0u) < 0xFFFFFFFFu))
            {
                impFile = archType.ImpFile;
            }

            if (hFile != IntPtr.Zero)
            {
                StormLib.SFileCloseFile(hFile);
            }
        }
        return(impFile);
    }