Пример #1
0
			protected void InitializeForExport(ProjectState state, IO.XmlStream s)
			{
				s.ReadAttributeOpt("export", ref mIsExported);

//				if (IsExported)
//					state.Compiler.AddExport(this);
			}
Пример #2
0
			public ScriptFunctionArg(ScriptFunction func, ProjectState state, IO.XmlStream s)
			{
				string type_name = null;
				s.ReadAttribute("type", ref type_name);

				if (!state.scriptingInterface.Types.Contains(type_name))
					throw new Debug.ExceptionLog("CheApe: value type '{0}' does not exist", type_name);

				type = state.scriptingInterface.GetValueType(type_name);
			}
Пример #3
0
			public ScriptFunction(ProjectState state, IO.XmlStream s) : base(state, s)
			{
				string return_type_name = null;
				s.ReadAttribute("returnType", ref return_type_name);
				s.ReadAttributeOpt("help", ref helpString);
				s.ReadAttributeOpt("helpArg", ref helpArgString);
				s.ReadAttributeOpt("internal", ref IsInternal);

				foreach (XmlNode n in s.Cursor.ChildNodes)
				{
					if (n.Name != "arg") continue;

					s.SaveCursor(n);
					args.Add(new ScriptFunctionArg(this, state, s));
					s.RestoreCursor();
				}

				if (!state.scriptingInterface.Types.Contains(return_type_name))
					throw new Debug.ExceptionLog("CheApe: value type '{0}' does not exist", return_type_name);

				returnType = state.scriptingInterface.GetValueType(return_type_name);
				help = state.Compiler.Strings.Add(helpString);
				helpArg = state.Compiler.Strings.Add(helpArgString);
			}
Пример #4
0
            protected Object(ProjectState state, IO.XmlStream s)
            {
                s.ReadAttribute("name", ref nameString);

                name = state.Compiler.Strings.Add(nameString);
            }
Пример #5
0
		void ProcessEnums(ProjectState state, IO.XmlStream s)
		{
			ProcessStringList(state, s, Enums, "Enum", "enum definition");
		}
Пример #6
0
		void ProcessTagDatas(ProjectState state, IO.XmlStream s)
		{
			foreach (XmlNode n in s.Cursor.ChildNodes)
			{
				if (n.Name != "TagData") continue;

				s.SaveCursor(n);
				var tagdata = new TagData(state, s);
				s.RestoreCursor();
				string name_str = tagdata.ToString();

				try { Data.Add(name_str, tagdata); }
				catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag data definition", name_str); }
			}
		}
Пример #7
0
			public virtual void Read(ProjectState state, IO.XmlStream s)
			{
				try { state.ImportedBlocks.Add(this.nameString, this); }
				catch (Exception) { }
			}
Пример #8
0
			/// <summary>
			/// Constructs a tag group definition from an xml definition node
			/// </summary>
			/// <param name="state"></param>
			/// <param name="s"></param>
			/// <remarks>Construct <see cref="TagGroup.Block"/> in the inheriting class's ctor</remarks>
			protected TagGroup(ProjectState state, IO.XmlStream s) : base(state, s)
			{
				s.ReadAttribute("groupTag", ref groupTag);
				s.ReadAttributeOpt("parentTag", ref parentTag);
				s.ReadAttribute("version", 10, ref version);
			}
Пример #9
0
			/// <summary>
			/// Constructs a tag reference definition from an xml definition node
			/// </summary>
			/// <param name="state"></param>
			/// <param name="s"></param>
			public TagReference(ProjectState state, IO.XmlStream s) : base(state, s)
			{
				s.ReadAttributeOpt("isNonResolving", ref IsNonResolving);

				foreach (XmlNode node in s.Cursor.ChildNodes)
					if (node.Name == "field")
						this.elements.Add(node.InnerText);
			}
Пример #10
0
			/// <summary>
			/// Constructs a data definition from an xml definition node
			/// </summary>
			/// <param name="state"></param>
			/// <param name="s"></param>
			public TagData(ProjectState state, IO.XmlStream s) : base(state, s)
			{
				s.ReadAttributeOpt("maxSize", 16, ref maxSize);
				s.ReadAttributeOpt("isNeverStreamed", ref IsNeverStreamed);
				s.ReadAttributeOpt("isTextData", ref IsTextData);
				s.ReadAttributeOpt("isDebugData", ref IsDebugData);
			}
Пример #11
0
			protected ObjectWithDebugName(ProjectState state, string nameString) : base()
			{
				name = state.Compiler.DebugStrings.Add(nameString);
			}
Пример #12
0
		protected abstract void ProcessDefinition(XmlNode node, ProjectState state, IO.XmlStream s);
Пример #13
0
 /// <summary>
 /// Constructs a tag group definition from an xml definition node
 /// </summary>
 /// <param name="state"></param>
 /// <param name="s"></param>
 /// <remarks>Construct <see cref="TagGroup.Block"/> in the inheriting class's ctor</remarks>
 protected TagGroup(ProjectState state, IO.XmlStream s) : base(state, s)
 {
     s.ReadAttribute("groupTag", ref groupTag);
     s.ReadAttributeOpt("parentTag", ref parentTag);
     s.ReadAttribute("version", 10, ref version);
 }
Пример #14
0
			protected ObjectWithDebugName(ProjectState state, IO.XmlStream s) : base()
			{
				s.ReadAttribute("name", ref nameString);
				InitializeForExport(state, s);

				name = state.Compiler.DebugStrings.Add(nameString);
			}
Пример #15
0
 public virtual void Read(ProjectState state, IO.XmlStream s)
 {
     try { state.ImportedBlocks.Add(this.nameString, this); }
     catch (Exception) { }
 }
Пример #16
0
 protected ObjectWithDebugName(ProjectState state, string nameString) : base()
 {
     name = state.Compiler.DebugStrings.Add(nameString);
 }
Пример #17
0
            protected ObjectWithDebugName(ProjectState state, IO.XmlStream s) : base()
            {
                s.ReadAttribute("name", ref nameString);

                name = state.Compiler.DebugStrings.Add(nameString);
            }
Пример #18
0
        /// <summary>
        /// Process a XML file containing CheApe definitions
        /// </summary>
        /// <param name="state"></param>
        /// <param name="s"></param>
        private void ProcessFile(ProjectState state, BlamLib.IO.XmlStream s)
        {
            int complexity = 1 +
                             PreprocessXmlNodeComplexity();

            BlamVersion def_engine = BlamVersion.Unknown;

            s.ReadAttribute("game", ref def_engine);
            if (def_engine != state.Definition.Engine)
            {
                Debug.Assert.If(false, "CheApe definition '{0}' is for {1}. Expected a {2} definition.", s.FileName, def_engine, state.Definition.Engine);
            }
            else
            {
                string name_str;
                foreach (XmlNode n in s.Cursor.ChildNodes)
                {
                    switch (n.Name)
                    {
                        #region Enums
                    case "enums":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "Enum")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            StringList list = new StringList(state, s);
                            s.RestoreCursor();
                            name_str = list.ToString();

                            try { Enums.Add(name_str, list); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "enum definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Flags
                    case "flags":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "Flag")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            StringList list = new StringList(state, s);
                            s.RestoreCursor();
                            name_str = list.ToString();

                            try { Flags.Add(name_str, list); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "flag definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Tag References
                    case "references":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "Reference")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            TagReference tagref = new TagReference(state, s);
                            s.RestoreCursor();
                            name_str = tagref.ToString();

                            try { References.Add(name_str, tagref); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag reference definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Tag Data
                    case "data":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "TagData")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            TagData tagdata = new TagData(state, s);
                            s.RestoreCursor();
                            name_str = tagdata.ToString();

                            try { Data.Add(name_str, tagdata); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag data definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Script Functions
                    case "scriptFunctions":
                        if (state.scriptingInterface == null)
                        {
                            break;
                        }

                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "function")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            ScriptFunction sc = new ScriptFunction(state, s);
                            s.RestoreCursor();
                            name_str = sc.ToString();

                            if (state.scriptingInterface.Functions.Contains(name_str))
                            {
                                Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', skipping...", "script function", name_str);
                                continue;
                            }

                            try { ScriptFunctions.Add(name_str, sc); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script function definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Script Globals
                    case "scriptGlobals":
                        if (state.scriptingInterface == null)
                        {
                            break;
                        }

                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "global")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            ScriptGlobal sc = new ScriptGlobal(state, s);
                            s.RestoreCursor();
                            name_str = sc.ToString();

                            if (state.scriptingInterface.Globals.Contains(name_str))
                            {
                                Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', ignoring...", "script global", name_str);
                                continue;
                            }

                            try { ScriptGlobals.Add(name_str, sc); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script global definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Fix-ups
                    case "fixups":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "fixup")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            Fixup fu = new Fixup(state, s);
                            s.RestoreCursor();
                            name_str = fu.ToString();

                            try { Fixups.Add(name_str, fu); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "fix-up definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                    default:
                        ProcessDefinition(n, state, s);
                        break;
                    }
                }
            }
        }
