コード例 #1
0
        public static DC6 Load(string filename, bool mpq = true, int textureSize = -1, bool loadAllDirections = false)
        {
            UnityEngine.Profiling.Profiler.BeginSample("DC6.DecodeDirection");
            try
            {
                Palette.LoadPalette(0);
                var bytes = mpq ? Mpq.ReadAllBytes(filename) : File.ReadAllBytes(filename);

                using (var stream = new MemoryStream(bytes))
                    using (var reader = new BinaryReader(stream))
                    {
                        int version1 = reader.ReadInt32();
                        var version2 = reader.ReadInt32();
                        var version3 = reader.ReadInt32();
                        if (version1 != 6 || version2 != 1 || version3 != 0)
                        {
                            Debug.LogWarning("Unknown dc6 version " + version1 + " " + version2 + " " + version3);
                            return(null);
                        }

                        DC6 dc6 = Load(stream, reader, bytes, textureSize, loadAllDirections);
                        return(dc6);
                    }
            }
            finally
            {
                UnityEngine.Profiling.Profiler.EndSample();
            }
        }
コード例 #2
0
ファイル: DS1.cs プロジェクト: zkactivity/Diablerie
        public static DS1 Load(string filename, bool mpq = true)
        {
            string lowerFilename = filename.ToLower();

            if (cache.ContainsKey(lowerFilename))
            {
                return(cache[lowerFilename]);
            }

            UnityEngine.Profiling.Profiler.BeginSample("DS1.Load");
            try
            {
                var    sw    = System.Diagnostics.Stopwatch.StartNew();
                byte[] bytes = mpq ? Mpq.ReadAllBytes(filename) : File.ReadAllBytes(filename);
                var    ds1   = Load(bytes);
                ds1.filename = filename;
                Debug.Log(Path.GetFileName(filename) + " loaded in " + sw.ElapsedMilliseconds + " ms");
                cache[lowerFilename] = ds1;
                return(ds1);
            }
            finally
            {
                UnityEngine.Profiling.Profiler.EndSample();
            }
        }
コード例 #3
0
ファイル: DCC.cs プロジェクト: r2d2m/Diablerie
 public static DCC Load(string filename, bool loadAllDirections = false, bool mpq = true)
 {
     UnityEngine.Profiling.Profiler.BeginSample("DCC.Load");
     try
     {
         var bytes = mpq ? Mpq.ReadAllBytes(filename) : File.ReadAllBytes(filename);
         DCC dcc   = Load(filename, bytes, loadAllDirections);
         return(dcc);
     }
     finally
     {
         UnityEngine.Profiling.Profiler.EndSample();
     }
 }
コード例 #4
0
ファイル: Palette.cs プロジェクト: pristupa/Diablerie
        private static Color32[] LoadPalette(PaletteType paletteType)
        {
            var palette     = new Color32[256];
            var palettePath = PaletteMappings[paletteType];
            var bytes       = Mpq.ReadAllBytes(palettePath);

            for (var i = 0; i < 256; ++i)
            {
                var offset = i * 4;
                var r      = bytes[offset];
                var g      = bytes[offset + 1];
                var b      = bytes[offset + 2];
                palette[i] = new Color32(r, g, b, 255);
            }
            palette[0]            = new Color(0, 0, 0, 0);
            Palettes[paletteType] = palette;
            return(palette);
        }
コード例 #5
0
        public static DT1 Load(string filename, Color32[] palette, bool mpq = true)
        {
            string lowerFilename = filename.ToLower();

            if (cache.ContainsKey(lowerFilename))
            {
                return(cache[lowerFilename]);
            }

            UnityEngine.Profiling.Profiler.BeginSample("DT1.Load");
            try
            {
                var sw    = System.Diagnostics.Stopwatch.StartNew();
                var bytes = mpq ? Mpq.ReadAllBytes(filename) : File.ReadAllBytes(filename);
                var dt1   = new DT1();
                dt1.filename = filename;

                using (var stream = new MemoryStream(bytes))
                    using (var reader = new BinaryReader(stream))
                    {
                        int version1 = reader.ReadInt32();
                        int version2 = reader.ReadInt32();
                        if (version1 != 7 || version2 != 6)
                        {
                            Debug.Log(string.Format("Can't read dt1 file, bad version ({0}.{1})", version1, version2));
                            return(dt1);
                        }

                        stream.Seek(260, SeekOrigin.Current);
                        ReadTiles(dt1, stream, reader, bytes, palette);
                    }

                cache[lowerFilename] = dt1;
                Debug.Log(dt1.filename + ", tiles " + dt1.tiles.Length + ", " + dt1.textures.Count + " textures, " +
                          sw.ElapsedMilliseconds + " ms");
                return(dt1);
            }
            finally
            {
                UnityEngine.Profiling.Profiler.EndSample();
            }
        }
