Example #1
0
        private static void WriteMethod()
        {
            writer.WriteLine("ZoneTileSet tiles;");
            writer.WriteLine("var sets = new ZoneTileSet[(int)MapId.End];");
            for (var i = 0; i < tileSets.Length; i++)
            {
                var tileSet = tileSets[i];
                var map     = (MapId)i;
                if (tileSet == null)
                {
                    continue;
                }

                writer.WriteLine("sets[(int)MapId.{0}] = tiles = new ZoneTileSet();", map);

                // Rows along the x-axis
                for (var x = 0; x < TerrainConstants.TilesPerMapSide; x++)
                {
                    // Columns along the y-axis
                    for (var y = 0; y < TerrainConstants.TilesPerMapSide; y++)
                    {
                        var grid = tileSet.ZoneGrids[y, x];
                        if (grid is ZoneGrid && ((ZoneGrid)grid).ZoneIds != null)
                        {
                            var sameId  = true;
                            var str     = new StringBuilder(10000);
                            var declStr = string.Format("tiles.ZoneGrids[{0},{1}] = ", y, x);
                            str.Append(string.Format("new ZoneGrid(new uint[{0},{0}] ", TerrainConstants.ChunksPerTileSide));
                            str.Append("{");
                            for (var col = 0; col < TerrainConstants.ChunksPerTileSide; col++)
                            {
                                //str.Append(writer.BaseWriter.Indent + "\t");
                                str.Append(GetLine(((ZoneGrid)grid).ZoneIds, col, TerrainConstants.ChunksPerTileSide, ref sameId));
                                if (col < TerrainConstants.ChunksPerTileSide - 1)
                                {
                                    str.Append(",");
                                }
                                //str.AppendLine();
                            }
                            str.Append("});");
                            if (sameId)
                            {
                                var zoneId = ((ZoneGrid)grid).ZoneIds[0, 0];
                                str = new StringBuilder(string.Format("new SimpleZoneGrid({0});", zoneId));
                            }

                            writer.WriteLine(declStr + str);
                        }
                    }
                }
            }
            writer.WriteLine("return sets;");
        }
Example #2
0
        private static void WriteSpellLinesMethod()
        {
            writer.WriteLine("SpellLine[] lines;");
            writer.WriteLine();

            for (var i = 0; i < Maps.Length; i++)
            {
                var map  = Maps[i];
                var clss = (ClassId)i;

                if (map != null)
                {
                    var listCount = map.Count;
                    var s         = 0;

                    writer.WriteMap((clss != 0 ? clss.ToString() : "Other") + " (" + listCount + ")");
                    writer.WriteLine("lines = new SpellLine[]");
                    writer.OpenBracket();

                    foreach (var set in map.Values)
                    {
                        var spells   = set.ToList();
                        var lineName = GetSpellLineName(spells.First());

                        spells.Sort((a, b) => a.Id.CompareTo(b.Id));                                    // first sort by rank and then by id
                        spells.Sort((a, b) => a.Rank.CompareTo(b.Rank));

                        writer.WriteLine("new SpellLine(SpellLineId." + lineName + ", ");
                        writer.IndentLevel++;
                        var j = 0;
                        foreach (var spell in spells)
                        {
                            j++;
                            writer.WriteIndent("SpellHandler.Get(SpellId." + spell.SpellId + ")");
                            if (j < set.Count)
                            {
                                writer.WriteLine(",");
                            }
                        }
                        writer.IndentLevel--;
                        writer.Write(")");
                        if (s < listCount - 1)
                        {
                            writer.WriteLine(",");
                        }
                        ++s;
                    }
                    writer.CloseBracket(true);
                    writer.WriteLine("AddSpellLines(ClassId.{0}, lines);", clss);
                    writer.WriteEndMap();
                    writer.WriteLine();
                }
            }
        }
