FindDataFile() public static méthode

public static FindDataFile ( string path ) : string
path string
Résultat string
Exemple #1
0
        public TileMatrixPatch(TileMatrix matrix, int index)
        {
            if (PatchLandEnabled)
            {
                var mapDataPath  = Core.FindDataFile($"mapdif{index}.mul", false);
                var mapIndexPath = Core.FindDataFile($"mapdifl{index}.mul", false);

                if (mapDataPath != null && mapIndexPath != null)
                {
                    LandBlocks = PatchLand(matrix, mapDataPath, mapIndexPath);
                }
            }

            if (PatchStaticsEnabled)
            {
                var staDataPath   = Core.FindDataFile($"stadif{index}.mul", false);
                var staIndexPath  = Core.FindDataFile($"stadifl{index}.mul", false);
                var staLookupPath = Core.FindDataFile($"stadifi{index}.mul", false);

                if (staDataPath != null && staIndexPath != null && staLookupPath != null)
                {
                    StaticBlocks = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
                }
            }
        }
        public TileMatrixPatch(TileMatrix matrix, int index)
        {
            if (!TileMatrixPatch.m_Enabled)
            {
                return;
            }
            object[] objArray1 = new object[1];
            objArray1[0] = index;
            string text1 = Core.FindDataFile("mapdif{0}.mul", objArray1);

            objArray1    = new object[1];
            objArray1[0] = index;
            string text2 = Core.FindDataFile("mapdifl{0}.mul", objArray1);

            if (File.Exists(text1) && File.Exists(text2))
            {
                this.m_LandBlocks = this.PatchLand(matrix, text1, text2);
            }
            objArray1    = new object[1];
            objArray1[0] = index;
            string text3 = Core.FindDataFile("stadif{0}.mul", objArray1);

            objArray1    = new object[1];
            objArray1[0] = index;
            string text4 = Core.FindDataFile("stadifl{0}.mul", objArray1);

            objArray1    = new object[1];
            objArray1[0] = index;
            string text5 = Core.FindDataFile("stadifi{0}.mul", objArray1);

            if ((File.Exists(text3) && File.Exists(text4)) && File.Exists(text5))
            {
                this.m_StaticBlocks = this.PatchStatics(matrix, text3, text4, text5);
            }
        }
Exemple #3
0
        public static void Configure()
        {
            string filePath = Core.FindDataFile("TileData.mul");

            if (File.Exists(filePath))
            {
                using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader bin = new BinaryReader(fs);

                    LandTable = new LandData[0x4000];

                    for (int i = 0; i < 0x4000; ++i)
                    {
                        if ((i & 0x1F) == 0)
                        {
                            bin.ReadInt32();                             // header
                        }

                        TileFlag flags = (TileFlag)bin.ReadInt64();
                        bin.ReadInt16();                         // skip 2 bytes -- textureID

                        LandTable[i] = new LandData(ReadNameString(bin), flags);
                    }

                    ItemTable = new ItemData[0x10000];

                    for (int i = 0; i < 0x10000; ++i)
                    {
                        if ((i & 0x1F) == 0)
                        {
                            bin.ReadInt32();                             // header
                        }

                        TileFlag flags   = (TileFlag)bin.ReadInt64();
                        int      weight  = bin.ReadByte();
                        int      quality = bin.ReadByte();
                        bin.ReadInt16();
                        bin.ReadByte();
                        int quantity = bin.ReadByte();
                        bin.ReadInt32();
                        bin.ReadByte();
                        int value  = bin.ReadByte();
                        int height = bin.ReadByte();

                        ItemTable[i] = new ItemData(ReadNameString(bin), flags, weight, quality, quantity, value, height);
                    }
                }

                MaxLandValue = LandTable.Length - 1;
                MaxItemValue = ItemTable.Length - 1;
            }
            else
            {
                log.Fatal("TileData.mul was not found. Make sure your x-runuo.xml is properly configured.");
                Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");

                throw new Exception(string.Format("TileData: {0} not found", filePath));
            }
        }