Пример #19
0
		/// <summary>
		/// Process a XML file containing CheApe tag definitions
		/// </summary>
		/// <param name="state"></param>
		/// <param name="file"></param>
		public void ProcessFile(ProjectState state, string file)
		{
			using (IO.XmlStream s = new BlamLib.IO.XmlStream(file, this))
			{
				ProcessFile(state, s);
			}
		}
Пример #20
0
			/// <summary>
			/// Constructs a string list from an xml definition node
			/// </summary>
			/// <param name="state"></param>
			/// <param name="s"></param>
			public StringList(ProjectState state, IO.XmlStream s) : base(state, s)
			{
				foreach (XmlNode node in s.Cursor.ChildNodes)
					if (node.Name == "field")
						this.elements.Add(state.Compiler.Strings.Add(node.InnerText));
			}
Пример #21
0
		/// <summary>
		/// Process a XML manifest file containing CheApe tag definitions
		/// </summary>
		/// <param name="state"></param>
		/// <param name="path"></param>
		/// <param name="name"></param>
		public void ProcessFile(ProjectState state, string path, string name)
		{
			using (IO.XmlStream s = new BlamLib.IO.XmlStream(path, name, this))
			{
				ProcessFile(state, s);
			}
		}
Пример #22
0
			/// <summary>
			/// Explicitly construct a tag reference definition
			/// </summary>
			/// <param name="state"></param>
			/// <param name="nameString"></param>
			/// <param name="isNonResolving"></param>
			/// <param name="tags"></param>
			/// <remarks>Adds itself to <paramref name="state"/>'s Importer's References list</remarks>
			internal TagReference(ProjectState state, string nameString, bool isNonResolving, params string[] tags) : base(state, nameString)
			{
				IsNonResolving = isNonResolving;
				elements.AddRange(tags);

				state.Importer.References.Add(nameString, this);
			}
Пример #23
0
		/// <summary>
		/// Process a XML file containing CheApe definitions
		/// </summary>
		/// <param name="state"></param>
		/// <param name="s"></param>
		private void ProcessFile(ProjectState state, BlamLib.IO.XmlStream s)
		{
			int complexity = 1 + 
				PreprocessXmlNodeComplexity();

			BlamVersion def_engine = BlamVersion.Unknown;
			s.ReadAttribute("game", ref def_engine);
			if (def_engine != state.Definition.Engine)
			{
				Debug.Assert.If(false, "CheApe definition '{0}' is for {1}. Expected a {2} definition.", s.FileName, def_engine, state.Definition.Engine);
			}
			else
			{
				foreach (XmlNode n in s.Cursor.ChildNodes)
				{
					switch (n.Name)
					{
						#region Enums
						case "enums":
							s.SaveCursor(n);
							ProcessEnums(state, s);
							s.RestoreCursor();
							break;
						#endregion

						#region Flags
						case "flags":
							s.SaveCursor(n);
							ProcessFlags(state, s);
							s.RestoreCursor();
							break;
						#endregion

						#region Tag References
						case "references":
							s.SaveCursor(n);
							ProcessTagReferences(state, s);
							s.RestoreCursor();
							break;
						#endregion

						#region Tag Data
						case "data":
							s.SaveCursor(n);
							ProcessTagDatas(state, s);
							s.RestoreCursor();
							break;
						#endregion

						#region Script Functions
						case "scriptFunctions":
							if (state.scriptingInterface == null) break;

							s.SaveCursor(n);
							ProcessScriptFunctions(state, s);
							s.RestoreCursor();
							break;
						#endregion

						#region Script Globals
						case "scriptGlobals":
							if (state.scriptingInterface == null) break;

							s.SaveCursor(n);
							ProcessScriptGlobals(state, s);
							s.RestoreCursor();
							break;
						#endregion

						#region Fix-ups
						case "fixups":
							s.SaveCursor(n);
							ProcessFixups(state, s);
							s.RestoreCursor();
							break;
						#endregion

						default:
							ProcessDefinition(n, state, s);
							break;
					}
				}
			}
		}
