using System; using System.Collections.Generic; using System.Text; using CommonLang; using CommonUI.Display; using CommonLang.Xml; using CommonLang.IO; using System.Xml; using System.IO; namespace CommonUI.Cell { abstract public class CPJLoader : IDisposable { readonly public HashMap ImgTable = new HashMap(); readonly public HashMap SprTable = new HashMap(); readonly public HashMap MapTable = new HashMap(); readonly public HashMap WorldTable = new HashMap(); abstract public Image LoadImage(string img); /** * input "{1234},{5678}" * return [1234][5678] */ public static String[] GetArray2D(String text) { text = text.Replace('{', ' '); String[] texts = text.Split(new string[] { "}," }, StringSplitOptions.RemoveEmptyEntries); for (int i = texts.Length - 1; i >= 0; --i) { texts[i] = texts[i].Trim(); } return texts; } /** * input 3,123,4,5678 * return [123] [5678] * @param text * @return */ public static String[] GetArray1D(String text) { TextInputStream reader = new TextInputStream(new StringReader(text), null); List list = new List(); try { String line = reader.GetUTF(); while (!string.IsNullOrEmpty(line)) { list.Add(line); line = reader.GetUTF(); } } catch (Exception e) { } return list.ToArray(); } /** * input 3,123,4,5678 * return [123] [5678] * @param text * @return */ public static String GetArray1DLines(String text) { TextInputStream reader = new TextInputStream(new StringReader(text), null); StringBuilder ret = new StringBuilder(); try { String line = reader.GetUTF(); while (!string.IsNullOrEmpty(line)) { ret.Append(line + "\n"); line = reader.GetUTF(); } } catch (Exception e) { } return ret.ToString(); } public void Dispose() { if (ImgTable != null) { ImgTable.Clear(); } if (SprTable != null) { SprTable.Clear(); } if (MapTable != null) { MapTable.Clear(); } if (WorldTable != null) { WorldTable.Clear(); } } public string DefaultSpriteName { get { foreach (string name in SprTable.Keys) { return name; } return null; } } public string DefaultImageName { get { foreach (string name in ImgTable.Keys) { return name; } return null; } } public string DefaultMapName { get { foreach (string name in MapTable.Keys) { return name; } return null; } } public string DefaultWorldName { get { foreach (string name in WorldTable.Keys) { return name; } return null; } } } public class CPJLoaderXML : CPJLoader { private string path; private String image_type; private bool image_tile; private bool image_group; public CPJLoaderXML(string file) { this.path = Resource.FormatPath(file); XmlDocument doc = XmlUtil.LoadXML(path); if(doc == null) { throw new Exception("XmlDocument load error " + file); } XmlElement element = doc.DocumentElement; foreach (XmlNode node in element.ChildNodes) { if (node is XmlElement) { XmlElement e = (XmlElement)node; if (e.Name.Equals("IMAGE_TYPE")) { image_type = e.InnerText.Trim(); } else if (e.Name.Equals("IMAGE_TILE")) { image_tile = Boolean.Parse(e.InnerText.Trim()); } else if (e.Name.Equals("IMAGE_GROUP")) { image_group = Boolean.Parse(e.InnerText.Trim()); } else if (e.Name.Equals("level")) { initLevel(e); } else if (e.Name.Equals("resource")) { initResource(e); } } } } private void initResource(XmlElement resource) { foreach (XmlNode node in resource.ChildNodes) { if (node is XmlElement) { XmlElement e = (XmlElement)node; if (e.Name.Equals("images")) { ImagesSet im = initImages(e); ImgTable.Add(im.Name, im); } else if (e.Name.Equals("map")) { MapSet ms = initMap(e); MapTable.Add(ms.Name, ms); } else if (e.Name.Equals("sprite")) { SpriteSet ss = initSprite(e); SprTable.Add(ss.Name, ss); } } } } private ImagesSet initImages(XmlElement images) { ImagesSet set = new ImagesSet( int.Parse(images.Attributes["index"].Value), images.Attributes["name"].Value); set.Count = int.Parse(images.Attributes[("size")].Value); set.ClipsX = new int[set.Count]; set.ClipsY = new int[set.Count]; set.ClipsW = new int[set.Count]; set.ClipsH = new int[set.Count]; set.ClipsKey = new String[set.Count]; String output_file = images.Attributes["output_file"].Value; String output_type = images.Attributes["output_type"].Value; if (!string.IsNullOrEmpty(output_file)) { set.Extention = output_file; } else { set.Extention = image_type; } if (output_type.Contains("tile")) { set.IsTiles = true; } else { set.IsTiles = image_tile; } if (images.HasAttribute("all_width")) { set.TotalW = int.Parse(images.Attributes["all_width"].Value); } if (images.HasAttribute("all_height")) { set.TotalH = int.Parse(images.Attributes["all_height"].Value); } if (images.HasAttribute("total_split")) { set.SplitSize = int.Parse(images.Attributes["total_split"].Value); } foreach (XmlNode node in images.ChildNodes) { if (node is XmlElement) { XmlElement e = (XmlElement)node; if (e.Name.Equals("clip")) { int index = int.Parse(e.Attributes["index"].Value); set.ClipsX[index] = int.Parse(e.Attributes["x"].Value); set.ClipsY[index] = int.Parse(e.Attributes["y"].Value); set.ClipsW[index] = int.Parse(e.Attributes["width"].Value); set.ClipsH[index] = int.Parse(e.Attributes["height"].Value); set.ClipsKey[index] = e.Attributes["data"].Value; } else if (e.Name.Equals("ImageInfo")) { set.ImageInfo = e.Value; } else if (e.Name.Equals("Append")) { set.AppendData = GetArray1DLines(e.Attributes["data"].Value); } } } return set; } private MapSet initMap(XmlElement map) { MapSet set = new MapSet( int.Parse(map.Attributes["index"].Value), map.Attributes["name"].Value); set.ImagesName = map.Attributes["images_name"].Value; set.XCount = int.Parse(map.Attributes["xcount"].Value); set.YCount = int.Parse(map.Attributes["ycount"].Value); set.CellW = int.Parse(map.Attributes["cellw"].Value); set.CellH = int.Parse(map.Attributes["cellh"].Value); set.LayerCount = int.Parse(map.Attributes["layer_count"].Value); int cdCount = int.Parse(map.Attributes["cd_part_count"].Value); set.BlocksType = new BlockType[cdCount]; set.BlocksMask = new int[cdCount]; set.BlocksX1 = new int[cdCount]; set.BlocksY1 = new int[cdCount]; set.BlocksX2 = new int[cdCount]; set.BlocksY2 = new int[cdCount]; set.BlocksW = new int[cdCount]; set.BlocksH = new int[cdCount]; set.TerrainTile = new int[set.LayerCount, set.YCount, set.XCount]; set.TerrainFlip = new int[set.LayerCount, set.YCount, set.XCount]; set.TerrainFlag = new int[set.LayerCount, set.YCount, set.XCount]; foreach (XmlNode node in map.ChildNodes) { if (node is XmlElement) { XmlElement e = (XmlElement)node; if (e.Name.Equals("cd_part")) { int index = int.Parse(e.Attributes["index"].Value); set.BlocksType[index] = "rect".Equals(e.Attributes["type"].Value) ? BlockType.CD_TYPE_RECT : BlockType.CD_TYPE_LINE; set.BlocksMask[index] = int.Parse(e.Attributes["mask"].Value); set.BlocksX1[index] = int.Parse(e.Attributes["x1"].Value); set.BlocksY1[index] = int.Parse(e.Attributes["y1"].Value); set.BlocksX2[index] = int.Parse(e.Attributes["x2"].Value); set.BlocksY2[index] = int.Parse(e.Attributes["y2"].Value); set.BlocksW[index] = int.Parse(e.Attributes["width"].Value); set.BlocksH[index] = int.Parse(e.Attributes["height"].Value); } else if (e.Name.Equals("layer")) { int layerIndex = int.Parse(e.Attributes["index"].Value); String[] tile_matrix = GetArray2D(e.Attributes["tile_matrix"].Value); String[] flip_matrix = GetArray2D(e.Attributes["flip_matrix"].Value); String[] flag_matrix = GetArray2D(e.Attributes["flag_matrix"].Value); for (int y = 0; y < set.YCount; y++) { String[] tline = tile_matrix[y].Split(','); String[] fline = flip_matrix[y].Split(','); String[] cline = flag_matrix[y].Split(','); for (int x = 0; x < set.XCount; x++) { set.TerrainTile[layerIndex, y, x] = int.Parse(tline[x]); set.TerrainFlip[layerIndex, y, x] = int.Parse(fline[x]); set.TerrainFlag[layerIndex, y, x] = int.Parse(cline[x]); } } } else if (e.Name.Equals("Append")) { set.AppendData = GetArray1DLines(e.Attributes["data"].Value); } } } return set; } private SpriteSet initSprite(XmlElement sprite) { SpriteSet set = new SpriteSet( int.Parse(sprite.Attributes["index"].Value), sprite.Attributes["name"].Value); set.ImagesName = sprite.Attributes["images_name"].Value; if (sprite.HasAttribute("complexMode")) { set.ComplexMode = Boolean.Parse(sprite.Attributes["complexMode"].Value); } else { set.ComplexMode = false; } int scenePartCount = int.Parse(sprite.Attributes["scene_part_count"].Value); int sceneFrameCount = int.Parse(sprite.Attributes["scene_frame_count"].Value); int cdCount = int.Parse(sprite.Attributes["cd_part_count"].Value); int collidesCount = int.Parse(sprite.Attributes["cd_frame_count"].Value); int animateCount = int.Parse(sprite.Attributes["animate_count"].Value); set.PartX = new float[scenePartCount]; set.PartY = new float[scenePartCount]; set.PartZ = new float[scenePartCount]; set.PartTileID = new int[scenePartCount]; set.PartTileTrans = new Trans[scenePartCount]; set.PartAlpha = new float[scenePartCount]; set.PartRotate = new float[scenePartCount]; set.PartScaleX = new float[scenePartCount]; set.PartScaleY = new float[scenePartCount]; set.PartAnchorX = new float[scenePartCount]; set.PartAnchorY = new float[scenePartCount]; set.Parts = new short[sceneFrameCount][]; set.BlocksMask = new int[cdCount]; set.BlocksX1 = new float[cdCount]; set.BlocksY1 = new float[cdCount]; set.BlocksW = new float[cdCount]; set.BlocksH = new float[cdCount]; set.Blocks = new short[collidesCount][]; set.AnimateCount = animateCount; set.AnimateNames = new String[animateCount]; set.FrameAnimate = new short[animateCount][]; set.FrameAlpha = new float[animateCount][]; set.FrameCDMap = new short[animateCount][]; set.FrameCDAtk = new short[animateCount][]; set.FrameCDDef = new short[animateCount][]; set.FrameCDExt = new short[animateCount][]; set.FrameDatas = new String[animateCount][]; //NodeList list = sprite.getChildNodes(); foreach (XmlNode node in sprite.ChildNodes) { if (node is XmlElement) { XmlElement e = (XmlElement)node; if (e.Name.Equals("scene_part")) { int index = int.Parse(e.Attributes["index"].Value); set.PartTileID[index] = int.Parse(e.Attributes["tile"].Value); set.PartX[index] = float.Parse(e.Attributes["x"].Value); set.PartY[index] = float.Parse(e.Attributes["y"].Value); set.PartZ[index] = float.Parse(e.Attributes["z"].Value); set.PartTileTrans[index] = (Trans)byte.Parse(e.Attributes["trans"].Value); set.PartAlpha[index] = float.Parse(e.Attributes["alpha"].Value, System.Globalization.CultureInfo.InvariantCulture); set.PartRotate[index] = float.Parse(e.Attributes["rotate"].Value, System.Globalization.CultureInfo.InvariantCulture); set.PartScaleX[index] = float.Parse(e.Attributes["scaleX"].Value, System.Globalization.CultureInfo.InvariantCulture); set.PartScaleY[index] = float.Parse(e.Attributes["scaleY"].Value, System.Globalization.CultureInfo.InvariantCulture); if (e.HasAttribute("anchorX")) { set.PartAnchorX[index] = float.Parse(e.Attributes["anchorX"].Value, System.Globalization.CultureInfo.InvariantCulture); set.PartAnchorY[index] = float.Parse(e.Attributes["anchorY"].Value, System.Globalization.CultureInfo.InvariantCulture); } } else if (e.Name.Equals("scene_frame")) { int index = int.Parse(e.Attributes["index"].Value); int frameCount = int.Parse(e.Attributes["data_size"].Value); set.Parts[index] = new short[frameCount]; if (frameCount > 0) { String[] data = e.Attributes["data"].Value.Split(','); for (int f = 0; f < frameCount; f++) { set.Parts[index][f] = short.Parse(data[f]); } } } else if (e.Name.Equals("cd_part")) { int index = int.Parse(e.Attributes["index"].Value); set.BlocksMask[index] = int.Parse(e.Attributes["mask"].Value); set.BlocksX1[index] = float.Parse(e.Attributes["x1"].Value); set.BlocksY1[index] = float.Parse(e.Attributes["y1"].Value); set.BlocksW[index] = float.Parse(e.Attributes["width"].Value); set.BlocksH[index] = float.Parse(e.Attributes["height"].Value); } else if (e.Name.Equals("cd_frame")) { int index = int.Parse(e.Attributes["index"].Value); int frameCount = int.Parse(e.Attributes["data_size"].Value); set.Blocks[index] = new short[frameCount]; if (frameCount > 0) { String[] data = e.Attributes["data"].Value.Split(','); for (int f = 0; f < frameCount; f++) { set.Blocks[index][f] = short.Parse(data[f]); } } } else if (e.Name.Equals("frames")) { TextInputStream AnimateNamesReader = new TextInputStream( new StringReader(e.Attributes["names"].Value), null); String[] frame_counts = e.Attributes["counts"].Value.Split(','); String[] frame_animate = GetArray2D(e.Attributes["animates"].Value); String[] frame_cd_map = GetArray2D(e.Attributes["cd_map"].Value); String[] frame_cd_atk = GetArray2D(e.Attributes["cd_atk"].Value); String[] frame_cd_def = GetArray2D(e.Attributes["cd_def"].Value); String[] frame_cd_ext = GetArray2D(e.Attributes["cd_ext"].Value); String[] frame_alpha = GetArray2D(e.Attributes["alpha"].Value); for (int i = 0; i < animateCount; i++) { set.AnimateNames[i] = AnimateNamesReader.GetUTF(); int frameCount = int.Parse(frame_counts[i]); String[] animate = frame_animate[i].Split(','); String[] cd_map = frame_cd_map[i].Split(','); String[] cd_atk = frame_cd_atk[i].Split(','); String[] cd_def = frame_cd_def[i].Split(','); String[] cd_ext = frame_cd_ext[i].Split(','); String[] alpha = frame_alpha[i].Split(','); set.FrameAnimate[i] = new short[frameCount]; set.FrameCDMap[i] = new short[frameCount]; set.FrameCDAtk[i] = new short[frameCount]; set.FrameCDDef[i] = new short[frameCount]; set.FrameCDExt[i] = new short[frameCount]; set.FrameAlpha[i] = new float[frameCount]; for (int f = 0; f < frameCount; f++) { set.FrameAnimate[i][f] = short.Parse(animate[f]); set.FrameCDMap[i][f] = short.Parse(cd_map[f]); set.FrameCDAtk[i][f] = short.Parse(cd_atk[f]); set.FrameCDDef[i][f] = short.Parse(cd_def[f]); set.FrameCDExt[i][f] = short.Parse(cd_ext[f]); set.FrameAlpha[i][f] = float.Parse(alpha[f]); } } if (e.HasAttribute("fdata")) { String[] frame_datas = GetArray2D(e.Attributes["fdata"].Value); for (int i = 0; i < animateCount; i++) { int frameCount = int.Parse(frame_counts[i]); TextInputStream frameDataReader = new TextInputStream( new StringReader(frame_datas[i])); set.FrameDatas[i] = new String[frameCount]; for (int f = 0; f < frameCount; f++) { set.FrameDatas[i][f] = frameDataReader.GetUTF(); } } } } else if (e.Name.Equals("Append")) { set.AppendData = GetArray1DLines(e.Attributes["data"].Value); } } } return set; } private void initLevel(XmlElement level) { foreach (XmlNode node in level.ChildNodes) { if (node is XmlElement) { XmlElement e = (XmlElement)node; if (e.Name.Equals("world")) { WorldSet ws = initWorld(e); WorldTable.Add(ws.Name, ws); } } } } private WorldSet initWorld(XmlElement world) { WorldSet set = new WorldSet( int.Parse(world.Attributes["index"].Value), world.Attributes["name"].Value); set.GridXCount = int.Parse(world.Attributes["grid_x_count"].Value); set.GridYCount = int.Parse(world.Attributes["grid_y_count"].Value); set.GridW = int.Parse(world.Attributes["grid_w"].Value); set.GridH = int.Parse(world.Attributes["grid_h"].Value); set.Width = int.Parse(world.Attributes["width"].Value); set.Height = int.Parse(world.Attributes["height"].Value); // int maps_count = int.Parse(world.Attributes["unit_count_map"]); // int sprs_count = int.Parse(world.Attributes["unit_count_sprite"]); // int wpss_count = int.Parse(world.Attributes["waypoint_count"]); // int wrss_count = int.Parse(world.Attributes["region_count"]); set.Data = GetArray1DLines(world.Attributes["data"].Value); int terrains_count = set.GridXCount * set.GridYCount; set.Terrian = new int[set.GridXCount, set.GridYCount]; String[] terrains = world.Attributes["terrain"].Value.Split(','); for (int i = 0; i < terrains_count; i++) { int x = i / set.GridYCount; int y = i % set.GridYCount; set.Terrian[x, y] = int.Parse(terrains[i]); } //NodeList list = world.getChildNodes(); foreach (XmlNode node in world.ChildNodes) { if (node is XmlElement) { XmlElement e = (XmlElement)node; if (e.Name.Equals("unit_map")) { WorldSet.MapObject map = new WorldSet.MapObject(); map.Index = int.Parse(e.Attributes["index"].Value); map.UnitName = e.Attributes["map_name"].Value; map.MapID = e.Attributes["id"].Value; map.X = int.Parse(e.Attributes["x"].Value); map.Y = int.Parse(e.Attributes["y"].Value); try { map.Priority = int.Parse(e.Attributes["priority"].Value); } catch (Exception e2) { } map.ImagesID = e.Attributes["images"].Value; map.Data = GetArray1DLines(e.Attributes["map_data"].Value); set.Maps.Add(map.Index, map); } else if (e.Name.Equals("unit_sprite")) { WorldSet.SpriteObject spr = new WorldSet.SpriteObject(); spr.Index = int.Parse(e.Attributes["index"].Value); spr.UnitName = e.Attributes["spr_name"].Value; spr.SprID = e.Attributes["id"].Value; spr.Anim = int.Parse(e.Attributes["animate_id"].Value); spr.Frame = int.Parse(e.Attributes["frame_id"].Value); spr.X = int.Parse(e.Attributes["x"].Value); spr.Y = int.Parse(e.Attributes["y"].Value); try { spr.Priority = int.Parse(e.Attributes["priority"].Value); } catch (Exception e2) { } spr.ImagesID = e.Attributes["images"].Value; spr.Data = GetArray1DLines(e.Attributes["spr_data"].Value); set.Sprs.Add(spr.Index, spr); } else if (e.Name.Equals("unit_image")) { WorldSet.ImageObject img = new WorldSet.ImageObject(); img.Index = int.Parse(e.Attributes["index"].Value); img.UnitName = e.Attributes["img_name"].Value; img.ImagesID = e.Attributes["id"].Value; img.TileID = int.Parse(e.Attributes["tile_id"].Value); img.ImgAnchor = (ImageAnchor)Enum.Parse(typeof(ImageAnchor), e.Attributes["anchor"].Value); img.ImgTrans = (ImageTrans)Enum.Parse(typeof(ImageTrans), e.Attributes["trans"].Value); img.X = int.Parse(e.Attributes["x"].Value); img.Y = int.Parse(e.Attributes["y"].Value); try { img.Priority = int.Parse(e.Attributes["priority"].Value); } catch (Exception e2) { } img.Data = GetArray1DLines(e.Attributes["img_data"].Value); set.Imgs.Add(img.Index, img); } else if (e.Name.Equals("waypoint")) { WorldSet.WaypointObject wp = new WorldSet.WaypointObject(); wp.Index = int.Parse(e.Attributes["index"].Value); wp.X = int.Parse(e.Attributes["x"].Value); wp.Y = int.Parse(e.Attributes["y"].Value); wp.Data = GetArray1DLines(e.Attributes["path_data"].Value); set.WayPoints.Add(wp.Index, wp); } else if (e.Name.Equals("region")) { WorldSet.RegionObject wr = new WorldSet.RegionObject(); wr.Index = int.Parse(e.Attributes["index"].Value); wr.X = int.Parse(e.Attributes["x"].Value); wr.Y = int.Parse(e.Attributes["y"].Value); wr.W = int.Parse(e.Attributes["width"].Value); wr.H = int.Parse(e.Attributes["height"].Value); wr.Data = GetArray1DLines(e.Attributes["region_data"].Value); set.Regions.Add(wr.Index, wr); } else if (e.Name.Equals("event")) { WorldSet.EventObject ev = new WorldSet.EventObject(); ev.Index = int.Parse(e.Attributes["index"].Value); ev.ID = int.Parse(e.Attributes["id"].Value); ev.X = int.Parse(e.Attributes["x"].Value); ev.Y = int.Parse(e.Attributes["y"].Value); ev.EventName = e.Attributes["event_name"].Value; ev.EventFile = e.Attributes["event_file"].Value; ev.Data = e.Attributes["event_data"].Value; set.Events.Add(ev.Index, ev); } } } foreach (XmlNode node in world.ChildNodes) { if (node is XmlElement) { XmlElement e = (XmlElement)node; if (e.Name.Equals("waypoint_link")) { int start = int.Parse(e.Attributes["start"].Value); int end = int.Parse(e.Attributes["end"].Value); set.WayPoints.Get(start).Nexts.Put(end, set.WayPoints.Get(end)); } } } return set; } public override Image LoadImage(string imgpath) { string output_dir = path.Substring(0, path.LastIndexOf('/')); Image ret = Driver.Instance.createImage(output_dir + "/" + imgpath); return ret; } } public class CPJLoaderBIN : CPJLoader { #region Constants private static readonly int VERSION_VALUE_1001 = 0x01000001; private static readonly int VERSION_VALUE_1002 = 0x01000002; private static readonly int VERSION_VALUE_2000 = 0x02000000; private static readonly byte[] VERSION = new byte[] { 0, 0, 0, 0 }; private static readonly byte[] CE_HEAD_START = new byte[] { (byte)'C', (byte)'E', (byte)'F', (byte)'S' }; private static readonly byte[] CE_IMG_START = new byte[] { (byte)'C', (byte)'E', (byte)'I', (byte)'M' }; private static readonly byte[] CE_SPR_START = new byte[] { (byte)'C', (byte)'E', (byte)'S', (byte)'P' }; private static readonly byte[] CE_MAP_START = new byte[] { (byte)'C', (byte)'E', (byte)'M', (byte)'P' }; private static readonly byte[] CE_WORLD_START = new byte[] { (byte)'C', (byte)'E', (byte)'W', (byte)'D' }; #endregion private byte[] version = new byte[VERSION.Length]; private long filesize; private string path; private string image_type; private bool image_tile; private bool image_group; public int VersionValue { get; private set; } public CPJLoaderBIN(string file) { this.path = Resource.FormatPath(file); var stream = Resource.LoadDataAsStream(path); if (stream != null) { try { var input = new InputStream(stream, null); byte[] head_trunk = new byte[4]; input.GetRawData(head_trunk, 0, head_trunk.Length); if (!CUtils.ArraysEqual(head_trunk, CE_HEAD_START)) { throw new Exception("Unknow File Type : CE_HEAD_START"); } input.GetRawData(version, 0, version.Length); this.filesize = input.GetS64(); this.image_group = input.GetBool(); this.image_tile = input.GetBool(); this.image_type = input.GetUTF(); this.VersionValue = 0; for (int i = 0; i < version.Length; i++) { VersionValue |= (((int)version[i]) << (i * 8)); } { // /////////////////////////////////////////// { input.GetRawData(head_trunk, 0, head_trunk.Length); if (!CUtils.ArraysEqual(head_trunk, CE_IMG_START)) { throw new Exception("Unknow File Type : CE_IMG_START"); } int imgSize = input.GetS32(); for (int i = 0; i < imgSize; i++) { ImagesSet im = readImagesSet(input); base.ImgTable.Put(im.Name, im); } } // /////////////////////////////////////////// { input.GetRawData(head_trunk, 0, head_trunk.Length); if (!CUtils.ArraysEqual(head_trunk, CE_SPR_START)) { throw new Exception("Unknow File Type : CE_SPR_START"); } int sprSize = input.GetS32(); for (int i = 0; i < sprSize; i++) { SpriteSet im = readSpriteSet(input); base.SprTable.Put(im.Name, im); } } // /////////////////////////////////////////// { input.GetRawData(head_trunk, 0, head_trunk.Length); if (!CUtils.ArraysEqual(head_trunk, CE_MAP_START)) { throw new Exception("Unknow File Type : CE_MAP_START"); } int mapSize = input.GetS32(); for (int i = 0; i < mapSize; i++) { MapSet im = readMapSet(input); base.MapTable.Put(im.Name, im); } } // /////////////////////////////////////////// { input.GetRawData(head_trunk, 0, head_trunk.Length); if (!CUtils.ArraysEqual(head_trunk, CE_WORLD_START)) { throw new Exception("Unknow File Type : CE_WORLD_START"); } int wdSize = input.GetS32(); for (int i = 0; i < wdSize; i++) { WorldSet im = readWorldSet(input); base.WorldTable.Put(im.Name, im); } } // /////////////////////////////////////////// } } finally { stream.Dispose(); } } } private ImagesSet readImagesSet(InputStream bis) { ImagesSet im = new ImagesSet( bis.GetS32(), bis.GetUTF()); im.Count = bis.GetS32(); im.ClipsX = new int[im.Count]; im.ClipsY = new int[im.Count]; im.ClipsW = new int[im.Count]; im.ClipsH = new int[im.Count]; im.ClipsKey = new String[im.Count]; for (int i = 0; i < im.Count; i++) { if (bis.GetBool()) { im.ClipsX[i] = bis.GetS32(); im.ClipsY[i] = bis.GetS32(); im.ClipsW[i] = bis.GetS32(); im.ClipsH[i] = bis.GetS32(); im.ClipsKey[i] = bis.GetUTF(); } } im.Extention = bis.GetUTF(); im.IsTiles = bis.GetBool(); im.ImageInfo = bis.GetUTF(); if (this.VersionValue >= VERSION_VALUE_1002) { im.TotalW = bis.GetS32(); im.TotalH = bis.GetS32(); im.SplitSize = bis.GetS32(); } im.AppendData = bis.GetUTF(); return im; } private SpriteSet readSpriteSet(InputStream bis) { SpriteSet im = new SpriteSet( bis.GetS32(), bis.GetUTF()); im.ImagesName = bis.GetUTF(); if (this.VersionValue >= VERSION_VALUE_1001) { im.ComplexMode = bis.GetBool(); } { int partCount = bis.GetS32(); im.PartX = new float[partCount]; im.PartY = new float[partCount]; im.PartZ = new float[partCount]; im.PartTileID = new int[partCount]; im.PartTileTrans = new Trans[partCount]; im.PartAlpha = new float[partCount]; im.PartRotate = new float[partCount]; im.PartScaleX = new float[partCount]; im.PartScaleY = new float[partCount]; im.PartAnchorX = new float[partCount]; im.PartAnchorY = new float[partCount]; for (int i = 0; i < partCount; i++) { if (this.VersionValue >= VERSION_VALUE_2000) { im.PartX[i] = bis.GetF32(); im.PartY[i] = bis.GetF32(); im.PartZ[i] = bis.GetF32(); } else { im.PartX[i] = bis.GetS16(); im.PartY[i] = bis.GetS16(); im.PartZ[i] = bis.GetS16(); } im.PartTileID[i] = bis.GetS32(); im.PartTileTrans[i] = bis.GetEnum8(); im.PartAlpha[i] = bis.GetF32(); im.PartRotate[i] = bis.GetF32(); im.PartScaleX[i] = bis.GetF32(); im.PartScaleY[i] = bis.GetF32(); im.PartAnchorX[i] = bis.GetF32(); im.PartAnchorY[i] = bis.GetF32(); } im.Parts = new short[bis.GetS32()][]; for (int i = 0; i < im.Parts.Length; i++) { im.Parts[i] = new short[bis.GetS32()]; for (int j = 0; j < im.Parts[i].Length; j++) { im.Parts[i][j] = bis.GetS16(); } } } { int cdCount = bis.GetS32(); im.BlocksMask = new int[cdCount]; im.BlocksX1 = new float[cdCount]; im.BlocksY1 = new float[cdCount]; im.BlocksW = new float[cdCount]; im.BlocksH = new float[cdCount]; for (int i = 0; i < cdCount; i++) { im.BlocksMask[i] = bis.GetS32(); if (this.VersionValue >= VERSION_VALUE_2000) { im.BlocksX1[i] = bis.GetF32(); im.BlocksY1[i] = bis.GetF32(); im.BlocksW[i] = bis.GetF32(); im.BlocksH[i] = bis.GetF32(); } else { im.BlocksX1[i] = bis.GetS16(); im.BlocksY1[i] = bis.GetS16(); im.BlocksW[i] = bis.GetS16(); im.BlocksH[i] = bis.GetS16(); } } im.Blocks = new short[bis.GetS32()][]; for (int i = 0; i < im.Blocks.Length; i++) { im.Blocks[i] = new short[bis.GetS32()]; for (int j = 0; j < im.Blocks[i].Length; j++) { im.Blocks[i][j] = bis.GetS16(); } } } { im.AnimateCount = bis.GetS32(); im.AnimateNames = new String[im.AnimateCount]; im.FrameAnimate = new short[im.AnimateCount][]; im.FrameCDMap = new short[im.AnimateCount][]; im.FrameCDAtk = new short[im.AnimateCount][]; im.FrameCDDef = new short[im.AnimateCount][]; im.FrameCDExt = new short[im.AnimateCount][]; im.FrameAlpha = new float[im.AnimateCount][]; im.FrameDatas = new String[im.AnimateCount][]; for (int i = 0; i < im.AnimateCount; i++) { im.AnimateNames[i] = bis.GetUTF(); int frameCount = bis.GetS32(); im.FrameAnimate[i] = new short[frameCount]; im.FrameCDMap[i] = new short[frameCount]; im.FrameCDAtk[i] = new short[frameCount]; im.FrameCDDef[i] = new short[frameCount]; im.FrameCDExt[i] = new short[frameCount]; im.FrameAlpha[i] = new float[frameCount]; im.FrameDatas[i] = new String[frameCount]; for (int j = 0; j < frameCount; j++) { im.FrameAnimate[i][j] = bis.GetS16(); im.FrameCDMap[i][j] = bis.GetS16(); im.FrameCDAtk[i][j] = bis.GetS16(); im.FrameCDDef[i][j] = bis.GetS16(); im.FrameCDExt[i][j] = bis.GetS16(); im.FrameAlpha[i][j] = bis.GetF32(); im.FrameDatas[i][j] = bis.GetUTF(); } } } im.AppendData = bis.GetUTF(); return im; } private MapSet readMapSet(InputStream bis) { MapSet im = new MapSet( bis.GetS32(), bis.GetUTF()); im.ImagesName = bis.GetUTF(); im.XCount = bis.GetS32(); im.YCount = bis.GetS32(); im.CellW = bis.GetS32(); im.CellH = bis.GetS32(); im.LayerCount = bis.GetS32(); int blockCount = bis.GetS32(); im.BlocksType = new BlockType[blockCount]; im.BlocksMask = new int[blockCount]; im.BlocksX1 = new int[blockCount]; im.BlocksY1 = new int[blockCount]; im.BlocksX2 = new int[blockCount]; im.BlocksY2 = new int[blockCount]; im.BlocksW = new int[blockCount]; im.BlocksH = new int[blockCount]; for (int i = 0; i < blockCount; i++) { im.BlocksType[i] = (BlockType)bis.GetS32(); im.BlocksMask[i] = bis.GetS32(); im.BlocksX1[i] = bis.GetS32(); im.BlocksY1[i] = bis.GetS32(); im.BlocksX2[i] = bis.GetS32(); im.BlocksY2[i] = bis.GetS32(); im.BlocksW[i] = bis.GetS32(); im.BlocksH[i] = bis.GetS32(); } im.TerrainTile = new int[im.LayerCount, im.YCount, im.XCount]; im.TerrainFlip = new int[im.LayerCount, im.YCount, im.XCount]; im.TerrainFlag = new int[im.LayerCount, im.YCount, im.XCount]; for (int i = 0; i < im.LayerCount; i++) { for (int y = 0; y < im.YCount; y++) { for (int x = 0; x < im.XCount; x++) { im.TerrainTile[i, y, x] = bis.GetS32(); im.TerrainFlip[i, y, x] = bis.GetS32(); im.TerrainFlag[i, y, x] = bis.GetS32(); } } } im.AppendData = bis.GetUTF(); return im; } private WorldSet readWorldSet(InputStream bis) { WorldSet im = new WorldSet( bis.GetS32(), bis.GetUTF()); im.GridXCount = bis.GetS32(); im.GridYCount = bis.GetS32(); im.GridW = bis.GetS32(); im.GridH = bis.GetS32(); im.Width = bis.GetS32(); im.Height = bis.GetS32(); im.Terrian = new int[im.GridXCount, im.GridYCount]; for (int x = 0; x < im.GridXCount; x++) { for (int y = 0; y < im.GridYCount; y++) { im.Terrian[x, y] = bis.GetS32(); } } { { int sprsCount = bis.GetS32(); for (int i = 0; i < sprsCount; i++) { WorldSet.SpriteObject o = new WorldSet.SpriteObject(); o.Index = bis.GetS32(); o.UnitName = bis.GetUTF(); o.SprID = bis.GetUTF(); o.ImagesID = bis.GetUTF(); o.Anim = bis.GetS32(); o.Frame = bis.GetS32(); o.X = bis.GetS32(); o.Y = bis.GetS32(); o.Priority = bis.GetS32(); o.Data = bis.GetUTF(); im.Sprs.Put(o.Index, o); } } { int mapsCount = bis.GetS32(); for (int i = 0; i < mapsCount; i++) { WorldSet.MapObject o = new WorldSet.MapObject(); o.Index = bis.GetS32(); o.UnitName = bis.GetUTF(); o.MapID = bis.GetUTF(); o.ImagesID = bis.GetUTF(); o.X = bis.GetS32(); o.Y = bis.GetS32(); o.Priority = bis.GetS32(); o.Data = bis.GetUTF(); im.Maps.Put(o.Index, o); } } { int imgsCount = bis.GetS32(); for (int i = 0; i < imgsCount; i++) { WorldSet.ImageObject o = new WorldSet.ImageObject(); o.Index = bis.GetS32(); o.UnitName = bis.GetUTF(); o.ImagesID = bis.GetUTF(); o.TileID = bis.GetS32(); o.X = bis.GetS32(); o.Y = bis.GetS32(); o.Priority = bis.GetS32(); o.ImgAnchor = (ImageAnchor)bis.GetS32(); o.ImgTrans = (ImageTrans)bis.GetS32(); o.Data = bis.GetUTF(); im.Imgs.Put(o.Index, o); } } { int wpCount = bis.GetS32(); for (int i = 0; i < wpCount; i++) { WorldSet.WaypointObject o = new WorldSet.WaypointObject(); o.Index = bis.GetS32(); o.X = bis.GetS32(); o.Y = bis.GetS32(); o.Data = bis.GetUTF(); int nextCount = bis.GetS32(); for (int j = 0; j < nextCount; j++) { int nid = bis.GetS32(); o.Nexts.Put(nid, null); } im.WayPoints.Put(o.Index, o); } foreach (WorldSet.WaypointObject o in im.WayPoints.Values) { foreach (int nid in o.Nexts.Keys) { o.Nexts.Put(nid, im.WayPoints.Get(nid)); } } } { int rgCount = bis.GetS32(); for (int i = 0; i < rgCount; i++) { WorldSet.RegionObject o = new WorldSet.RegionObject(); o.Index = bis.GetS32(); o.X = bis.GetS32(); o.Y = bis.GetS32(); o.W = bis.GetS32(); o.H = bis.GetS32(); o.Data = bis.GetUTF(); im.Regions.Put(o.Index, o); } } { int evCount = bis.GetS32(); for (int i = 0; i < evCount; i++) { WorldSet.EventObject o = new WorldSet.EventObject(); o.Index = bis.GetS32(); o.ID = bis.GetS64(); o.EventName = bis.GetUTF(); o.EventFile = bis.GetUTF(); o.X = bis.GetS32(); o.Y = bis.GetS32(); o.Data = bis.GetUTF(); im.Events.Put(o.Index, o); } } } im.Data = bis.GetUTF(); return im; } public override Image LoadImage(string imgpath) { string output_dir = path.Substring(0, path.LastIndexOf('/')); Image ret = Driver.Instance.createImage(output_dir + "/" + imgpath); return ret; } } }