Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace D2Project.Formats
- {
- //DT1 - tile format with graphics
- public class DT1
- {
- struct Header
- {
- public long x1;
- public long x2;
- public long zeros;
- public long nb_block;
- public long bh_ptr;
- }
- class Tile
- {
- public struct Header
- {
- public long direction;
- public long roof_y;
- public byte sound;
- public byte animated;
- public long size_y;
- public long size_x;
- public long zeros1;
- public long orientation;
- public long main_index;
- public long sub_index;
- public long frame;
- public long unknown_a;
- public long unknown_b;
- public long unknown_c;
- public long unknown_d;
- public long floor_flags;
- public long zeros2;
- public long data_ptr;
- public long length;
- public long sub_block;
- public long zeros3;
- }
- public Header header;
- public class Block
- {
- public struct Header
- {
- public long x; //2
- public long y; //2
- public long zeros1; //2
- public long grid_x; //1
- public long grid_y; //1
- public long format; //2
- public long length; //4
- public long zeros2; //2
- public long file_offset; //4
- }
- public Header header;
- }
- public Block[] blocks;
- }
- Header header;
- Tile[] tiles;
- byte[] file;
- public DT1(byte[] f)
- {
- file = f;
- Console.WriteLine("Reading DT1");
- header.x1 = BitConverter.ToInt32(f.Take(4).ToArray(), 0);
- header.x2 = BitConverter.ToInt32(f.Skip(4).Take(4).ToArray(), 0);
- header.nb_block = BitConverter.ToInt32(f.Skip(268).Take(4).ToArray(), 0);
- header.bh_ptr = BitConverter.ToInt32(f.Skip(272).Take(4).ToArray(), 0);
- Console.WriteLine("{0} {1} {2} {3}", header.x1, header.x2, header.nb_block, header.bh_ptr);
- tiles = new Tile[header.nb_block];
- int offset = (int)header.bh_ptr;
- for (int i = 0; i < header.nb_block; i++)
- {
- tiles[i] = new Tile();
- tiles[i].header.direction = BitConverter.ToInt32(f.Skip(offset).Take(4).ToArray(), 0);
- tiles[i].header.roof_y = BitConverter.ToInt16(f.Skip(offset + 4).Take(2).ToArray(), 0);
- tiles[i].header.sound = f.Skip(offset + 6).Take(1).ToArray()[0];
- tiles[i].header.animated = f.Skip(offset + 7).Take(1).ToArray()[0];
- tiles[i].header.size_y = BitConverter.ToInt32(f.Skip(offset + 8).Take(4).ToArray(), 0);
- tiles[i].header.size_x = BitConverter.ToInt32(f.Skip(offset + 12).Take(4).ToArray(), 0);
- tiles[i].header.orientation = BitConverter.ToInt32(f.Skip(offset + 20).Take(4).ToArray(), 0);
- tiles[i].header.main_index = BitConverter.ToInt32(f.Skip(offset + 24).Take(4).ToArray(), 0);
- tiles[i].header.sub_index = BitConverter.ToInt32(f.Skip(offset + 28).Take(4).ToArray(), 0);
- tiles[i].header.frame = BitConverter.ToInt32(f.Skip(offset + 32).Take(4).ToArray(), 0);
- tiles[i].header.floor_flags = BitConverter.ToInt32(f.Skip(offset + 40).Take(25).ToArray(), 0);
- tiles[i].header.data_ptr = BitConverter.ToInt32(f.Skip(offset + 72).Take(4).ToArray(), 0);
- tiles[i].header.length = BitConverter.ToInt32(f.Skip(offset + 76).Take(4).ToArray(), 0);
- tiles[i].header.sub_block = BitConverter.ToInt32(f.Skip(offset + 80).Take(4).ToArray(), 0);
- tiles[i].blocks = new Tile.Block[tiles[i].header.sub_block];
- int offset2 = (int)tiles[i].header.data_ptr;
- for (int j = 0; j < tiles[i].header.sub_block; j++)
- {
- tiles[i].blocks[j] = new Tile.Block();
- tiles[i].blocks[j].header.x = BitConverter.ToInt16(f.Skip(offset2).Take(2).ToArray(), 0);
- tiles[i].blocks[j].header.y = BitConverter.ToInt16(f.Skip(offset2 + 2).Take(2).ToArray(), 0);
- tiles[i].blocks[j].header.grid_x = f.Skip(offset2 + 6).Take(1).ToArray()[0];
- tiles[i].blocks[j].header.grid_y = f.Skip(offset2 + 7).Take(1).ToArray()[0];
- tiles[i].blocks[j].header.format = BitConverter.ToInt16(f.Skip(offset2 + 8).Take(2).ToArray(), 0);
- tiles[i].blocks[j].header.length = BitConverter.ToInt32(f.Skip(offset2 + 10).Take(4).ToArray(), 0);
- tiles[i].blocks[j].header.file_offset = BitConverter.ToInt32(f.Skip(offset2 + 16).Take(4).ToArray(), 0);
- offset2 += 20;
- }
- offset += 96;
- }
- }
- public SFML.Graphics.Image GetImage()
- {
- // SFML.Graphics.Image img = new SFML.Graphics.Image((uint)32, (uint)32, SFML.Graphics.Color.Red);
- // return img;
- SFML.Graphics.Image img = new SFML.Graphics.Image((uint)256, (uint)256, SFML.Graphics.Color.Transparent);
- for (int i = 0; i < 80; i++)
- {
- for (int j = 0; j < 160; j++)
- {
- img.SetPixel((uint)i, (uint)j, Engine.Instance.graphics.palettes[Palette.Names.Act1].GetColor(file[14100+j+i*80]));
- }
- }
- return img;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement