private string DecompileHsdtScripts() { using (IReader reader = _streamManager.OpenRead()) { ScriptTable scripts = _scriptFile.LoadScripts(reader); if (scripts is null) { return(""); } OpcodeLookup opcodes = _buildInfo.ScriptInfo; var generator = new BlamScriptGenerator(scripts, opcodes, _buildInfo, _endian); return(generator.Decompile(_scriptFile.Name, App.AssemblyStorage.AssemblySettings.ShowScriptInfo)); } }
private void DecompileScripts(object streamManager) { DateTime startTime = DateTime.Now; ScriptTable scripts; using (IReader reader = ((IStreamManager)streamManager).OpenRead()) { scripts = _scriptFile.LoadScripts(reader); if (scripts == null) { return; } } OpcodeLookup opcodes = _buildInfo.ScriptInfo; var generator = new BlamScriptGenerator(scripts, opcodes, _endian); var code = new IndentedTextWriter(new StringWriter()); generator.WriteComment("Decompiled with Assembly", code); generator.WriteComment("", code); generator.WriteComment("Source file: " + _scriptFile.Name, code); generator.WriteComment("Start time: " + startTime, code); generator.WriteComment("", code); generator.WriteComment("Remember that all script code is property of Bungie/343 Industries.", code); generator.WriteComment("You have no rights. Play nice.", code); code.WriteLine(); int counter = 0; if (scripts.Variables != null) { generator.WriteComment("VARIABLES", code); foreach (ScriptGlobal variable in scripts.Variables) { code.Write("(variable {0} {1} ", opcodes.GetTypeInfo((ushort)variable.Type).Name, variable.Name); generator.WriteExpression(variable.ExpressionIndex, code); if (_showInfo) { code.WriteLine(")\t\t; Index: {0}, Expression Index: {1}", counter.ToString(), variable.ExpressionIndex.Index.ToString()); } else { code.WriteLine(")"); } counter++; } code.WriteLine(); counter = 0; } generator.WriteComment("GLOBALS", code); foreach (ScriptGlobal global in scripts.Globals) { code.Write("(global {0} {1} ", opcodes.GetTypeInfo((ushort)global.Type).Name, global.Name); generator.WriteExpression(global.ExpressionIndex, code); if (_showInfo) { code.WriteLine(")\t\t; Index: {0}, Expression Index: {1}", counter.ToString(), global.ExpressionIndex.Index.ToString()); } else { code.WriteLine(")"); } counter++; } code.WriteLine(); counter = 0; generator.WriteComment("SCRIPTS", code); foreach (Script script in scripts.Scripts) { if (_showInfo) { generator.WriteComment(string.Format("Index: {0}, Expression Index: {1}", counter.ToString(), script.RootExpressionIndex.Index.ToString()), code); } code.Write("(script {0} {1} ", opcodes.GetScriptTypeName((ushort)script.ExecutionType), opcodes.GetTypeInfo((ushort)script.ReturnType).Name); if (script.Parameters != null && script.Parameters.Count > 0) { code.Write("({0} (", script.Name); bool firstParam = true; foreach (ScriptParameter param in script.Parameters) { if (!firstParam) { code.Write(", "); } code.Write("{1} {0}", param.Name, opcodes.GetTypeInfo((ushort)param.Type).Name); firstParam = false; } code.Write("))"); } else { code.Write(script.Name); } code.Indent++; code.WriteLine(); generator.WriteExpression(script.RootExpressionIndex, code, _buildInfo.HeaderSize == 0x1E000); code.Indent--; code.WriteLine(); code.WriteLine(")"); code.WriteLine(); counter++; } DateTime endTime = DateTime.Now; TimeSpan duration = endTime.Subtract(startTime); generator.WriteComment("Decompilation finished in ~" + duration.TotalSeconds + "s", code); Dispatcher.Invoke(new Action(delegate { txtScript.Text = code.InnerWriter.ToString(); })); }