Пример #24
0
			/// <summary>
			/// Constructs a block definition from an xml definition node
			/// </summary>
			/// <param name="state"></param>
			/// <param name="s"></param>
			protected Block(ProjectState state, IO.XmlStream s) : base(state, s)
			{
				try { state.ImportedBlocks.Add(this.nameString, this); }
				catch (Exception) { }

				#region DisplayName
				if (s.ReadAttributeOpt("displayName", ref displayString)) displayName = state.Compiler.Strings.Add(displayString);
				else { displayName = name; displayString = nameString; }
				#endregion
			}
Пример #25
0
			internal void ExplicitlyExport(ProjectState state)
			{
//				mIsExported = true;
//				state.Compiler.AddExport(this);
			}
Пример #26
0
			bool TypeIndexIsExplanation(ProjectState state)
			{
				return state.Definition.FieldTypes[typeIndex].Name == "Explanation";
			}
Пример #27
0
			void SyncDefinitionWithState(ProjectState state)
			{
				if (TypeIndexIsExplanation(state))
				{
					if (definition == null) // Explanation requires a definition, so we'll implicitly use an empty string
						definition = "";
					else
					{
						// since halo internally uses "|n" and "|t", we'll just use these >=D
						definition = definition.Replace("~N", "\n").Replace("~T", "    ");
					}

					definition = state.Compiler.Strings.Add(definition).ToString("X"); // set definition to be the value of string's address in the pool
				}
				else ValidateDefinition(state);
			}
Пример #28
0
		static void ProcessStringList(ProjectState state, IO.XmlStream s, Dictionary<string, StringList> listDic,
			string elementName, string listTypeName)
		{
			foreach (XmlNode n in s.Cursor.ChildNodes)
			{
				if (n.Name != elementName) continue;

				s.SaveCursor(n);
				var list = new StringList(state, s);
				s.RestoreCursor();
				string name_str = list.ToString();

				try { listDic.Add(name_str, list); }
				catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, listTypeName, name_str); }
			}
		}
Пример #29
0
			public ScriptGlobal(ProjectState state, IO.XmlStream s) : base(state, s)
			{
				string type_name = null;
				s.ReadAttribute("type", ref type_name);
				s.ReadAttributeOpt("internal", ref IsInternal);

				if (!state.scriptingInterface.Types.Contains(type_name))
					throw new Debug.ExceptionLog("CheApe: value type '{0}' does not exist", type_name);

				type = state.scriptingInterface.GetValueType(type_name);
			}
Пример #30
0
		void ProcessFlags(ProjectState state, IO.XmlStream s)
		{
			ProcessStringList(state, s, Enums, "Flag", "flag definition");
		}
Пример #31
0
            public Fixup(ProjectState state, IO.XmlStream s) : base(state, s)
            {
                string temp = string.Empty;

                s.ReadAttribute("guerilla", 16, ref addressGuerilla);
                s.ReadAttribute("tool", 16, ref addressTool);
                s.ReadAttribute("sapien", 16, ref addressSapien);

                s.ReadAttribute("type", ref type);

                #region Definition
                if (type != FixupType.Field && s.ReadAttributeOpt("definition", ref temp))
                {
                    if (type == FixupType.String || type == FixupType.StringPtr)
                    {
                        definition = state.Compiler.RamAddString(temp, out definitionLength).ToString("X8");
                    }
                    else if (type == FixupType.Memory)
                    {
                        definition = state.Compiler.RamAddMemory(temp, out definitionLength).ToString("X8");
                    }
                    else if (type == FixupType.Pointer)
                    {
                        definition = temp;
                    }

                    definitionGuerilla       =
                        definitionTool       =
                            definitionSapien =
                                ToPointer();
                }
                else
                {
                    definition = null;
                }
                #endregion

                if (definition == null)
                {
                    foreach (XmlNode node in s.Cursor.ChildNodes)
                    {
                        if (node.Name == "definition")
                        {
                            s.SaveCursor(node);

                            if (type != FixupType.Field)
                            {
                                bool is_string = type == FixupType.String;

                                // this will be set to false when not all platforms have a definition
                                bool add_def_memory = true;
                                if (add_def_memory)
                                {
                                    add_def_memory = ReadSingleDefinition(state, s, "guerilla", ref definitionGuerilla);
                                }
                                else
                                {
                                    definitionGuerilla = uint.MaxValue;
                                }
                                if (add_def_memory)
                                {
                                    add_def_memory = ReadSingleDefinition(state, s, "tool", ref definitionTool);
                                }
                                else
                                {
                                    definitionTool = uint.MaxValue;
                                }
                                if (add_def_memory)
                                {
                                    add_def_memory = ReadSingleDefinition(state, s, "sapien", ref definitionSapien);
                                }
                                else
                                {
                                    definitionSapien = uint.MaxValue;
                                }

                                // Houston, we forgot a platform...
                                if (!add_def_memory && definitionGuerilla != uint.MaxValue)
                                {
                                    // TODO: error here
                                }
                            }
                            else
                            {
                                foreach (XmlNode fnode in s.Cursor.ChildNodes)
                                {
                                    if (fnode.Name == "field")
                                    {
                                        s.SaveCursor(fnode);
                                        field = new Field(state, s);
                                        s.RestoreCursor();
                                        break;
                                    }
                                }
                            }

                            s.RestoreCursor();
                            break;
                        }
                    }
                }
            }
