static LevelBuilder() { Palette.LoadPalette(0); var dt1 = DT1.Load(Application.streamingAssetsPath + "/ds1edit.dt1", mpq: false); specialTiles.Add(dt1.tiles); }
public string ToFixedSizeString() { StringBuilder sb = new StringBuilder(); sb.Append(ID.ToString().PadLeft(10, '0')); sb.Append('^'); sb.Append(INT1.ToString().PadLeft(10, '0')); sb.Append('^'); sb.Append(INT2.ToString().PadLeft(10, '0')); sb.Append('^'); sb.Append(INT3.ToString().PadLeft(10, '0')); sb.Append('^'); sb.Append(DT1.PadLeft(25, '#')); sb.Append('^'); sb.Append(DT2.PadLeft(25, '#')); sb.Append('^'); sb.Append(DT3.PadLeft(25, '#')); sb.Append('^'); sb.Append(VAR1.PadLeft(100, '#')); sb.Append('^'); sb.Append(VAR2.PadLeft(100, '#')); sb.Append('^'); sb.Append(VAR3.PadLeft(100, '#')); return(sb.ToString()); }
static LevelBuilder() { var palette = Palette.GetPalette(PaletteType.Act1); var dt1 = DT1.Load(Application.streamingAssetsPath + "/ds1edit.dt1", palette, mpq: false); specialTiles.Add(dt1.tiles); }
public void MergTest1() { // Merge DataTable dt3 = DT1.Copy(); dt3.Merge(DT2, true); Console.Read(); }
static DS1 Load(byte[] bytes) { using (var stream = new MemoryStream(bytes)) using (var reader = new BinaryReader(stream)) { DS1 ds1 = new DS1(); ds1.version = reader.ReadInt32(); ds1.width = reader.ReadInt32() + 1; ds1.height = reader.ReadInt32() + 1; int act = 0; if (ds1.version >= 8) { act = reader.ReadInt32(); act = Mathf.Min(act, 4); } int tagType = 0; if (ds1.version >= 10) { tagType = reader.ReadInt32(); } if (ds1.version >= 3) { Palette.LoadPalette(act); ds1.dt1Files = ReadDependencies(reader); ds1.tileSampler = new DT1.Sampler(); foreach (var dt1Filename in ds1.dt1Files) { var dt1 = DT1.Load(dt1Filename); ds1.tileSampler.Add(dt1.tiles); } } if ((ds1.version >= 9) && (ds1.version <= 13)) { stream.Seek(8, SeekOrigin.Current); } ReadLayers(ds1, bytes, reader, stream, tagType); ReadObjects(ds1, reader, act); try { ReadGroups(ds1, reader, tagType); } catch (EndOfStreamException) { // in fact there can be less groups than expected } return(ds1); } }
private void InitTileSampler() { tileSampler = new DT1.Sampler(); if (info != null) { foreach (var dt1Filename in info.type.dt1Files) { var dt1 = DT1.Load(dt1Filename); tileSampler.Add(dt1.tiles); } } }
static public void LoadDS1() { var assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); if (!Application.isPlaying) { DT1.ResetCache(); DS1.ResetCache(); } var ds1 = DS1.Load(assetPath, mpq: false); var level = new LevelBuilder(ds1); level.Instantiate(new Vector2i(0, 0)); }
static public void ConvertDT1ToPNG() { var assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); if (!Application.isPlaying) { DT1.ResetCache(); } var lowerPath = assetPath.ToLower(); Color32[] palette; if (lowerPath.Contains("act2")) { palette = Palette.GetPalette(PaletteType.Act2); } else if (lowerPath.Contains("act3")) { palette = Palette.GetPalette(PaletteType.Act3); } else if (lowerPath.Contains("act4")) { palette = Palette.GetPalette(PaletteType.Act4); } else if (lowerPath.Contains("act5")) { palette = Palette.GetPalette(PaletteType.Act5); } else { palette = Palette.GetPalette(PaletteType.Act1); } var dt1 = DT1.Load(assetPath, palette, mpq: false); int i = 0; foreach (var texture in dt1.textures) { var pngData = texture.EncodeToPNG(); Object.DestroyImmediate(texture); var pngPath = assetPath + "." + i + ".png"; File.WriteAllBytes(pngPath, pngData); AssetDatabase.ImportAsset(pngPath); ++i; } }
static public DT1 Load(string filename, 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); } 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(); } }
static void ReadTiles(DT1 dt1, Stream stream, BinaryReader reader, byte[] bytes) { int tileCount = reader.ReadInt32(); reader.ReadInt32(); // Pointer in file to Tile Headers (= 276) dt1.tiles = new Tile[tileCount]; for (int i = 0; i < tileCount; ++i) { dt1.tiles[i].Read(reader); } int textureSize = CalcTextureSize(dt1.tiles); var packer = new TexturePacker(textureSize, textureSize); Material material = null; Texture2D texture = null; Color32[] pixels = null; for (int i = 0; i < tileCount; ++i) { var tile = dt1.tiles[i]; if (tile.width == 0 || tile.height == 0) { Debug.Log(string.Format("Zero size {0}x{1}", tile.width, tile.height)); continue; } var pack = packer.put(tile.width, -tile.height); if (pack.newTexture) { if (texture != null) { texture.SetPixels32(pixels); texture.Apply(false); } texture = new Texture2D(textureSize, textureSize, TextureFormat.ARGB32, false); texture.filterMode = FilterMode.Point; dt1.textures.Add(texture); material = new Material(Shader.Find("Sprite")); material.mainTexture = texture; pixels = new Color32[textureSize * textureSize]; } tile.textureX = pack.x; tile.textureY = pack.y; tile.texture = texture; tile.material = material; if ((tile.orientation == 0 || tile.orientation == 15) && tile.height != 0) { // floor or roof tile.height = -79; } else if (tile.orientation > 0 && tile.orientation < 15) { tile.textureY += (-tile.height); } else if (tile.orientation > 15) { tile.textureY += Math.Min(96, -tile.height); } dt1.tiles[i] = tile; stream.Seek(tile.blockHeaderPointer, SeekOrigin.Begin); for (int block = 0; block < tile.blockCount; ++block) { int x = reader.ReadInt16(); int y = reader.ReadInt16(); reader.ReadBytes(2); // zeros reader.ReadByte(); // gridX reader.ReadByte(); // gridY short format = reader.ReadInt16(); int length = reader.ReadInt32(); reader.ReadBytes(2); // zeros int fileOffset = reader.ReadInt32(); int blockDataPosition = tile.blockHeaderPointer + fileOffset; if (format == 1) { drawBlockIsometric(pixels, textureSize, tile.textureX + x, tile.textureY + y, bytes, blockDataPosition, length); } else { drawBlockNormal(pixels, textureSize, tile.textureX + x, tile.textureY + y, bytes, blockDataPosition, length); } } } if (texture != null) { texture.SetPixels32(pixels); texture.Apply(false); } }