Example #3
0
        private static void WriteMethod()
        {
            var arr = MapBoundaryUtil.ExportBoundaries();

            writer.WriteLine("var boxes = new BoundingBox[(int)MapId.End];");
            for (var i = 0; i < arr.Length; i++)
            {
                var bounds = arr[i];
                var map    = (MapId)i;
                if (bounds == default(BoundingBox))
                {
                    continue;
                }

                writer.WriteLine(
                    "boxes[(int)MapId.{0}] = new BoundingBox(new Vector3({1}f, {2}f, {3}f), new Vector3({4}f, {5}f, {6}f));",
                    map,
                    bounds.Min.X, bounds.Min.Y, bounds.Min.Z,
                    bounds.Max.X, bounds.Max.Y, bounds.Max.Z);
            }
            writer.WriteLine("return boxes;");
        }
        private static void DumpToFile(string outputFileName)
        {
            using (var writer = new CodeFileWriter(outputFileName, "WCell.Constants.Spells", "SpellFailedReason : byte", "enum", ""))
            {
                var len = SpellFailures.Count;
                var val = 0;
                for (var i = 0; i < len; i++, val++)
                {
                    if (unfindableMap.ContainsKey(i))
                    {
                        WriteVal(writer, unfindableMap[i], i);
                        val++;
                    }

                    WriteVal(writer, SpellFailures[i], val);
                }
                writer.WriteLine("Ok = 0xFF");
            }
        }
		private static void DumpToFile(string outputFileName)
		{
			using (var writer = new CodeFileWriter(outputFileName, "WCell.Constants.Spells", "SpellFailedReason : byte", "enum", ""))
			{
				var len = SpellFailures.Count;
				var val = 0;
				for (var i = 0; i < len; i++, val++)
				{
					if (unfindableMap.ContainsKey(i))
					{
						WriteVal(writer, unfindableMap[i], i);
						val++;
					}

					WriteVal(writer, SpellFailures[i], val);
				}
				writer.WriteLine("Ok = 0xFF");
			}
		}
