private static void _loadEntry(Table <int, ReadableTuple <int> > table, LuaKeyValue item) { int itemIndex = Int32.Parse(item.Key.Substring(1, item.Key.Length - 2)); LuaList itemProperties = item.Value as LuaList; LuaList contentProperties; StringBuilder resources; if (itemProperties != null) { foreach (LuaKeyValue itemProperty in itemProperties.Variables) { switch (itemProperty.Key) { case "UI_Type": table.SetRaw(itemIndex, ClientCheevoAttributes.UiType, ((LuaValue)itemProperty.Value).Value); break; case "group": table.SetRaw(itemIndex, ClientCheevoAttributes.GroupId, DbIOMethods.RemoveQuotes(((LuaValue)itemProperty.Value).Value)); break; case "major": table.SetRaw(itemIndex, ClientCheevoAttributes.Major, ((LuaValue)itemProperty.Value).Value); break; case "minor": table.SetRaw(itemIndex, ClientCheevoAttributes.Minor, ((LuaValue)itemProperty.Value).Value); break; case "title": table.SetRaw(itemIndex, ClientCheevoAttributes.Name, DbIOMethods.RemoveQuotes(((LuaValue)itemProperty.Value).Value)); break; case "reward": case "content": contentProperties = itemProperty.Value as LuaList; if (contentProperties == null) { continue; } foreach (LuaKeyValue contentProperty in contentProperties.Variables) { switch (contentProperty.Key) { case "summary": table.SetRaw(itemIndex, ClientCheevoAttributes.Summary, DbIOMethods.RemoveQuotes(((LuaValue)contentProperty.Value).Value)); break; case "details": table.SetRaw(itemIndex, ClientCheevoAttributes.Details, DbIOMethods.RemoveQuotes(((LuaValue)contentProperty.Value).Value)); break; case "title": table.SetRaw(itemIndex, ClientCheevoAttributes.RewardTitleId, ((LuaValue)contentProperty.Value).Value); break; case "buff": table.SetRaw(itemIndex, ClientCheevoAttributes.RewardBuff, ((LuaValue)contentProperty.Value).Value); break; case "item": table.SetRaw(itemIndex, ClientCheevoAttributes.RewardId, ((LuaValue)contentProperty.Value).Value); break; } } break; case "resource": resources = new StringBuilder(); contentProperties = itemProperty.Value as LuaList; if (contentProperties == null) { continue; } foreach (LuaKeyValue contentProperty in contentProperties.Variables) { int resId = Int32.Parse(contentProperty.Key.Substring(1, contentProperty.Key.Length - 2)); LuaList resourceProperties = contentProperty.Value as LuaList; if (resourceProperties == null) { continue; } resources.Append(resId); foreach (LuaKeyValue resourceProperty in resourceProperties.Variables) { string value = ((LuaValue)resourceProperty.Value).Value; resources.Append("__%"); resources.Append(resourceProperty.Key); resources.Append("__%"); if (value.StartsWith("\"")) { resources.Append(DbIOMethods.RemoveQuotes(value)); } else { resources.Append(value); } } resources.Append("__&"); } table.SetRaw(itemIndex, ClientCheevoAttributes.Resources, resources.ToString()); break; case "score": table.SetRaw(itemIndex, ClientCheevoAttributes.Score, ((LuaValue)itemProperty.Value).Value); break; } } } }
private static void _loadEntry(Table <int, ReadableTuple <int> > table, LuaKeyValue item) { int itemIndex = Int32.Parse(item.Key.Substring(1, item.Key.Length - 2)); LuaList itemProperties = item.Value as LuaList; LuaList itemList; if (itemProperties != null) { foreach (LuaKeyValue itemProperty in itemProperties.Variables) { switch (itemProperty.Key) { case "unidentifiedDisplayName": table.SetRaw(itemIndex, ClientItemAttributes.UnidentifiedDisplayName, DbIOMethods.RemoveQuotes(((LuaValue)itemProperty.Value).Value)); break; case "unidentifiedResourceName": table.SetRaw(itemIndex, ClientItemAttributes.UnidentifiedResourceName, DbIOMethods.RemoveQuotes(((LuaValue)itemProperty.Value).Value)); break; case "identifiedDisplayName": table.SetRaw(itemIndex, ClientItemAttributes.IdentifiedDisplayName, DbIOMethods.RemoveQuotes(((LuaValue)itemProperty.Value).Value)); break; case "identifiedResourceName": table.SetRaw(itemIndex, ClientItemAttributes.IdentifiedResourceName, DbIOMethods.RemoveQuotes(((LuaValue)itemProperty.Value).Value)); break; case "slotCount": table.SetRaw(itemIndex, ClientItemAttributes.NumberOfSlots, ((LuaValue)itemProperty.Value).Value); break; case "ClassNum": table.SetRaw(itemIndex, ClientItemAttributes.ClassNumber, ((LuaValue)itemProperty.Value).Value); break; case "costume": table.SetRaw(itemIndex, ClientItemAttributes.IsCostume, Boolean.Parse(((LuaValue)itemProperty.Value).Value)); break; case "unidentifiedDescriptionName": itemList = itemProperty.Value as LuaList; if (itemList != null) { StringBuilder b = new StringBuilder(); b.Append("\r\n"); foreach (LuaValue itemDescItem in itemList.Variables) { b.Append(DbIOMethods.RemoveQuotes(itemDescItem.Value)); b.Append("\r\n"); } table.SetRaw(itemIndex, ClientItemAttributes.UnidentifiedDescription, b.ToString()); } break; case "identifiedDescriptionName": itemList = itemProperty.Value as LuaList; if (itemList != null) { StringBuilder b = new StringBuilder(); b.Append("\r\n"); foreach (LuaValue itemDescItem in itemList.Variables) { b.Append(DbIOMethods.RemoveQuotes(itemDescItem.Value)); b.Append("\r\n"); } table.SetRaw(itemIndex, ClientItemAttributes.IdentifiedDescription, b.ToString()); } break; } } } }
public static void Loader(AbstractDb <int> db, string file) { if (file == null) { Debug.Ignore(() => DbDebugHelper.OnUpdate(db.DbSource, null, "achievement_list table will not be loaded.")); return; } LuaList list; var table = db.Table; var metaGrf = db.ProjectDatabase.MetaGrf; string outputPath = GrfPath.Combine(SdeAppConfiguration.TempPath, Path.GetFileName(file)); byte[] itemData = metaGrf.GetData(file); if (itemData == null) { Debug.Ignore(() => DbDebugHelper.OnUpdate(db.DbSource, file, "File not found.")); return; } File.WriteAllBytes(outputPath, itemData); if (!File.Exists(outputPath)) { return; } if (Methods.ByteArrayCompare(itemData, 0, 4, new byte[] { 0x1b, 0x4c, 0x75, 0x61 }, 0)) { // Decompile lub file Lub lub = new Lub(itemData); var text = lub.Decompile(); itemData = EncodingService.DisplayEncoding.GetBytes(text); File.WriteAllBytes(outputPath, itemData); } DbIOMethods.DetectAndSetEncoding(itemData); using (LuaReader reader = new LuaReader(outputPath, DbIOMethods.DetectedEncoding)) { list = reader.ReadAll(); } LuaKeyValue itemVariable = list.Variables[0] as LuaKeyValue; if (itemVariable != null && itemVariable.Key == "achievement_tbl") { LuaList items = itemVariable.Value as LuaList; if (items != null) { foreach (LuaKeyValue item in items.Variables) { _loadEntry(table, item); } } } else { // Possible copy-paste data foreach (LuaKeyValue item in list.Variables) { _loadEntry(table, item); } } Debug.Ignore(() => DbDebugHelper.OnLoaded(db.DbSource, metaGrf.FindTkPath(file), db)); }
private static void _loadEntry(Table <int, ReadableTuple <int> > table, LuaKeyValue item) { int itemIndex = Int32.Parse(item.Key.Substring(1, item.Key.Length - 2)); LuaList itemProperties = item.Value as LuaList; LuaList contentProperties; StringBuilder resources; if (itemProperties != null) { foreach (LuaKeyValue itemProperty in itemProperties.Variables) { switch (itemProperty.Key) { case "UI_Type": table.SetRaw(itemIndex, ClientCheevoAttributes.UiType, ((LuaValue)itemProperty.Value).Value); break; case "group": table.SetRaw(itemIndex, ClientCheevoAttributes.GroupId, DbIOMethods.RemoveQuotes(((LuaValue)itemProperty.Value).Value)); break; case "major": table.SetRaw(itemIndex, ClientCheevoAttributes.Major, ((LuaValue)itemProperty.Value).Value); break; case "minor": table.SetRaw(itemIndex, ClientCheevoAttributes.Minor, ((LuaValue)itemProperty.Value).Value); break; case "title": table.SetRaw(itemIndex, ClientCheevoAttributes.Name, DbIOMethods.RemoveQuotes(((LuaValue)itemProperty.Value).Value)); break; case "reward": case "content": contentProperties = itemProperty.Value as LuaList; if (contentProperties == null) { continue; } try { foreach (LuaKeyValue contentProperty in contentProperties.Variables) { switch (contentProperty.Key) { case "summary": table.SetRaw(itemIndex, ClientCheevoAttributes.Summary, DbIOMethods.RemoveQuotes(((LuaValue)contentProperty.Value).Value)); break; case "details": table.SetRaw(itemIndex, ClientCheevoAttributes.Details, DbIOMethods.RemoveQuotes(((LuaValue)contentProperty.Value).Value)); break; case "title": table.SetRaw(itemIndex, ClientCheevoAttributes.RewardTitleId, ((LuaValue)contentProperty.Value).Value); break; case "buff": table.SetRaw(itemIndex, ClientCheevoAttributes.RewardBuff, ((LuaValue)contentProperty.Value).Value); break; case "item": table.SetRaw(itemIndex, ClientCheevoAttributes.RewardId, ((LuaValue)contentProperty.Value).Value); break; } } } catch (Exception err) { ErrorHandler.HandleException(err); } break; case "resource": resources = new StringBuilder(); contentProperties = itemProperty.Value as LuaList; if (contentProperties == null) { continue; } foreach (LuaKeyValue contentProperty in contentProperties.Variables) { try { int resId; if (!Int32.TryParse(contentProperty.Key.Substring(1, contentProperty.Key.Length - 2), out resId)) { DbIOErrorHandler.Handle(StackTraceException.GetStrackTraceException(), String.Format("ID: {0}, file: '{1}', exception: '{2}'", itemIndex.ToString(CultureInfo.InvariantCulture), TextFileHelper.LatestFile, "Invalid resource ID, found \"" + contentProperty.Key + "\", expected an integer."), ErrorLevel.Warning); continue; } LuaList resourceProperties = contentProperty.Value as LuaList; if (resourceProperties == null) { continue; } resources.Append(resId); foreach (LuaKeyValue resourceProperty in resourceProperties.Variables) { string value = ((LuaValue)resourceProperty.Value).Value; resources.Append("__%"); resources.Append(resourceProperty.Key); resources.Append("__%"); if (value.StartsWith("\"")) { resources.Append(DbIOMethods.RemoveQuotes(value)); } else { resources.Append(value); } } resources.Append("__&"); } catch (Exception err) { throw new Exception("Failed to read resource for ID " + itemIndex, err); } } table.SetRaw(itemIndex, ClientCheevoAttributes.Resources, resources.ToString()); break; case "score": table.SetRaw(itemIndex, ClientCheevoAttributes.Score, ((LuaValue)itemProperty.Value).Value); break; } } } }