コード例 #6
0
ファイル: Palette.cs プロジェクト: sausage88/Diablerie
        public static Color32[] LoadPalette(int act)
        {
            if (palettes.ContainsKey(act))
            {
                palette = palettes[act];
                return(palette);
            }

            palette = new Color32[256];
            var bytes = Mpq.ReadAllBytes(@"data\global\palette\ACT" + (act + 1) + @"\Pal.PL2");

            for (int i = 0; i < 256; ++i)
            {
                int  offset = i * 4;
                byte r      = bytes[offset];
                byte g      = bytes[offset + 1];
                byte b      = bytes[offset + 2];
                palette[i] = new Color32(r, g, b, 255);
            }
            palette[0]    = new Color(0, 0, 0, 0);
            palettes[act] = palette;
            return(palette);
        }
コード例 #7
0
ファイル: COF.cs プロジェクト: sausage88/Diablerie
        public static COF Load(string basePath, string token, string weaponClass, string mode)
        {
            var filename = basePath + @"\" + token + @"\cof\" + token + mode + weaponClass + ".cof";

            if (cache.ContainsKey(filename))
            {
                return(cache[filename]);
            }

            UnityEngine.Profiling.Profiler.BeginSample("COF.Load");

            COF cof = new COF();

            cof.basePath = basePath;
            cof.token    = token;
            cof.mode     = mode;

            byte[] bytes = Mpq.ReadAllBytes(filename);
            using (var stream = new MemoryStream(bytes))
                using (var reader = new BinaryReader(stream))
                {
                    cof.layerCount         = reader.ReadByte();
                    cof.framesPerDirection = reader.ReadByte();
                    cof.directionCount     = reader.ReadByte();
                    stream.Seek(25, SeekOrigin.Current);

                    cof.compositLayers = new Layer[16];
                    cof.layers         = new Layer[cof.layerCount];

                    for (int i = 0; i < cof.layerCount; ++i)
                    {
                        Layer layer = new Layer();
                        layer.index         = i;
                        layer.compositIndex = reader.ReadByte();
                        layer.name          = layerNames[layer.compositIndex];

                        layer.shadow = reader.ReadByte() != 0;
                        reader.ReadByte();

                        bool transparent = reader.ReadByte() != 0;
                        int  blendMode   = reader.ReadByte();
                        if (transparent)
                        {
                            layer.material = Materials.softAdditive;
                        }
                        else
                        {
                            layer.material = Materials.normal;
                        }

                        layer.weaponClass = System.Text.Encoding.Default.GetString(reader.ReadBytes(4), 0, 3);

                        cof.layers[i] = layer;
                        cof.compositLayers[layer.compositIndex] = layer;
                    }

                    stream.Seek(cof.framesPerDirection, SeekOrigin.Current);
                    cof.priority = reader.ReadBytes(cof.directionCount * cof.framesPerDirection * cof.layerCount);
                }

            AnimData animData = new AnimData();

            if (AnimData.Find(token + mode + weaponClass, ref animData))
            {
                cof.frameDuration = animData.frameDuration;
                float refFrameCount = referenceFrameCount.GetValueOrDefault(token + mode, animData.framesPerDir);
                cof.frameDuration *= animData.framesPerDir / refFrameCount;
            }
            else
            {
                Debug.LogWarning("animdata not found " + (token + mode + weaponClass));
            }

            cache.Add(filename, cof);

            UnityEngine.Profiling.Profiler.EndSample();
            return(cof);
        }