From 6dd7d4cc90e221fd1912d118a323103fa78281e2 Mon Sep 17 00:00:00 2001 From: Martin Benjamins Date: Mon, 22 Jul 2024 16:46:09 +0200 Subject: [PATCH] Add WIP VO page and WIP model info --- Controllers/ModelController.cs | 142 +++++++++++++++++++++++++++++++++ Services/FileLinker.cs | 2 +- WoWFormatLib | 2 +- WoWNamingLib | 2 +- wow.tools.local.csproj | 2 +- wwwroot/db/broadcasttext.html | 2 +- wwwroot/js/files.js | 23 ++++++ 7 files changed, 170 insertions(+), 5 deletions(-) create mode 100644 Controllers/ModelController.cs diff --git a/Controllers/ModelController.cs b/Controllers/ModelController.cs new file mode 100644 index 0000000..5c9dceb --- /dev/null +++ b/Controllers/ModelController.cs @@ -0,0 +1,142 @@ +using Microsoft.AspNetCore.Mvc; +using System.Runtime.Serialization; +using System.Text.RegularExpressions; +using wow.tools.local.Services; +using WoWFormatLib.FileProviders; +using WoWFormatLib.FileReaders; +using WoWFormatLib.Structs.WMO; + +namespace wow.tools.local.Controllers +{ + [Route("model/")] + public class ModelController(IDBCManager dbcManager) : Controller + { + private readonly DBCManager dbcManager = (DBCManager)dbcManager; + + [Route("info")] + [HttpGet] + public string Info(int fileDataID) + { + if(!FileProvider.HasProvider(CASC.BuildName)) + { + var casc = new CASCFileProvider(); + casc.InitCasc(CASC.cascHandler); + FileProvider.SetProvider(casc, CASC.BuildName); + } + + FileProvider.SetDefaultBuild(CASC.BuildName); + + var returnString = ""; + + var type = CASC.Types[fileDataID]; + if (type == "wmo") + { + var wmoReader = new WMOReader(); + var wmo = wmoReader.LoadWMO((uint)fileDataID); + + returnString += "

Groups

"; + returnString += ""; + for (var i = 0; i < wmo.groupInfo.Length; i++) + { + var group = wmo.groupInfo[i]; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + } + + returnString += "
GroupFlags: " + group.flags + "Flags2: " + wmo.groupInfo2[i].flags2 + "'lodIndex' " + wmo.groupInfo2[i].lodIndex + "
"; + + returnString += "

Group names

"; + returnString += ""; + for (var gn = 0; gn < wmo.groupNames.Length; gn++) + { + returnString += ""; + } + returnString += "
" + wmo.groupNames[gn].name + "
"; + + returnString += "

Group FileDataIDs

"; + returnString += ""; + foreach (var gfdid in wmo.groupFileDataIDs) + { + returnString += ""; + var groupFilename = CASC.Listfile.TryGetValue((int)gfdid, out var gfilename) ? gfilename.ToString() : ""; + returnString += ""; + returnString += ""; + } + returnString += "
" + gfdid + "" + groupFilename + "
"; + + returnString += "

Materials

"; + returnString += ""; + for (var i = 0; i < wmo.materials.Length; i++) + { + var material = wmo.materials[i]; + + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + } + returnString += "
Material " + i + "Flags: " + material.flags + "BlendMode: " + material.blendMode + "GroundType: " + material.groundType + "Shader: " + GetEnumMemberAttrValue(material.shader) + "
"; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + + if ((uint)material.shader == 23) + { + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + } + else + { + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + returnString += ""; + } + + returnString += "
Texture1" + material.texture1 + "" + (CASC.Listfile.TryGetValue((int)material.texture1, out var texture1Filename) ? texture1Filename : "Unknown filename") + "
Color (SIDN)" + material.color1 + "" + ARGBToDiv(material.color1) + "
Frame color (SIDN)" + material.color1b + "" + ARGBToDiv(material.color1b) + "
Texture 2" + material.texture2 + "" + (CASC.Listfile.TryGetValue((int)material.texture2, out var texture2Filename) ? texture2Filename : "Unknown filename") + "
Diff color" + material.color2 + "" + ARGBToDiv(material.color2) + "
Texture 3" + material.texture3 + "" + (CASC.Listfile.TryGetValue((int)material.texture3, out var texture3Filename) ? texture3Filename : "Unknown filename") + "
Texture 4" + material.color3 + "" + (CASC.Listfile.TryGetValue((int)material.color3, out var t4n) ? t4n : "Unknown filename") + "
Texture 5" + material.flags3 + "" + (CASC.Listfile.TryGetValue((int)material.flags3, out var t5n) ? t5n : "Unknown filename") + "
Texture 6" + material.runtimeData0 + "" + (CASC.Listfile.TryGetValue((int)material.runtimeData0, out var t6n) ? t6n : "Unknown filename") + "
Texture 7" + material.runtimeData1 + "" + (CASC.Listfile.TryGetValue((int)material.runtimeData1, out var t7n) ? t7n : "Unknown filename") + "
Texture 8" + material.runtimeData2 + "" + (CASC.Listfile.TryGetValue((int)material.runtimeData2, out var t8n) ? t8n : "Unknown filename") + "
Texture 9" + material.runtimeData3 + "" + (CASC.Listfile.TryGetValue((int)material.runtimeData3, out var t9n) ? t9n : "Unknown filename") + "
Unk color" + material.color3 + "" + ARGBToDiv(material.color3) + "
Flags 2" + material.flags3 + "
Runtime data 0" + material.runtimeData0 + "
Runtime data 1" + material.runtimeData1 + "
Runtime data 2" + material.runtimeData2 + "
Runtime data 3" + material.runtimeData3 + "
"; + } + return returnString; + } + + private string GetEnumMemberAttrValue(T enumVal) + { + var enumType = typeof(T); + var memInfo = enumType.GetMember(enumVal.ToString()); + var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType().FirstOrDefault(); + if (attr != null) + { + return attr.Value; + } + + return null; + } + + private string ARGBToDiv(uint argb) + { + var a = (byte)(argb >> 24); + var r = (byte)(argb >> 16); + var g = (byte)(argb >> 8); + var b = (byte)(argb >> 0); + + return "
 
"; + } + } +} diff --git a/Services/FileLinker.cs b/Services/FileLinker.cs index 73041d5..b6d763e 100644 --- a/Services/FileLinker.cs +++ b/Services/FileLinker.cs @@ -249,7 +249,7 @@ public static void LinkWMO(uint fileDataID, bool forceRecheck = false, bool need insertEntry(insertCmd, material.texture3, "wmo texture"); } - if (material.shader == 23) + if ((uint)material.shader == 23) { if (material.color3 != 0 && !inserted.Contains(material.color3)) { diff --git a/WoWFormatLib b/WoWFormatLib index 39b5e0a..cf955f1 160000 --- a/WoWFormatLib +++ b/WoWFormatLib @@ -1 +1 @@ -Subproject commit 39b5e0a7052f8cc3fcf095ab911cd6fa4731b9f2 +Subproject commit cf955f1c60c000986fa7e5303875ba1baf432a09 diff --git a/WoWNamingLib b/WoWNamingLib index 84cf7ed..85257a1 160000 --- a/WoWNamingLib +++ b/WoWNamingLib @@ -1 +1 @@ -Subproject commit 84cf7edacda064c7fe29dc744149adac92dda558 +Subproject commit 85257a153569409aaa5b2cf059ea22c5b9ceb90c diff --git a/wow.tools.local.csproj b/wow.tools.local.csproj index ce55cb1..0a57f69 100644 --- a/wow.tools.local.csproj +++ b/wow.tools.local.csproj @@ -7,7 +7,7 @@ https://github.com/Marlamin/wow.tools.local git README.md - 0.4.6 + 0.4.7 diff --git a/wwwroot/db/broadcasttext.html b/wwwroot/db/broadcasttext.html index 7f225c9..55cf31a 100644 --- a/wwwroot/db/broadcasttext.html +++ b/wwwroot/db/broadcasttext.html @@ -41,7 +41,7 @@

NPC VO lines

-

Note: The data backing this page only update when VO naming is run on the naming page. Restart required after.

+

Note: Some of the data backing this page only update when VO naming is run on the naming page. Restart required after.

SKIT IDFiles    Note: only FDIDs and filenames are searchableBroadcastText
diff --git a/wwwroot/js/files.js b/wwwroot/js/files.js index c2f091a..752c507 100644 --- a/wwwroot/js/files.js +++ b/wwwroot/js/files.js @@ -230,12 +230,35 @@ function fillPreviewModal(buildconfig, filedataid, type) { } html += ""; } else if (type == "m2" || type == "wmo") { + html += ""; + html += "
"; + html += "
"; html += ""; if (type == "m2") { html += ""; }else if(type == "wmo"){ html += ""; } + html += "
"; + html += "
"; + html += "
";
+        html += "
"; + html += "
"; + html += "
"; + html += "
"; + html += "
"; + + fetch("/casc/json?fileDataID=" + filedataid).then((response) => response.text()).then((text) => { + document.getElementById('jsonHolder').innerHTML = text; + }); + + fetch("/model/info?fileDataID=" + filedataid).then((response) => response.text()).then((text) => { + document.getElementById('modelinfoHolder').innerHTML = text; + }); } else if (type == "xml" || type == "lua" || type == "txt" || type == "srt" || type == "toc") { fetch(url).then((response) => response.text()).then((text) => { document.getElementById('codeHolder').innerHTML = text;