Exemple #4
0
        static MultiData()
        {
            string multiUOPPath = Core.FindDataFile("MultiCollection.uop");

            if (File.Exists(multiUOPPath))
            {
                LoadUOP(multiUOPPath);
                UsingUOPFormat = true;
                return;
            }

            string idxPath = Core.FindDataFile("multi.idx");
            string mulPath = Core.FindDataFile("multi.mul");

            if (File.Exists(idxPath) && File.Exists(mulPath))
            {
                var idx = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                m_IndexReader = new BinaryReader(idx);

                var stream = new FileStream(mulPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                m_StreamReader = new BinaryReader(stream);

                string vdPath = Core.FindDataFile("verdata.mul");

                if (!File.Exists(vdPath))
                {
                    return;
                }

                using FileStream fs = new FileStream(vdPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                BinaryReader bin = new BinaryReader(fs);

                int count = bin.ReadInt32();

                for (int i = 0; i < count; ++i)
                {
                    int file   = bin.ReadInt32();
                    int index  = bin.ReadInt32();
                    int lookup = bin.ReadInt32();
                    int length = bin.ReadInt32();
                    bin.ReadInt32(); // extra

                    if (file == 14 && index >= 0 && lookup >= 0 && length > 0)
                    {
                        bin.BaseStream.Seek(lookup, SeekOrigin.Begin);

                        Components[index] = new MultiComponentList(bin, length / 12);

                        bin.BaseStream.Seek(24 + i * 20, SeekOrigin.Begin);
                    }
                }

                bin.Close();
            }
            else
            {
                Console.WriteLine("Warning: Multi data files not found");
            }
        }
Exemple #5
0
        // Methods
        static TileData()
        {
            BinaryReader reader1;
            int          num1;
            TileFlag     flag1;
            int          num2;
            TileFlag     flag2;
            int          num3;
            int          num4;
            int          num5;
            int          num6;
            int          num7;

            TileData.m_StringBuffer = new byte[20];
            string text1 = Core.FindDataFile("TileData.mul");

            if (File.Exists(text1))
            {
                using (FileStream stream1 = new FileStream(text1, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    reader1             = new BinaryReader(stream1);
                    TileData.m_LandData = new LandData[16384];
                    for (num1 = 0; (num1 < 16384); ++num1)
                    {
                        if ((num1 & 31) == 0)
                        {
                            reader1.ReadInt32();
                        }
                        flag1 = ((TileFlag)reader1.ReadInt32());
                        reader1.ReadInt16();
                        TileData.m_LandData[num1] = new LandData(TileData.ReadNameString(reader1), flag1);
                    }
                    TileData.m_ItemData = new ItemData[16384];
                    for (num2 = 0; (num2 < 16384); ++num2)
                    {
                        if ((num2 & 31) == 0)
                        {
                            reader1.ReadInt32();
                        }
                        flag2 = ((TileFlag)reader1.ReadInt32());
                        num3  = reader1.ReadByte();
                        num4  = reader1.ReadByte();
                        reader1.ReadInt16();
                        reader1.ReadByte();
                        num5 = reader1.ReadByte();
                        reader1.ReadInt32();
                        reader1.ReadByte();
                        num6 = reader1.ReadByte();
                        num7 = reader1.ReadByte();
                        TileData.m_ItemData[num2] = new ItemData(TileData.ReadNameString(reader1), flag2, num3, num4, num5, num6, num7);
                    }
                    return;
                }
            }
            Console.WriteLine("TileData.mul was not found");
            Console.WriteLine("Make sure your Scripts/Misc/DataPath.cs is properly configured");
            Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");
            throw new Exception(string.Format("TileData: {0} not found", text1));
        }
Exemple #6
0
        static TileData()
        {
            string filePath = Core.FindDataFile("TileData.mul");

            if (File.Exists(filePath))
            {
                using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader bin = new BinaryReader(fs);

                    m_LandData = new LandData[0x4000];

                    for (int i = 0; i < 0x4000; ++i)
                    {
                        if ((i & 0x1F) == 0)
                        {
                            bin.ReadInt32();                             // header
                        }

                        TileFlag flags = (TileFlag)bin.ReadInt32();
                        bin.ReadInt16();                         // skip 2 bytes -- textureID

                        m_LandData[i] = new LandData(ReadNameString(bin), flags);
                    }

                    m_ItemData = new ItemData[0x4000];

                    for (int i = 0; i < 0x4000; ++i)
                    {
                        if ((i & 0x1F) == 0)
                        {
                            bin.ReadInt32();                             // header
                        }

                        TileFlag flags   = (TileFlag)bin.ReadInt32();
                        int      weight  = bin.ReadByte();
                        int      quality = bin.ReadByte();
                        bin.ReadInt16();
                        bin.ReadByte();
                        int quantity = bin.ReadByte();
                        bin.ReadInt32();
                        bin.ReadByte();
                        int value  = bin.ReadByte();
                        int height = bin.ReadByte();

                        m_ItemData[i] = new ItemData(ReadNameString(bin), flags, weight, quality, quantity, value, height);
                    }
                }
            }
            else
            {
                Console.WriteLine("TileData.mul was not found");
                Console.WriteLine("Make sure your Scripts/Misc/DataPath.cs is properly configured");
                Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");

                throw new Exception(String.Format("TileData: {0} not found", filePath));
            }
        }
Exemple #7
0
        /// <summary>
        ///     Reads animdata.mul and fills <see cref="AnimData" />
        /// </summary>
        public static void Initialize()
        {
            AnimData = new Hashtable();
            string path = Core.FindDataFile("animdata.mul");

            if (path != null)
            {
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (BinaryReader bin = new BinaryReader(fs))
                    {
                        unsafe
                        {
                            int     id = 0;
                            int     h  = 0;
                            byte    unk;
                            byte    fcount;
                            byte    finter;
                            byte    fstart;
                            sbyte[] fdata;
                            m_Header = new int[bin.BaseStream.Length / (4 + 8 * (64 + 4))];
                            while (h < m_Header.Length)
                            {
                                m_Header[h++] = bin.ReadInt32(); // chunk header
                                                                 // Read 8 tiles
                                byte[] buffer = bin.ReadBytes(544);
                                fixed(byte *buf = buffer)
                                {
                                    byte *data = buf;

                                    for (int i = 0; i < 8; ++i, ++id)
                                    {
                                        fdata = new sbyte[64];
                                        for (int j = 0; j < 64; ++j)
                                        {
                                            fdata[j] = (sbyte)*data++;
                                        }
                                        unk    = *data++;
                                        fcount = *data++;
                                        finter = *data++;
                                        fstart = *data++;
                                        if (fcount > 0)
                                        {
                                            AnimData[id] = new Data(fdata, unk, fcount, finter, fstart);
                                        }
                                    }
                                }
                            }
                            int remaining = (int)(bin.BaseStream.Length - bin.BaseStream.Position);
                            if (remaining > 0)
                            {
                                m_Unknown = bin.ReadBytes(remaining);
                            }
                        }
                    }
                }
            }
        }
Exemple #8
0
        public FileIndex(string idxFile, string mulFile, int entryCount)
            : this(entryCount)
        {
            do
            {
                _IdxPath = Core.FindDataFile(idxFile);
                _BinPath = Core.FindDataFile(mulFile);

                try
                {
                    if (_IdxPath != null && System.IO.File.Exists(_IdxPath))
                    {
                        FileStream index;

                        try
                        { index = new FileStream(_IdxPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); }
                        catch { index = null; }

                        if (index != null)
                        {
                            using (index)
                            {
                                IdxLength = (int)index.Length;
                                IdxCount  = IdxLength / EntryDataSize;

                                if (Index.Length != IdxCount)
                                {
                                    Index = new Entry3D[IdxCount];
                                }

                                unsafe
                                {
                                    fixed(Entry3D *buffer = Index)
                                    NativeReader.Read(index, buffer, IdxLength);
                                }
                            }

                            _IdxLoaded = true;
                        }
                    }
                }
                catch { }

                try
                {
                    if (_BinPath != null)
                    {
                        try
                        { File = new FileInfo(_BinPath); }
                        catch { File = null; }

                        _BinLoaded = File?.Exists ?? false;
                    }
                }
                catch { }
            }while (CheckRetry());
        }
Exemple #9
0
        static MultiData()
        {
            string idxPath = Core.FindDataFile("Multi.idx");
            string mulPath = Core.FindDataFile("Multi.mul");

            if (File.Exists(idxPath) && File.Exists(mulPath))
            {
                m_Index       = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                m_IndexReader = new BinaryReader(m_Index);

                m_Stream       = new FileStream(mulPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                m_StreamReader = new BinaryReader(m_Stream);

                m_Components = new MultiComponentList[(int)(m_Index.Length / 12)];

                string vdPath = Core.FindDataFile("Verdata.mul");

                if (File.Exists(vdPath))
                {
                    using (FileStream fs = new FileStream(vdPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryReader bin = new BinaryReader(fs);

                        int count = bin.ReadInt32();

                        for (int i = 0; i < count; ++i)
                        {
                            int file   = bin.ReadInt32();
                            int index  = bin.ReadInt32();
                            int lookup = bin.ReadInt32();
                            int length = bin.ReadInt32();
                            /*int extra = */
                            bin.ReadInt32();

                            if (file == 14 && index >= 0 && index < m_Components.Length && lookup >= 0 && length > 0)
                            {
                                bin.BaseStream.Seek(lookup, SeekOrigin.Begin);

                                m_Components[index] = new MultiComponentList(bin, length / 12);

                                bin.BaseStream.Seek(24 + (i * 20), SeekOrigin.Begin);
                            }
                        }

                        bin.Close();
                    }
                }
            }
            else
            {
                log.Warning("Multi data files not found");

                m_Components = new MultiComponentList[0];
            }
        }
Exemple #10
0
        static MultiData()
        {
            var multiUOPPath = Core.FindDataFile("MultiCollection.uop", false);

            if (File.Exists(multiUOPPath))
            {
                LoadUOP(multiUOPPath);
                UsingUOPFormat = true;
                return;
            }

            var idxPath = Core.FindDataFile("multi.idx");
            var mulPath = Core.FindDataFile("multi.mul");

            var idx = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);

            m_IndexReader = new BinaryReader(idx);

            var stream = new FileStream(mulPath, FileMode.Open, FileAccess.Read, FileShare.Read);

            m_StreamReader = new BinaryReader(stream);

            var vdPath = Core.FindDataFile("verdata.mul", false);

            if (!File.Exists(vdPath))
            {
                return;
            }

            using var fs = new FileStream(vdPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            var bin = new BinaryReader(fs);

            var count = bin.ReadInt32();

            for (var i = 0; i < count; ++i)
            {
                var file   = bin.ReadInt32();
                var index  = bin.ReadInt32();
                var lookup = bin.ReadInt32();
                var length = bin.ReadInt32();
                bin.ReadInt32(); // extra

                if (file == 14 && index >= 0 && lookup >= 0 && length > 0)
                {
                    bin.BaseStream.Seek(lookup, SeekOrigin.Begin);

                    Components[index] = new MultiComponentList(bin, length / 12);

                    bin.BaseStream.Seek(24 + i * 20, SeekOrigin.Begin);
                }
            }

            bin.Close();
        }
        public static void Configure()
        {
            string filePath = Core.FindDataFile("TileData.mul");

            if (filePath != null)
            {
                using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader bin = new BinaryReader(fs);

                    m_LandData = new LandData[0x4000];

                    for (int i = 0; i < 0x4000; ++i)
                    {
                        if ((i & 0x1F) == 0)
                        {
                            bin.ReadInt32();                             // header
                        }

                        TileFlag flags = (TileFlag)bin.ReadInt32();
                        bin.ReadInt16();                         // skip 2 bytes -- textureID

                        m_LandData[i] = new LandData(ReadNameString(bin), flags);
                    }

                    m_ItemData = new ItemData[0x4000];

                    for (int i = 0; i < 0x4000; ++i)
                    {
                        if ((i & 0x1F) == 0)
                        {
                            bin.ReadInt32();                             // header
                        }

                        TileFlag flags   = (TileFlag)bin.ReadInt32();
                        int      weight  = bin.ReadByte();
                        int      quality = bin.ReadByte();
                        bin.ReadInt16();
                        bin.ReadByte();
                        int quantity = bin.ReadByte();
                        bin.ReadInt32();
                        bin.ReadByte();
                        int value  = bin.ReadByte();
                        int height = bin.ReadByte();

                        m_ItemData[i] = new ItemData(ReadNameString(bin), flags, weight, quality, quantity, value, height);
                    }
                }
            }
            else
            {
                throw new Exception("TileData.mul was not found");
            }
        }
Exemple #12
0
        static MultiData()
        {
            string idxPath = Core.FindDataFile("multi.idx");
            string mulPath = Core.FindDataFile("multi.mul");

            if (File.Exists(idxPath) && File.Exists(mulPath))
            {
                Index       = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                IndexReader = new BinaryReader(Index);

                Stream       = new FileStream(mulPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                StreamReader = new BinaryReader(Stream);

                Components = new MultiComponentList[(int)(Index.Length / 12)];

                string vdPath = Core.FindDataFile("verdata.mul");

                if (File.Exists(vdPath))
                {
                    using FileStream fs = new(vdPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    BinaryReader bin = new BinaryReader(fs);

                    int count = bin.ReadInt32();

                    for (int i = 0; i < count; ++i)
                    {
                        int file   = bin.ReadInt32();
                        int index  = bin.ReadInt32();
                        int lookup = bin.ReadInt32();
                        int length = bin.ReadInt32();
                        _ = bin.ReadInt32();

                        if (file == 14 && index >= 0 && index < Components.Length && lookup >= 0 && length > 0)
                        {
                            bin.BaseStream.Seek(lookup, SeekOrigin.Begin);

                            Components[index] = new MultiComponentList(bin, length / 12);

                            bin.BaseStream.Seek(24 + (i * 20), SeekOrigin.Begin);
                        }
                    }

                    bin.Close();
                }
            }
            else
            {
                Console.WriteLine("Warning: Multi data files not found");

                Components = Array.Empty <MultiComponentList>();
            }
        }
Exemple #13
0
        public StringList(string language, bool format)
        {
            Language = language;
            Table    = new Dictionary <int, string>();

            string path = Core.FindDataFile(string.Format("Cliloc.{0}", language));

            if (path == null)
            {
                log.Warning("Cliloc.{0} not found", language);
                Entries = new StringEntry[0];
                return;
            }

            log.Info("Loading localization strings");

            List <StringEntry> list = new List <StringEntry>();

            using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                byte[] buffer = new byte[1024];

                bin.ReadInt32();
                bin.ReadInt16();

                while (bin.BaseStream.Length != bin.BaseStream.Position)
                {
                    int number = bin.ReadInt32();
                    bin.ReadByte();
                    int length = bin.ReadInt16();

                    if (length > buffer.Length)
                    {
                        buffer = new byte[(length + 1023) & ~1023];
                    }

                    bin.Read(buffer, 0, length);
                    string text = Encoding.UTF8.GetString(buffer, 0, length);

                    if (format)
                    {
                        text = FormatArguments(text);
                    }

                    list.Add(new StringEntry(number, text));
                    Table[number] = text;
                }
            }

            Entries = list.ToArray();
        }
        public StringList(string language, bool format)
        {
            m_Language = language;
            m_Table    = new Hashtable();

            string path = Core.FindDataFile(String.Format("cliloc.{0}", language));

            if (path == null)
            {
                Console.WriteLine("Warning: cliloc.{0} not found", language);
                m_Entries = new StringEntry[0];
                return;
            }

            Console.Write("Localization strings: Loading...");

            ArrayList list = new ArrayList();

            using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                bin.ReadInt32();
                bin.ReadInt16();

                while (bin.PeekChar() != -1)
                {
                    int number = bin.ReadInt32();
                    bin.ReadByte();
                    int length = bin.ReadInt16();

                    if (length > m_Buffer.Length)
                    {
                        m_Buffer = new byte[(length + 1023) & ~1023];
                    }

                    bin.Read(m_Buffer, 0, length);
                    string text = Encoding.UTF8.GetString(m_Buffer, 0, length);

                    if (format)
                    {
                        text = FormatArguments(text);
                    }

                    list.Add(new StringEntry(number, text));
                    m_Table[number] = text;
                }
            }

            m_Entries = (StringEntry[])list.ToArray(typeof(StringEntry));

            Console.WriteLine("done");
        }
Exemple #15
0
        // Methods
        static MultiData()
        {
            string       text3;
            BinaryReader reader1;
            int          num1;
            int          num2;
            int          num3;
            int          num4;
            int          num5;
            int          num6;
            string       text1 = Core.FindDataFile("Multi.idx");
            string       text2 = Core.FindDataFile("Multi.mul");

            if (File.Exists(text1) && File.Exists(text2))
            {
                MultiData.m_Index        = new FileStream(text1, FileMode.Open, FileAccess.Read, FileShare.Read);
                MultiData.m_IndexReader  = new BinaryReader(MultiData.m_Index);
                MultiData.m_Stream       = new FileStream(text2, FileMode.Open, FileAccess.Read, FileShare.Read);
                MultiData.m_StreamReader = new BinaryReader(MultiData.m_Stream);
                MultiData.m_Components   = new MultiComponentList[((int)(MultiData.m_Index.Length / 12))];
                text3 = Core.FindDataFile("Verdata.mul");
                if (!File.Exists(text3))
                {
                    return;
                }
                using (FileStream stream1 = new FileStream(text3, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    reader1 = new BinaryReader(stream1);
                    num1    = reader1.ReadInt32();
                    for (num2 = 0; (num2 < num1); ++num2)
                    {
                        num3 = reader1.ReadInt32();
                        num4 = reader1.ReadInt32();
                        num5 = reader1.ReadInt32();
                        num6 = reader1.ReadInt32();
                        reader1.ReadInt32();
                        if ((((num3 == 14) && (num4 >= 0)) && ((num4 < MultiData.m_Components.Length) && (num5 >= 0))) && (num6 > 0))
                        {
                            reader1.BaseStream.Seek(num5, SeekOrigin.Begin);
                            MultiData.m_Components[num4] = new MultiComponentList(reader1, (num6 / 12));
                            reader1.BaseStream.Seek((24 + (num2 * 20)), SeekOrigin.Begin);
                        }
                    }
                    return;
                }
            }
            Console.WriteLine("Warning: Multi data files not found");
            MultiData.m_Components = new MultiComponentList[0];
        }
Exemple #16
0
        public StringList(string language, bool format)
        {
            Language = language;

            string path = Core.FindDataFile(string.Format("Cliloc.{0}", language));

            if (path == null)
            {
                Console.WriteLine("Cliloc.{0} not found", language);
                Entries = new List <StringEntry>(0);
                return;
            }

            StringTable = new Dictionary <int, string>();
            EntryTable  = new Dictionary <int, StringEntry>();
            Entries     = new List <StringEntry>();

            using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                byte[] buffer = new byte[1024];

                bin.ReadInt32();
                bin.ReadInt16();

                while (bin.BaseStream.Length != bin.BaseStream.Position)
                {
                    int number = bin.ReadInt32();
                    bin.ReadByte(); // flag
                    int length = bin.ReadInt16();

                    if (length > buffer.Length)
                    {
                        buffer = new byte[(length + 1023) & ~1023];
                    }

                    bin.Read(buffer, 0, length);
                    string text = Encoding.UTF8.GetString(buffer, 0, length);

                    StringEntry se = new StringEntry(number, text);
                    Entries.Add(se);

                    StringTable[number] = text;
                    EntryTable[number]  = se;
                }
            }
        }
Exemple #17
0
        public StringList(string language, bool format)
        {
            Language = language;

            var path = Core.FindDataFile($"Cliloc.{language}");

            if (path == null)
            {
                Console.WriteLine($"Cliloc.{language} not found");
                return;
            }

            using (var bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                var buffer = new byte[1024];

                bin.ReadInt32();
                bin.ReadInt16();

                while (bin.BaseStream.Length != bin.BaseStream.Position)
                {
                    var number = bin.ReadInt32();

                    bin.ReadByte(); // flag

                    int length = bin.ReadInt16();

                    if (length > buffer.Length)
                    {
                        buffer = new byte[(length + 1023) & ~1023];
                    }

                    bin.Read(buffer, 0, length);

                    var text = Encoding.UTF8.GetString(buffer, 0, length);

                    var se = new StringEntry(number, text);

                    EntryTable[number]  = se;
                    StringTable[number] = text;
                }
            }
        }
Exemple #18
0
        public static void AddCliloc(string lang)
        {
            StringList list = StringList.GetList(lang);

            if (list == null)
            {
                list = StringList.AddLanguage(lang);
            }

            string path = Core.FindDataFile(String.Format("cliloc.{0}", lang));

            if (path == null)
            {
                Console.WriteLine("Warning: cliloc.{0} not found", lang);
                return;
            }

            using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read), Encoding.ASCII))
            {
                bin.ReadInt32();
                bin.ReadInt16();

                Encoding utf8 = Encoding.GetEncoding("UTF-8", new EncoderReplacementFallback(""), new DecoderReplacementFallback(""));

                while (bin.PeekChar() != -1)
                {
                    int number = bin.ReadInt32();
                    bin.ReadByte();                     //State in Cliloc
                    int length = bin.ReadInt16();       //Max of 65535 characters

                    StringEntry entry = new StringEntry(number, LState.Original, StringList.FormatArguments(utf8.GetString(bin.ReadBytes(length))));

                    list.Table[number] = entry;
                }

                bin.Close();
            }
        }
Exemple #19
0
        public FileIndex(string idxFile, string mulFile, int length)
        {
            Index = new Entry3D[length];

            var idxPath = Core.FindDataFile(idxFile);

            _Path = Core.FindDataFile(mulFile);

            if (idxPath != null && _Path != null)
            {
                using (var index = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Stream = new FileStream(_Path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                    var count = (int)(index.Length / 12);
                    IdxLength = index.Length;
                    Index     = new Entry3D[count];
                    var gc     = GCHandle.Alloc(Index, GCHandleType.Pinned);
                    var buffer = new byte[index.Length];
                    index.Read(buffer, 0, (int)index.Length);
                    Marshal.Copy(buffer, 0, gc.AddrOfPinnedObject(), (int)index.Length);
                    gc.Free();
                }
            }
        }
        public TileMatrixPatch(TileMatrix matrix, int index)
        {
            if (!Enabled)
            {
                return;
            }

            var mapDataPath  = Core.FindDataFile($"mapdif{index}.mul", false);
            var mapIndexPath = Core.FindDataFile($"mapdifl{index}.mul", false);

            if (File.Exists(mapDataPath) && File.Exists(mapIndexPath))
            {
                m_LandBlocks = PatchLand(matrix, mapDataPath, mapIndexPath);
            }

            var staDataPath   = Core.FindDataFile($"stadif{index}.mul", false);
            var staIndexPath  = Core.FindDataFile($"stadifl{index}.mul", false);
            var staLookupPath = Core.FindDataFile($"stadifi{index}.mul", false);

            if (File.Exists(staDataPath) && File.Exists(staIndexPath) && File.Exists(staLookupPath))
            {
                m_StaticBlocks = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
            }
        }
        public TileMatrixPatch(TileMatrix matrix, int index)
        {
            if (!m_Enabled)
            {
                return;
            }

            string mapDataPath  = Core.FindDataFile("mapdif{0}.mul", index);
            string mapIndexPath = Core.FindDataFile("mapdifl{0}.mul", index);

            if (File.Exists(mapDataPath) && File.Exists(mapIndexPath))
            {
                m_LandBlocks = PatchLand(matrix, mapDataPath, mapIndexPath);
            }

            string staDataPath   = Core.FindDataFile("stadif{0}.mul", index);
            string staIndexPath  = Core.FindDataFile("stadifl{0}.mul", index);
            string staLookupPath = Core.FindDataFile("stadifi{0}.mul", index);

            if (File.Exists(staDataPath) && File.Exists(staIndexPath) && File.Exists(staLookupPath))
            {
                m_StaticBlocks = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath);
            }
        }