Пример #32
0
			void ValidateDefinition(ProjectState state)
			{
				if (string.IsNullOrEmpty(definition) && state.Definition.FieldTypes[typeIndex].RequiresDefinition)
					throw new Debug.ExceptionLog("\"{0}\" of type {1} has no definition", nameString, state.Definition.FieldTypes[typeIndex].Name);
			}
Пример #33
0
 bool TypeIndexIsExplanation(ProjectState state)
 {
     return(state.Definition.FieldTypes[typeIndex].Name == "Explanation");
 }
Пример #34
0
		protected Compiler(BlamVersion engine)
		{
			Head = new CacheFileHeader(engine);
			MemoryStream = null;
			OwnerState = null;

			DebugStrings = new Util.StringPool(true);
			RamMemory = new BlamLib.IO.EndianWriter(new System.IO.MemoryStream(1024), this);
		}
Пример #35
0
			protected Object(ProjectState state, IO.XmlStream s)
			{
				s.ReadAttribute("name", ref nameString);
				InitializeForExport(state, s);

				name = state.Compiler.Strings.Add(nameString);
			}
Пример #36
0
		void ProcessScriptGlobals(ProjectState state, IO.XmlStream s)
		{
			foreach (XmlNode n in s.Cursor.ChildNodes)
			{
				if (n.Name != "global") continue;

				s.SaveCursor(n);
				var sg = new ScriptGlobal(state, s);
				s.RestoreCursor();
				string name_str = sg.ToString();

				if (state.scriptingInterface.Globals.Contains(name_str))
				{
					Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', ignoring...", "script global", name_str);
					continue;
				}

				try { ScriptGlobals.Add(name_str, sg); }
				catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script global definition", name_str); }
			}
		}
Пример #37
0
			/// <summary>
			/// Constructs a field from an xml definition node
			/// </summary>
			/// <param name="state"></param>
			/// <param name="s"></param>
			public Field(ProjectState state, IO.XmlStream s)
			{
				string temp = string.Empty;

				#region Type
				s.ReadAttribute("type", ref temp);

				typeIndex = state.Definition.GetTypeIndex(temp);
				Debug.Assert.If(typeIndex != -1, "Not a usable field type: {0}", temp);
				#endregion

				#region Name
				nameString = temp = XmlInterface.BuildEditorNameString(s);

				name = state.Compiler.Strings.Add(temp);
				#endregion

				#region Definition
				if (s.ReadAttributeOpt("definition", ref definition) || TypeIndexIsExplanation(state))
				{
					SyncDefinitionWithState(state);
				}
				else if(state.Definition.FieldTypes[typeIndex].RequiresDefinition)
					throw new Debug.ExceptionLog("\"{0}\" of type {1} has no definition", nameString, state.Definition.FieldTypes[typeIndex].Name);
				#endregion
			}
Пример #38
0
			/// <summary>
			/// Explicitly construct a tag field
			/// </summary>
			/// <param name="state"></param>
			/// <param name="type_index"></param>
			/// <param name="name_string"></param>
			/// <param name="def"></param>
			internal Field(ProjectState state, int type_index, string name_string, string def)
			{
				Debug.Assert.If(type_index != -1, "Invalid field type given to explicit Import.Field");
				typeIndex = type_index;

				nameString = name_string;
				name = state.Compiler.Strings.Add(nameString);

				definition = def;
				SyncDefinitionWithState(state);
			}
Пример #39
0
 protected abstract void ProcessDefinition(XmlNode node, ProjectState state, IO.XmlStream s);