private ulong HashParse(string word) { if (word.StartsWith("0x")) { return(ulong.Parse(word.Substring(2), NumberStyles.HexNumber)); } return(Hash40Util.StringToHash40(word)); }
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); }
private void SetNodeParamValue(ParamStruct root, ulong hex40, object value) { var paramValue = ((ParamValue)root.Nodes[hex40]); if (paramValue.TypeKey == ParamType.hash40) { paramValue.Value = Hash40Util.StringToHash40(value.ToString()); } else { paramValue.Value = value; } }
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); }
public PrcHexMapping(string strValue) { Value = Hash40Util.StringToHash40(strValue); }
public bool GenerateBgmPrcFile(List <BgmDbNewEntry> bgmEntries, string outputFilePath) { var saveNoIndex = (short)(_coreBgmDb.OrderByDescending(p => p.SaveNo).First().SaveNo + 1); var testDispOrderIndex = (short)(_coreBgmDb.OrderByDescending(p => p.TestDispOrder).First().TestDispOrder + 1); var menuValueIndex = _coreBgmDb.OrderByDescending(p => p.MenuValue).First().MenuValue + 1; var t = new ParamFile(); t.Open(_resourceService.GetBgmDbResource()); //DBROOT var dbRoot = t.Root.Nodes[HEX_CAT_DBROOT] as ParamList; foreach (var bgmEntry in bgmEntries) { var newEntry = dbRoot.Nodes[1].Clone() as ParamStruct; SetNodeParamValue(newEntry, HEX_UI_BGM_ID, bgmEntry.UiBgmId); SetNodeParamValue(newEntry, HEX_STREAM_SET_ID, bgmEntry.StreamSetId); SetNodeParamValue(newEntry, HEX_RARITY, bgmEntry.Rarity); SetNodeParamValue(newEntry, HEX_RECORD_TYPE, bgmEntry.RecordType); SetNodeParamValue(newEntry, HEX_UI_GAMETITLE_ID, bgmEntry.UiGameTitleId); SetNodeParamValue(newEntry, HEX_NAME_ID, bgmEntry.NameId); //SetNodeParamValue(newEntry, HEX_SAVE_NO, saveNoIndex); SetNodeParamValue(newEntry, HEX_TEST_DISP_ORDER, testDispOrderIndex); SetNodeParamValue(newEntry, HEX_MENU_VALUE, menuValueIndex); SetNodeParamValue(newEntry, HEX_SHOP_PRICE, (uint)0); dbRoot.Nodes.Add(newEntry); saveNoIndex++; testDispOrderIndex++; menuValueIndex++; } //STREAM_SET var streamSet = t.Root.Nodes[HEX_CAT_STREAM_SET] as ParamList; foreach (var bgmEntry in bgmEntries) { var newEntry = streamSet.Nodes[0].Clone() as ParamStruct; SetNodeParamValue(newEntry, HEX_STREAM_SET_ID, bgmEntry.StreamSetId); SetNodeParamValue(newEntry, HEX_INFO0, bgmEntry.Info0); streamSet.Nodes.Add(newEntry); } //ASSIGNED_INFO var assignedInfo = t.Root.Nodes[HEX_CAT_ASSIGNED_INFO] as ParamList; foreach (var bgmEntry in bgmEntries) { var newEntry = assignedInfo.Nodes[0].Clone() as ParamStruct; SetNodeParamValue(newEntry, HEX_INFO_ID, bgmEntry.InfoId); SetNodeParamValue(newEntry, HEX_STREAM_ID, bgmEntry.StreamId); assignedInfo.Nodes.Add(newEntry); } //STREAM_PROPERTY var streamProperty = t.Root.Nodes[HEX_CAT_STREAM_PROPERTY] as ParamList; foreach (var bgmEntry in bgmEntries) { var newEntry = streamProperty.Nodes[0].Clone() as ParamStruct; SetNodeParamValue(newEntry, HEX_STREAM_ID, bgmEntry.StreamId); SetNodeParamValue(newEntry, HEX_DATA_NAME0, bgmEntry.DataName0); streamProperty.Nodes.Add(newEntry); } //BGM PLAYLIST (QUICK & DIRTY) foreach (var bgmEntry in bgmEntries) { if (bgmEntry.Playlists == null) { continue; } foreach (var playlist in bgmEntry.Playlists) { var playlistId = playlist.Id; if (!playlistId.StartsWith("bgm")) { _logger.LogWarning("The playlist_id for song '{Song}' must start with 'bgm', skipping...", bgmEntry.ToneName); continue; } var hexValue = Hash40Util.StringToHash40(playlistId); ParamList bgmPlaylist = null; ParamStruct newEntry = null; //If the playlist doesn't exist... if (!t.Root.Nodes.ContainsKey(hexValue)) { var playlistToClone = t.Root.Nodes[HEX_PLAYLIST_EXAMPLE] as ParamList; bgmPlaylist = playlistToClone.Clone() as ParamList; t.Root.Nodes.Add(hexValue, bgmPlaylist); if (bgmPlaylist.Nodes.Count > 1) { bgmPlaylist.Nodes.RemoveRange(1, bgmPlaylist.Nodes.Count - 1); newEntry = bgmPlaylist.Nodes[0] as ParamStruct; } } else { bgmPlaylist = t.Root.Nodes[hexValue] as ParamList; newEntry = bgmPlaylist.Nodes[0].Clone() as ParamStruct; bgmPlaylist.Nodes.Add(newEntry); } //Add song SetNodeParamValue(newEntry, HEX_UI_BGM_ID, bgmEntry.UiBgmId); for (int i = 0; i <= 15; i++) { SetNodeParamValue(newEntry, string.Format(HEX_ORDERNBR, i), (short)(bgmPlaylist.Nodes.Count)); SetNodeParamValue(newEntry, string.Format(HEX_INCIDENCENBR, i), (ushort)500); } } } t.Save(outputFilePath); return(true); }
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); } } }
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); } } }