示例#1
0
文件: WzLua.cs 项目: stu98832/libwz
        /// <summary> 從<see cref="WzFile"/>中讀取資料並建立<see cref="WzLua"/>實體 </summary>
        public static WzLua FromWzFile(WzFile file)
        {
            WzLua lua = new WzLua();

            WzFileStream fs = new WzFileStream(file.Stream, WzKeyType.K);

            fs.BaseOffset = file.Offset;
            lua.Name      = file.Name;
            lua.Read(fs);

            return(lua);
        }
示例#2
0
文件: WzLua.cs 项目: stu98832/libwz
        /// <summary> 使用指定的加密金鑰,將加密過的<see cref="WzLua"/>資料寫入<see cref="WzFile"/>中 </summary>
        /// <param name="name"> <see cref="WzFile"/>的名子 </param>
        /// <param name="key"> 加密金鑰 </param>
        public WzFile ToWzFile(string name, WzKeyType key = WzKeyType.None)
        {
            WzFile file = new WzFile(name, key);

            WzFileStream stream = new WzFileStream(file.Stream, file.KeyType);

            this.Write(stream);
            file.Size = (int)stream.Length;
            stream.Dispose(false);

            return(file);
        }
示例#3
0
        /// <summary> 透過指定路徑取得對應的<see cref="WzVariant"/> </summary>
        /// <param name="path"> <see cref="WzVariant"/>的所在位置 </param>
        /// <param name="img"> 尋找時所開啟的<see cref="WzImage"/>物件 </param>
        public WzVariant GetVariant(string path, ref WzImage img)
        {
            int    index = path.IndexOf(".img/") + 4;
            WzFile file  = this[path.Substring(0, index)] as WzFile;

            if (file != null)
            {
                img = WzImage.FromWzFile(file);
                return(img[path.Substring(index + 1)]);
            }
            return(WzVariant.Null);
        }
示例#4
0
        internal bool Read(WzFileStream zs)
        {
            this.Items.Clear();
            zs.Seek(this.Offset);

            int count = zs.Read4(true);

            for (int i = 0; i < count; i++)
            {
                WzArchiveItem     item = null;
                WzArchiveItemType itemtype;
                string            itemname = zs.StringPool.DirectoryRead(out itemtype, WzArchiveItemType.Reference);

                if (itemtype == WzArchiveItemType.Directory)
                {
                    item = new WzDirectory(itemname);
                }
                else if (itemtype == WzArchiveItemType.File)
                {
                    item = new WzFile(itemname, zs.KeyType)
                    {
                        Stream = zs.BaseStream
                    };
                }
                else
                {
                    throw new InvalidDataException("Undefined item type : " + (int)itemtype);
                }

                item.Size     = zs.Read4(true);
                item.Checksum = zs.Read4(true);
                uint offKey = HashTools.GenerateOffsetKey((uint)zs.Tell(), this.Archive.DataOffset, this.Archive.Hash);
                item.Offset = HashTools.DecryptOffsetHash(zs.Read4u(), offKey, this.Archive.DataOffset);

                if ((item.Offset + item.Size) > zs.Length)
                {
                    return(false);
                }

                this.Add(item);
            }
            for (int i = 0; i < this.Items.Count; i++)
            {
                if (this.Items[i].Type == WzArchiveItemType.Directory)
                {
                    (this.Items[i] as WzDirectory).Read(zs);
                }
            }

            return(true);
        }
示例#5
0
        /// <summary> 從<see cref="WzFile"/>中讀取資料並建立<see cref="WzImage"/>實體 </summary>
        /// <param name="file"> </param>
        /// <param name="dynamic"> 是否使用動態讀取。使用動態讀取可以減少圖片和聲音佔用大量記憶體空間,但讀取速度會稍微慢一點 </param>
        public static WzImage FromWzFile(WzFile file, bool dynamic = false)
        {
            if (file == null)
            {
                return(null);
            }

            WzImage      img = new WzImage();
            WzFileStream fs  = new WzFileStream(file.Stream, file.KeyType);

            fs.BaseOffset = file.Offset;
            fs.Seek(file.Offset);
            fs.DynamicRead = dynamic;
            img.Read(fs);

            if (!dynamic)
            {
                fs.Dispose(false);
            }
            return(img);
        }