@@ -27,6 +27,7 @@ static class Program
2727 static string base_dir = Path . Combine ( Directory . GetCurrentDirectory ( ) , "bin" ) ;
2828 static Random random = new Random ( ) ;
2929 static string [ ] args ;
30+ static string build_id = Guid . NewGuid ( ) . ToString ( ) . Replace ( "-" , "" ) ;
3031
3132 [ STAThread ]
3233 static void Main ( string [ ] argv )
@@ -87,22 +88,24 @@ enum ScriptType
8788 LocalScript ,
8889 ModuleScript
8990 }
90- static void ParseScripts ( XmlDocument doc , int offset , ScriptType type = ScriptType . LocalScript )
91+ static void ParseScripts ( XmlNodeList scripts , int offset , ScriptType type = ScriptType . LocalScript )
9192 {
9293 bool isModule = type == ScriptType . ModuleScript ;
93- string scriptTypeString = isModule ? "ModuleScript" : "LocalScript" ;
94- string baseMatch = "//Item[@class='" + scriptTypeString + "']" ;
95- string propertiesMatch = baseMatch + "/Properties" ;
96- XmlNodeList localscripts = doc . DocumentElement . SelectNodes ( baseMatch ) ;
9794 int count = 0 ;
98- foreach ( XmlNode script in localscripts )
95+ foreach ( XmlNode script in scripts )
9996 {
10097 count ++ ;
101- XmlNode name = script . SelectSingleNode ( propertiesMatch + "/string[@name='Name']" ) ;
102- XmlNode source = script . SelectSingleNode ( propertiesMatch + "/ProtectedString[@name='Source']" ) ;
103- XmlNode guid = script . SelectSingleNode ( propertiesMatch + "/string[@name='ScriptGuid']" ) ;
98+ XmlNode properties = script . SelectSingleNode ( "./Properties[1]" ) ;
99+ XmlNode name = properties . SelectSingleNode ( "./string[@name='Name'][1]" ) ;
100+ XmlNode source = properties . SelectSingleNode ( "./ProtectedString[@name='Source'][1]" ) ;
101+ XmlNode guid = properties . SelectSingleNode ( "./string[@name='ScriptGuid'][1]" ) ;
104102 XmlNode referent = script . Attributes . GetNamedItem ( "referent" ) ;
105- Logger . Info ( count . ToString ( ) + "/" + localscripts . Count . ToString ( ) + " Loading \" " + name . InnerText . ToString ( ) + "\" " ) ;
103+ if ( name == null || source == null || guid == null || referent == null )
104+ {
105+ Logger . Debug ( "Script attribute was null or ignored!" ) ;
106+ continue ;
107+ }
108+ Logger . Info ( count . ToString ( ) + "/" + scripts . Count . ToString ( ) + " - Loading \" " + name . InnerText . ToString ( ) + "\" " ) ;
106109 if ( referent != null
107110 && source != null
108111 && guid != null
@@ -122,12 +125,22 @@ static void ParseScripts(XmlDocument doc, int offset, ScriptType type = ScriptTy
122125 {
123126 Logger . Warn ( "Skipping script" ) ;
124127 }
128+ ParseScripts ( script . SelectNodes ( "./Item[@class='" + ( isModule ? "ModuleScript" : "LocalScript" ) + "']" ) , offset , type ) ;
125129 }
126130 }
127131
132+ static void SetClientMetadata ( XmlDocument doc , Dictionary < string , object > metadata )
133+ {
134+ XmlNode buildData = doc . SelectSingleNode ( "//Item[@class='StringValue'][1]" ) ;
135+ XmlNode properties = buildData . SelectSingleNode ( "./Properties[1]" ) ;
136+ XmlNode value = properties . SelectSingleNode ( "./string[@name='Value'][1]" ) ;
137+ value . InnerText = JsonConvert . SerializeObject ( metadata ) ;
138+ }
139+
128140 static void CompileFile ( string fileName , int offset )
129141 {
130142 var build_options = new Dictionary < string , object > { } ;
143+ build_options . Add ( "BuildId" , build_id ) ;
131144 build_options . Add ( "Version" , ver + "b" ) ;
132145 build_options . Add ( "Offset" , offset ) ;
133146 //build_options.Add("Arguments", args);
@@ -138,16 +151,17 @@ static void CompileFile(string fileName, int offset)
138151 string outfile = Path . GetDirectoryName ( infile ) + "\\ Compiled_" + Path . GetFileName ( infile ) ;
139152 doc . Load ( infile ) ;
140153 Logger . Info ( "Loading ModuleScripts" ) ;
141- ParseScripts ( doc , offset , ScriptType . ModuleScript ) ;
154+ ParseScripts ( doc . DocumentElement . SelectNodes ( "//Item[@class='ModuleScript']" ) , offset , ScriptType . ModuleScript ) ;
142155 Logger . Ok ( "All ModuleScripts compiled" ) ;
143156 Logger . Info ( "Loading LocalScripts" ) ;
144- ParseScripts ( doc , offset , ScriptType . LocalScript ) ;
157+ ParseScripts ( doc . DocumentElement . SelectNodes ( "//Item[@class='LocalScript']" ) , offset , ScriptType . LocalScript ) ;
145158 Logger . Ok ( "All LocalScripts compiled" ) ;
146159 doc . Save ( outfile ) ;
147160 Logger . Info ( "Adding client script" ) ;
148- string client_data = File . ReadAllText ( Path . Combine ( base_dir , "client.xml" ) ) . Replace ( "%builddata%" , JsonConvert . SerializeObject ( build_options ) ) ;
161+ string client_data = File . ReadAllText ( Path . Combine ( base_dir , "client.xml" ) ) ;
149162 XmlDocument client_xml = new XmlDocument ( ) ;
150163 client_xml . LoadXml ( client_data ) ;
164+ SetClientMetadata ( client_xml , build_options ) ;
151165 XmlNode replicated_first = doc . DocumentElement . SelectSingleNode ( "//Item[@class='ReplicatedFirst']" ) ;
152166 var emptyNamepsaces = new XmlSerializerNamespaces ( new [ ] {
153167 XmlQualifiedName . Empty
@@ -187,6 +201,7 @@ static void PromptToCompile(string openfile = null)
187201 {
188202 var offset = 0 ; //random.Next(26, 255);
189203 Logger . Debug ( "Using an offset of " + offset . ToString ( ) ) ;
204+ Logger . Debug ( "Build id " + build_id ) ;
190205 if ( openfile == null )
191206 {
192207 using ( OpenFileDialog openFileDialog = new OpenFileDialog ( ) )
0 commit comments