Exemple #22
0
        public FileIndex(
            string uopFile,
            int length,
            string uopEntryExtension,
            int idxLength,
            bool hasExtra)
        {
            Index = new Entry3D[length];

            MulPath = Core.FindDataFile(uopFile);

            /* UOP files support code, written by Wyatt (c) www.ruosi.org
             * idxLength variable was added for compatibility with legacy code for art (see art.cs)
             * At the moment the only UOP file having entries with extra field is gumpartlegacy.uop,
             * and it's two dwords in the beginning of the entry.
             * It's possible that UOP can include some entries with unknown hash: not really unknown for me, but
             * not useful for reading legacy entries. That's why i removed unknown hash exception throwing from this code
             */
            if (MulPath != null && MulPath.EndsWith(".uop"))
            {
                using (FileStream index = new FileStream(MulPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    Stream = new FileStream(MulPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);

                    FileInfo fi         = new FileInfo(MulPath);
                    string   uopPattern = fi.Name.Replace(fi.Extension, "").ToLowerInvariant();

                    using (BinaryReader br = new BinaryReader(Stream))
                    {
                        br.BaseStream.Seek(0, SeekOrigin.Begin);

                        if (br.ReadInt32() != 0x50594D)
                        {
                            return;
                        }

                        br.ReadInt64(); // version + signature
                        long nextBlock = br.ReadInt64();
                        br.ReadInt32(); // block capacity
                        int count = br.ReadInt32();

                        if (idxLength > 0)
                        {
                            IdxLength = idxLength * 12;
                        }

                        Dictionary <ulong, int> hashes = new Dictionary <ulong, int>();

                        for (int i = 0; i < length; i++)
                        {
                            string entryName = string.Format("build/{0}/{1:D8}{2}", uopPattern, i, uopEntryExtension);
                            ulong  hash      = UOPHash.HashLittle2(entryName);

                            if (!hashes.ContainsKey(hash))
                            {
                                hashes.Add(hash, i);
                            }
                        }

                        br.BaseStream.Seek(nextBlock, SeekOrigin.Begin);

                        do
                        {
                            int filesCount = br.ReadInt32();
                            nextBlock = br.ReadInt64();

                            for (int i = 0; i < filesCount; i++)
                            {
                                long  offset             = br.ReadInt64();
                                int   headerLength       = br.ReadInt32();
                                int   compressedLength   = br.ReadInt32();
                                int   decompressedLength = br.ReadInt32();
                                ulong hash = br.ReadUInt64();
                                br.ReadUInt32(); // Adler32
                                short flag = br.ReadInt16();

                                int entryLength = flag == 1 ? compressedLength : decompressedLength;

                                if (offset == 0)
                                {
                                    continue;
                                }

                                if (hashes.TryGetValue(hash, out int idx))
                                {
                                    if (idx < 0 || idx > Index.Length)
                                    {
                                        return;
                                    }

                                    Index[idx].lookup = (int)(offset + headerLength);
                                    Index[idx].length = entryLength;

                                    if (hasExtra)
                                    {
                                        long curPos = br.BaseStream.Position;

                                        br.BaseStream.Seek(offset + headerLength, SeekOrigin.Begin);

                                        byte[] extra = br.ReadBytes(8);

                                        ushort extra1 = (ushort)((extra[3] << 24) | (extra[2] << 16) | (extra[1] << 8) | extra[0]);
                                        ushort extra2 = (ushort)((extra[7] << 24) | (extra[6] << 16) | (extra[5] << 8) | extra[4]);

                                        Index[idx].lookup += 8;
                                        Index[idx].extra   = extra1 << 16 | extra2;

                                        br.BaseStream.Seek(curPos, SeekOrigin.Begin);
                                    }
                                }
                            }
                        }while (br.BaseStream.Seek(nextBlock, SeekOrigin.Begin) != 0);
                    }
                }
            }
        }
Exemple #23
0
        public TileMatrix(Map owner, int fileIndex, int mapID, int width, int height)
        {
            lock (m_Instances) {
                for (int i = 0; i < m_Instances.Count; ++i)
                {
                    TileMatrix tm = m_Instances[i];

                    if (tm.m_FileIndex == fileIndex)
                    {
                        lock (m_FileShare) {
                            lock (tm.m_FileShare) {
                                tm.m_FileShare.Add(this);
                                m_FileShare.Add(tm);
                            }
                        }
                    }
                }

                m_Instances.Add(this);
            }

            m_FileIndex   = fileIndex;
            m_Width       = width;
            m_Height      = height;
            m_BlockWidth  = width >> 3;
            m_BlockHeight = height >> 3;

            m_Owner = owner;

            if (fileIndex != 0x7F)
            {
                string mapPath = Core.FindDataFile("map{0}.mul", fileIndex);

                if (File.Exists(mapPath))
                {
                    m_Map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                }
                else
                {
                    mapPath = Core.FindDataFile("map{0}LegacyMUL.uop", fileIndex);

                    if (File.Exists(mapPath))
                    {
                        m_Map      = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        m_MapIndex = new UOPIndex(m_Map);
                    }
                }

                string indexPath = Core.FindDataFile("staidx{0}.mul", fileIndex);

                if (File.Exists(indexPath))
                {
                    m_Index       = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    m_IndexReader = new BinaryReader(m_Index);
                }

                string staticsPath = Core.FindDataFile("statics{0}.mul", fileIndex);

                if (File.Exists(staticsPath))
                {
                    m_Statics = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                }
            }

            m_EmptyStaticBlock = new StaticTile[8][][];

            for (int i = 0; i < 8; ++i)
            {
                m_EmptyStaticBlock[i] = new StaticTile[8][];

                for (int j = 0; j < 8; ++j)
                {
                    m_EmptyStaticBlock[i][j] = new StaticTile[0];
                }
            }

            m_InvalidLandBlock = new LandTile[196];

            m_LandTiles     = new LandTile[m_BlockWidth][][];
            m_StaticTiles   = new StaticTile[m_BlockWidth][][][][];
            m_StaticPatches = new int[m_BlockWidth][];
            m_LandPatches   = new int[m_BlockWidth][];

            m_Patch = new TileMatrixPatch(this, mapID);
        }
        static ProfessionInfo()
        {
            var profs = new List <ProfessionInfo>
            {
                new()
                {
                    ID       = 0, // Custom
                    Name     = "Advanced",
                    TopLevel = false,
                    GumpID   = 5571
                }
            };

            var file = Core.FindDataFile("prof.txt", false);

            if (!File.Exists(file))
            {
                var parent = Path.Combine(Core.BaseDirectory, "Data/Professions");
                file = Path.Combine(ExpansionInfo.GetEraFolder(parent), "prof.txt");
            }

            var maxProf = 0;

            if (File.Exists(file))
            {
                using var s = File.OpenText(file);

                while (!s.EndOfStream)
                {
                    var line = s.ReadLine();

                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    line = line.Trim();

                    if (!line.InsensitiveStartsWith("Begin"))
                    {
                        continue;
                    }

                    var prof = new ProfessionInfo();

                    int stats;
                    int valid;
                    var skills = stats = valid = 0;

                    while (!s.EndOfStream)
                    {
                        line = s.ReadLine();

                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }

                        line = line.Trim();

                        if (line.InsensitiveStartsWith("End"))
                        {
                            if (valid >= 4)
                            {
                                profs.Add(prof);
                            }

                            break;
                        }

                        var cols  = line.Split('\t', StringSplitOptions.RemoveEmptyEntries);
                        var key   = cols[0].ToLowerInvariant();
                        var value = cols[1].Trim('"');

                        if (key == "type" && value != "profession")
                        {
                            break;
                        }

                        switch (key)
                        {
                        case "truename":
                        {
                            prof.Name = value;
                            ++valid;
                        }
                        break;

                        case "nameid":
                            prof.NameID = Utility.ToInt32(value);
                            break;

                        case "descid":
                            prof.DescID = Utility.ToInt32(value);
                            break;

                        case "desc":
                        {
                            prof.ID = Utility.ToInt32(value);
                            if (prof.ID > maxProf)
                            {
                                maxProf = prof.ID;
                            }

                            ++valid;
                        }
                        break;

                        case "toplevel":
                            prof.TopLevel = Utility.ToBoolean(value);
                            break;

                        case "gump":
                            prof.GumpID = Utility.ToInt32(value);
                            break;

                        case "skill":
                        {
                            if (!TryGetSkillName(value, out var skillName))
                            {
                                break;
                            }

                            prof.Skills[skills++] = new SkillNameValue(skillName, Utility.ToInt32(cols[2]));

                            if (skills == prof.Skills.Length)
                            {
                                ++valid;
                            }
                        }
                        break;

                        case "stat":
                        {
                            if (!Enum.TryParse(value, out StatType stat))
                            {
                                break;
                            }

                            prof.Stats[stats++] = new StatNameValue(stat, Utility.ToInt32(cols[2]));

                            if (stats == prof.Stats.Length)
                            {
                                ++valid;
                            }
                        }
                        break;
                        }
                    }
                }
            }

            Professions = new ProfessionInfo[1 + maxProf];

            foreach (var p in profs)
            {
                Professions[p.ID] = p;
            }

            profs.Clear();
            profs.TrimExcess();
        }