Example #6
0
 public static void WriteWCellInfo()
 {
     using (var writer = new CodeFileWriter(Path.Combine(ToolConfig.WCellConstantsRoot, "WCellInfo.cs"),
                                            "WCell.Constants", "WCellInfo", "static class"))
     {
         writer.WriteSummary(@"The official codename of the current WCell build");
         writer.WriteLine("public const string Codename = \"Amethyst\";");
         writer.WriteLine();
         writer.WriteSummary(@"The color of the current WCell codename");
         writer.WriteLine(@"public const ChatColor CodenameColor = ChatColor.Purple;");
         writer.WriteLine();
         writer.WriteSummary("The version of the WoW Client that is currently supported.");
         writer.WriteLine("public static readonly ClientVersion RequiredVersion = new ClientVersion({0}, {1}, {2}, {3});",
                          WoWFile.Version.Major, WoWFile.Version.Minor, WoWFile.Version.Revision, WoWFile.Version.Build);
         writer.WriteLine();
     }
 }
		public void Write(string fileName)
		{
			using (var writer = new CodeFileWriter(fileName,
			                                       "WCell.Constants.Updates", "UpdateFields",
			                                       CodeFileWriter.StaticTag + " " + CodeFileWriter.Class, 
												   "",
			                                       "System"))
			{
				writer.ExecuteSafely(() =>{
				                          	writer.WriteIndent("public static readonly ");
				                          	writer.Array(UpdateFieldTypeName, "AllFields", 2, ";", () =>{
				                          	                                                            	for (var i = 0;
				                          	                                                            	     i < m_fields.Length;
				                          	                                                            	     i++)
				                          	                                                            	{
				                          	                                                            		var fieldArr = m_fields[i];
				                          	                                                            		writer.WriteRegion(
				                          	                                                            			((ObjectTypeId) i).ToString());
				                          	                                                            		writer.NewArray("UpdateField", ",",
				                          	                                                            		                () =>{
				                          	                                                            		                     	foreach (
				                          	                                                            		                     		var field in
				                          	                                                            		                     			fieldArr)
				                          	                                                            		                     	{
				                          	                                                            		                     		if (field != null)
				                          	                                                            		                     		{
				                          	                                                            		                     			writer.
				                          	                                                            		                     				WriteCommentLine(
				                          	                                                            		                     				field.FullName);
				                          	                                                            		                     			var flags =
				                          	                                                            		                     				Utility.
				                          	                                                            		                     					GetSetIndicesEnum
				                          	                                                            		                     					(field.Flags);

				                          	                                                            		                     			var args = new[]
				                          	                                                            		                     			           	{
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Flags",
				                          	                                                            		                     			           			flags
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				TransformList
				                          	                                                            		                     			           				((
				                          	                                                            		                     			           					flag)
				                          	                                                            		                     			           				 =>
				                          	                                                            		                     			           				 "UpdateFieldFlags." +
				                          	                                                            		                     			           				 flag)
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				ToString
				                          	                                                            		                     			           				(" | "))
				                          	                                                            		                     			           		,
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Group",
				                          	                                                            		                     			           			"ObjectTypeId." +
				                          	                                                            		                     			           			field
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				Group)
				                          	                                                            		                     			           		,
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Name",
				                          	                                                            		                     			           			"\"" +
				                          	                                                            		                     			           			field
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				Name +
				                          	                                                            		                     			           			"\"")
				                          	                                                            		                     			           		,
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Offset",
				                          	                                                            		                     			           			field
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				Offset)
				                          	                                                            		                     			           		,
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Size",
				                          	                                                            		                     			           			field
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				Size)
				                          	                                                            		                     			           		,
				                          	                                                            		                     			           		new KeyValuePair
				                          	                                                            		                     			           			<
				                          	                                                            		                     			           			string
				                          	                                                            		                     			           			,
				                          	                                                            		                     			           			object
				                          	                                                            		                     			           			>(
				                          	                                                            		                     			           			"Type",
				                          	                                                            		                     			           			"UpdateFieldType." +
				                          	                                                            		                     			           			field
				                          	                                                            		                     			           				.
				                          	                                                            		                     			           				Type)
				                          	                                                            		                     			           	};
				                          	                                                            		                     			writer.NewInit(
				                          	                                                            		                     				UpdateFieldTypeName,
				                          	                                                            		                     				args, ",");
				                          	                                                            		                     		}
				                          	                                                            		                     		else
				                          	                                                            		                     		{
				                          	                                                            		                     			writer.WriteLine(
				                          	                                                            		                     				"null,");
				                          	                                                            		                     		}
				                          	                                                            		                     	}
				                          	                                                            		                });
				                          	                                                            		writer.WriteEndRegion();
				                          	                                                            		writer.WriteLine();
				                          	                                                            	}
				                          	});
				                          	writer.WriteLine();

				                          	//writer.WriteStaticMethod("Init", () => {

				                          	//});

				                          	//writer.WriteStaticCTor(() => {
				                          	//    writer.Call("Init");
				                          	//});
				});
			}
		}
 static void WriteVal(CodeFileWriter writer, string name, int value)
 {
     name = name.Replace("SPELL_FAILED_", "");
     name = name.ToCamelCase();
     writer.WriteLine("{0} = {1},", name, value);
 }
		static void WriteVal(CodeFileWriter writer, string name, int value)
		{
			name = name.Replace("SPELL_FAILED_", "");
			name = name.ToCamelCase();
			writer.WriteLine("{0} = {1},", name, value);
		}
		public static void WriteWCellInfo()
		{
			using (var writer = new CodeFileWriter(Path.Combine(ToolConfig.WCellConstantsRoot, "WCellInfo.cs"),
												   "WCell.Constants", "WCellInfo", "static class", "", "WCell.Constants.Misc"))
			{
				writer.WriteSummary(@"The official codename of the current WCell build");
				writer.WriteLine("public const string Codename = \"Amethyst\";");
				writer.WriteLine();
				writer.WriteSummary(@"The color of the current WCell codename");
				writer.WriteLine(@"public const ChatColor CodenameColor = ChatColor.Purple;");
				writer.WriteLine();
				writer.WriteSummary("The version of the WoW Client that is currently supported.");
				writer.WriteLine("public static readonly ClientVersion RequiredVersion = new ClientVersion({0}, {1}, {2}, {3});",
				                 WoWFile.Version.Major, WoWFile.Version.Minor, WoWFile.Version.Revision, WoWFile.Version.Build);
				writer.WriteLine();
			}
		}
