public int?SupplyDuration(int spellID, uint?effectIndex) { // How is effectIndex used here? effectIndex ??= 1; var spellMiscRow = dbcManager.FindRecords("spellMisc", build, "SpellID", spellID, true).Result; if (spellMiscRow.Count == 0) { Console.WriteLine("Unable to find Spell ID " + spellID + " in spell misc"); return(null); } var spellDurationID = (ushort)spellMiscRow[0]["DurationIndex"]; if (spellDurationID == 0) { Console.WriteLine("Unable to find duration for Spell ID " + spellID + " index " + effectIndex); return(null); } var spellDurationDB = dbcManager.GetOrLoad("SpellDuration", build).Result; if (spellDurationDB.TryGetValue(spellDurationID, out var durationRow)) { return((int)durationRow["Duration"]); } Console.WriteLine("Unable to find duration for Spell ID " + spellID + " index " + effectIndex); return(null); }
public string Diff(string name, string build1, string build2) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(build1) || string.IsNullOrEmpty(build2)) { return("Invalid arguments! Require name, build1, build2"); } Logger.WriteLine("Serving diff for " + name + " between " + build1 + " and " + build2); var dbc1 = dbcManager.GetOrLoad(name, build1).BackingCollection; var dbc2 = dbcManager.GetOrLoad(name, build2).BackingCollection; var comparer = new DBComparer(dbc1, dbc2); WoWToolsDiffResult diff = (WoWToolsDiffResult)comparer.Diff(DiffType.WoWTools); return(diff.ToJSONString()); }
public async Task <string> Diff(string name, string build1, string build2, bool useHotfixesFor1 = false, bool useHotfixesFor2 = false) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(build1) || string.IsNullOrEmpty(build2)) { return("Invalid arguments! Require name, build1, build2"); } Logger.WriteLine("Serving diff for " + name + " between " + build1 + " and " + build2); var dbc1 = (IDictionary)await dbcManager.GetOrLoad(name, build1, useHotfixesFor1); var dbc2 = (IDictionary)await dbcManager.GetOrLoad(name, build2, useHotfixesFor2); var comparer = new DBComparer(dbc1, dbc2); WoWToolsDiffResult diff = (WoWToolsDiffResult)comparer.Diff(DiffType.WoWTools); return(diff.ToJSONString()); }
public async Task <string> Get(string name, string build, bool useHotfixes = false) { if (name == null || build == null) { return("Not enough variables"); } var storage = await dbcManager.GetOrLoad(name, build, useHotfixes); if (!storage.Values.Any()) { throw new Exception("No rows found!"); } var returnString = ""; foreach (var encryptedSection in storage.GetEncryptedSections()) { returnString += encryptedSection.Key.ToString("X16") + " " + encryptedSection.Value + "\n"; } return(returnString); }
public Dictionary <uint, List <uint> > Get(int filedataid, string build) { Logger.WriteLine("Serving texture lookup for filedataid " + filedataid + " build " + build); var modelFileData = dbcManager.GetOrLoad("modelfiledata", build); var itemDisplayInfo = dbcManager.GetOrLoad("itemdisplayinfo", build); var textureFileData = dbcManager.GetOrLoad("texturefiledata", build); var creatureModelData = dbcManager.GetOrLoad("creaturemodeldata", build); var creatureDisplayInfo = dbcManager.GetOrLoad("creaturedisplayinfo", build); var returnList = new Dictionary <uint, List <uint> >(); if (modelFileData.ContainsKey(filedataid)) { dynamic mfdEntry = modelFileData[filedataid]; foreach (dynamic idiEntry in itemDisplayInfo.Values) { if (idiEntry.ModelResourcesID[0] != mfdEntry.ModelResourcesID && idiEntry.ModelResourcesID[1] != mfdEntry.ModelResourcesID) { continue; } var textureFileDataList = new List <uint>(); foreach (dynamic tfdEntry in textureFileData.Values) { if (tfdEntry.MaterialResourcesID == idiEntry.ModelMaterialResourcesID[0] || tfdEntry.MaterialResourcesID == idiEntry.ModelMaterialResourcesID[1]) { textureFileDataList.Add((uint)tfdEntry.FileDataID); } } returnList.Add((uint)idiEntry.ID, textureFileDataList); } foreach (dynamic cmdEntry in creatureModelData.Values) { if (cmdEntry.FileDataID != filedataid) { continue; } foreach (dynamic cdiEntry in creatureDisplayInfo.Values) { if (cdiEntry.ModelID != cmdEntry.ID) { continue; } returnList.Add((uint)cdiEntry.ID, new List <uint> { (uint)cdiEntry.TextureVariationFileDataID[0], (uint)cdiEntry.TextureVariationFileDataID[1], (uint)cdiEntry.TextureVariationFileDataID[2] }); } break; } } return(returnList); }
public async Task <IActionResult> GetUnkItems() { var build = "9.0.1.35522"; var itemDB = await dbcManager.GetOrLoad("Item", build); var itemSparseDB = await dbcManager.GetOrLoad("ItemSparse", build, true); var itemSearchNameDB = await dbcManager.GetOrLoad("ItemSearchName", build, true); var unkItems = new List <int>(); foreach (var itemID in itemDB.Keys) { if (!itemSparseDB.ContainsKey(itemID) && !itemSearchNameDB.ContainsKey(itemID)) { unkItems.Add(itemID); } } return(Ok(unkItems)); }
public async Task <PeekResult> Get(string name, string build, string col, int val, bool useHotfixes = false, bool calcOffset = true) { Logger.WriteLine("Serving foreign key row for " + name + "::" + col + " (" + build + ", hotfixes: " + useHotfixes + ") value " + val); var storage = await dbcManager.GetOrLoad(name, build, useHotfixes); var result = new PeekResult(); result.values = new Dictionary <string, string>(); if (!storage.Values.Any()) { return(result); } var offset = 0; var recordFound = false; if (!calcOffset && col == "ID") { if (storage.TryGetValue(val, out DBCDRow row)) { for (var i = 0; i < storage.AvailableColumns.Length; ++i) { string fieldName = storage.AvailableColumns[i]; if (fieldName != col) { continue; } var field = row[fieldName]; // Don't think FKs to arrays are possible, so only check regular value if (field.ToString() == val.ToString()) { for (var j = 0; j < storage.AvailableColumns.Length; ++j) { string subfieldName = storage.AvailableColumns[j]; var subfield = row[subfieldName]; if (subfield is Array a) { for (var k = 0; k < a.Length; k++) { result.values.Add(subfieldName + "[" + k + "]", a.GetValue(k).ToString()); } } else { result.values.Add(subfieldName, subfield.ToString()); } } } } } } else { foreach (DBCDRow row in storage.Values) { if (recordFound) { continue; } offset++; for (var i = 0; i < storage.AvailableColumns.Length; ++i) { string fieldName = storage.AvailableColumns[i]; if (fieldName != col) { continue; } var field = row[fieldName]; // Don't think FKs to arrays are possible, so only check regular value if (field.ToString() == val.ToString()) { for (var j = 0; j < storage.AvailableColumns.Length; ++j) { string subfieldName = storage.AvailableColumns[j]; var subfield = row[subfieldName]; if (subfield is Array a) { for (var k = 0; k < a.Length; k++) { result.values.Add(subfieldName + "[" + k + "]", a.GetValue(k).ToString()); } } else { result.values.Add(subfieldName, subfield.ToString()); } } recordFound = true; } } } } result.offset = offset; return(result); }
public ActionResult ExportCSV(string name, string build, bool newLinesInStrings = true) { Logger.WriteLine("Exporting DBC " + name + " for build " + build); try { var storage = dbcManager.GetOrLoad(name, build); if (!storage.Values.Any()) { throw new Exception("No rows found!"); } var headerWritten = false; using (var exportStream = new MemoryStream()) using (var exportWriter = new StreamWriter(exportStream)) { foreach (DBCDRow item in storage.Values) { // Write CSV header if (!headerWritten) { for (var j = 0; j < storage.AvailableColumns.Length; ++j) { string fieldname = storage.AvailableColumns[j]; var field = item[fieldname]; var isEndOfRecord = j == storage.AvailableColumns.Length - 1; if (field is Array a) { for (var i = 0; i < a.Length; i++) { var isEndOfArray = a.Length - 1 == i; exportWriter.Write($"{fieldname}[{i}]"); if (!isEndOfArray) { exportWriter.Write(","); } } } else { exportWriter.Write(fieldname); } if (!isEndOfRecord) { exportWriter.Write(","); } } headerWritten = true; exportWriter.WriteLine(); } for (var i = 0; i < storage.AvailableColumns.Length; ++i) { var field = item[storage.AvailableColumns[i]]; var isEndOfRecord = i == storage.AvailableColumns.Length - 1; if (field is Array a) { for (var j = 0; j < a.Length; j++) { var isEndOfArray = a.Length - 1 == j; exportWriter.Write(a.GetValue(j)); if (!isEndOfArray) { exportWriter.Write(","); } } } else { var value = field; if (value.GetType() == typeof(string)) { value = StringToCSVCell((string)value, newLinesInStrings); } exportWriter.Write(value); } if (!isEndOfRecord) { exportWriter.Write(","); } } exportWriter.WriteLine(); } exportWriter.Dispose(); return(new FileContentResult(exportStream.ToArray(), "application/octet-stream") { FileDownloadName = Path.ChangeExtension(name, ".csv") }); } } catch (FileNotFoundException e) { Logger.WriteLine("DBC " + name + " for build " + build + " not found: " + e.Message); return(NotFound()); } catch (Exception e) { Logger.WriteLine("Error during CSV generation for DBC " + name + " for build " + build + ": " + e.Message); return(BadRequest()); } }
private async Task <IDBCDStorage> GetStorage(string name, string build, bool useHotfixes = false, LocaleFlags locale = LocaleFlags.All_WoW) { return(await dbcManager.GetOrLoad(name, build, useHotfixes, locale)); }
public async Task <HeaderResult> Get(string name, string build) { Logger.WriteLine("Serving headers for " + name + " (" + build + ")"); var result = new HeaderResult(); try { var storage = await dbcManager.GetOrLoad(name, build); if (!dbdProvider.TryGetDefinition(name, out var definition)) { throw new KeyNotFoundException("Definition for " + name); } result.headers = new List <string>(); result.fks = new Dictionary <string, string>(); result.comments = new Dictionary <string, string>(); result.unverifieds = new List <string>(); if (!storage.Values.Any()) { for (var j = 0; j < storage.AvailableColumns.Length; ++j) { var fieldName = storage.AvailableColumns[j]; result.headers.Add(fieldName); if (definition.columnDefinitions.TryGetValue(fieldName, out var columnDef)) { if (columnDef.foreignTable != null) { result.fks.Add(fieldName, columnDef.foreignTable + "::" + columnDef.foreignColumn); } if (columnDef.comment != null) { result.comments.Add(fieldName, columnDef.comment); } if (!columnDef.verified) { result.unverifieds.Add(fieldName); } } } } else { foreach (DBCDRow item in storage.Values) { for (var j = 0; j < storage.AvailableColumns.Length; ++j) { string fieldName = storage.AvailableColumns[j]; var field = item[fieldName]; if (field is Array a) { for (var i = 0; i < a.Length; i++) { result.headers.Add($"{fieldName}[{i}]"); if (definition.columnDefinitions.TryGetValue(fieldName, out var columnDef)) { if (columnDef.foreignTable != null) { result.fks.Add($"{fieldName}[{i}]", columnDef.foreignTable + "::" + columnDef.foreignColumn); } if (columnDef.comment != null) { result.comments.Add($"{fieldName}[{i}]", columnDef.comment); } if (!columnDef.verified) { result.unverifieds.Add($"{fieldName}[{i}]"); } } } } else { result.headers.Add(fieldName); if (definition.columnDefinitions.TryGetValue(fieldName, out var columnDef)) { if (columnDef.foreignTable != null) { result.fks.Add(fieldName, columnDef.foreignTable + "::" + columnDef.foreignColumn); } if (columnDef.comment != null) { result.comments.Add(fieldName, columnDef.comment); } if (!columnDef.verified) { result.unverifieds.Add(fieldName); } } } } break; } } result.relationsToColumns = new Dictionary <string, List <string> >(); foreach (var column in result.headers) { var relationsToCol = dbdProvider.GetRelationsToColumn(name + "::" + column, true); if (relationsToCol.Count > 0) { result.relationsToColumns.Add(column, relationsToCol); } } } catch (Exception e) { Logger.WriteLine("Error occured during serving data: " + e.Message); result.error = e.Message.Replace(SettingManager.dbcDir, ""); } return(result); }
public DataTablesResult Get(string name, string build, int draw, int start, int length) { var searching = false; var searchValue = Request.Query["search[value]"]; if (string.IsNullOrWhiteSpace(searchValue)) { Logger.WriteLine("Serving data " + start + "," + length + " for dbc " + name + " (" + build + ") for draw " + draw); } else { searching = true; Logger.WriteLine("Serving data " + start + "," + length + " for dbc " + name + " (" + build + ") for draw " + draw + " with filter " + searchValue); } var result = new DataTablesResult { draw = draw }; try { var storage = dbcManager.GetOrLoad(name, build); if (storage == null) { throw new Exception("Definitions for this DB/version combo not found in definition cache!"); } result.recordsTotal = storage.Values.Count(); result.data = new List <List <string> >(); var resultCount = 0; foreach (DBCDRow item in storage.Values) { var rowList = new List <string>(); var matches = false; for (var i = 0; i < storage.AvailableColumns.Length; ++i) { var field = item[storage.AvailableColumns[i]]; if (field is Array a) { for (var j = 0; j < a.Length; j++) { var val = a.GetValue(j).ToString(); if (searching) { if (val.Contains(searchValue, StringComparison.InvariantCultureIgnoreCase)) { matches = true; } } val = System.Web.HttpUtility.HtmlEncode(val); rowList.Add(val); } } else { var val = field.ToString(); if (searching) { if (val.Contains(searchValue, StringComparison.InvariantCultureIgnoreCase)) { matches = true; } } val = System.Web.HttpUtility.HtmlEncode(val); rowList.Add(val); } } if (searching) { if (matches) { resultCount++; result.data.Add(rowList); } } else { resultCount++; result.data.Add(rowList); } } result.recordsFiltered = resultCount; var takeLength = length; if ((start + length) > resultCount) { takeLength = resultCount - start; } result.data = result.data.GetRange(start, takeLength); } catch (Exception e) { Logger.WriteLine("Error occured during serving data: " + e.Message); result.error = e.Message.Replace(SettingManager.dbcDir, ""); } return(result); }
public async Task <PeekResult> Get(string name, string build, string col, int val, bool useHotfixes = false, string pushIDs = "") { Logger.WriteLine("Serving peek row for " + name + "::" + col + " (" + build + ", hotfixes: " + useHotfixes + ") value " + val); List <int> pushIDList = null; if (useHotfixes && pushIDs != "") { pushIDList = new List <int>(); var pushIDsExploded = pushIDs.Split(','); if (pushIDsExploded.Length > 0) { foreach (var pushID in pushIDs.Split(',')) { if (int.TryParse(pushID, out int pushIDInt)) { pushIDList.Add(pushIDInt); } } } } var storage = await dbcManager.GetOrLoad(name, build, useHotfixes, LocaleFlags.All_WoW, pushIDList); var result = new PeekResult { values = new Dictionary <string, string>() }; if (!storage.Values.Any()) { return(result); } if (col == "ID" && storage.TryGetValue(val, out var rowByIndex)) { foreach (var fieldName in storage.AvailableColumns) { if (fieldName != col) { continue; } var field = rowByIndex[fieldName]; // Don't think FKs to arrays are possible, so only check regular value if (field.ToString() != val.ToString()) { continue; } foreach (var subfieldName in storage.AvailableColumns) { var subfield = rowByIndex[subfieldName]; if (subfield is Array a) { for (var k = 0; k < a.Length; k++) { result.values.Add(subfieldName + "[" + k + "]", a.GetValue(k).ToString()); } } else { result.values.Add(subfieldName, subfield.ToString()); } } } } else { var recordFound = false; foreach (var row in storage.Values) { if (recordFound) { continue; } foreach (var fieldName in storage.AvailableColumns) { if (fieldName != col) { continue; } var field = row[fieldName]; // Don't think FKs to arrays are possible, so only check regular value if (field.ToString() != val.ToString()) { continue; } foreach (var subfieldName in storage.AvailableColumns) { var subfield = row[subfieldName]; if (subfield is Array a) { for (var k = 0; k < a.Length; k++) { result.values.Add(subfieldName + "[" + k + "]", a.GetValue(k).ToString()); } } else { result.values.Add(subfieldName, subfield.ToString()); } } recordFound = true; } } } return(result); }
public async Task <List <Dictionary <string, string> > > Get(string name, string build, string col, int val, bool useHotfixes = false, bool calcOffset = true) { Logger.WriteLine("Finding results for " + name + "::" + col + " (" + build + ", hotfixes: " + useHotfixes + ") value " + val); var storage = await dbcManager.GetOrLoad(name, build, useHotfixes); var result = new List <Dictionary <string, string> >(); if (!storage.Values.Any()) { return(result); } if (!calcOffset && col == "ID") { if (storage.TryGetValue(val, out DBCDRow row)) { for (var i = 0; i < storage.AvailableColumns.Length; ++i) { string fieldName = storage.AvailableColumns[i]; if (fieldName != col) { continue; } var field = row[fieldName]; // Don't think FKs to arrays are possible, so only check regular value if (field.ToString() == val.ToString()) { var newDict = new Dictionary <string, string>(); for (var j = 0; j < storage.AvailableColumns.Length; ++j) { string subfieldName = storage.AvailableColumns[j]; var subfield = row[subfieldName]; if (subfield is Array a) { for (var k = 0; k < a.Length; k++) { newDict.Add(subfieldName + "[" + k + "]", a.GetValue(k).ToString()); } } else { newDict.Add(subfieldName, subfield.ToString()); } } result.Add(newDict); } } } } else { var arrIndex = 0; if (col.Contains("[")) { arrIndex = int.Parse(col.Split("[")[1].Replace("]", string.Empty)); col = col.Split("[")[0]; } foreach (DBCDRow row in storage.Values) { for (var i = 0; i < storage.AvailableColumns.Length; ++i) { string fieldName = storage.AvailableColumns[i]; if (fieldName != col) { continue; } var field = row[fieldName]; if (field is Array arrayField) { field = arrayField.GetValue(arrIndex).ToString(); } // Don't think FKs to arrays are possible, so only check regular value if (field.ToString() == val.ToString()) { var newDict = new Dictionary <string, string>(); for (var j = 0; j < storage.AvailableColumns.Length; ++j) { string subfieldName = storage.AvailableColumns[j]; var subfield = row[subfieldName]; if (subfield is Array a) { for (var k = 0; k < a.Length; k++) { newDict.Add(subfieldName + "[" + k + "]", a.GetValue(k).ToString()); } } else { newDict.Add(subfieldName, subfield.ToString()); } } result.Add(newDict); } } } } return(result); }
public async Task <DataTablesResult> Get(CancellationToken cancellationToken, string name, string build, int draw, int start, int length, bool useHotfixes = false, LocaleFlags locale = LocaleFlags.All_WoW) { var parameters = new Dictionary <string, string>(); if (Request.Method == "POST") { // POST, what site uses foreach (var post in Request.Form) { parameters.Add(post.Key, post.Value); } if (parameters.ContainsKey("draw")) { draw = int.Parse(parameters["draw"]); } if (parameters.ContainsKey("start")) { start = int.Parse(parameters["start"]); } if (parameters.ContainsKey("length")) { length = int.Parse(parameters["length"]); } } else { // GET, backwards compatibility for scripts/users using this foreach (var get in Request.Query) { parameters.Add(get.Key, get.Value); } } if (!parameters.TryGetValue("search[value]", out var searchValue) || string.IsNullOrWhiteSpace(searchValue)) { Logger.WriteLine("Serving data " + start + "," + length + " for dbc " + name + " (" + build + ") for draw " + draw); } else { Logger.WriteLine("Serving data " + start + "," + length + " for dbc " + name + " (" + build + ") for draw " + draw + " with search " + searchValue); } var result = new DataTablesResult { draw = draw }; try { cancellationToken.ThrowIfCancellationRequested(); var storage = await dbcManager.GetOrLoad(name, build, useHotfixes, locale); if (storage == null) { throw new Exception("Definitions for this DB and version combination not found in definition cache!"); } result.recordsTotal = storage.Values.Count(); result.data = new List <string[]>(); if (storage.Values.Count == 0 || storage.AvailableColumns.Length == 0) { return(result); } var viewFilter = new DBCViewFilter(storage, parameters, WebUtility.HtmlEncode); result.data = viewFilter.GetRecords(cancellationToken).ToList(); result.recordsFiltered = result.data.Count; var takeLength = length; if ((start + length) > result.recordsFiltered) { takeLength = result.recordsFiltered - start; } // Temp hackfix: If requested count is higher than the amount of filtered records an error occurs and all rows are returned crashing tabs for large DBs. if (takeLength < 0) { start = 0; takeLength = 0; } result.data = result.data.GetRange(start, takeLength); } catch (Exception e) { Logger.WriteLine("Error occured during serving data: " + e.Message); result.error = e.Message.Replace(SettingManager.dbcDir, ""); } return(result); }