Example #1
0
        public XmlDocument DisassembleEncrypted(string fileLocation, string labelsFileLocation = "")
        {
            labelName = labelsFileLocation;

            if (!string.IsNullOrEmpty(labelName))
            {
                try
                {
                    if (hashToStringLabels == null)
                    {
                        hashToStringLabels = LabelIO.GetHashStringDict(labelName);
                    }
                }
                catch (Exception ex)
                {
                    UiHelper.PopUpMessage(ex.Message);
                    return(new XmlDocument());
                }
            }

            file = new ParamFile();
            file.Open(fileLocation);

            xml = new XmlDocument();
            xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", null));
            xml.AppendChild(ParamStruct2Node(file.Root));

            return(xml);
        }
Example #2
0
        public void AssmebleEncrypted(XmlDocument doc, string fileLocation, string labelsFileLocation)
        {
            stringToHashLabels = new OrderedDictionary <string, ulong>();
            if (!string.IsNullOrEmpty(labelsFileLocation))
            {
                try
                {
                    stringToHashLabels = LabelIO.GetStringHashDict(labelsFileLocation);
                }
                catch (Exception ex)
                {
                    UiHelper.PopUpMessage(ex.Message);
                    return;
                }
            }

            file = new ParamFile(Node2ParamStruct(doc.DocumentElement));

            file.Save(fileLocation);
        }
Example #3
0
        static void Main(string[] args)
        {
            LuaFiles           = new List <string>();
            HashToStringLabels = new OrderedDictionary <ulong, string>();
            StringToHashLabels = new OrderedDictionary <string, ulong>();
            Resources.SetUp();

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-h":
                case "-help":
                    Console.WriteLine(Resources.Help);
                    PrintedHelp = true;
                    break;

                case "-a":
                case "-api":
                    Console.WriteLine(Resources.LuaAPI);
                    PrintedHelp = true;
                    break;

                case "-l":
                    HashToStringLabels = LabelIO.GetHashStringDict(args[++i]);
                    StringToHashLabels = LabelIO.GetStringHashDict(args[i]);
                    LabelsLoaded       = true;
                    break;

                case "-s":
                case "-safe":
                case "-sandbox":
                    Sandbox = true;
                    break;

                default:
                    if (args[i].StartsWith("-"))
                    {
                        throw new Exception($"unknown command {args[i]}");
                    }
                    else
                    {
                        LuaFiles.Add(args[i]);
                    }
                    break;
                }
            }

            if (LuaFiles.Count == 0)
            {
                if (!PrintedHelp)
                {
                    Console.WriteLine("No input files specified. See -h for help");
                }
                return;
            }

            foreach (var file in LuaFiles)
            {
                using (L = new Lua())
                {
                    L.State.Encoding = Encoding.UTF8;
                    //set globals
                    L["Lib"]        = new LuaParamGlobal();
                    L["sandboxed"]  = Sandbox;
                    L["labeled"]    = LabelsLoaded;
                    L["hash"]       = new Func <string, ulong>(Hash40Util.StringToHash40);
                    L["label"]      = new Func <ulong, string>((hash) => Hash40Util.FormatToString(hash, HashToStringLabels));
                    L["label2hash"] = new Func <string, ulong>((label) => Hash40Util.LabelToHash40(label, StringToHashLabels));

                    L.DoString(Resources.LuaSandbox);

                    L.DoFile(file);
                }
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            stopwatch = new Stopwatch();
            bool   helpPrinted = false;
            string input       = null;
            string output      = null;

            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "-d":
                        mode = BuildMode.Disassemble;
                        break;

                    case "-a":
                        mode = BuildMode.Assemble;
                        break;

                    case "-h":
                    case "-help":
                        Console.WriteLine(HelpText);
                        helpPrinted = true;
                        break;

                    case "-o":
                        output = args[++i];
                        break;

                    case "-l":
                        labelName = args[++i];
                        break;

                    default:
                        input = args[i];
                        break;
                    }
                }
                if (input == null || mode == BuildMode.Invalid)
                {
                    if (!helpPrinted)
                    {
                        Console.WriteLine(HelpText);
                    }
                    return;
                }
                if (mode == BuildMode.Disassemble)
                {
                    if (string.IsNullOrEmpty(output))
                    {
                        output = Path.GetFileNameWithoutExtension(input) + ".xml";
                    }
                    hashToStringLabels = new OrderedDictionary <ulong, string>();
                    if (!string.IsNullOrEmpty(labelName))
                    {
                        hashToStringLabels = LabelIO.GetHashStringDict(labelName);
                    }

                    Console.WriteLine("Initializing...");
                    stopwatch.Start();
                    file = new ParamFile();
                    file.Open(input);

                    Console.WriteLine("Disassembling...");
                    xml = new XmlDocument();
                    xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", null));
                    xml.AppendChild(ParamStruct2Node(file.Root));
                    XmlWriterSettings settings = new XmlWriterSettings()
                    {
                        Indent = true
                    };
                    XmlWriter writer  = XmlWriter.Create(output, settings);
                    var       dirname = Path.GetDirectoryName(output);
                    if (!string.IsNullOrEmpty(dirname))
                    {
                        Directory.CreateDirectory(dirname);
                    }
                    xml.Save(writer);

                    stopwatch.Stop();
                    Console.WriteLine("Finished in {0} seconds", stopwatch.Elapsed.TotalSeconds);
                }
                else
                {
                    if (string.IsNullOrEmpty(output))
                    {
                        output = Path.GetFileNameWithoutExtension(input) + ".prc";
                    }
                    stringToHashLabels = new OrderedDictionary <string, ulong>();
                    if (!string.IsNullOrEmpty(labelName))
                    {
                        stringToHashLabels = LabelIO.GetStringHashDict(labelName);
                    }

                    Console.WriteLine("Initializing...");
                    stopwatch.Start();
                    xml = new XmlDocument();
                    xml.Load(input);
                    file = new ParamFile(Node2ParamStruct(xml.DocumentElement));

                    Console.WriteLine("Assembling...");
                    var dirname = Path.GetDirectoryName(output);
                    if (!string.IsNullOrEmpty(dirname))
                    {
                        Directory.CreateDirectory(dirname);
                    }
                    file.Save(output);

                    stopwatch.Stop();
                    Console.WriteLine("Finished in {0} seconds", stopwatch.Elapsed.TotalSeconds);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                if (e.InnerException == null)
                {
                    Console.WriteLine(e.StackTrace);
                }
                else
                {
                    Console.WriteLine(e.InnerException.StackTrace);
                }
            }
        }