Example #11
0
        public static void WriteEnum <T>(
            string enumName,
            string group,
            IEnumerable <T> values,
            bool hexadecimal,
            Validator <T> validator,
            GetField <T> getNameDelegate,
            GetField <T> getCommentDelegate,
            GetField <T, string> getDuplNameDelegate,
            GetField <T> getIdDelegate)
        {
            var dir = Path.Combine(Dir, group);

            Directory.CreateDirectory(dir);

            string file = Path.Combine(dir, enumName + ".cs");

            Console.Write("Writing enum {0} to {1}...", enumName, new DirectoryInfo(file).FullName);

            bool first = true;

            using (var writer = new CodeFileWriter(new StreamWriter(file),
                                                   "WCell.Constants." + group, enumName, "enum"))
            {
                var lines = new List <string>(values.Count());

                var names = new Dictionary <string, int>(values.Count());

                foreach (var item in values)
                {
                    if (item == null || !validator(item))
                    {
                        continue;
                    }

                    string name = getNameDelegate(item).Replace("%", "Percent");

                    name = name.Replace("'s", "s");

                    string[] parts = Regex.Split(name, @"\s+|[^\w\d_]+", RegexOptions.None);

                    for (int i = 0; i < parts.Length; i++)
                    {
                        string part = parts[i];
                        if (part.Length == 0)
                        {
                            continue;
                        }
                        //if (part.Length > 1) {
                        //    part = part.ToLower();
                        string firstChar = part[0] + "";
                        part = firstChar.ToUpper() + part.Substring(1);
                        //}
                        //else {
                        //    part = part.ToUpper();
                        //}

                        parts[i] = part;
                    }

                    name = string.Join("", parts);

                    // against digits at the start
                    Match numMatch = NumRegex.Match(name);
                    if (numMatch.Success)
                    {
                        string num = GetNumString(numMatch.Value);
                        if (name.Length > num.Length)
                        {
                            name = num + name.Substring(numMatch.Value.Length, 1).ToUpper() + name.Substring(numMatch.Value.Length + 1);
                        }
                        else
                        {
                            name = num;
                        }
                    }

                    int count;
                    if (!names.TryGetValue(name, out count))
                    {
                        names.Add(name, 1);
                    }
                    else
                    {
                        names.Remove(name);
                        names.Add(name, ++count);

                        string duplName = null;
                        if (getDuplNameDelegate != null)
                        {
                            duplName = getDuplNameDelegate(item, name);
                        }

                        if (duplName != null)
                        {
                            name = duplName;
                        }
                        else
                        {
                            name = name + "_" + count;
                        }
                    }

                    string val = getIdDelegate(item);
                    if (hexadecimal)
                    {
                        try
                        {
                            int ival = Convert.ToInt32(val);

                            val = string.Format("0x{0:x}", ival);
                        }
                        catch { };
                    }

                    if (first)
                    {
                        first = false;
                        if (long.Parse(val) > 0)
                        {
                            writer.WriteLine("None = 0,");
                        }
                    }

                    string comment = "";
                    if (getCommentDelegate != null)
                    {
                        comment = getCommentDelegate(item);
                        if (comment != null)
                        {
                            string[] commentLines = comment.Split(new string[] { "\n", "\r\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
                            if (commentLines.Length > 0)
                            {
                                writer.StartSummary();
                                foreach (string line in commentLines)
                                {
                                    writer.WriteXmlCommentLine(line);
                                }
                                writer.EndSummary();
                            }
                        }
                    }
                    writer.WriteLine(string.Format("{0} = {1},", name, val));
                }

                writer.WriteLine("End");

                writer.Finish();

                Console.WriteLine(" Done.");
            }
        }
Example #12
0
        public void Write(string fileName)
        {
            using (var writer = new CodeFileWriter(fileName,
                                                   "WCell.Constants.Updates", "UpdateFields",
                                                   CodeFileWriter.StaticTag + " " + CodeFileWriter.Class,
                                                   "",
                                                   "System"))
            {
                writer.ExecuteSafely(() =>
                {
                    writer.WriteIndent("public static readonly ");
                    writer.Array(UpdateFieldTypeName, "AllFields", 2, ";", () =>
                    {
                        for (var i = 0; i < m_fields.Length; i++)
                        {
                            var fieldArr = m_fields[i];
                            writer.WriteRegion(((ObjectTypeId)i).ToString());
                            writer.NewArray("UpdateField", ",", () =>
                            {
                                foreach (var field in fieldArr)
                                {
                                    if (field != null)
                                    {
                                        writer.WriteCommentLine(field.FullName);
                                        var flags = Utility.GetSetIndicesEnum(field.Flags);

                                        var args = new[]
                                        {
                                            new KeyValuePair <string, object> ("Flags", flags.TransformList((flag) =>
                                                                                                            "UpdateFieldFlags." +
                                                                                                            flag)
                                                                               .
                                                                               ToString
                                                                                   (" | "))
                                            ,
                                            new KeyValuePair
                                            <
                                                string
                                                ,
                                                object
                                            >(
                                                "Group",
                                                "ObjectTypeId." +
                                                field
                                                .
                                                Group)
                                            ,
                                            new KeyValuePair
                                            <
                                                string
                                                ,
                                                object
                                            >(
                                                "Name",
                                                "\"" +
                                                field
                                                .
                                                Name +
                                                "\"")
                                            ,
                                            new KeyValuePair
                                            <
                                                string
                                                ,
                                                object
                                            >(
                                                "Offset",
                                                field
                                                .
                                                Offset)
                                            ,
                                            new KeyValuePair
                                            <
                                                string
                                                ,
                                                object
                                            >(
                                                "Size",
                                                field
                                                .
                                                Size)
                                            ,
                                            new KeyValuePair
                                            <
                                                string
                                                ,
                                                object
                                            >(
                                                "Type",
                                                "UpdateFieldType." +
                                                field
                                                .
                                                Type)
                                        };
                                        writer.NewInit(
                                            UpdateFieldTypeName,
                                            args, ",");
                                    }
                                    else
                                    {
                                        writer.WriteLine(
                                            "null,");
                                    }
                                }
                            });
                            writer.WriteEndRegion();
                            writer.WriteLine();
                        }
                    });
                    writer.WriteLine();

                    //writer.WriteStaticMethod("Init", () => {

                    //});

                    //writer.WriteStaticCTor(() => {
                    //    writer.Call("Init");
                    //});
                });
            }
        }
Example #13
0
        public static void WriteEnum <T>(
            string enumName,
            string enumSuffix,
            string group,
            IEnumerable <T> values,
            bool hexadecimal,
            Validator <T> validator,
            GetField <T> getNameDelegate,
            GetField <T> getCommentDelegate,
            GetField <T, string> getDuplNameDelegate,
            GetField <T> getIdDelegate)
        {
            Init();
            var dir = Path.Combine(Dir, group);

            Directory.CreateDirectory(dir);

            var file = Path.Combine(dir, enumName + ".cs");

            Console.Write("Writing enum {0} to {1}...", enumName, new DirectoryInfo(file).FullName);

            var first = true;

            using (var writer = new CodeFileWriter(file,
                                                   "WCell.Constants." + group, enumName, "enum", enumSuffix))
            {
                try
                {
                    var names = new Dictionary <string, int>(values.Count());

                    foreach (T item in values)
                    {
                        if (item == null || item.Equals(default(T)) || !validator(item))
                        {
                            continue;
                        }

                        var name = getNameDelegate(item);

                        if (name == null)
                        {
                            throw new Exception(string.Format("Name for Item {0} in {1}/{2} was null.", item, group, enumName));
                        }

                        name = BeautifyName(name);

                        int count;
                        if (!names.TryGetValue(name, out count))
                        {
                            names.Add(name, 1);
                        }
                        else
                        {
                            names.Remove(name);
                            names.Add(name, ++count);

                            string duplName = null;
                            if (getDuplNameDelegate != null)
                            {
                                duplName = getDuplNameDelegate(item, name);
                            }

                            if (duplName != null)
                            {
                                name = duplName;
                            }
                            else
                            {
                                name = name + "_" + count;
                            }
                        }

                        var val = getIdDelegate(item);
                        if (hexadecimal)
                        {
                            int ival;
                            if (int.TryParse(val, out ival))
                            {
                                val = string.Format("0x{0:x}", ival);
                            }
                        }

                        if (first)
                        {
                            first = false;
                            long id;
                            if (!long.TryParse(val, out id))
                            {
                                throw new InvalidDataException("Invalid ID was not numeric: " + val);
                            }

                            if (id > 0)
                            {
                                writer.WriteLine("None = 0,");
                            }
                        }

                        string comment;
                        if (getCommentDelegate != null)
                        {
                            comment = getCommentDelegate(item);
                            if (comment != null)
                            {
                                var commentLines = comment.Split(new[] { "\n", "\r\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
                                if (commentLines.Length > 0)
                                {
                                    writer.StartSummary();
                                    foreach (string line in commentLines)
                                    {
                                        writer.WriteXmlCommentLine(line);
                                    }
                                    writer.EndSummary();
                                }
                            }
                        }
                        writer.WriteLine(string.Format("{0} = {1},", name, val));
                    }

                    writer.WriteLine("End");

                    writer.Finish();

                    Console.WriteLine(" Done.");
                }
                catch (Exception ex)
                {
                    writer.OnException(ex);
                }
            }
        }