public bool Init() { if (Tree.ParserMessages.Count > 0) { Console.WriteLine("Bad syntax in line {0}.", Tree.ParserMessages[0].Location.Line); Console.ReadKey(); return(false); } var file = new FileStructure(); CompiledPub.AddRange(new byte[64]); PrepareStrings(Tree.Root); int functionsNodeIndex = Tree.Root.ChildNodes.FindIndex(e => e.Term.Name == "functions"); file.CodeSectionStart = CompiledPub.Count; file.NumOfFunctions = (ushort)Tree.Root.ChildNodes[functionsNodeIndex].ChildNodes.Count; if (functionsNodeIndex != -1) { foreach (ParseTreeNode childNode in Tree.Root.ChildNodes[functionsNodeIndex].ChildNodes) { EmitFunction(childNode); } } file.GscFunctions = CompiledPub.Count; file.NumOfFunctions = (ushort)Functions.Count; WriteFunctionsStructToFile(); file.ExternalFunctions = CompiledPub.Count; file.NumOfExternalFunctions = (ushort)Calls.Count; WriteCallStackToFile(); file.RefStrings = CompiledPub.Count; file.NumofRefStrings = (ushort)RefStrings.Count; WriteRefsToStringsToFile(); file.Size = CompiledPub.Count; file.Size2 = CompiledPub.Count; file.Header = new byte[] { 0x80, 0x47, 0x53, 0x43, 0x0D, 0x0A, 0x00, 0x06 }; file.Name = 0x40; Directory.CreateDirectory(Path.GetDirectoryName(Filename) + @"\Compiled\"); using (var writer = File.Create(Path.GetDirectoryName(Filename) + @"\Compiled\" + Path.GetFileName(Filename))) { writer.Write(CompiledPub.ToArray(), 0, CompiledPub.Count); } return(true); }
public bool Init(string rel, bool poperrormessage = false) { if (Tree.ParserMessages.Count > 0) { if (poperrormessage) { MessageBox.Show(String.Format("Bad syntax in line {0}.", Tree.ParserMessages[0].Location.Line)); } else { CompiledPub.Clear(); AddString(String.Format("Bad syntax in line {0}.", Tree.ParserMessages[0].Location.Line)); } return false; } CompiledPub.AddRange(new byte[64]); AddString(rel); PrepareStrings(Tree.Root); int includesNodeIndex = Tree.Root.ChildNodes.FindIndex(e => e.Term.Name == "includes"); int functionsNodeIndex = Tree.Root.ChildNodes.FindIndex(e => e.Term.Name == "functions"); int animTreesNodeIndex = Tree.Root.ChildNodes.FindIndex(e => e.Term.Name == "usingAnimTree"); var file = new FileStructure(); file.PtrToIncludes = CompiledPub.Count; if (includesNodeIndex != -1) { file.NumofIncludes = (byte)Tree.Root.ChildNodes[includesNodeIndex].ChildNodes.Count; foreach (ParseTreeNode childNode in Tree.Root.ChildNodes[includesNodeIndex].ChildNodes) { EmitInclude(childNode.FindTokenAndGetValue()); } } if (animTreesNodeIndex != -1) { _animTree.NamePtr = GetStringPosByName(Tree.Root.ChildNodes[animTreesNodeIndex].FindTokenAndGetValue()); _animTree.Unknown = 2; file.NumOfAnimTrees = 1; } file.CodeSectionStart = CompiledPub.Count; file.NumOfFunctions = (ushort)Tree.Root.ChildNodes[functionsNodeIndex].ChildNodes.Count; if (functionsNodeIndex != -1) { foreach (ParseTreeNode childNode in Tree.Root.ChildNodes[functionsNodeIndex].ChildNodes) { EmitFunction(childNode); } } file.GscFunctions = CompiledPub.Count; file.NumOfFunctions = (ushort)Functions.Count; WriteFunctionsStructToFile(); file.ExternalFunctions = CompiledPub.Count; file.NumOfExternalFunctions = (ushort)Calls.Count; WriteCallStackToFile(); file.PtrTousingAnimTrees = CompiledPub.Count; WriteAnimTreesToFile(); file.RefStrings = CompiledPub.Count; file.NumofRefStrings = (ushort)RefStrings.Count; WriteRefsToStringsToFile(); file.Size = CompiledPub.Count; file.Size2 = CompiledPub.Count; file.Header = new byte[] { 0x80, 0x47, 0x53, 0x43, 0x0D, 0x0A, 0x00, 0x06 }; file.Name = 0x40; // Directory.CreateDirectory(Path.GetDirectoryName(Filename) + @"\Compiled\"); // using (var writer = File.Create(Path.GetDirectoryName(Filename) + @"\Compiled\" + Path.GetFileName(Filename))) // { // writer.Write(CompiledPub.ToArray(), 0, CompiledPub.Count); // } return true; }