Skip to content

Commit

Permalink
WIP local modelviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlamin committed Nov 26, 2022
1 parent 538480b commit 1a2aed9
Show file tree
Hide file tree
Showing 52 changed files with 18,225 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "7.0.0",
"commands": [
"dotnet-ef"
]
}
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,6 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml

# Listfile
listfile.csv
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "CascLib"]
path = CascLib
url = https://github.com/WoW-Tools/CascLib
[submodule "DBCD"]
path = DBCD
url = https://github.com/wowdev/DBCD
[submodule "WoWDBDefs"]
path = WoWDBDefs
url = https://github.com/wowdev/WoWDBDefs
1 change: 1 addition & 0 deletions CascLib
Submodule CascLib added at 2b194b
31 changes: 31 additions & 0 deletions Controllers/CASCController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Mvc;
using wow.tools.local.Services;

namespace wow.tools.local.Controllers
{
[Route("casc/")]
[ApiController]
public class CASCController : Controller
{
[Route("fdid")]
[HttpGet]
public FileStreamResult File(uint fileDataID)
{
return new FileStreamResult(CASC.GetFileByID(fileDataID), "application/octet-stream")
{
FileDownloadName = fileDataID.ToString()
};
}

[Route("buildname")]
[HttpGet]
public string BuildName()
{
// WOW-46801patch10.0.2_PTR
var splitName= CASC.BuildName.Replace("WOW-", "").Split("patch");
var buildName = splitName[1].Split("_")[0] + "." + splitName[0];
Console.WriteLine("Set modelviewer build name as " + buildName);
return buildName;
}
}
}
138 changes: 138 additions & 0 deletions Controllers/DBCFindController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using DBCD;
using wow.tools.local.Services;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace wow.tools.local.Controllers
{
[Route("dbc/find")]
[ApiController]
public class DBCFindController : ControllerBase
{
private readonly DBCManager dbcManager;

public DBCFindController(IDBCManager dbcManager) => this.dbcManager = (DBCManager)dbcManager;

// GET: find/
[HttpGet]
public string Get()
{
return "No DBC selected!";
}

// GET: find/name
[HttpGet("{name}")]
public async Task<List<Dictionary<string, string>>> Get(string name, string build, string col, int val, bool useHotfixes = false, bool calcOffset = true)
{
Console.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;
}
}
}
145 changes: 145 additions & 0 deletions Controllers/DBCPeekController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using DBCD;
using wow.tools.local.Services;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CASCLib;

namespace wow.tools.local.Controllers
{
[Route("dbc/peek")]
[ApiController]
public class DBCPeekController : ControllerBase
{
private readonly DBCManager dbcManager;

public DBCPeekController(IDBCManager dbcManager)
{
this.dbcManager = dbcManager as DBCManager;
}

public class PeekResult
{
public Dictionary<string, string> values { get; set; }
public int offset { get; set; }
}

// GET: peek/
[HttpGet]
public string Get()
{
return "No DBC selected!";
}

// GET: peek/name
[HttpGet("{name}")]
public async Task<PeekResult> Get(string name, string build, string col, int val, bool useHotfixes = false, string pushIDs = "")
{
Console.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;
}
}
}
Loading

0 comments on commit 1a2aed9

Please sign in to comment.