static int Main(string[] args) { string source = ""; string target = ""; string filename = ""; if (args.Length < 2) { Console.WriteLine("SucDecompiler by sucklead (http://dcotetools.sucklead.com/p/sucdecompiler.html)"); Console.WriteLine("Version [{0}]", Assembly.GetExecutingAssembly().GetName().Version); Console.WriteLine(); Console.WriteLine("To decompile a single file"); Console.WriteLine("SucDecompiler {binary directory} {target directory} {binary filename}"); Console.WriteLine(@"e.g. To decompile bin\gamescripts\01_house\$debug\debugblack.bin into directory src"); Console.WriteLine("from the directory below bin:"); Console.WriteLine(@"SucDecompiler bin src gamescripts\01_house\$debug\debugblack.hfs"); Console.WriteLine(); Console.WriteLine("To decompile all files in a directory"); Console.WriteLine("SucDecompiler {binary directory} {target directory}"); Console.WriteLine("e.g. to decompile everything in bin to src"); Console.WriteLine("from the directory below bin:"); Console.WriteLine("SucDecompiler bin src"); Console.WriteLine(); Console.WriteLine("Easiest way to run it is from within the Scripts directory:"); Console.WriteLine("SucDecompiler bin src"); Console.WriteLine(); Console.WriteLine("The file fixtable.csv holds a list of fixes for specific files."); Console.WriteLine("They are to fix bugs in the original source and once those bugs"); Console.WriteLine("are fixed they won't be needed anymore."); return(1); } //set source and target source = args[0].Replace("/", "\\"); target = args[1].Replace("/", "\\"); Console.WriteLine("SucDecompiler by sucklead started at {0}", DateTime.Now); Console.WriteLine("Version [{0}]", Assembly.GetExecutingAssembly().GetName().Version); Console.WriteLine("Binaries -> {0}", source); Console.WriteLine("Target Source -> {0}", target); //FunctionTable.LoadData(); string fixTableFile = "fixtable.csv"; if (!File.Exists(fixTableFile)) { fixTableFile = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "fixtable.csv"); if (!File.Exists(fixTableFile)) { Console.WriteLine("Fix table fixtable.csv not found!"); return(-5); } } FixTable.LoadFixTable(fixTableFile); //set the options DeCompiler deCompiler = new DeCompiler(); deCompiler.SourceDirectory = source; deCompiler.TargetDirectory = target; if (args.Length > 2) { for (int a = 2; a < args.Length; a++) { filename = args[a].Replace("/", "\\"); filename = filename.Replace(".hfs", ".bin"); if (filename.StartsWith(source)) { filename = filename.Substring(target.Length + 1); } if (File.Exists(Path.Combine(source, filename))) { deCompiler.DeCompileFile(filename); } else { Console.WriteLine("ERROR: Decompile target {0} does not exist", Path.Combine(source, filename)); //Console.ReadLine(); return(3); } } } else { filename = ""; if (Directory.Exists(source)) { deCompiler.DeCompileDirectory(source); } else { Console.WriteLine("ERROR: Decompile source {0} does not exist", source); //Console.ReadLine(); return(4); } } //save function table if anything has changed //FunctionTable.SaveData(); Console.WriteLine("Decompile completed at {0}.", DateTime.Now); //Console.WriteLine("\n\nPress <Enter> to exit.."); //Console.ReadLine(); return(0); }
public void BuildVariables(ParsedContent parsedContent) { Variables = new Dictionary <short, Variable>(); ValueList = new List <ValueViewModel>(); this.ValueList = new List <ValueViewModel>(); foreach (Value value in parsedContent.ValuesList) { ValueViewModel valueViewModel = new ValueViewModel() { Address = value.Address, AddressHex = (short)(value.Address - parsedContent.BaseAddress + parsedContent.StartOfValues), AddressHexBase = (short)(value.Address + parsedContent.StartOfValues), DataType = value.DataType, Reference = value.Reference, IsMe = value.IsMe, IsPlayer = value.IsPlayer }; if (value.SubValues.Count > 0) { if (valueViewModel.DataType == DataTypeType.Float) { valueViewModel.SubValue1 = BitConverter.ToSingle(BitConverter.GetBytes((Int32)(value.SubValues[0])), 0); } else { valueViewModel.SubValue1 = value.SubValues[0]; } } if (value.SubValues.Count > 1) { valueViewModel.SubValue2 = value.SubValues[1]; } if (value.SubValues.Count > 2) { valueViewModel.SubValue3 = value.SubValues[2]; } if (value.SubValues.Count > 3) { valueViewModel.SubValue4 = value.SubValues[3]; } if (value.SubValues.Count > 4) { valueViewModel.SubValue5 = value.SubValues[4]; } this.ValueList.Add(valueViewModel); //build variables list if (!Variables.ContainsKey(value.Address)) { Variable v = new Variable() { Address = value.Address, DataType = value.DataType.ToString(), //Name = "var" + value.DataType.ToString() + value.Address.ToString() }; if (value.IsMe || value.IsPlayer) { v.Used = true; v.Static = true; } switch (v.DataType.ToLower()) { case ("int"): v.Name = "nVar" + v.Address.ToString(); break; case ("string"): v.Name = "szVar" + v.Address.ToString(); break; case ("point"): v.Name = "ptVar" + v.Address.ToString(); v.Static = false; //points are never static break; case ("character"): v.Name = "cVar" + v.Address.ToString(); break; case ("float"): v.Name = "fVar" + v.Address.ToString(); break; case ("quaternion"): v.Name = "qVar" + v.Address.ToString(); break; } if (FixTable.isStaticFix(parsedContent.ScriptName, v.Name)) { v.Static = false; } Variables.Add(value.Address, v); } } //work out which variables are static or unused for (int i = 0; i < parsedContent.OpCodeList.Count; i++) { Operation operation = parsedContent.OpCodeList[i]; if (operation.OpCode == OpCodeType.OP_GETTOP) { if (Variables.ContainsKey(operation.DataIndex.Value)) { Variables[operation.DataIndex.Value].Static = false; Variables[operation.DataIndex.Value].Used = true; } } else if (operation.OpCode == OpCodeType.OP_PUSH) { if (Variables.ContainsKey(operation.DataIndex.Value)) { Variables[operation.DataIndex.Value].Used = true; } } } }