Example #1
0
        private string GetNodeParamValueHash40(ParamStruct root, ulong hex40)
        {
            var paramValue = root.Nodes[hex40] as ParamValue;

            if (paramValue.TypeKey == ParamType.hash40)
            {
                return(Hash40Util.FormatToString((ulong)paramValue.Value, _paramLabels));
            }
            return(string.Empty);
        }
Example #2
0
        XmlNode ParamStruct2Node(ParamStruct structure)
        {
            XmlNode xmlNode = xml.CreateElement([email protected]());

            foreach (var node in structure.Nodes)
            {
                XmlNode      childNode = Param2Node(node.Value);
                XmlAttribute attr      = xml.CreateAttribute("hash");
                attr.Value = Hash40Util.FormatToString(node.Key, hashToStringLabels);
                childNode.Attributes.Append(attr);
                xmlNode.AppendChild(childNode);
            }
            return(xmlNode);
        }
Example #3
0
        private void ReadPrc(IParam node, object objToMap, PropertyInfo propertyInfo)
        {
            //List
            if (node is ParamList)
            {
                if (node.TypeKey != ParamType.list)
                {
                    throw new Exception("Data error");
                }

                var nodeList = node as ParamList;

                //Instanciate list
                var newList = Activator.CreateInstance(propertyInfo.PropertyType);
                var dictKey = MapDictionaryKeyFromPropertyInfo(propertyInfo);
                propertyInfo.SetValue(objToMap, newList);

                //Regular case - List
                if (dictKey == null)
                {
                    var newListObj = GetListObjectType(newList.GetType());
                    var newListAdd = newList.GetType().GetMethod("Add");

                    //Set in property
                    foreach (var nodeChild in nodeList.Nodes)
                    {
                        var newObjInstance = Activator.CreateInstance(newListObj);
                        newListAdd.Invoke(newList, new[] { newObjInstance });
                        ReadPrc(nodeChild, newObjInstance, null);
                    }
                }
                //Dictionary case - PrcDictionary
                else
                {
                    var newDictObj = GetDictionaryObjectType(newList.GetType());
                    var newListAdd = newList.GetType().GetMethod("Add", new[] { newDictObj.Item1, newDictObj.Item2 });

                    //Set in property
                    foreach (var nodeChild in nodeList.Nodes)
                    {
                        var id             = (ParamValue)((ParamStruct)nodeChild).Nodes[dictKey];
                        var idStr          = Hash40Util.FormatToString((ulong)(id.Value), _paramHashes);
                        var newObjInstance = Activator.CreateInstance(newDictObj.Item2);
                        newListAdd.Invoke(newList, new[] { idStr, newObjInstance });
                        ReadPrc(nodeChild, newObjInstance, null);
                    }
                }
            }
            else if (node is ParamStruct)
            {
                if (node.TypeKey != ParamType.@struct)
                {
                    throw new Exception("Data error");
                }

                var nodeStruct = node as ParamStruct;
                ReadPrc(nodeStruct.Nodes, objToMap);
            }
            else if (node is ParamValue)
            {
                if (node.TypeKey == ParamType.@struct || node.TypeKey == ParamType.list)
                {
                    throw new Exception("Data error");
                }

                var nodeValue = node as ParamValue;
                if (nodeValue.TypeKey == ParamType.hash40)
                {
                    propertyInfo.SetValue(objToMap, new PrcHash40((ulong)nodeValue.Value, _paramHashes));
                }
                else
                {
                    propertyInfo.SetValue(objToMap, nodeValue.Value);
                }
            }
        }
Example #4
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);
                }
            }
        }