Exemple #25
0
        static MultiData()
        {
            Components = new Dictionary <int, MultiComponentList>();

            var multicollectionPath = Core.FindDataFile("MultiCollection.uop");

            if (File.Exists(multicollectionPath))
            {
                UOPLoad(multicollectionPath);
                UsingUOPFormat = true;
            }
            else
            {
                var idxPath = Core.FindDataFile("multi.idx");
                var mulPath = Core.FindDataFile("multi.mul");

                if (File.Exists(idxPath) && File.Exists(mulPath))
                {
                    var idx = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    m_IndexReader = new BinaryReader(idx);

                    var stream = new FileStream(mulPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    m_StreamReader = new BinaryReader(stream);

                    var vdPath = Core.FindDataFile("verdata.mul");

                    if (File.Exists(vdPath))
                    {
                        using (var fs = new FileStream(vdPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            var bin = new BinaryReader(fs);

                            var count = bin.ReadInt32();

                            for (var i = 0; i < count; ++i)
                            {
                                var file   = bin.ReadInt32();
                                var index  = bin.ReadInt32();
                                var lookup = bin.ReadInt32();
                                var length = bin.ReadInt32();
                                /*int extra = */
                                bin.ReadInt32();

                                if (file == 14 && index >= 0 && lookup >= 0 && length > 0)
                                {
                                    bin.BaseStream.Seek(lookup, SeekOrigin.Begin);

                                    Components[index] = new MultiComponentList(bin, length / 12);

                                    bin.BaseStream.Seek(24 + (i * 20), SeekOrigin.Begin);
                                }
                            }

                            bin.Close();
                        }
                    }
                    else
                    {
                        Console.WriteLine("Warning: Multi data files not found!");
                    }
                }
            }
        }
Exemple #26
0
        static MultiData()
        {
            m_Components = new Dictionary <int, MultiComponentList>();

            string multicollectionPath = Core.FindDataFile("MultiCollection.uop");

            if (File.Exists(multicollectionPath))
            {
                UOPLoad(multicollectionPath);
                UsingUOPFormat = true;
            }
            else
            {
                string idxPath = Core.FindDataFile("multi.idx");
                string mulPath = Core.FindDataFile("multi.mul");

                if (File.Exists(idxPath) && File.Exists(mulPath))
                {
                    FileStream idx = new FileStream(idxPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    m_IndexReader = new BinaryReader(idx);

                    FileStream stream = new FileStream(mulPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    m_StreamReader = new BinaryReader(stream);

                    string vdPath = Core.FindDataFile("verdata.mul");

                    if (File.Exists(vdPath))
                    {
                        using (FileStream fs = new FileStream(vdPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            BinaryReader bin = new BinaryReader(fs);

                            int count = bin.ReadInt32();

                            for (int i = 0; i < count; ++i)
                            {
                                int file   = bin.ReadInt32();
                                int index  = bin.ReadInt32();
                                int lookup = bin.ReadInt32();
                                int length = bin.ReadInt32();
                                /*int extra = */
                                bin.ReadInt32();

                                if (file == 14 && index >= 0 && lookup >= 0 && length > 0)
                                {
                                    bin.BaseStream.Seek(lookup, SeekOrigin.Begin);

                                    m_Components[index] = new MultiComponentList(bin, length / 12);

                                    bin.BaseStream.Seek(24 + (i * 20), SeekOrigin.Begin);
                                }
                            }

                            bin.Close();
                        }
                    }
                    else
                    {
                        Console.WriteLine("Warning: verdata.mul not found. This is okay, modern clients have this deprecated.");
                    }
                }
            }
        }
Exemple #27
0
        static HueData()
        {
            int index = 0;

            if (CheckFile)
            {
                string path = Core.FindDataFile("hues.mul");

                if (path != null)
                {
                    using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        int blockCount = (int)fs.Length / 708;

                        if (blockCount > 375)
                        {
                            blockCount = 375;
                        }

                        m_Header = new int[blockCount];

                        int    structsize = Marshal.SizeOf(typeof(HueEntry));
                        byte[] buffer     = new byte[blockCount * (4 + 8 * structsize)];

                        GCHandle gc = GCHandle.Alloc(buffer, GCHandleType.Pinned);

                        try
                        {
                            fs.Read(buffer, 0, buffer.Length);

                            long currpos = 0;

                            for (int i = 0; i < blockCount; ++i)
                            {
                                IntPtr ptrheader = new IntPtr((long)gc.AddrOfPinnedObject() + currpos);

                                currpos += 4;

                                m_Header[i] = (int)Marshal.PtrToStructure(ptrheader, typeof(int));

                                for (int j = 0; j < 8; ++j, ++index)
                                {
                                    IntPtr ptr = new IntPtr((long)gc.AddrOfPinnedObject() + currpos);

                                    currpos += structsize;

                                    HueEntry cur = (HueEntry)Marshal.PtrToStructure(ptr, typeof(HueEntry));

                                    List[index] = new Hue(index, cur);
                                }
                            }
                        }
                        finally
                        {
                            gc.Free();
                        }
                    }
                }
            }

            while (index < List.Length)
            {
                List[index] = new Hue(index);

                ++index;
            }
        }
Exemple #28
0
        public TileMatrix(Map owner, int fileIndex, int mapID, int width, int height)
        {
            lock (m_Instances)
            {
                for (var i = 0; i < m_Instances.Count; ++i)
                {
                    var tm = m_Instances[i];

                    if (tm.m_FileIndex == fileIndex)
                    {
                        lock (m_FileShare)
                        {
                            lock (tm.m_FileShare)
                            {
                                tm.m_FileShare.Add(this);
                                m_FileShare.Add(tm);
                            }
                        }
                    }
                }

                m_Instances.Add(this);
            }

            m_FileIndex = fileIndex;
            BlockWidth  = width >> 3;
            BlockHeight = height >> 3;

            m_Owner = owner;

            if (fileIndex != 0x7F)
            {
                var mapPath = Core.FindDataFile($"map{fileIndex}LegacyMUL.uop", false, true);

                if (mapPath != null)
                {
                    m_MapStream = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    m_MapIndex  = new UOPIndex(m_MapStream);
                }
                else
                {
                    mapPath = Core.FindDataFile($"map{fileIndex}.mul", false, true);

                    if (mapPath != null)
                    {
                        m_MapStream = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    }
                }

                var indexPath = Core.FindDataFile($"staidx{fileIndex}.mul", false, true);

                if (indexPath != null)
                {
                    IndexStream   = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    m_IndexReader = new BinaryReader(IndexStream);
                }

                var staticsPath = Core.FindDataFile($"statics{fileIndex}.mul", false, true);

                if (staticsPath != null)
                {
                    DataStream = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                }
            }

            EmptyStaticBlock = new StaticTile[8][][];

            for (var i = 0; i < 8; ++i)
            {
                EmptyStaticBlock[i] = new StaticTile[8][];

                for (var j = 0; j < 8; ++j)
                {
                    EmptyStaticBlock[i][j] = Array.Empty <StaticTile>();
                }
            }

            m_InvalidLandBlock = new LandTile[196];

            m_LandTiles     = new LandTile[BlockWidth][][];
            m_StaticTiles   = new StaticTile[BlockWidth][][][][];
            m_StaticPatches = new int[BlockWidth][];
            m_LandPatches   = new int[BlockWidth][];

            Patch = new TileMatrixPatch(this, mapID);
        }
Exemple #29
0
        public FileIndex(string uopFile, int entryCount, string entryExt, bool extended)
            : this(entryCount)
        {
            do
            {
                _IdxPath = _BinPath = Core.FindDataFile(uopFile);

                try
                {
                    if (_BinPath != null)
                    {
                        try
                        { File = new FileInfo(_BinPath); }
                        catch { File = null; }

                        _BinLoaded = File?.Exists ?? false;
                    }
                }
                catch { }

                try
                {
                    if (File != null)
                    {
                        using (var stream = new FileStream(File.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                            using (var reader = new BinaryReader(stream))
                            {
                                if (reader.ReadInt32() == 0x50594D)
                                {
                                    reader.ReadInt64();                             // version + signature

                                    var nextBlock = reader.ReadInt64();

                                    reader.ReadInt32();                             // block capacity
                                    reader.ReadInt32();                             // block count

                                    var hashes = new Dictionary <ulong, int>();

                                    var root = $"build/{Path.GetFileNameWithoutExtension(_IdxPath).ToLowerInvariant()}";

                                    for (var i = 0; i < entryCount; i++)
                                    {
                                        hashes[UOPHash.HashLittle2($"{root}/{i:D8}{entryExt}")] = i;
                                    }

                                    stream.Seek(nextBlock, SeekOrigin.Begin);

                                    do
                                    {
                                        var filesCount = reader.ReadInt32();

                                        nextBlock = reader.ReadInt64();

                                        for (var i = 0; i < filesCount; i++)
                                        {
                                            var offset             = reader.ReadInt64();
                                            var headerLength       = reader.ReadInt32();
                                            var compressedLength   = reader.ReadInt32();
                                            var decompressedLength = reader.ReadInt32();
                                            var hash = reader.ReadUInt64();

                                            reader.ReadUInt32();                                     // Adler32

                                            var flag = reader.ReadInt16();

                                            var entryLength = flag == 1 ? compressedLength : decompressedLength;

                                            if (offset == 0 || !hashes.TryGetValue(hash, out var idx))
                                            {
                                                continue;
                                            }

                                            if (idx < 0 || idx > Index.Length)
                                            {
                                                continue;
                                            }

                                            Index[idx].Offset = (int)(offset + headerLength);
                                            Index[idx].Size   = entryLength;

                                            if (!extended)
                                            {
                                                continue;
                                            }

                                            var curPos = stream.Position;

                                            stream.Seek(offset + headerLength, SeekOrigin.Begin);

                                            var extra  = reader.ReadBytes(8);
                                            var extra1 = (ushort)((extra[3] << 24) | (extra[2] << 16) | (extra[1] << 8) | extra[0]);
                                            var extra2 = (ushort)((extra[7] << 24) | (extra[6] << 16) | (extra[5] << 8) | extra[4]);

                                            Index[idx].Offset += 8;
                                            Index[idx].Data    = extra1 << 16 | extra2;

                                            stream.Seek(curPos, SeekOrigin.Begin);
                                        }
                                    }while (stream.Seek(nextBlock, SeekOrigin.Begin) != 0);

                                    _IdxLoaded = true;
                                }
                            }
                    }
                }
                catch { }
            }while (CheckRetry());
        }
Exemple #30
0
        public FileIndex(string uopFile, int length, string uopEntryExtension, int idxLength, bool hasExtra)
        {
            Index = new Entry3D[length];

            _Path = Core.FindDataFile(uopFile);

            if (_Path != null && _Path.EndsWith(".uop"))
            {
                using (var index = new FileStream(_Path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Stream = new FileStream(_Path, FileMode.Open, FileAccess.Read, FileShare.Read);

                    var fi = new FileInfo(_Path);

                    var uopPattern = fi.Name.Replace(fi.Extension, "").ToLowerInvariant();

                    using (var br = new BinaryReader(Stream))
                    {
                        br.BaseStream.Seek(0, SeekOrigin.Begin);

                        if (br.ReadInt32() != 0x50594D)
                        {
                            return;
                        }

                        br.ReadInt64();                         // version + signature

                        var nextBlock = br.ReadInt64();

                        br.ReadInt32();                         // block capacity

                        var count = br.ReadInt32();

                        if (idxLength > 0)
                        {
                            IdxLength = idxLength * 12;
                        }

                        var hashes = new Dictionary <ulong, int>();

                        for (var i = 0; i < length; i++)
                        {
                            var entryName = System.String.Format("build/{0}/{1:D8}{2}", uopPattern, i, uopEntryExtension);

                            var hash = UOPHash.HashLittle2(entryName);

                            if (!hashes.ContainsKey(hash))
                            {
                                hashes.Add(hash, i);
                            }
                        }

                        br.BaseStream.Seek(nextBlock, SeekOrigin.Begin);

                        do
                        {
                            var filesCount = br.ReadInt32();

                            nextBlock = br.ReadInt64();

                            for (var i = 0; i < filesCount; i++)
                            {
                                var offset             = br.ReadInt64();
                                var headerLength       = br.ReadInt32();
                                var compressedLength   = br.ReadInt32();
                                var decompressedLength = br.ReadInt32();
                                var hash = br.ReadUInt64();

                                br.ReadUInt32();                                 // Adler32

                                var flag = br.ReadInt16();

                                var entryLength = flag == 1 ? compressedLength : decompressedLength;

                                if (offset == 0)
                                {
                                    continue;
                                }

                                if (hashes.TryGetValue(hash, out var idx))
                                {
                                    if (idx < 0 || idx > Index.Length)
                                    {
                                        return;
                                    }

                                    Index[idx].lookup = (int)(offset + headerLength);

                                    Index[idx].length = entryLength;

                                    if (hasExtra)
                                    {
                                        var curPos = br.BaseStream.Position;

                                        br.BaseStream.Seek(offset + headerLength, SeekOrigin.Begin);

                                        var extra  = br.ReadBytes(8);
                                        var extra1 = (ushort)((extra[3] << 24) | (extra[2] << 16) | (extra[1] << 8) | extra[0]);
                                        var extra2 = (ushort)((extra[7] << 24) | (extra[6] << 16) | (extra[5] << 8) | extra[4]);

                                        Index[idx].lookup += 8;
                                        Index[idx].extra   = extra1 << 16 | extra2;

                                        br.BaseStream.Seek(curPos, SeekOrigin.Begin);
                                    }
                                }
                            }
                        }while (br.BaseStream.Seek(nextBlock, SeekOrigin.Begin) != 0);
                    }
                }
            }
        }