public static Bitmap GetLand(int index) { index &= 16383; if (Art.m_Cache[index] != null) { return(Art.m_Cache[index]); } int length; int extra; bool patched; Stream stream = Art.m_FileIndex.Seek(index, out length, out extra, out patched); if (stream == null) { return((Bitmap)null); } else { return(Art.m_Cache[index] = Art.LoadLand(stream)); } }
public static Bitmap GetStatic(int index) { index += 16384; index &= (int)ushort.MaxValue; if (Art.m_Cache[index] != null) { return(Art.m_Cache[index]); } int length; int extra; bool patched; Stream stream = Art.m_FileIndex.Seek(index, out length, out extra, out patched); if (stream == null) { return((Bitmap)null); } else { return(Art.m_Cache[index] = Art.LoadStatic(stream)); } }
public static Bitmap GetLand(int index) { int num; int num1; bool flag; index = index & 16383; if (Art.m_Cache[index] != null) { return(Art.m_Cache[index]); } Stream stream = Art.m_FileIndex.Seek(index, out num, out num1, out flag); if (stream == null) { return(null); } Bitmap[] mCache = Art.m_Cache; Bitmap bitmap = Art.LoadLand(stream); Bitmap bitmap1 = bitmap; mCache[index] = bitmap; return(bitmap1); }
public static MultiComponentList Load(int index) { try { int length, extra; bool patched; var stream = m_FileIndex.Seek(index, out length, out extra, out patched); if (stream == null) { return(MultiComponentList.Empty); } if (PostHSFormat || Art.IsUOAHS()) { return(new MultiComponentList(new BinaryReader(stream), length / 16)); } return(new MultiComponentList(new BinaryReader(stream), length / 12)); } catch { return(MultiComponentList.Empty); } }
public static Bitmap GetStatic(int index, out bool patched, bool checkMaxID = true) { return(Art.GetStatic(index, out patched, checkMaxID)); }
public void Set(ushort id, sbyte z, sbyte flag) { Id = Art.GetLegalItemID(id); Z = z; Flag = flag; }
public TileData(Art art) { m_art = art; }
private int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath) { using ( FileStream fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read), fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read), fsLookup = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader indexReader = new BinaryReader(fsIndex), lookupReader = new BinaryReader(fsLookup)) { int count = Math.Min((int)(indexReader.BaseStream.Length / 4), (int)(lookupReader.BaseStream.Length / 12)); var lists = new HuedTileList[8][]; for (int x = 0; x < 8; ++x) { lists[x] = new HuedTileList[8]; for (int y = 0; y < 8; ++y) { lists[x][y] = new HuedTileList(); } } for (int i = 0; i < count; ++i) { int blockID = indexReader.ReadInt32(); int blockX = blockID / matrix.BlockHeight; int blockY = blockID % matrix.BlockHeight; int offset = lookupReader.ReadInt32(); int length = lookupReader.ReadInt32(); lookupReader.ReadInt32(); // Extra if (offset < 0 || length <= 0) { if (StaticBlocks[blockX] == null) { StaticBlocks[blockX] = new HuedTile[matrix.BlockHeight][][][]; } StaticBlocks[blockX][blockY] = TileMatrix.EmptyStaticBlock; continue; } fsData.Seek(offset, SeekOrigin.Begin); int tileCount = length / 7; if (m_TileBuffer.Length < tileCount) { m_TileBuffer = new StaticTile[tileCount]; } StaticTile[] staTiles = m_TileBuffer; GCHandle gc = GCHandle.Alloc(staTiles, GCHandleType.Pinned); try { if (m_Buffer == null || m_Buffer.Length < length) { m_Buffer = new byte[length]; } fsData.Read(m_Buffer, 0, length); Marshal.Copy(m_Buffer, 0, gc.AddrOfPinnedObject(), length); for (int j = 0; j < tileCount; ++j) { StaticTile cur = staTiles[j]; lists[cur.m_X & 0x7][cur.m_Y & 0x7].Add(Art.GetLegalItemID(cur.m_ID), cur.m_Hue, cur.m_Z); } var tiles = new HuedTile[8][][]; for (int x = 0; x < 8; ++x) { tiles[x] = new HuedTile[8][]; for (int y = 0; y < 8; ++y) { tiles[x][y] = lists[x][y].ToArray(); } } if (StaticBlocks[blockX] == null) { StaticBlocks[blockX] = new HuedTile[matrix.BlockHeight][][][]; } StaticBlocks[blockX][blockY] = tiles; } finally { gc.Free(); } } return(count); } } }
public static Map Tokuno(RadarCol radarCol, TileData tileData, Hues hues, Files files, Art art) { return(new Map(4, 4, 1448, 1448, radarCol, tileData, hues, files, art)); }
/// <summary> /// Returns Bitmap of Multi to maximumHeight /// </summary> /// <param name="maximumHeight"></param> /// <returns></returns> public Bitmap GetImage(int maximumHeight = 300) { if (Width == 0 || Height == 0) { return(null); } int xMin = 1000, yMin = 1000; int xMax = -1000, yMax = -1000; for (int x = 0; x < Width; ++x) { for (int y = 0; y < Height; ++y) { foreach (var mTile in Tiles[x][y]) { Bitmap bmp = Art.GetStatic(mTile.Id); if (bmp == null) { continue; } int px = (x - y) * 22; int py = (x + y) * 22; px -= (bmp.Width / 2); py -= mTile.Z << 2; py -= bmp.Height; if (px < xMin) { xMin = px; } if (py < yMin) { yMin = py; } px += bmp.Width; py += bmp.Height; if (px > xMax) { xMax = px; } if (py > yMax) { yMax = py; } } } } var canvas = new Bitmap(xMax - xMin, yMax - yMin); Graphics gfx = Graphics.FromImage(canvas); gfx.Clear(Color.Transparent); for (int x = 0; x < Width; ++x) { for (int y = 0; y < Height; ++y) { foreach (var mTile in Tiles[x][y]) { Bitmap bmp = Art.GetStatic(mTile.Id); if (bmp == null) { continue; } if (mTile.Z > maximumHeight) { continue; } int px = (x - y) * 22; int py = (x + y) * 22; px -= (bmp.Width / 2); py -= mTile.Z << 2; py -= bmp.Height; px -= xMin; py -= yMin; gfx.DrawImageUnscaled(bmp, px, py, bmp.Width, bmp.Height); } } } gfx.Dispose(); return(canvas); }
/// <summary> /// Saves <see cref="LandData"/> and <see cref="ItemData"/> to tiledata.mul /// </summary> /// <param name="FileName"></param> public static void SaveTileData(string FileName) { using (FileStream fs = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Write)) { using (BinaryWriter bin = new BinaryWriter(fs)) { int j = 0; bool useNewTileDataFormat = Art.IsUOAHS(); for (int i = 0; i < 0x4000; ++i) { if ((i & 0x1F) == 0) { bin.Write(landheader[j++]); //header } bin.Write((int)m_LandData[i].Flags); if (useNewTileDataFormat) { bin.Write((int)m_LandData[i].Unk1); } bin.Write(m_LandData[i].TextureID); byte[] b = new byte[20]; if (m_LandData[i].Name != null) { byte[] bb = Encoding.Default.GetBytes(m_LandData[i].Name); if (bb.Length > 20) { Array.Resize(ref bb, 20); } bb.CopyTo(b, 0); } bin.Write(b); } j = 0; for (int i = 0; i < m_ItemData.Length; ++i) { if ((i & 0x1F) == 0) { bin.Write(itemheader[j++]); // header } bin.Write((int)m_ItemData[i].Flags); if (useNewTileDataFormat) { bin.Write((int)m_ItemData[i].Unk1); } bin.Write(m_ItemData[i].Weight); bin.Write(m_ItemData[i].Quality); bin.Write(m_ItemData[i].MiscData); bin.Write(m_ItemData[i].Unk2); bin.Write(m_ItemData[i].Quantity); bin.Write(m_ItemData[i].Animation); bin.Write(m_ItemData[i].Unk3); bin.Write(m_ItemData[i].Hue); bin.Write(m_ItemData[i].StackingOffset); //unk4 bin.Write(m_ItemData[i].Value); //unk5 bin.Write(m_ItemData[i].Height); byte[] b = new byte[20]; if (m_ItemData[i].Name != null) { byte[] bb = Encoding.Default.GetBytes(m_ItemData[i].Name); if (bb.Length > 20) { Array.Resize(ref bb, 20); } bb.CopyTo(b, 0); } bin.Write(b); } } } }
public static Map Trammel(RadarCol radarCol, TileData tileData, Hues hues, Files files, Art art) { return(new Map(0, 1, 6144, 4096, radarCol, tileData, hues, files, art)); }
public static Map Ilshenar(RadarCol radarCol, TileData tileData, Hues hues, Files files, Art art) { return(new Map(2, 2, 2304, 1600, radarCol, tileData, hues, files, art)); }
public static Map Felucca(RadarCol radarCol, TileData tileData, Hues hues, Files files, Art art) { return(new Map(0, 0, 6144, 4096, radarCol, tileData, hues, files, art)); }
public Map(string path, int fileIndex, int mapID, int width, int height, RadarCol radarCol, TileData tileData, Hues hues, Files files, Art art) { m_FileIndex = fileIndex; m_MapID = mapID; m_Width = width; m_Height = height; this._RadarCol = radarCol; this._TileData = tileData; this._Hues = hues; m_path = path; _files = files; _Art = art; }
public static Map TerMur(RadarCol radarCol, TileData tileData, Hues hues, Files files, Art art) { return(new Map(5, 5, 1280, 4096, radarCol, tileData, hues, files, art)); }
public static void Measure(Bitmap img, out int xMin, out int yMin, out int xMax, out int yMax) { Art.Measure(img, out xMin, out yMin, out xMax, out yMax); }
public TileMatrixPatch(TileMatrix matrix, int index, string path, Art art, Files _files) { this._Art = art; BlockWidth = matrix.BlockWidth; BlockHeight = matrix.BlockWidth; LandBlocksCount = StaticBlocksCount = 0; string mapDataPath, mapIndexPath; if (path == null) { mapDataPath = _files.GetFilePath("mapdif{0}.mul", index); mapIndexPath = _files.GetFilePath("mapdifl{0}.mul", index); } else { mapDataPath = Path.Combine(path, String.Format("mapdif{0}.mul", index)); if (!File.Exists(mapDataPath)) { mapDataPath = null; } mapIndexPath = Path.Combine(path, String.Format("mapdifl{0}.mul", index)); if (!File.Exists(mapIndexPath)) { mapIndexPath = null; } } if (mapDataPath != null && mapIndexPath != null) { LandBlocks = new Tile[matrix.BlockWidth][][]; LandBlocksCount = PatchLand(matrix, mapDataPath, mapIndexPath); } string staDataPath, staIndexPath, staLookupPath; if (path == null) { staDataPath = _files.GetFilePath("stadif{0}.mul", index); staIndexPath = _files.GetFilePath("stadifl{0}.mul", index); staLookupPath = _files.GetFilePath("stadifi{0}.mul", index); } else { staDataPath = Path.Combine(path, String.Format("stadif{0}.mul", index)); if (!File.Exists(staDataPath)) { staDataPath = null; } staIndexPath = Path.Combine(path, String.Format("stadifl{0}.mul", index)); if (!File.Exists(staIndexPath)) { staIndexPath = null; } staLookupPath = Path.Combine(path, String.Format("stadifi{0}.mul", index)); if (!File.Exists(staLookupPath)) { staLookupPath = null; } } if (staDataPath != null && staIndexPath != null && staLookupPath != null) { StaticBlocks = new HuedTile[matrix.BlockWidth][][][][]; StaticBlocksCount = PatchStatics(matrix, staDataPath, staIndexPath, staLookupPath); } }
public TileList(Art art) { this.art = art; m_Tiles = new List <Tile>(); }
public static void DefragStatics(string path, Map map, int width, int height, bool remove) { string indexPath = Files.GetFilePath("staidx{0}.mul", map.FileIndex); FileStream m_Index; BinaryReader m_IndexReader; if (indexPath != null) { m_Index = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read); m_IndexReader = new BinaryReader(m_Index); } else { return; } string staticsPath = Files.GetFilePath("statics{0}.mul", map.FileIndex); FileStream m_Statics; BinaryReader m_StaticsReader; if (staticsPath != null) { m_Statics = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read); m_StaticsReader = new BinaryReader(m_Statics); } else { return; } int blockx = width >> 3; int blocky = height >> 3; string idx = Path.Combine(path, String.Format("staidx{0}.mul", map.FileIndex)); string mul = Path.Combine(path, String.Format("statics{0}.mul", map.FileIndex)); using ( FileStream fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write), fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write)) { var memidx = new MemoryStream(); var memmul = new MemoryStream(); using (BinaryWriter binidx = new BinaryWriter(memidx), binmul = new BinaryWriter(memmul)) { for (int x = 0; x < blockx; ++x) { for (int y = 0; y < blocky; ++y) { try { m_IndexReader.BaseStream.Seek(((x * blocky) + y) * 12, SeekOrigin.Begin); int lookup = m_IndexReader.ReadInt32(); int length = m_IndexReader.ReadInt32(); int extra = m_IndexReader.ReadInt32(); if (((lookup < 0 || length <= 0) && (!map.Tiles.PendingStatic(x, y))) || (map.Tiles.IsStaticBlockRemoved(x, y))) { binidx.Write(-1); // lookup binidx.Write(-1); // length binidx.Write(-1); // extra } else { if ((lookup >= 0) && (length > 0)) { m_Statics.Seek(lookup, SeekOrigin.Begin); } var fsmullength = (int)binmul.BaseStream.Position; int count = length / 7; if (!remove) //without duplicate remove { bool firstitem = true; for (int i = 0; i < count; ++i) { ushort graphic = m_StaticsReader.ReadUInt16(); byte sx = m_StaticsReader.ReadByte(); byte sy = m_StaticsReader.ReadByte(); sbyte sz = m_StaticsReader.ReadSByte(); short shue = m_StaticsReader.ReadInt16(); if ((graphic >= 0) && (graphic <= Art.GetMaxItemID())) { if (shue < 0) { shue = 0; } if (firstitem) { binidx.Write((int)binmul.BaseStream.Position); //lookup firstitem = false; } binmul.Write(graphic); binmul.Write(sx); binmul.Write(sy); binmul.Write(sz); binmul.Write(shue); } } StaticTile[] tilelist = map.Tiles.GetPendingStatics(x, y); if (tilelist != null) { for (int i = 0; i < tilelist.Length; ++i) { if ((tilelist[i].m_ID >= 0) && (tilelist[i].m_ID <= Art.GetMaxItemID())) { if (tilelist[i].m_Hue < 0) { tilelist[i].m_Hue = 0; } if (firstitem) { binidx.Write((int)binmul.BaseStream.Position); //lookup firstitem = false; } binmul.Write(tilelist[i].m_ID); binmul.Write(tilelist[i].m_X); binmul.Write(tilelist[i].m_Y); binmul.Write(tilelist[i].m_Z); binmul.Write(tilelist[i].m_Hue); } } } } else //with duplicate remove { var tilelist = new StaticTile[count]; int j = 0; for (int i = 0; i < count; ++i) { var tile = new StaticTile(); tile.m_ID = m_StaticsReader.ReadUInt16(); tile.m_X = m_StaticsReader.ReadByte(); tile.m_Y = m_StaticsReader.ReadByte(); tile.m_Z = m_StaticsReader.ReadSByte(); tile.m_Hue = m_StaticsReader.ReadInt16(); if ((tile.m_ID >= 0) && (tile.m_ID <= Art.GetMaxItemID())) { if (tile.m_Hue < 0) { tile.m_Hue = 0; } bool first = true; for (int k = 0; k < j; ++k) { if ((tilelist[k].m_ID == tile.m_ID) && ((tilelist[k].m_X == tile.m_X) && (tilelist[k].m_Y == tile.m_Y)) && (tilelist[k].m_Z == tile.m_Z) && (tilelist[k].m_Hue == tile.m_Hue)) { first = false; break; } } if (first) { tilelist[j] = tile; j++; } } } if (map.Tiles.PendingStatic(x, y)) { StaticTile[] pending = map.Tiles.GetPendingStatics(x, y); StaticTile[] old = tilelist; tilelist = new StaticTile[old.Length + pending.Length]; old.CopyTo(tilelist, 0); for (int i = 0; i < pending.Length; ++i) { if ((pending[i].m_ID >= 0) && (pending[i].m_ID <= Art.GetMaxItemID())) { if (pending[i].m_Hue < 0) { pending[i].m_Hue = 0; } bool first = true; for (int k = 0; k < j; ++k) { if ((tilelist[k].m_ID == pending[i].m_ID) && ((tilelist[k].m_X == pending[i].m_X) && (tilelist[k].m_Y == pending[i].m_Y)) && (tilelist[k].m_Z == pending[i].m_Z) && (tilelist[k].m_Hue == pending[i].m_Hue)) { first = false; break; } } if (first) { tilelist[j++] = pending[i]; } } } } if (j > 0) { binidx.Write((int)binmul.BaseStream.Position); //lookup for (int i = 0; i < j; ++i) { binmul.Write(tilelist[i].m_ID); binmul.Write(tilelist[i].m_X); binmul.Write(tilelist[i].m_Y); binmul.Write(tilelist[i].m_Z); binmul.Write(tilelist[i].m_Hue); } } } fsmullength = (int)binmul.BaseStream.Position - fsmullength; if (fsmullength > 0) { binidx.Write(fsmullength); //length if (extra == -1) { extra = 0; } binidx.Write(extra); //extra } else { binidx.Write(-1); //lookup binidx.Write(-1); //length binidx.Write(-1); //extra } } } catch // fill the rest { binidx.BaseStream.Seek(((x * blocky) + y) * 12, SeekOrigin.Begin); for (; x < blockx; ++x) { for (; y < blocky; ++y) { binidx.Write(-1); //lookup binidx.Write(-1); //length binidx.Write(-1); //extra } y = 0; } } } } memidx.WriteTo(fsidx); memmul.WriteTo(fsmul); } } m_IndexReader.Close(); m_StaticsReader.Close(); }
public unsafe static void Initialize() { string filePath = Files.GetFilePath("tiledata.mul"); if (filePath != null) { using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { bool useNeWTileDataFormat = Art.IsUOAHS(); landheader = new int[512]; int j = 0; m_LandData = new LandData[0x4000]; byte[] buffer = new byte[fs.Length]; GCHandle gc = GCHandle.Alloc(buffer, GCHandleType.Pinned); long currpos = 0; try { fs.Read(buffer, 0, buffer.Length); for (int i = 0; i < 0x4000; i += 32) { IntPtr ptrheader = new IntPtr((long)gc.AddrOfPinnedObject() + currpos); currpos += 4; landheader[j++] = (int)Marshal.PtrToStructure(ptrheader, typeof(int)); for (int count = 0; count < 32; ++count) { IntPtr ptr = new IntPtr((long)gc.AddrOfPinnedObject() + currpos); if (useNeWTileDataFormat) { currpos += sizeof(NewLandTileDataMul); NewLandTileDataMul cur = (NewLandTileDataMul)Marshal.PtrToStructure(ptr, typeof(NewLandTileDataMul)); m_LandData[i + count] = new LandData(cur); } else { currpos += sizeof(OldLandTileDataMul); OldLandTileDataMul cur = (OldLandTileDataMul)Marshal.PtrToStructure(ptr, typeof(OldLandTileDataMul)); m_LandData[i + count] = new LandData(cur); } } } long remaining = buffer.Length - currpos; int structsize = useNeWTileDataFormat ? sizeof(NewItemTileDataMul) : sizeof(OldItemTileDataMul); itemheader = new int[(remaining / ((structsize * 32) + 4))]; int itemlength = itemheader.Length * 32; m_ItemData = new ItemData[itemlength]; m_HeightTable = new int[itemlength]; j = 0; for (int i = 0; i < itemlength; i += 32) { IntPtr ptrheader = new IntPtr((long)gc.AddrOfPinnedObject() + currpos); currpos += 4; itemheader[j++] = (int)Marshal.PtrToStructure(ptrheader, typeof(int)); for (int count = 0; count < 32; ++count) { IntPtr ptr = new IntPtr((long)gc.AddrOfPinnedObject() + currpos); if (useNeWTileDataFormat) { currpos += sizeof(NewItemTileDataMul); NewItemTileDataMul cur = (NewItemTileDataMul)Marshal.PtrToStructure(ptr, typeof(NewItemTileDataMul)); m_ItemData[i + count] = new ItemData(cur); m_HeightTable[i + count] = cur.height; } else { currpos += sizeof(OldItemTileDataMul); OldItemTileDataMul cur = (OldItemTileDataMul)Marshal.PtrToStructure(ptr, typeof(OldItemTileDataMul)); m_ItemData[i + count] = new ItemData(cur); m_HeightTable[i + count] = cur.height; } } } } finally { gc.Free(); } } } }
public void Set(ushort id, sbyte z) { m_ID = Art.GetLegalItemID(id); m_Z = z; }
public TileMatrix(int fileIndex, int mapID, int width, int height, string path, Map map, Art art, Files files) { Width = width; Height = height; _Map = map; this.art = art; BlockWidth = width >> 3; BlockHeight = height >> 3; _files = files; if (path == null) { mapPath = _files.GetFilePath("map{0}.mul", fileIndex); if (String.IsNullOrEmpty(mapPath) || !File.Exists(mapPath)) { mapPath = _files.GetFilePath("map{0}LegacyMUL.uop", fileIndex); } if (mapPath != null && mapPath.EndsWith(".uop")) { IsUOPFormat = true; } } else { mapPath = Path.Combine(path, String.Format("map{0}.mul", fileIndex)); if (!File.Exists(mapPath)) { mapPath = Path.Combine(path, String.Format("map{0}LegacyMUL.uop", fileIndex)); } if (!File.Exists(mapPath)) { mapPath = null; } else if (mapPath != null && mapPath.EndsWith(".uop")) { IsUOPFormat = true; } } if (path == null) { indexPath = _files.GetFilePath("staidx{0}.mul", fileIndex); } else { indexPath = Path.Combine(path, String.Format("staidx{0}.mul", fileIndex)); if (!File.Exists(indexPath)) { indexPath = null; } } if (path == null) { staticsPath = _files.GetFilePath("statics{0}.mul", fileIndex); } else { staticsPath = Path.Combine(path, String.Format("statics{0}.mul", fileIndex)); if (!File.Exists(staticsPath)) { staticsPath = null; } } EmptyStaticBlock = new HuedTile[8][][]; for (int i = 0; i < 8; ++i) { EmptyStaticBlock[i] = new HuedTile[8][]; for (int j = 0; j < 8; ++j) { EmptyStaticBlock[i][j] = new HuedTile[0]; } } InvalidLandBlock = new Tile[196]; m_LandTiles = new Tile[BlockWidth][][]; m_StaticTiles = new HuedTile[BlockWidth][][][][]; Patch = new TileMatrixPatch(this, mapID, path, art, _files); }
public static Map Malas(RadarCol radarCol, TileData tileData, Hues hues, Files files, Art art) { return(new Map(3, 3, 2560, 2048, radarCol, tileData, hues, files, art)); }
private unsafe HuedTile[][][] ReadStaticBlock(int x, int y) { try { if (!StaticIndexInit) { InitStatics(); } if (m_Statics == null || !m_Statics.CanRead || !m_Statics.CanSeek) { if (staticsPath == null) { m_Statics = null; } else { m_Statics = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read); } } if (m_Statics == null) { return(EmptyStaticBlock); } int lookup = m_StaticIndex[(x * BlockHeight) + y].lookup; int length = m_StaticIndex[(x * BlockHeight) + y].length; if (lookup < 0 || length <= 0) { return(EmptyStaticBlock); } else { int count = length / 7; m_Statics.Seek(lookup, SeekOrigin.Begin); if (m_Buffer == null || m_Buffer.Length < length) { m_Buffer = new byte[length]; } GCHandle gc = GCHandle.Alloc(m_Buffer, GCHandleType.Pinned); try { m_Statics.Read(m_Buffer, 0, length); if (m_Lists == null) { m_Lists = new HuedTileList[8][]; for (int i = 0; i < 8; ++i) { m_Lists[i] = new HuedTileList[8]; for (int j = 0; j < 8; ++j) { m_Lists[i][j] = new HuedTileList(); } } } HuedTileList[][] lists = m_Lists; for (int i = 0; i < count; ++i) { IntPtr ptr = new IntPtr((long)gc.AddrOfPinnedObject() + i * sizeof(StaticTile)); StaticTile cur = (StaticTile)Marshal.PtrToStructure(ptr, typeof(StaticTile)); lists[cur.m_X & 0x7][cur.m_Y & 0x7].Add(Art.GetLegalItemID(cur.m_ID), cur.m_Hue, cur.m_Z); } HuedTile[][][] tiles = new HuedTile[8][][]; for (int i = 0; i < 8; ++i) { tiles[i] = new HuedTile[8][]; for (int j = 0; j < 8; ++j) { tiles[i][j] = lists[i][j].ToArray(); } } return(tiles); } finally { gc.Free(); } } } finally { //if (m_Statics != null) // m_Statics.Close(); } }
/* * // TODO: unused method * /// <summary> * /// Returns Bitmap of Multi * /// </summary> * /// <returns></returns> * public Bitmap GetImage() * { * return GetImage(300); * } */ /// <summary> /// Returns Bitmap of Multi to maximumHeight /// </summary> /// <param name="maximumHeight"></param> /// <returns></returns> public Bitmap GetImage(int maximumHeight) { if (Width == 0 || Height == 0) { return(null); } int xMin = 1000, yMin = 1000; int xMax = -1000, yMax = -1000; for (int x = 0; x < Width; ++x) { for (int y = 0; y < Height; ++y) { MTile[] tiles = Tiles[x][y]; for (int i = 0; i < tiles.Length; ++i) { Bitmap bmp = Art.GetStatic(tiles[i].ID); if (bmp == null) { continue; } int px = (x - y) * 22; int py = (x + y) * 22; px -= (bmp.Width / 2); py -= tiles[i].Z << 2; py -= bmp.Height; if (px < xMin) { xMin = px; } if (py < yMin) { yMin = py; } px += bmp.Width; py += bmp.Height; if (px > xMax) { xMax = px; } if (py > yMax) { yMax = py; } } } } var canvas = new Bitmap(xMax - xMin, yMax - yMin); Graphics gfx = Graphics.FromImage(canvas); gfx.Clear(Color.Transparent); for (int x = 0; x < Width; ++x) { for (int y = 0; y < Height; ++y) { MTile[] tiles = Tiles[x][y]; for (int i = 0; i < tiles.Length; ++i) { Bitmap bmp = Art.GetStatic(tiles[i].ID); if (bmp == null) { continue; } if (tiles[i].Z > maximumHeight) { continue; } int px = (x - y) * 22; int py = (x + y) * 22; px -= (bmp.Width / 2); py -= tiles[i].Z << 2; py -= bmp.Height; px -= xMin; py -= yMin; gfx.DrawImageUnscaled(bmp, px, py, bmp.Width, bmp.Height); } // TODO: check what this was for. It looks unused/unfinished. //int tx = (x - y) * 22; //int ty = (x + y) * 22; //tx -= xMin; //ty -= yMin; } } gfx.Dispose(); return(canvas); }
public void Set(ushort id, sbyte z, sbyte flag) { m_ID = Art.GetLegalItemID(id); m_Z = z; m_Flag = flag; }
private unsafe HuedTile[][][] ReadStaticBlock(int x, int y) { if (!StaticIndexInit) { InitStatics(); } if (_statics?.CanRead != true || !_statics.CanSeek) { _statics = _staticsPath == null ? null : new FileStream(_staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read); } if (_statics == null) { return(EmptyStaticBlock); } int lookup = _staticIndex[(x * BlockHeight) + y].Lookup; int length = _staticIndex[(x * BlockHeight) + y].Length; if (lookup < 0 || length <= 0) { return(EmptyStaticBlock); } int count = length / 7; _statics.Seek(lookup, SeekOrigin.Begin); if (_buffer == null || _buffer.Length < length) { _buffer = new byte[length]; } GCHandle gc = GCHandle.Alloc(_buffer, GCHandleType.Pinned); try { _statics.Read(_buffer, 0, length); if (_lists == null) { _lists = new HuedTileList[8][]; for (int i = 0; i < 8; ++i) { _lists[i] = new HuedTileList[8]; for (int j = 0; j < 8; ++j) { _lists[i][j] = new HuedTileList(); } } } HuedTileList[][] lists = _lists; for (int i = 0; i < count; ++i) { var ptr = new IntPtr((long)gc.AddrOfPinnedObject() + (i * sizeof(StaticTile))); var cur = (StaticTile)Marshal.PtrToStructure(ptr, typeof(StaticTile)); lists[cur.X & 0x7][cur.Y & 0x7].Add(Art.GetLegalItemID(cur.Id), cur.Hue, cur.Z); } var tiles = new HuedTile[8][][]; for (int i = 0; i < 8; ++i) { tiles[i] = new HuedTile[8][]; for (int j = 0; j < 8; ++j) { tiles[i][j] = lists[i][j].ToArray(); } } return(tiles); } finally { gc.Free(); } }
/// <summary> /// Returns Bitmap of Multi to maxheight /// </summary> /// <param name="maxheight"></param> /// <returns></returns> public Bitmap GetImage(int maxheight) { if (m_Width == 0 || m_Height == 0) { return(null); } int xMin = 1000, yMin = 1000; int xMax = -1000, yMax = -1000; for (int x = 0; x < m_Width; ++x) { for (int y = 0; y < m_Height; ++y) { MTile[] tiles = m_Tiles[x][y]; for (int i = 0; i < tiles.Length; ++i) { Bitmap bmp = Art.GetStatic(tiles[i].ID); if (bmp == null) { continue; } int px = (x - y) * 22; int py = (x + y) * 22; px -= (bmp.Width / 2); py -= tiles[i].Z << 2; py -= bmp.Height; if (px < xMin) { xMin = px; } if (py < yMin) { yMin = py; } px += bmp.Width; py += bmp.Height; if (px > xMax) { xMax = px; } if (py > yMax) { yMax = py; } } } } Bitmap canvas = new Bitmap(xMax - xMin, yMax - yMin); Graphics gfx = Graphics.FromImage(canvas); gfx.Clear(Color.White); for (int x = 0; x < m_Width; ++x) { for (int y = 0; y < m_Height; ++y) { MTile[] tiles = m_Tiles[x][y]; for (int i = 0; i < tiles.Length; ++i) { Bitmap bmp = Art.GetStatic(tiles[i].ID); if (bmp == null) { continue; } if ((tiles[i].Z) > maxheight) { continue; } int px = (x - y) * 22; int py = (x + y) * 22; px -= (bmp.Width / 2); py -= tiles[i].Z << 2; py -= bmp.Height; px -= xMin; py -= yMin; gfx.DrawImageUnscaled(bmp, px, py, bmp.Width, bmp.Height); } int tx = (x - y) * 22; int ty = (x + y) * 22; tx -= xMin; ty -= yMin; } } gfx.Dispose(); return(canvas); }
public void Set(ushort id, sbyte z) { Id = Art.GetLegalItemID(id); Z = z; }