From ba57013c37d7dfc44ee6106eb94d174a5d901141 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:58:54 +0000 Subject: [PATCH] style: format code with dotnet-format This commit fixes the style issues introduced in 74a543c according to the output from dotnet-format. Details: None --- VBLauncher/EditorWindow.NonUI.cs | 128 +-- VBLauncher/EditorWindow.cs | 1373 +++++++++++++------------ VBLauncher/Extensions.cs | 508 ++++----- VBLauncher/GrpBrowser.cs | 81 +- VBLauncher/ModLoader.cs | 4 +- VBLauncher/Options.cs | 129 ++- VBLauncher/VB3DLib/GrannyFormats.cs | 12 +- VBLauncher/VB3DLib/VanBurenFormats.cs | 1152 ++++++++++----------- 8 files changed, 1734 insertions(+), 1653 deletions(-) diff --git a/VBLauncher/EditorWindow.NonUI.cs b/VBLauncher/EditorWindow.NonUI.cs index bfffad7..2fbbc55 100644 --- a/VBLauncher/EditorWindow.NonUI.cs +++ b/VBLauncher/EditorWindow.NonUI.cs @@ -26,7 +26,7 @@ private void OpenFromGRP() _filename = grpb.FileName; LoadFile(grpb.FileBytes, "." + grpb.Extension); } - + private void SaveFile() { var sfd = new SaveFileDialog { Filter = $"Van Buren Data File|*{_extension}", ValidateNames = true, DefaultExt = _extension }; @@ -37,7 +37,7 @@ private void SaveFile() File.WriteAllBytes(sfd.FileName, (byte[])_currentFile.ToByte().ToArray()); } } - + private void SetEngStfLocation() { var ofd = new OpenFileDialog { Multiselect = false, CheckFileExists = true, Filter = "English.stf|*.stf" }; @@ -45,7 +45,7 @@ private void SetEngStfLocation() MySettingsProperty.Settings.STFDir = ofd.FileName; _stf = Extensions.STFToTXT(File.ReadAllBytes(ofd.FileName)).ToArray(); } - + private bool CheckAndLoadStf() { if (string.IsNullOrEmpty(MySettingsProperty.Settings.STFDir)) @@ -69,7 +69,7 @@ private bool CheckAndLoadStf() _stf = Extensions.STFToTXT(File.ReadAllBytes(MySettingsProperty.Settings.STFDir)).ToArray(); return true; } - + private void FullSTFToText() { var ofd = new OpenFileDialog { Filter = "String Table File|*.stf", Multiselect = false }; @@ -82,7 +82,7 @@ private void FullSTFToText() } } } - + private void FullTextToSTF() { var ofd = new OpenFileDialog { Filter = "Text File|*.txt", Multiselect = false }; @@ -104,69 +104,69 @@ void ExtractAllGRPFiles(bool conv = false) grpb.extractFile(-1, conv); DarkMessageBox.ShowInformation("Done Extracting", "Finished"); } - + private void LoadFile(byte[] fb, string ext) + { + if (CheckAndLoadStf()) { - if (CheckAndLoadStf()) - { - switch (ext ?? "") - { - case ".amo": - { - DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); - break; - } - case ".arm": - { - DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); - break; - } - case ".con": - { - DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); - break; - } - case ".crt": - { - _currentFile = fb.ReadCRT(); - break; - } - case ".dor": - { - DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); - break; - } - case ".int": - { - DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); - break; - } - case ".itm": - { - _currentFile = fb.ReadITM(); - break; - } - case ".map": - { - _currentFile = fb.ReadMap(); - break; - } - case ".use": - { - DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); - break; - } - case ".wea": - { - DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); - break; - } - } - } - else + switch (ext ?? "") { - DarkMessageBox.ShowError($".STF Not selected, loading of {_filename} aborted", ".STF Not Selected"); + case ".amo": + { + DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); + break; + } + case ".arm": + { + DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); + break; + } + case ".con": + { + DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); + break; + } + case ".crt": + { + _currentFile = fb.ReadCRT(); + break; + } + case ".dor": + { + DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); + break; + } + case ".int": + { + DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); + break; + } + case ".itm": + { + _currentFile = fb.ReadITM(); + break; + } + case ".map": + { + _currentFile = fb.ReadMap(); + break; + } + case ".use": + { + DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); + break; + } + case ".wea": + { + DarkMessageBox.ShowMessage("Not yet implemented", "Not Implemented"); + break; + } } } + else + { + DarkMessageBox.ShowError($".STF Not selected, loading of {_filename} aborted", ".STF Not Selected"); + } + } } diff --git a/VBLauncher/EditorWindow.cs b/VBLauncher/EditorWindow.cs index 6138d2f..68356bd 100644 --- a/VBLauncher/EditorWindow.cs +++ b/VBLauncher/EditorWindow.cs @@ -56,66 +56,66 @@ public void Run() _window.Height); ImGui.StyleColorsDark(); ApplyAltUIColours(); - + var io = ImGui.GetIO(); io.ConfigFlags |= ImGuiConfigFlags.DockingEnable; if (File.Exists(@"C:\Windows\Fonts\segoeui.ttf")) { - _font = io.Fonts.AddFontFromFileTTF(@"C:\Windows\Fonts\segoeui.ttf", 17f); - _imguiRenderer.RecreateFontDeviceTexture(); + _font = io.Fonts.AddFontFromFileTTF(@"C:\Windows\Fonts\segoeui.ttf", 17f); + _imguiRenderer.RecreateFontDeviceTexture(); } MainLoop(); } private void MainLoop() - { - var stopwatch = Stopwatch.StartNew(); - const double targetFrameTime = 1.0 / 60.0; - - // set window icon - var stream = new MemoryStream(); - var bmp = Resources.VBEditor.ToBitmap(); - bmp.Save(stream, ImageFormat.Bmp); - Sdl2WindowExtensions.SetWindowIcon(_window, stream.ToArray()); - - while (_window.Exists) - { - var frameStartTime = stopwatch.Elapsed.TotalSeconds; - - // Handle input - var inputSnapshot = _window.PumpEvents(); - if (!_window.Exists) break; - - // Update ImGui - _imguiRenderer.Update((float)targetFrameTime, inputSnapshot); - if (_font is { } font) - { - ImGui.PushFont(font); - } - - DrawImGui(); - - // Render frame - _commandList.Begin(); - _commandList.SetFramebuffer(_graphicsDevice.MainSwapchain.Framebuffer); - _commandList.ClearColorTarget(0, RgbaFloat.CornflowerBlue); - _imguiRenderer.Render(_graphicsDevice, _commandList); - _commandList.End(); - _graphicsDevice.SubmitCommands(_commandList); - _graphicsDevice.SwapBuffers(_graphicsDevice.MainSwapchain); - - // Frame timing control - var frameEndTime = stopwatch.Elapsed.TotalSeconds; - var frameDuration = frameEndTime - frameStartTime; - if (!(frameDuration < targetFrameTime)) continue; - var sleepTime = (int)((targetFrameTime - frameDuration) * 1000); - Thread.Sleep(sleepTime); - } - - DisposeResources(); - } - + { + var stopwatch = Stopwatch.StartNew(); + const double targetFrameTime = 1.0 / 60.0; + + // set window icon + var stream = new MemoryStream(); + var bmp = Resources.VBEditor.ToBitmap(); + bmp.Save(stream, ImageFormat.Bmp); + Sdl2WindowExtensions.SetWindowIcon(_window, stream.ToArray()); + + while (_window.Exists) + { + var frameStartTime = stopwatch.Elapsed.TotalSeconds; + + // Handle input + var inputSnapshot = _window.PumpEvents(); + if (!_window.Exists) break; + + // Update ImGui + _imguiRenderer.Update((float)targetFrameTime, inputSnapshot); + if (_font is { } font) + { + ImGui.PushFont(font); + } + + DrawImGui(); + + // Render frame + _commandList.Begin(); + _commandList.SetFramebuffer(_graphicsDevice.MainSwapchain.Framebuffer); + _commandList.ClearColorTarget(0, RgbaFloat.CornflowerBlue); + _imguiRenderer.Render(_graphicsDevice, _commandList); + _commandList.End(); + _graphicsDevice.SubmitCommands(_commandList); + _graphicsDevice.SwapBuffers(_graphicsDevice.MainSwapchain); + + // Frame timing control + var frameEndTime = stopwatch.Elapsed.TotalSeconds; + var frameDuration = frameEndTime - frameStartTime; + if (!(frameDuration < targetFrameTime)) continue; + var sleepTime = (int)((targetFrameTime - frameDuration) * 1000); + Thread.Sleep(sleepTime); + } + + DisposeResources(); + } + private void OnWindowResized() { _graphicsDevice.MainSwapchain.Resize((uint)_window.Width, (uint)_window.Height); @@ -128,7 +128,7 @@ private void DisposeResources() _imguiRenderer.Dispose(); _graphicsDevice.Dispose(); } - + // Enumeration for PushStyleColor() / PopStyleColor() private enum ImGuiCol { @@ -187,78 +187,78 @@ private enum ImGuiCol ModalWindowDimBg, // Darken/colorize entire screen behind a modal window, when one is active } - private Vector4 ColToVec(Color col) => new (col.R / 255f, col.G / 255f, col.B / 255f, col.A / 255f); - + private Vector4 ColToVec(Color col) => new(col.R / 255f, col.G / 255f, col.B / 255f, col.A / 255f); + // TODO: ensure all used colors are set from ThemeProvider private void ApplyAltUIColours() { - var colors = ImGui.GetStyle().Colors; - colors[(int)ImGuiCol.Text] = ColToVec(ThemeProvider.Theme.Colors.LightText); - colors[(int)ImGuiCol.TextDisabled] = ColToVec(ThemeProvider.Theme.Colors.DisabledText); - colors[(int)ImGuiCol.WindowBg] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); - colors[(int)ImGuiCol.ChildBg] = new Vector4(1f, 0f, 0f, 1f); - colors[(int)ImGuiCol.PopupBg] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); - colors[(int)ImGuiCol.Border] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); - colors[(int)ImGuiCol.BorderShadow] = new Vector4(0f, 0f, 0f, 0f); - colors[(int)ImGuiCol.FrameBg] = ColToVec(ThemeProvider.Theme.Colors.LightBackground); - colors[(int)ImGuiCol.FrameBgHovered] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); - colors[(int)ImGuiCol.FrameBgActive] = new Vector4(0.2f, 0.22f, 0.23f, 1f); - colors[(int)ImGuiCol.TitleBg] = ColToVec(ThemeProvider.Theme.Colors.LightBackground); - colors[(int)ImGuiCol.TitleBgActive] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); - colors[(int)ImGuiCol.TitleBgCollapsed] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); - colors[(int)ImGuiCol.MenuBarBg] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); - colors[(int)ImGuiCol.ScrollbarBg] = ColToVec(ThemeProvider.Theme.Colors.LightBackground); - colors[(int)ImGuiCol.ScrollbarGrab] = new Vector4(0.34f, 0.34f, 0.34f, 1f); - colors[(int)ImGuiCol.ScrollbarGrabHovered] = new Vector4(0.4f, 0.4f, 0.4f, 1f); - colors[(int)ImGuiCol.ScrollbarGrabActive] = new Vector4(0.56f, 0.56f, 0.56f, 1f); - colors[(int)ImGuiCol.CheckMark] = ColToVec(ThemeProvider.Theme.Colors.LightText); - colors[(int)ImGuiCol.SliderGrab] = new Vector4(0.34f, 0.34f, 0.34f, 1f); - colors[(int)ImGuiCol.SliderGrabActive] = new Vector4(0.56f, 0.56f, 0.56f, 1f); - colors[(int)ImGuiCol.Button] = ColToVec(ThemeProvider.Theme.Colors.LightBackground); - colors[(int)ImGuiCol.ButtonHovered] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); - colors[(int)ImGuiCol.ButtonActive] = new Vector4(0.2f, 0.22f, 0.23f, 1f); - colors[(int)ImGuiCol.Header] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); - colors[(int)ImGuiCol.HeaderHovered] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); - colors[(int)ImGuiCol.HeaderActive] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); - colors[(int)ImGuiCol.Separator] = new Vector4(0f, 0f, 0f, 0f); - colors[(int)ImGuiCol.SeparatorHovered] = new Vector4(0f, 0f, 0f, 0f); - colors[(int)ImGuiCol.SeparatorActive] = new Vector4(0f, 0f, 0f, 0f); - colors[(int)ImGuiCol.ResizeGrip] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); - colors[(int)ImGuiCol.ResizeGripHovered] = new Vector4(0.44f, 0.44f, 0.44f, 1f); - colors[(int)ImGuiCol.ResizeGripActive] = new Vector4(0.4f, 0.44f, 0.47f, 1f); - colors[(int)ImGuiCol.Tab] = ColToVec(ThemeProvider.Theme.Colors.LightBackground); - colors[(int)ImGuiCol.TabHovered] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); - colors[(int)ImGuiCol.TabActive] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); - colors[(int)ImGuiCol.TabUnfocused] = ColToVec(ThemeProvider.Theme.Colors.HeaderBackground); - colors[(int)ImGuiCol.TabUnfocusedActive] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); - colors[(int)ImGuiCol.PlotLines] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); - colors[(int)ImGuiCol.PlotLinesHovered] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); - colors[(int)ImGuiCol.PlotHistogram] = new Vector4(0.15f, 0.15f, 0.15f, 1f); - colors[(int)ImGuiCol.PlotHistogramHovered] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); - colors[(int)ImGuiCol.TableHeaderBg] = new Vector4(1f, 0f, 1f, 1f); - colors[(int)ImGuiCol.TableBorderStrong] = new Vector4(0f, 1f, 1f, 1f); - colors[(int)ImGuiCol.TableBorderLight] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); - colors[(int)ImGuiCol.TableRowBg] = new Vector4(0f, 0f, 0f, 1f); - colors[(int)ImGuiCol.TableRowBgAlt] = new Vector4(1f, 0f, 1f, 1f); - colors[(int)ImGuiCol.TextSelectedBg] = new Vector4(0.2f, 0.22f, 0.23f, 1f); - colors[(int)ImGuiCol.DragDropTarget] = new Vector4(0.33f, 0.67f, 0.86f, 1f); - colors[(int)ImGuiCol.NavHighlight] = new Vector4(0.24f, 0.24f, 0.24f, 1f); - colors[(int)ImGuiCol.NavWindowingHighlight] = new Vector4(1f, 0f, 1f, 1f); - colors[(int)ImGuiCol.NavWindowingDimBg] = new Vector4(0f, 1f, 1f, 1f); - colors[(int)ImGuiCol.ModalWindowDimBg] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); - - var style = ImGui.GetStyle(); - style.ScrollbarSize = 15; - style.WindowRounding = 7; - style.ChildRounding = 4; - style.FrameRounding = 3; - style.PopupRounding = 4; - style.ScrollbarRounding = 9; - style.GrabRounding = 3; - style.TabRounding = 4; - style.WindowBorderSize = 1f; - // enable borders on buttons, textboxes, etc. - style.FrameBorderSize = 1f; + var colors = ImGui.GetStyle().Colors; + colors[(int)ImGuiCol.Text] = ColToVec(ThemeProvider.Theme.Colors.LightText); + colors[(int)ImGuiCol.TextDisabled] = ColToVec(ThemeProvider.Theme.Colors.DisabledText); + colors[(int)ImGuiCol.WindowBg] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); + colors[(int)ImGuiCol.ChildBg] = new Vector4(1f, 0f, 0f, 1f); + colors[(int)ImGuiCol.PopupBg] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); + colors[(int)ImGuiCol.Border] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); + colors[(int)ImGuiCol.BorderShadow] = new Vector4(0f, 0f, 0f, 0f); + colors[(int)ImGuiCol.FrameBg] = ColToVec(ThemeProvider.Theme.Colors.LightBackground); + colors[(int)ImGuiCol.FrameBgHovered] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); + colors[(int)ImGuiCol.FrameBgActive] = new Vector4(0.2f, 0.22f, 0.23f, 1f); + colors[(int)ImGuiCol.TitleBg] = ColToVec(ThemeProvider.Theme.Colors.LightBackground); + colors[(int)ImGuiCol.TitleBgActive] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); + colors[(int)ImGuiCol.TitleBgCollapsed] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); + colors[(int)ImGuiCol.MenuBarBg] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); + colors[(int)ImGuiCol.ScrollbarBg] = ColToVec(ThemeProvider.Theme.Colors.LightBackground); + colors[(int)ImGuiCol.ScrollbarGrab] = new Vector4(0.34f, 0.34f, 0.34f, 1f); + colors[(int)ImGuiCol.ScrollbarGrabHovered] = new Vector4(0.4f, 0.4f, 0.4f, 1f); + colors[(int)ImGuiCol.ScrollbarGrabActive] = new Vector4(0.56f, 0.56f, 0.56f, 1f); + colors[(int)ImGuiCol.CheckMark] = ColToVec(ThemeProvider.Theme.Colors.LightText); + colors[(int)ImGuiCol.SliderGrab] = new Vector4(0.34f, 0.34f, 0.34f, 1f); + colors[(int)ImGuiCol.SliderGrabActive] = new Vector4(0.56f, 0.56f, 0.56f, 1f); + colors[(int)ImGuiCol.Button] = ColToVec(ThemeProvider.Theme.Colors.LightBackground); + colors[(int)ImGuiCol.ButtonHovered] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); + colors[(int)ImGuiCol.ButtonActive] = new Vector4(0.2f, 0.22f, 0.23f, 1f); + colors[(int)ImGuiCol.Header] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); + colors[(int)ImGuiCol.HeaderHovered] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); + colors[(int)ImGuiCol.HeaderActive] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); + colors[(int)ImGuiCol.Separator] = new Vector4(0f, 0f, 0f, 0f); + colors[(int)ImGuiCol.SeparatorHovered] = new Vector4(0f, 0f, 0f, 0f); + colors[(int)ImGuiCol.SeparatorActive] = new Vector4(0f, 0f, 0f, 0f); + colors[(int)ImGuiCol.ResizeGrip] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); + colors[(int)ImGuiCol.ResizeGripHovered] = new Vector4(0.44f, 0.44f, 0.44f, 1f); + colors[(int)ImGuiCol.ResizeGripActive] = new Vector4(0.4f, 0.44f, 0.47f, 1f); + colors[(int)ImGuiCol.Tab] = ColToVec(ThemeProvider.Theme.Colors.LightBackground); + colors[(int)ImGuiCol.TabHovered] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); + colors[(int)ImGuiCol.TabActive] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); + colors[(int)ImGuiCol.TabUnfocused] = ColToVec(ThemeProvider.Theme.Colors.HeaderBackground); + colors[(int)ImGuiCol.TabUnfocusedActive] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); + colors[(int)ImGuiCol.PlotLines] = ColToVec(ThemeProvider.Theme.Colors.DefaultBackground); + colors[(int)ImGuiCol.PlotLinesHovered] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); + colors[(int)ImGuiCol.PlotHistogram] = new Vector4(0.15f, 0.15f, 0.15f, 1f); + colors[(int)ImGuiCol.PlotHistogramHovered] = ColToVec(ThemeProvider.Theme.Colors.TransparentBackground); + colors[(int)ImGuiCol.TableHeaderBg] = new Vector4(1f, 0f, 1f, 1f); + colors[(int)ImGuiCol.TableBorderStrong] = new Vector4(0f, 1f, 1f, 1f); + colors[(int)ImGuiCol.TableBorderLight] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); + colors[(int)ImGuiCol.TableRowBg] = new Vector4(0f, 0f, 0f, 1f); + colors[(int)ImGuiCol.TableRowBgAlt] = new Vector4(1f, 0f, 1f, 1f); + colors[(int)ImGuiCol.TextSelectedBg] = new Vector4(0.2f, 0.22f, 0.23f, 1f); + colors[(int)ImGuiCol.DragDropTarget] = new Vector4(0.33f, 0.67f, 0.86f, 1f); + colors[(int)ImGuiCol.NavHighlight] = new Vector4(0.24f, 0.24f, 0.24f, 1f); + colors[(int)ImGuiCol.NavWindowingHighlight] = new Vector4(1f, 0f, 1f, 1f); + colors[(int)ImGuiCol.NavWindowingDimBg] = new Vector4(0f, 1f, 1f, 1f); + colors[(int)ImGuiCol.ModalWindowDimBg] = ColToVec(ThemeProvider.Theme.Colors.GreySelection); + + var style = ImGui.GetStyle(); + style.ScrollbarSize = 15; + style.WindowRounding = 7; + style.ChildRounding = 4; + style.FrameRounding = 3; + style.PopupRounding = 4; + style.ScrollbarRounding = 9; + style.GrabRounding = 3; + style.TabRounding = 4; + style.WindowBorderSize = 1f; + // enable borders on buttons, textboxes, etc. + style.FrameBorderSize = 1f; } private void DrawImGui() @@ -283,32 +283,32 @@ private void DrawImGui() if (ImGui.MenuItem("Open\tCtrl+O")) OpenFile(); if (ImGui.MenuItem("Open From .grp")) - OpenFromGRP(); + OpenFromGRP(); if (ImGui.MenuItem("Save\tCtrl+S")) - SaveFile(); + SaveFile(); ImGui.EndMenu(); } if (ImGui.BeginMenu("Options")) - { - if (ImGui.MenuItem("Set English.stf Location")) - SetEngStfLocation(); - ImGui.EndMenu(); - } + { + if (ImGui.MenuItem("Set English.stf Location")) + SetEngStfLocation(); + ImGui.EndMenu(); + } if (ImGui.BeginMenu("Tools")) - { - if (ImGui.MenuItem(".stf to .txt")) - FullSTFToText(); - if (ImGui.MenuItem(".txt to .stf")) - FullTextToSTF(); - if (ImGui.MenuItem("Extract All .grp Files")) - ExtractAllGRPFiles(); - if (ImGui.MenuItem("Extract + Convert All .grp Files")) - ExtractAllGRPFiles(true); - if (ImGui.MenuItem("Show .grp Browser")) - using (var grpb = new GrpBrowser(null, true)) - grpb.ShowDialog(); - ImGui.EndMenu(); - } + { + if (ImGui.MenuItem(".stf to .txt")) + FullSTFToText(); + if (ImGui.MenuItem(".txt to .stf")) + FullTextToSTF(); + if (ImGui.MenuItem("Extract All .grp Files")) + ExtractAllGRPFiles(); + if (ImGui.MenuItem("Extract + Convert All .grp Files")) + ExtractAllGRPFiles(true); + if (ImGui.MenuItem("Show .grp Browser")) + using (var grpb = new GrpBrowser(null, true)) + grpb.ShowDialog(); + ImGui.EndMenu(); + } ImGui.EndMainMenuBar(); } @@ -317,27 +317,27 @@ private void DrawImGui() switch (_currentFile) { - case CRT: - DrawCRT(); - break; - case ITM: - DrawITM(); - break; - case Map: - DrawMap(); - break; + case CRT: + DrawCRT(); + break; + case ITM: + DrawITM(); + break; + case Map: + DrawMap(); + break; } } - + private void STFBox(string text, ref int sr) { - ImGui.Text(text); - ImGui.InputInt("##" + text, ref sr); - if (sr == 0) return; - ImGui.SameLine(); - ImGui.PushItemWidth(-1); - ImGui.InputText("##" + text + "in", ref _stf[sr - 1], 100u); - ImGui.PopItemWidth(); + ImGui.Text(text); + ImGui.InputInt("##" + text, ref sr); + if (sr == 0) return; + ImGui.SameLine(); + ImGui.PushItemWidth(-1); + ImGui.InputText("##" + text + "in", ref _stf[sr - 1], 100u); + ImGui.PopItemWidth(); } private void DrawCRT() @@ -351,22 +351,22 @@ private void DrawCRT() private void DrawITM() { - DrawEEN2(); - DrawGENT(); - DrawGITM(); + DrawEEN2(); + DrawGENT(); + DrawGITM(); } - + private void DrawMap() { - DrawEMAP(); - DrawEME2(); - DrawECAM(); - DrawEMEP(); - DrawEMEF(); - DrawEMSD(); - DrawEPTH(); - DrawTrigger(); - Draw2MWT(); + DrawEMAP(); + DrawEME2(); + DrawECAM(); + DrawEMEP(); + DrawEMEF(); + DrawEMSD(); + DrawEPTH(); + DrawTrigger(); + Draw2MWT(); } private void DrawEEN2() @@ -390,7 +390,7 @@ private void DrawEEN2() private string _eeovTemp = ""; private void DrawEEOV(EEOVc eeov) { - ImGui.PushItemWidth(-1); + ImGui.PushItemWidth(-1); ImGui.Text("Entity Name"); ImGui.InputText("##EntityName", ref eeov.s1, 100u); ImGui.Text("Dialog File"); @@ -408,19 +408,19 @@ private void DrawEEOV(EEOVc eeov) ImGui.SameLine(); if (ImGui.Button(" + ##Inventory")) { - if (string.IsNullOrWhiteSpace(_eeovTemp)) return; - eeov.inv = eeov.inv.Append(_eeovTemp).ToArray(); - _eeovTemp = ""; + if (string.IsNullOrWhiteSpace(_eeovTemp)) return; + eeov.inv = eeov.inv.Append(_eeovTemp).ToArray(); + _eeovTemp = ""; } ImGui.SameLine(); if (ImGui.Button(" - ##Inventory")) - { - if (_eeovSelected == -1) return; - var tmp = eeov.inv.ToList(); - tmp.RemoveAt(_eeovSelected); - eeov.inv = tmp.ToArray(); - _eeovSelected = -1; - } + { + if (_eeovSelected == -1) return; + var tmp = eeov.inv.ToList(); + tmp.RemoveAt(_eeovSelected); + eeov.inv = tmp.ToArray(); + _eeovSelected = -1; + } } private void DrawGENT() @@ -448,13 +448,13 @@ private void DrawGENT() private void DrawGCHR() { - if (_currentFile.GCHR is not GCHRc gchr) return; - ImGui.Begin("GCHR"); - ImGui.Text("Name"); - ImGui.InputText("##Name", ref gchr.name, 100u); - ImGui.End(); + if (_currentFile.GCHR is not GCHRc gchr) return; + ImGui.Begin("GCHR"); + ImGui.Text("Name"); + ImGui.InputText("##Name", ref gchr.name, 100u); + ImGui.End(); } - + private int _gcreSpecial; private readonly string[] _gcreSpecials = ["Strength", "Perception", "Endurance", "Charisma", "Intelligence", "Agility", "Luck"]; private int _gcreSkill; @@ -468,103 +468,103 @@ private void DrawGCHR() private string _gcreTemp = ""; private void DrawGCRE() { - if (_currentFile.GCRE is not GCREc gcre) return; - ImGui.Begin("GCRE"); - ImGui.Columns(2, "gcreColumns"); - ImGui.Text("Special"); - ImGui.Combo("##Special", ref _gcreSpecial, _gcreSpecials, _gcreSpecials.Length); - ImGui.SameLine(); - ImGui.PushItemWidth(-1); - ImGui.InputInt("##SpecialVal", ref gcre.Special[_gcreSpecial]); - ImGui.PopItemWidth(); - ImGui.Text("Skills"); - ImGui.Combo("##Skills", ref _gcreSkill, _gcreSkills, _gcreSkills.Length); - var skill = gcre.Skills.FirstOrDefault(s => s.Index == _gcreSkill); - ImGui.PushItemWidth(-1); - ImGui.SameLine(); - if (skill is not null) - { - ImGui.InputInt("##SkillVal", ref skill.Value); - } - else - { - var tmpVal = 0; - if (ImGui.InputInt("##SkillVal", ref tmpVal) && tmpVal != 0) - { - gcre.Skills.Add(new Skill(_gcreSkill, tmpVal)); - } - } - ImGui.PopItemWidth(); - ImGui.Text("Traits"); - ImGui.Combo("##Traits", ref _gcreTrait, _gcreTraits, _gcreTraits.Length); - var traitSel = gcre.Traits.Contains(_gcreTrait); - ImGui.SameLine(); - if (ImGui.Checkbox("Trait Active", ref traitSel)) - { - if (traitSel) - gcre.Traits.Add(_gcreTrait); - else - gcre.Traits.Remove(_gcreTrait); - } - ImGui.Text("Tag Skills"); - ImGui.Combo("##TagSkills", ref _gcreTag, _gcreSkills, _gcreSkills.Length); - var tagSel = gcre.TagSkills.Contains(_gcreTag); - ImGui.SameLine(); - if (ImGui.Checkbox("Tag Active", ref tagSel)) - { - if (tagSel) - gcre.TagSkills.Add(_gcreTag); - else - gcre.TagSkills.Remove(_gcreTag); - } - ImGui.Text("Portrait"); - ImGui.InputText("##Portrait", ref gcre.PortStr, 100u); - ImGui.Text("Age"); - ImGui.InputInt("##Age", ref gcre.Age); - ImGui.NextColumn(); - ImGui.Text("Socket"); - ImGui.Combo("##Socket", ref _gcreSocket, _gcreSockets, _gcreSockets.Length); - var sock = _gcreSocket switch - { - 0 => gcre.Hea, - 1 => gcre.Hai, - 2 => gcre.Pon, - 3 => gcre.Mus, - 4 => gcre.Bea, - 5 => gcre.Eye, - 6 => gcre.Bod, - 7 => gcre.Han, - 8 => gcre.Fee, - 9 => gcre.Bac, - 10 => gcre.Sho, - 11 => gcre.Van, - _ => throw new ArgumentOutOfRangeException() - }; - ImGui.Text("Socket Model"); - ImGui.InputText("##Model", ref sock.Model, 100u); - ImGui.Text("Socket Texture"); - ImGui.InputText("##Texture", ref sock.Tex, 100u); - ImGui.Text("Equipped Items"); - ImGui.ListBox("##Equipped", ref _gcreEquipped, gcre.Inventory, gcre.Inventory.Length); - ImGui.InputText("##EquippedItem", ref _gcreTemp, 100u); - ImGui.SameLine(); - if (ImGui.Button(" + ##Equipped")) - { - if (string.IsNullOrWhiteSpace(_gcreTemp)) return; - gcre.Inventory = gcre.Inventory.Append(_gcreTemp).ToArray(); - _gcreTemp = ""; - } - ImGui.SameLine(); - if (ImGui.Button(" - ##Equipped")) - { - if (_gcreEquipped == -1) return; - var tmp = gcre.Inventory.ToList(); - tmp.RemoveAt(_gcreEquipped); - gcre.Inventory = tmp.ToArray(); - _gcreEquipped = -1; - } - _gwamNames = gcre.GWAM.Select(i => _stf[i.NameSR - 1]).ToArray(); - ImGui.End(); + if (_currentFile.GCRE is not GCREc gcre) return; + ImGui.Begin("GCRE"); + ImGui.Columns(2, "gcreColumns"); + ImGui.Text("Special"); + ImGui.Combo("##Special", ref _gcreSpecial, _gcreSpecials, _gcreSpecials.Length); + ImGui.SameLine(); + ImGui.PushItemWidth(-1); + ImGui.InputInt("##SpecialVal", ref gcre.Special[_gcreSpecial]); + ImGui.PopItemWidth(); + ImGui.Text("Skills"); + ImGui.Combo("##Skills", ref _gcreSkill, _gcreSkills, _gcreSkills.Length); + var skill = gcre.Skills.FirstOrDefault(s => s.Index == _gcreSkill); + ImGui.PushItemWidth(-1); + ImGui.SameLine(); + if (skill is not null) + { + ImGui.InputInt("##SkillVal", ref skill.Value); + } + else + { + var tmpVal = 0; + if (ImGui.InputInt("##SkillVal", ref tmpVal) && tmpVal != 0) + { + gcre.Skills.Add(new Skill(_gcreSkill, tmpVal)); + } + } + ImGui.PopItemWidth(); + ImGui.Text("Traits"); + ImGui.Combo("##Traits", ref _gcreTrait, _gcreTraits, _gcreTraits.Length); + var traitSel = gcre.Traits.Contains(_gcreTrait); + ImGui.SameLine(); + if (ImGui.Checkbox("Trait Active", ref traitSel)) + { + if (traitSel) + gcre.Traits.Add(_gcreTrait); + else + gcre.Traits.Remove(_gcreTrait); + } + ImGui.Text("Tag Skills"); + ImGui.Combo("##TagSkills", ref _gcreTag, _gcreSkills, _gcreSkills.Length); + var tagSel = gcre.TagSkills.Contains(_gcreTag); + ImGui.SameLine(); + if (ImGui.Checkbox("Tag Active", ref tagSel)) + { + if (tagSel) + gcre.TagSkills.Add(_gcreTag); + else + gcre.TagSkills.Remove(_gcreTag); + } + ImGui.Text("Portrait"); + ImGui.InputText("##Portrait", ref gcre.PortStr, 100u); + ImGui.Text("Age"); + ImGui.InputInt("##Age", ref gcre.Age); + ImGui.NextColumn(); + ImGui.Text("Socket"); + ImGui.Combo("##Socket", ref _gcreSocket, _gcreSockets, _gcreSockets.Length); + var sock = _gcreSocket switch + { + 0 => gcre.Hea, + 1 => gcre.Hai, + 2 => gcre.Pon, + 3 => gcre.Mus, + 4 => gcre.Bea, + 5 => gcre.Eye, + 6 => gcre.Bod, + 7 => gcre.Han, + 8 => gcre.Fee, + 9 => gcre.Bac, + 10 => gcre.Sho, + 11 => gcre.Van, + _ => throw new ArgumentOutOfRangeException() + }; + ImGui.Text("Socket Model"); + ImGui.InputText("##Model", ref sock.Model, 100u); + ImGui.Text("Socket Texture"); + ImGui.InputText("##Texture", ref sock.Tex, 100u); + ImGui.Text("Equipped Items"); + ImGui.ListBox("##Equipped", ref _gcreEquipped, gcre.Inventory, gcre.Inventory.Length); + ImGui.InputText("##EquippedItem", ref _gcreTemp, 100u); + ImGui.SameLine(); + if (ImGui.Button(" + ##Equipped")) + { + if (string.IsNullOrWhiteSpace(_gcreTemp)) return; + gcre.Inventory = gcre.Inventory.Append(_gcreTemp).ToArray(); + _gcreTemp = ""; + } + ImGui.SameLine(); + if (ImGui.Button(" - ##Equipped")) + { + if (_gcreEquipped == -1) return; + var tmp = gcre.Inventory.ToList(); + tmp.RemoveAt(_gcreEquipped); + gcre.Inventory = tmp.ToArray(); + _gcreEquipped = -1; + } + _gwamNames = gcre.GWAM.Select(i => _stf[i.NameSR - 1]).ToArray(); + ImGui.End(); } private readonly string[] _gwamDamageTypes = ["Ballistic", "Bio", "Electric", "EMP", "General", "Heat"]; @@ -572,49 +572,50 @@ private void DrawGCRE() private int _gwamIndex; private void DrawGWAM() { - if (_currentFile.GCRE is not GCREc gcre) return; - ImGui.Begin("GWAM"); - // i believe every isntance of GWAM can have more than one. - ImGui.Combo("##gwams", ref _gwamIndex, _gwamNames, _gwamNames.Length); - ImGui.SameLine(); - if (ImGui.Button(" + ")) { - gcre.GWAM.Add(new GWAMc()); - _gwamIndex = gcre.GWAM.Count - 1; - } - ImGui.SameLine(); - if (ImGui.Button(" - ")) - gcre.GWAM.RemoveAt(_gwamIndex); - if (_gwamIndex >= gcre.GWAM.Count) - _gwamIndex = gcre.GWAM.Count - 1; - if (_gwamNames.Length == 0) - { - ImGui.End(); - return; - } - GWAMc gwam = gcre.GWAM[_gwamIndex]; - // .wea also has GWAM but isn't implemented yet. get later. - ImGui.Columns(3, "gwamColumns"); - ImGui.Text("Animation"); - ImGui.InputInt("##Animation", ref gwam.Anim); - ImGui.Text("Range"); - ImGui.InputInt("##Range", ref gwam.Range); - ImGui.Text("Action Points"); - ImGui.InputInt("##AP", ref gwam.AP); - ImGui.NextColumn(); - ImGui.Text("Damage Type"); - ImGui.Combo("##DamageType", ref gwam.DmgType, _gwamDamageTypes, _gwamDamageTypes.Length); - ImGui.Text("Min Dmg"); - ImGui.InputInt("##MinDmg", ref gwam.MinDmg); - ImGui.NextColumn(); - ImGui.Text("Shots Fired"); - ImGui.InputInt("##ShotsFired", ref gwam.ShotsFired); - ImGui.Text("Max Dmg"); - ImGui.InputInt("##MaxDmg", ref gwam.MaxDmg); - ImGui.Columns(); - STFBox("Attack Name", ref gwam.NameSR); - ImGui.Text("Effect"); - ImGui.InputText("##Effect", ref gwam.VegName, 100u); - ImGui.End(); + if (_currentFile.GCRE is not GCREc gcre) return; + ImGui.Begin("GWAM"); + // i believe every isntance of GWAM can have more than one. + ImGui.Combo("##gwams", ref _gwamIndex, _gwamNames, _gwamNames.Length); + ImGui.SameLine(); + if (ImGui.Button(" + ")) + { + gcre.GWAM.Add(new GWAMc()); + _gwamIndex = gcre.GWAM.Count - 1; + } + ImGui.SameLine(); + if (ImGui.Button(" - ")) + gcre.GWAM.RemoveAt(_gwamIndex); + if (_gwamIndex >= gcre.GWAM.Count) + _gwamIndex = gcre.GWAM.Count - 1; + if (_gwamNames.Length == 0) + { + ImGui.End(); + return; + } + GWAMc gwam = gcre.GWAM[_gwamIndex]; + // .wea also has GWAM but isn't implemented yet. get later. + ImGui.Columns(3, "gwamColumns"); + ImGui.Text("Animation"); + ImGui.InputInt("##Animation", ref gwam.Anim); + ImGui.Text("Range"); + ImGui.InputInt("##Range", ref gwam.Range); + ImGui.Text("Action Points"); + ImGui.InputInt("##AP", ref gwam.AP); + ImGui.NextColumn(); + ImGui.Text("Damage Type"); + ImGui.Combo("##DamageType", ref gwam.DmgType, _gwamDamageTypes, _gwamDamageTypes.Length); + ImGui.Text("Min Dmg"); + ImGui.InputInt("##MinDmg", ref gwam.MinDmg); + ImGui.NextColumn(); + ImGui.Text("Shots Fired"); + ImGui.InputInt("##ShotsFired", ref gwam.ShotsFired); + ImGui.Text("Max Dmg"); + ImGui.InputInt("##MaxDmg", ref gwam.MaxDmg); + ImGui.Columns(); + STFBox("Attack Name", ref gwam.NameSR); + ImGui.Text("Effect"); + ImGui.InputText("##Effect", ref gwam.VegName, 100u); + ImGui.End(); } private int _gitmSocket; @@ -623,390 +624,392 @@ private void DrawGWAM() private readonly string[] _gitmSlots = ["Body", "Head", "Hands"]; private void DrawGITM() { - if (_currentFile.GITM is not GITMc gitm) return; - ImGui.Begin("GITM"); - ImGui.Columns(3, "gitmColumns"); - ImGui.Text("Type"); - ImGui.Combo("##Type", ref gitm.type, _gitmTypes, _gitmTypes.Length); - ImGui.NextColumn(); - ImGui.Text("Slot"); - ImGui.Combo("##Slot", ref gitm.eqslot, _gitmSlots, _gitmSlots.Length); - ImGui.SameLine(); - ImGui.Checkbox("Equippable", ref gitm.equip); - ImGui.NextColumn(); - ImGui.Text("Reload"); - ImGui.InputInt("##Reload", ref gitm.reload); - ImGui.SameLine(); - // TODO: figure out how melee works - var tempBool = false; - ImGui.Checkbox("Melee", ref tempBool); - ImGui.Columns(); - - ImGui.Text("Hide Socket"); - ImGui.Checkbox("Hair", ref gitm.hHai); - ImGui.SameLine(); - ImGui.Checkbox("Beard", ref gitm.hBea); - ImGui.SameLine(); - ImGui.Checkbox("Moustache", ref gitm.hMus); - ImGui.SameLine(); - ImGui.Checkbox("Eye", ref gitm.hEye); - ImGui.SameLine(); - ImGui.Checkbox("Ponytail", ref gitm.hPon); - ImGui.SameLine(); - ImGui.Checkbox("Vanity", ref gitm.hVan); - - ImGui.Text("Socket"); - ImGui.Combo("##Socket", ref _gitmSocket, _gitmSockets, _gitmSockets.Length); - var sock = _gitmSocket switch - { - 0 => gitm.Eye, - 1 => gitm.Bod, - 2 => gitm.Bac, - 3 => gitm.Han, - 4 => gitm.Fee, - 5 => gitm.Sho, - 6 => gitm.Van, - 7 => gitm.IHS, - _ => throw new ArgumentOutOfRangeException() - }; - ImGui.Text("Socket Model"); - ImGui.InputText("##Model", ref sock.Model, 100u); - ImGui.Text("Socket Texture"); - ImGui.InputText("##Texture", ref sock.Tex, 100u); - - ImGui.End(); + if (_currentFile.GITM is not GITMc gitm) return; + ImGui.Begin("GITM"); + ImGui.Columns(3, "gitmColumns"); + ImGui.Text("Type"); + ImGui.Combo("##Type", ref gitm.type, _gitmTypes, _gitmTypes.Length); + ImGui.NextColumn(); + ImGui.Text("Slot"); + ImGui.Combo("##Slot", ref gitm.eqslot, _gitmSlots, _gitmSlots.Length); + ImGui.SameLine(); + ImGui.Checkbox("Equippable", ref gitm.equip); + ImGui.NextColumn(); + ImGui.Text("Reload"); + ImGui.InputInt("##Reload", ref gitm.reload); + ImGui.SameLine(); + // TODO: figure out how melee works + var tempBool = false; + ImGui.Checkbox("Melee", ref tempBool); + ImGui.Columns(); + + ImGui.Text("Hide Socket"); + ImGui.Checkbox("Hair", ref gitm.hHai); + ImGui.SameLine(); + ImGui.Checkbox("Beard", ref gitm.hBea); + ImGui.SameLine(); + ImGui.Checkbox("Moustache", ref gitm.hMus); + ImGui.SameLine(); + ImGui.Checkbox("Eye", ref gitm.hEye); + ImGui.SameLine(); + ImGui.Checkbox("Ponytail", ref gitm.hPon); + ImGui.SameLine(); + ImGui.Checkbox("Vanity", ref gitm.hVan); + + ImGui.Text("Socket"); + ImGui.Combo("##Socket", ref _gitmSocket, _gitmSockets, _gitmSockets.Length); + var sock = _gitmSocket switch + { + 0 => gitm.Eye, + 1 => gitm.Bod, + 2 => gitm.Bac, + 3 => gitm.Han, + 4 => gitm.Fee, + 5 => gitm.Sho, + 6 => gitm.Van, + 7 => gitm.IHS, + _ => throw new ArgumentOutOfRangeException() + }; + ImGui.Text("Socket Model"); + ImGui.InputText("##Model", ref sock.Model, 100u); + ImGui.Text("Socket Texture"); + ImGui.InputText("##Texture", ref sock.Tex, 100u); + + ImGui.End(); } private Vector3 _tempColor = new(1f, 1f, 1f); private void DrawEMAP() { - if (_currentFile.EMAP is not EMAPc emap) return; - _tempColor = new Vector3(emap.col.R / 255f, emap.col.G / 255f, emap.col.B / 255f); - ImGui.Begin("EMAP"); - ImGui.PushItemWidth(-1); - ImGui.Text("Map Mesh"); - ImGui.InputText("##MapMesh", ref emap.s1, 100u); - ImGui.Text("Height Map"); - ImGui.InputText("##HeightMap", ref emap.s2, 100u); - ImGui.Text("Minimap Texture"); - ImGui.InputText("##MinimapTexture", ref emap.s3, 100u); - ImGui.Text("Lighting Colour"); - ImGui.ColorEdit3("Lighting Colour", ref _tempColor); - emap.col = Color.FromArgb(255, (int)(_tempColor.X * 255), (int)(_tempColor.Y * 255), (int)(_tempColor.Z * 255)); - ImGui.Checkbox("Ignore Lighting", ref emap.il); - ImGui.End(); - if (_currentFile is not Map map) return; - - if (_currentFile.EME2.Count > 0) - _eme2Names = map.EME2.Select(e => e.name).ToArray(); - if (_currentFile.EMEP.Count > 0) - _emepNames = map.EMEP.Select(e => e.index.ToString()).ToArray(); - if (_currentFile.EMEF.Count > 0) - _emefNames = map.EMEF.Select(e => e.s1).ToArray(); - if (_currentFile.EMSD.Count > 0) - _emsdNames = map.EMSD.Select(e => e.s1).ToArray(); - if (_currentFile.EPTH.Count > 0) - _epthNames = map.EPTH.Select(e => e.name).ToArray(); - if (_currentFile.Triggers.Count <= 0) return; - _triggerNames = new string[_currentFile.Triggers.Count]; - for (var i = 0; i < _currentFile.Triggers.Count; i++) - _triggerNames[i] = i.ToString(); + if (_currentFile.EMAP is not EMAPc emap) return; + _tempColor = new Vector3(emap.col.R / 255f, emap.col.G / 255f, emap.col.B / 255f); + ImGui.Begin("EMAP"); + ImGui.PushItemWidth(-1); + ImGui.Text("Map Mesh"); + ImGui.InputText("##MapMesh", ref emap.s1, 100u); + ImGui.Text("Height Map"); + ImGui.InputText("##HeightMap", ref emap.s2, 100u); + ImGui.Text("Minimap Texture"); + ImGui.InputText("##MinimapTexture", ref emap.s3, 100u); + ImGui.Text("Lighting Colour"); + ImGui.ColorEdit3("Lighting Colour", ref _tempColor); + emap.col = Color.FromArgb(255, (int)(_tempColor.X * 255), (int)(_tempColor.Y * 255), (int)(_tempColor.Z * 255)); + ImGui.Checkbox("Ignore Lighting", ref emap.il); + ImGui.End(); + if (_currentFile is not Map map) return; + + if (_currentFile.EME2.Count > 0) + _eme2Names = map.EME2.Select(e => e.name).ToArray(); + if (_currentFile.EMEP.Count > 0) + _emepNames = map.EMEP.Select(e => e.index.ToString()).ToArray(); + if (_currentFile.EMEF.Count > 0) + _emefNames = map.EMEF.Select(e => e.s1).ToArray(); + if (_currentFile.EMSD.Count > 0) + _emsdNames = map.EMSD.Select(e => e.s1).ToArray(); + if (_currentFile.EPTH.Count > 0) + _epthNames = map.EPTH.Select(e => e.name).ToArray(); + if (_currentFile.Triggers.Count <= 0) return; + _triggerNames = new string[_currentFile.Triggers.Count]; + for (var i = 0; i < _currentFile.Triggers.Count; i++) + _triggerNames[i] = i.ToString(); } private int _eme2Index; private string[] _eme2Names; private void DrawEME2() { - if (_currentFile is not Map map) return; - ImGui.Begin("EME2"); - ImGui.Combo("##EME2", ref _eme2Index, _eme2Names, _eme2Names.Length); - ImGui.SameLine(); - if (ImGui.Button(" + ")) { - map.EME2.Add(new EME2c()); - _eme2Index = map.EME2.Count - 1; - } - ImGui.SameLine(); - if (ImGui.Button(" - ")) - map.EME2.RemoveAt(_eme2Index); - if (_eme2Index >= map.EME2.Count) - _eme2Index = map.EME2.Count - 1; - if (_eme2Names.Length == 0) - { - ImGui.End(); - return; - } - var eme2 = map.EME2[_eme2Index]; - ImGui.Text("Creature File"); - ImGui.InputText("##CreatureFile", ref eme2.name, 100u); - DrawEEOV(eme2.EEOV); - ImGui.InputFloat4("XYZR", ref eme2.l); - ImGui.End(); + if (_currentFile is not Map map) return; + ImGui.Begin("EME2"); + ImGui.Combo("##EME2", ref _eme2Index, _eme2Names, _eme2Names.Length); + ImGui.SameLine(); + if (ImGui.Button(" + ")) + { + map.EME2.Add(new EME2c()); + _eme2Index = map.EME2.Count - 1; + } + ImGui.SameLine(); + if (ImGui.Button(" - ")) + map.EME2.RemoveAt(_eme2Index); + if (_eme2Index >= map.EME2.Count) + _eme2Index = map.EME2.Count - 1; + if (_eme2Names.Length == 0) + { + ImGui.End(); + return; + } + var eme2 = map.EME2[_eme2Index]; + ImGui.Text("Creature File"); + ImGui.InputText("##CreatureFile", ref eme2.name, 100u); + DrawEEOV(eme2.EEOV); + ImGui.InputFloat4("XYZR", ref eme2.l); + ImGui.End(); } private void DrawECAM() { - if (_currentFile.ECAM is not ECAMc ecam) return; - ImGui.Begin("ECAM"); - ImGui.Text("Camera Position"); - ImGui.InputFloat4("##XYZR", ref ecam.p); - ImGui.End(); + if (_currentFile.ECAM is not ECAMc ecam) return; + ImGui.Begin("ECAM"); + ImGui.Text("Camera Position"); + ImGui.InputFloat4("##XYZR", ref ecam.p); + ImGui.End(); } private int _emepIndex; private string[] _emepNames; private void DrawEMEP() { - if (_currentFile is not Map map) return; - ImGui.Begin("EMEP"); - ImGui.Combo("##EMEP", ref _emepIndex, _emepNames, _emepNames.Length); - ImGui.SameLine(); - if (ImGui.Button(" + ")) - { - map.EMEP.Add(new EMEPc()); - _emepIndex = map.EMEP.Count - 1; - } - ImGui.SameLine(); - if (ImGui.Button(" - ")) - map.EMEP.RemoveAt(_emepIndex); - if (_emepIndex >= map.EMEP.Count) - _emepIndex = map.EMEP.Count - 1; - if (_emepNames.Length == 0) - { - ImGui.End(); - return; - } - var emep = map.EMEP[_emepIndex]; - ImGui.Text("Entry Point ID"); - ImGui.InputInt("##EntryPointID", ref emep.index); - ImGui.Text("Position"); - ImGui.InputFloat3("##XYZ", ref emep.p); - ImGui.SameLine(); - ImGui.InputFloat("##R", ref emep.r); - ImGui.End(); + if (_currentFile is not Map map) return; + ImGui.Begin("EMEP"); + ImGui.Combo("##EMEP", ref _emepIndex, _emepNames, _emepNames.Length); + ImGui.SameLine(); + if (ImGui.Button(" + ")) + { + map.EMEP.Add(new EMEPc()); + _emepIndex = map.EMEP.Count - 1; + } + ImGui.SameLine(); + if (ImGui.Button(" - ")) + map.EMEP.RemoveAt(_emepIndex); + if (_emepIndex >= map.EMEP.Count) + _emepIndex = map.EMEP.Count - 1; + if (_emepNames.Length == 0) + { + ImGui.End(); + return; + } + var emep = map.EMEP[_emepIndex]; + ImGui.Text("Entry Point ID"); + ImGui.InputInt("##EntryPointID", ref emep.index); + ImGui.Text("Position"); + ImGui.InputFloat3("##XYZ", ref emep.p); + ImGui.SameLine(); + ImGui.InputFloat("##R", ref emep.r); + ImGui.End(); } - + private int _emefIndex; private string[] _emefNames; private void DrawEMEF() - { - if (_currentFile is not Map map) return; - ImGui.Begin("EMEF"); - ImGui.Combo("##EMEF", ref _emefIndex, _emefNames, _emefNames.Length); - ImGui.SameLine(); - if (ImGui.Button(" + ")) - { - map.EMEF.Add(new EMEFc()); - _emefIndex = map.EMEF.Count - 1; - } - ImGui.SameLine(); - if (ImGui.Button(" - ")) - map.EMEF.RemoveAt(_emefIndex); - if (_emefIndex >= map.EMEF.Count) - _emefIndex = map.EMEF.Count - 1; - if (_emefNames.Length == 0) - { - ImGui.End(); - return; - } - var emef = map.EMEF[_emefIndex]; - ImGui.Text("Effect ID"); - ImGui.InputText("##EffectID", ref emef.s1, 100u); - ImGui.Text("Effect File"); - ImGui.InputText("##EffectFile", ref emef.s2, 100u); - ImGui.Text("Position"); - ImGui.InputFloat4("##XYZR", ref emef.l); - ImGui.End(); - } + { + if (_currentFile is not Map map) return; + ImGui.Begin("EMEF"); + ImGui.Combo("##EMEF", ref _emefIndex, _emefNames, _emefNames.Length); + ImGui.SameLine(); + if (ImGui.Button(" + ")) + { + map.EMEF.Add(new EMEFc()); + _emefIndex = map.EMEF.Count - 1; + } + ImGui.SameLine(); + if (ImGui.Button(" - ")) + map.EMEF.RemoveAt(_emefIndex); + if (_emefIndex >= map.EMEF.Count) + _emefIndex = map.EMEF.Count - 1; + if (_emefNames.Length == 0) + { + ImGui.End(); + return; + } + var emef = map.EMEF[_emefIndex]; + ImGui.Text("Effect ID"); + ImGui.InputText("##EffectID", ref emef.s1, 100u); + ImGui.Text("Effect File"); + ImGui.InputText("##EffectFile", ref emef.s2, 100u); + ImGui.Text("Position"); + ImGui.InputFloat4("##XYZR", ref emef.l); + ImGui.End(); + } private int _emsdIndex; private string[] _emsdNames; - private void DrawEMSD() - { - if (_currentFile is not Map map) return; - ImGui.Begin("EMSD"); - ImGui.Combo("##EMSD", ref _emsdIndex, _emsdNames, _emsdNames.Length); - ImGui.SameLine(); - if (ImGui.Button(" + ")) - { - map.EMSD.Add(new EMSDc()); - _emsdIndex = map.EMSD.Count - 1; - } - ImGui.SameLine(); - if (ImGui.Button(" - ")) - map.EMSD.RemoveAt(_emsdIndex); - if (_emsdIndex >= map.EMSD.Count) - _emsdIndex = map.EMSD.Count - 1; - if (_emsdNames.Length == 0) - { - ImGui.End(); - return; - } - var emsd = map.EMSD[_emsdIndex]; - ImGui.Text("Sound ID"); - ImGui.InputText("##SoundID", ref emsd.s1, 100u); - ImGui.Text("Sound File"); - ImGui.InputText("##SoundFile", ref emsd.s2, 100u); - ImGui.Text("Position"); - ImGui.InputFloat3("##XYZ", ref emsd.l); - ImGui.End(); - } - - private int _epthIndex; - private string[] _epthNames; - private int _epthPoint; - private void DrawEPTH() - { - if (_currentFile is not Map map) return; - ImGui.Begin("EPTH"); - ImGui.Combo("##EPTH", ref _epthIndex, _epthNames, _epthNames.Length); - ImGui.SameLine(); - if (ImGui.Button(" + ")) - { - map.EPTH.Add(new EPTHc()); - _epthIndex = map.EPTH.Count - 1; - } - ImGui.SameLine(); - if (ImGui.Button(" - ")) - map.EPTH.RemoveAt(_epthIndex); - if (_epthIndex >= map.EPTH.Count) - _epthIndex = map.EPTH.Count - 1; - if (_epthNames.Length == 0) - { - ImGui.End(); - return; - } - EPTHc epth = map.EPTH[_epthIndex]; - ImGui.Text("Path ID"); - ImGui.InputText("##PathID", ref epth.name, 100u); - ImGui.Text("Point"); - // create string array of point indices - var points = new string[epth.p.Count]; - for (var i = 0; i < epth.p.Count; i++) - points[i] = i.ToString(); - ImGui.Combo("##Point", ref _epthPoint, points, points.Length); - ImGui.SameLine(); - if (ImGui.Button(" + ##Point")) - { - epth.p.Add(new Vector4()); - _epthPoint = epth.p.Count - 1; - } - ImGui.SameLine(); - if (ImGui.Button(" - ##Point")) - epth.p.RemoveAt(_epthPoint); - if (_epthPoint >= epth.p.Count) - _epthPoint = epth.p.Count - 1; - var point = epth.p[_epthPoint]; - ImGui.Text("Position"); - ImGui.InputFloat4("##XYZR", ref point); - } - - private int _triggerIndex; - private string[] _triggerNames; - private readonly string[] _triggerTypes = ["B (?)", "Script", "Level Transition"]; - private int _triggerPoint; - private void DrawTrigger() - { - if (_currentFile is not Map map) return; - ImGui.Begin("Trigger"); - ImGui.Combo("##Trigger", ref _triggerIndex, _triggerNames, _triggerNames.Length); - ImGui.SameLine(); - if (ImGui.Button(" + ")) - { - map.Triggers.Add(new Trigger()); - _triggerIndex = map.Triggers.Count - 1; - } - ImGui.SameLine(); - if (ImGui.Button(" - ")) - map.Triggers.RemoveAt(_triggerIndex); - if (_triggerIndex >= map.Triggers.Count) - _triggerIndex = map.Triggers.Count - 1; - if (_triggerNames.Length == 0) - { - ImGui.End(); - return; - } - - var trigger = map.Triggers[_triggerIndex]; - ImGui.Text("Trigger Type"); - var triggerIndex = trigger.ExTR.type switch - { - "B" => 0, - "S" => 1, - "T" => 2, - _ => -1 - }; - if (ImGui.Combo("##TriggerType", ref triggerIndex, _triggerTypes, _triggerTypes.Length)) - { - trigger.ExTR.type = triggerIndex switch - { - 0 => "B", - 1 => "S", - 2 => "T", - _ => throw new ArgumentOutOfRangeException() - }; - } - ImGui.Text("Trigger Value"); - ImGui.InputText("##TriggerValue", ref trigger.ExTR.s, 100u); - // TODO: what is EMTR.n? - // create string array of point indices - var points = new string[trigger.EMTR.r.Count]; - for (var i = 0; i < trigger.EMTR.r.Count; i++) - points[i] = i.ToString(); - ImGui.Text("Point"); - ImGui.Combo("##Point", ref _triggerPoint, points, points.Length); - ImGui.SameLine(); - if (ImGui.Button(" + ##Point")) - { - trigger.EMTR.r.Add(new Vector3()); - _triggerPoint = trigger.EMTR.r.Count - 1; - } - ImGui.SameLine(); - if (ImGui.Button(" - ##Point")) - trigger.EMTR.r.RemoveAt(_triggerPoint); - if (_triggerPoint >= trigger.EMTR.r.Count) - _triggerPoint = trigger.EMTR.r.Count - 1; - var point = trigger.EMTR.r[_triggerPoint]; - ImGui.Text("Position"); - ImGui.InputFloat3("##XYZR", ref point); - ImGui.End(); - } - - // ReSharper disable once InconsistentNaming - 2 is part of the abbreviation - private int _2mwtChunk; - private void Draw2MWT() - { - if (_currentFile._2MWT is not _2MWTc _2mwt) return; - ImGui.Begin("2MWT"); - ImGui.PushItemWidth(-1); - ImGui.Text("Water Mesh"); // i think? - ImGui.InputText("##WaterMesh", ref _2mwt.mpf, 100u); - ImGui.Checkbox("Static Water", ref _2mwt.frozen); - ImGui.SameLine(); - ImGui.Checkbox("Dark Water", ref _2mwt.dark); - // create string array of location indices - var chunks = new string[_2mwt.chunks.Count]; - for (var i = 0; i < _2mwt.chunks.Count; i++) - chunks[i] = i.ToString(); - ImGui.Text("Water Chunk"); - ImGui.Combo("##Chunk", ref _2mwtChunk, chunks, chunks.Length); - ImGui.SameLine(); - if (ImGui.Button(" + ")) { - _2mwt.chunks.Add(new _2MWTChunk()); - _2mwtChunk = _2mwt.chunks.Count - 1; - } - ImGui.SameLine(); - if (ImGui.Button(" - ")) - _2mwt.chunks.RemoveAt(_2mwtChunk); - if (_2mwtChunk >= _2mwt.chunks.Count) - _2mwtChunk = _2mwt.chunks.Count - 1; - var chunk = _2mwt.chunks[_2mwtChunk]; - ImGui.Text("Water Lightmap"); - ImGui.InputText("##WaterTexture", ref chunk.tex, 100u); - ImGui.Text("Position"); - ImGui.InputFloat3("##XYZ", ref chunk.loc); - ImGui.Text("Lightmap UV"); - ImGui.InputFloat2("##UV", ref chunk.texloc); - ImGui.End(); - } + private void DrawEMSD() + { + if (_currentFile is not Map map) return; + ImGui.Begin("EMSD"); + ImGui.Combo("##EMSD", ref _emsdIndex, _emsdNames, _emsdNames.Length); + ImGui.SameLine(); + if (ImGui.Button(" + ")) + { + map.EMSD.Add(new EMSDc()); + _emsdIndex = map.EMSD.Count - 1; + } + ImGui.SameLine(); + if (ImGui.Button(" - ")) + map.EMSD.RemoveAt(_emsdIndex); + if (_emsdIndex >= map.EMSD.Count) + _emsdIndex = map.EMSD.Count - 1; + if (_emsdNames.Length == 0) + { + ImGui.End(); + return; + } + var emsd = map.EMSD[_emsdIndex]; + ImGui.Text("Sound ID"); + ImGui.InputText("##SoundID", ref emsd.s1, 100u); + ImGui.Text("Sound File"); + ImGui.InputText("##SoundFile", ref emsd.s2, 100u); + ImGui.Text("Position"); + ImGui.InputFloat3("##XYZ", ref emsd.l); + ImGui.End(); + } + + private int _epthIndex; + private string[] _epthNames; + private int _epthPoint; + private void DrawEPTH() + { + if (_currentFile is not Map map) return; + ImGui.Begin("EPTH"); + ImGui.Combo("##EPTH", ref _epthIndex, _epthNames, _epthNames.Length); + ImGui.SameLine(); + if (ImGui.Button(" + ")) + { + map.EPTH.Add(new EPTHc()); + _epthIndex = map.EPTH.Count - 1; + } + ImGui.SameLine(); + if (ImGui.Button(" - ")) + map.EPTH.RemoveAt(_epthIndex); + if (_epthIndex >= map.EPTH.Count) + _epthIndex = map.EPTH.Count - 1; + if (_epthNames.Length == 0) + { + ImGui.End(); + return; + } + EPTHc epth = map.EPTH[_epthIndex]; + ImGui.Text("Path ID"); + ImGui.InputText("##PathID", ref epth.name, 100u); + ImGui.Text("Point"); + // create string array of point indices + var points = new string[epth.p.Count]; + for (var i = 0; i < epth.p.Count; i++) + points[i] = i.ToString(); + ImGui.Combo("##Point", ref _epthPoint, points, points.Length); + ImGui.SameLine(); + if (ImGui.Button(" + ##Point")) + { + epth.p.Add(new Vector4()); + _epthPoint = epth.p.Count - 1; + } + ImGui.SameLine(); + if (ImGui.Button(" - ##Point")) + epth.p.RemoveAt(_epthPoint); + if (_epthPoint >= epth.p.Count) + _epthPoint = epth.p.Count - 1; + var point = epth.p[_epthPoint]; + ImGui.Text("Position"); + ImGui.InputFloat4("##XYZR", ref point); + } + + private int _triggerIndex; + private string[] _triggerNames; + private readonly string[] _triggerTypes = ["B (?)", "Script", "Level Transition"]; + private int _triggerPoint; + private void DrawTrigger() + { + if (_currentFile is not Map map) return; + ImGui.Begin("Trigger"); + ImGui.Combo("##Trigger", ref _triggerIndex, _triggerNames, _triggerNames.Length); + ImGui.SameLine(); + if (ImGui.Button(" + ")) + { + map.Triggers.Add(new Trigger()); + _triggerIndex = map.Triggers.Count - 1; + } + ImGui.SameLine(); + if (ImGui.Button(" - ")) + map.Triggers.RemoveAt(_triggerIndex); + if (_triggerIndex >= map.Triggers.Count) + _triggerIndex = map.Triggers.Count - 1; + if (_triggerNames.Length == 0) + { + ImGui.End(); + return; + } + + var trigger = map.Triggers[_triggerIndex]; + ImGui.Text("Trigger Type"); + var triggerIndex = trigger.ExTR.type switch + { + "B" => 0, + "S" => 1, + "T" => 2, + _ => -1 + }; + if (ImGui.Combo("##TriggerType", ref triggerIndex, _triggerTypes, _triggerTypes.Length)) + { + trigger.ExTR.type = triggerIndex switch + { + 0 => "B", + 1 => "S", + 2 => "T", + _ => throw new ArgumentOutOfRangeException() + }; + } + ImGui.Text("Trigger Value"); + ImGui.InputText("##TriggerValue", ref trigger.ExTR.s, 100u); + // TODO: what is EMTR.n? + // create string array of point indices + var points = new string[trigger.EMTR.r.Count]; + for (var i = 0; i < trigger.EMTR.r.Count; i++) + points[i] = i.ToString(); + ImGui.Text("Point"); + ImGui.Combo("##Point", ref _triggerPoint, points, points.Length); + ImGui.SameLine(); + if (ImGui.Button(" + ##Point")) + { + trigger.EMTR.r.Add(new Vector3()); + _triggerPoint = trigger.EMTR.r.Count - 1; + } + ImGui.SameLine(); + if (ImGui.Button(" - ##Point")) + trigger.EMTR.r.RemoveAt(_triggerPoint); + if (_triggerPoint >= trigger.EMTR.r.Count) + _triggerPoint = trigger.EMTR.r.Count - 1; + var point = trigger.EMTR.r[_triggerPoint]; + ImGui.Text("Position"); + ImGui.InputFloat3("##XYZR", ref point); + ImGui.End(); + } + + // ReSharper disable once InconsistentNaming - 2 is part of the abbreviation + private int _2mwtChunk; + private void Draw2MWT() + { + if (_currentFile._2MWT is not _2MWTc _2mwt) return; + ImGui.Begin("2MWT"); + ImGui.PushItemWidth(-1); + ImGui.Text("Water Mesh"); // i think? + ImGui.InputText("##WaterMesh", ref _2mwt.mpf, 100u); + ImGui.Checkbox("Static Water", ref _2mwt.frozen); + ImGui.SameLine(); + ImGui.Checkbox("Dark Water", ref _2mwt.dark); + // create string array of location indices + var chunks = new string[_2mwt.chunks.Count]; + for (var i = 0; i < _2mwt.chunks.Count; i++) + chunks[i] = i.ToString(); + ImGui.Text("Water Chunk"); + ImGui.Combo("##Chunk", ref _2mwtChunk, chunks, chunks.Length); + ImGui.SameLine(); + if (ImGui.Button(" + ")) + { + _2mwt.chunks.Add(new _2MWTChunk()); + _2mwtChunk = _2mwt.chunks.Count - 1; + } + ImGui.SameLine(); + if (ImGui.Button(" - ")) + _2mwt.chunks.RemoveAt(_2mwtChunk); + if (_2mwtChunk >= _2mwt.chunks.Count) + _2mwtChunk = _2mwt.chunks.Count - 1; + var chunk = _2mwt.chunks[_2mwtChunk]; + ImGui.Text("Water Lightmap"); + ImGui.InputText("##WaterTexture", ref chunk.tex, 100u); + ImGui.Text("Position"); + ImGui.InputFloat3("##XYZ", ref chunk.loc); + ImGui.Text("Lightmap UV"); + ImGui.InputFloat2("##UV", ref chunk.texloc); + ImGui.End(); + } } } diff --git a/VBLauncher/Extensions.cs b/VBLauncher/Extensions.cs index e2cca80..9e0edd5 100644 --- a/VBLauncher/Extensions.cs +++ b/VBLauncher/Extensions.cs @@ -346,7 +346,7 @@ public static GCREc ToGCREc(this byte[] b) Van = new Socket(GetString(b, Vanmo, b[Vanmo - 2]), GetString(b, Vanto, b[Vanto - 2])), Inventory = inv.ToArray(), GWAM = (from i in gl - select ToGWAMc(b.Skip(i).Take(BitConverter.ToInt32(b, i + 8)).ToArray())).ToList() + select ToGWAMc(b.Skip(i).Take(BitConverter.ToInt32(b, i + 8)).ToArray())).ToList() }; } @@ -554,326 +554,326 @@ public static byte[] TXTToSTF(IEnumerable s) b.AddRange(BitConverter.GetBytes(o)); b.AddRange(BitConverter.GetBytes(s.ElementAtOrDefault(i).Length)); b.AddRange([0x7E, 0xE3, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0]); - o += s.ElementAtOrDefault(i).Length; - } + o += s.ElementAtOrDefault(i).Length; + } - b.AddRange(ToFixedBytes(ref s)); + b.AddRange(ToFixedBytes(ref s)); return b.ToArray(); } - // Replace CrLf with "|~" and replace em dash with minus/hyphen - public static void PreParse(this byte[] b) + // Replace CrLf with "|~" and replace em dash with minus/hyphen + public static void PreParse(this byte[] b) + { + var strStart = BitConverter.ToInt32(b, 12); + var l = b.Locate([0xD, 0xA]); + foreach (var m in l) { - var strStart = BitConverter.ToInt32(b, 12); - var l = b.Locate([0xD, 0xA]); - foreach (var m in l) + if (m >= strStart) { - if (m >= strStart) - { - Write(b, m, [0x7C, 0x7E]); - } + Write(b, m, [0x7C, 0x7E]); } + } - l = b.Locate([0x96]); - foreach (var m in l) + l = b.Locate([0x96]); + foreach (var m in l) + { + if (m >= strStart) { - if (m >= strStart) - { - Write(b, m, [0x2D]); - } + Write(b, m, [0x2D]); } } + } - // Turn the string array into the chunk of bytes, replacing "|~" with CrLf - public static byte[] ToFixedBytes(ref IEnumerable s) - { - var bl = new List(); - foreach (var stri in s) - bl.AddRange(Encoding.ASCII.GetBytes(stri)); - var b = bl; - var l = b.ToArray().Locate([0x7C, 0x7E]); - foreach (var m in l) - Write(b.ToArray(), m, [0xD, 0xA]); - return b.ToArray(); - } + // Turn the string array into the chunk of bytes, replacing "|~" with CrLf + public static byte[] ToFixedBytes(ref IEnumerable s) + { + var bl = new List(); + foreach (var stri in s) + bl.AddRange(Encoding.ASCII.GetBytes(stri)); + var b = bl; + var l = b.ToArray().Locate([0x7C, 0x7E]); + foreach (var m in l) + Write(b.ToArray(), m, [0xD, 0xA]); + return b.ToArray(); + } - #endregion + #endregion - #region Read Classes From Bytes + #region Read Classes From Bytes - public static CRT ReadCRT(this byte[] b) + public static CRT ReadCRT(this byte[] b) + { + var cf = new CRT + { + EEN2 = ToEEN2c(b.GetRegions("EEN2")[0]), + GENT = ToGENTc(b.GetRegions("GENT")[0]), + GCRE = b.GetRegions("GCRE")[0].ToGCREc() + }; + try + { + cf.GCHR = ToGCHRc(b.GetRegions("GCHR")[0]); + } + catch { - var cf = new CRT - { - EEN2 = ToEEN2c(b.GetRegions("EEN2")[0]), - GENT = ToGENTc(b.GetRegions("GENT")[0]), - GCRE = b.GetRegions("GCRE")[0].ToGCREc() - }; - try - { - cf.GCHR = ToGCHRc(b.GetRegions("GCHR")[0]); - } - catch - { - } - - return cf; } - public static Map ReadMap(this byte[] b) + return cf; + } + + public static Map ReadMap(this byte[] b) + { + var cf = new Map { - var cf = new Map - { - EMAP = b.GetRegions("EMAP")[0].ToEMAPc(), - EME2 = (from x in b.GetRegions("EME2") + EMAP = b.GetRegions("EMAP")[0].ToEMAPc(), + EME2 = (from x in b.GetRegions("EME2") select x.ToEME2c()).ToList(), - EMEP = (from x in b.GetRegions("EMEP") + EMEP = (from x in b.GetRegions("EMEP") select x.ToEMEPc()).ToList() - }; - try - { - cf.ECAM = b.GetRegions("ECAM")[0].ToECAMc(); - } - catch - { - } - - try - { - cf._2MWT = b.GetRegions("2MWT")[0].To2MWTc(); - } - catch - { - } - - cf.Triggers = b.GetTriggers(); - cf.EPTH = (from x in b.GetRegions("EPTH") - select x.ToEPTHc()).ToList(); - cf.EMSD = (from x in b.GetRegions("EMSD") - select x.ToEMSDc()).ToList(); - try - { - cf.EMNP = b.GetRegions("EMNP")[0].ToEMNPc(); - } - catch - { - } - - try - { - cf.EMFG = b.GetRegions("EMFG")[0].ToEMFGc(); - } - catch - { - } - - cf.EMNO = (from x in b.GetRegions("EMNO") - select x.ToEMNOc()).ToList(); - cf.EMEF = (from x in b.GetRegions("EMEF") - select x.ToEMEFc()).ToList(); - return cf; + }; + try + { + cf.ECAM = b.GetRegions("ECAM")[0].ToECAMc(); + } + catch + { } - public static ITM ReadITM(this byte[] b) + try + { + cf._2MWT = b.GetRegions("2MWT")[0].To2MWTc(); + } + catch { - var cf = new ITM - { - EEN2 = ToEEN2c(b.GetRegions("EEN2")[0]), - GENT = ToGENTc(b.GetRegions("GENT")[0]), - GITM = b.GetRegions("GITM")[0].ToGITMc() - }; - return cf; } - public static ARM ReadARM(this byte[] b) + cf.Triggers = b.GetTriggers(); + cf.EPTH = (from x in b.GetRegions("EPTH") + select x.ToEPTHc()).ToList(); + cf.EMSD = (from x in b.GetRegions("EMSD") + select x.ToEMSDc()).ToList(); + try + { + cf.EMNP = b.GetRegions("EMNP")[0].ToEMNPc(); + } + catch { - var cf = new ARM - { - EEN2 = ToEEN2c(b.GetRegions("EEN2")[0]), - GENT = ToGENTc(b.GetRegions("GENT")[0]), - GITM = b.GetRegions("GITM")[0].ToGITMc(), - GIAR = b.GetRegions("GIAR")[0].ToGIARc() - }; - return cf; } - public static USE ReadUSE(this byte[] b) + try + { + cf.EMFG = b.GetRegions("EMFG")[0].ToEMFGc(); + } + catch { - var cf = new USE - { - EEN2 = ToEEN2c(b.GetRegions("EEN2")[0]), - GENT = ToGENTc(b.GetRegions("GENT")[0]), - GOBJ = b.GetRegions("GOBJ")[0].ToGOBJc() - }; - return cf; } - #endregion + cf.EMNO = (from x in b.GetRegions("EMNO") + select x.ToEMNOc()).ToList(); + cf.EMEF = (from x in b.GetRegions("EMEF") + select x.ToEMEFc()).ToList(); + return cf; + } - #region Byte array search + public static ITM ReadITM(this byte[] b) + { + var cf = new ITM + { + EEN2 = ToEEN2c(b.GetRegions("EEN2")[0]), + GENT = ToGENTc(b.GetRegions("GENT")[0]), + GITM = b.GetRegions("GITM")[0].ToGITMc() + }; + return cf; + } - private static readonly int[] Empty = []; + public static ARM ReadARM(this byte[] b) + { + var cf = new ARM + { + EEN2 = ToEEN2c(b.GetRegions("EEN2")[0]), + GENT = ToGENTc(b.GetRegions("GENT")[0]), + GITM = b.GetRegions("GITM")[0].ToGITMc(), + GIAR = b.GetRegions("GIAR")[0].ToGIARc() + }; + return cf; + } - /// Searches for a byte array within another byte array. - /// An integer array containing all locations of the given bytes - public static int[] Locate(this byte[] self, byte[] candidate) + public static USE ReadUSE(this byte[] b) + { + var cf = new USE { - if (self is null | candidate is null | !self.Any() | !candidate.Any() | - candidate.Count() > self.Count()) - { - return Empty; - } + EEN2 = ToEEN2c(b.GetRegions("EEN2")[0]), + GENT = ToGENTc(b.GetRegions("GENT")[0]), + GOBJ = b.GetRegions("GOBJ")[0].ToGOBJc() + }; + return cf; + } - var list = new ConcurrentBag(); - Parallel.For(0, self.Count() - candidate.Count(), (i) => - { - var match = true; - for (int j = 0, loopTo = candidate.Count() - 1; j <= loopTo; j++) - { - if (self[i + j] == candidate[j]) continue; - match = false; - break; - } + #endregion - if (match) - { - list.Add(i); - } - }); - var sortedList = - list.OrderBy(i => i) - .ToArray(); // ensure list is in order of location for (hopefully) identical file output - return sortedList.Length == 0 ? Empty : sortedList; - } + #region Byte array search - #endregion + private static readonly int[] Empty = []; - public static string GetString(IEnumerable b) + /// Searches for a byte array within another byte array. + /// An integer array containing all locations of the given bytes + public static int[] Locate(this byte[] self, byte[] candidate) + { + if (self is null | candidate is null | !self.Any() | !candidate.Any() | + candidate.Count() > self.Count()) { - return Encoding.ASCII.GetString(b.ToArray()); + return Empty; } - public static string GetString(byte[] b, int i1, int i2) + var list = new ConcurrentBag(); + Parallel.For(0, self.Count() - candidate.Count(), (i) => { - return Encoding.ASCII.GetString(b.ToArray(), i1, i2); - } + var match = true; + for (int j = 0, loopTo = candidate.Count() - 1; j <= loopTo; j++) + { + if (self[i + j] == candidate[j]) continue; + match = false; + break; + } - // Finds all locations of a given header, reads size, copies that section into byte array, puts array in list. - public static byte[][] GetRegions(this byte[] b, string hs) - { - var hn = Encoding.ASCII.GetBytes(hs); - var hc = b.Locate(hn); - return (from l in hc + if (match) + { + list.Add(i); + } + }); + var sortedList = + list.OrderBy(i => i) + .ToArray(); // ensure list is in order of location for (hopefully) identical file output + return sortedList.Length == 0 ? Empty : sortedList; + } + + #endregion + + public static string GetString(IEnumerable b) + { + return Encoding.ASCII.GetString(b.ToArray()); + } + + public static string GetString(byte[] b, int i1, int i2) + { + return Encoding.ASCII.GetString(b.ToArray(), i1, i2); + } + + // Finds all locations of a given header, reads size, copies that section into byte array, puts array in list. + public static byte[][] GetRegions(this byte[] b, string hs) + { + var hn = Encoding.ASCII.GetBytes(hs); + var hc = b.Locate(hn); + return (from l in hc let tl = BitConverter.ToInt32(b, l + 8) select b.Skip(l).Take(tl).ToArray()).ToArray(); - } + } - // Finds all triggers for .map files, and the subsequent trigger info chunk - public static List GetTriggers(this byte[] b) - { - var hc = b.Locate("EMTR"u8.ToArray()); - return (from l in hc + // Finds all triggers for .map files, and the subsequent trigger info chunk + public static List GetTriggers(this byte[] b) + { + var hc = b.Locate("EMTR"u8.ToArray()); + return (from l in hc let tl = BitConverter.ToInt32(b, l + 8) let h1 = b.Skip(l).Take(tl).ToArray() let h2 = b.Skip(l + tl).Take(b[l + tl + 8]).ToArray() select new Trigger { EMTR = h1.ToEMTRc(), ExTR = h2.ToExTRc() }).ToList(); - } + } - /// - /// This function copies a byte array into another - /// - public static void Write(this byte[] b, int offset, IEnumerable value) - { - Buffer.BlockCopy(value.ToArray(), 0, b, offset, value.Count()); - } + /// + /// This function copies a byte array into another + /// + public static void Write(this byte[] b, int offset, IEnumerable value) + { + Buffer.BlockCopy(value.ToArray(), 0, b, offset, value.Count()); + } - /// - /// This function copies a string as ascii bytes into a byte array - /// - public static void Write(this byte[] b, int offset, string value) - { - Write(b, offset, Encoding.ASCII.GetBytes(value)); - } + /// + /// This function copies a string as ascii bytes into a byte array + /// + public static void Write(this byte[] b, int offset, string value) + { + Write(b, offset, Encoding.ASCII.GetBytes(value)); + } - /// - /// This function copies a byte into a byte array - /// - public static void Write(this byte[] b, int offset, byte value) - { - Write(b, offset, [value]); - } + /// + /// This function copies a byte into a byte array + /// + public static void Write(this byte[] b, int offset, byte value) + { + Write(b, offset, [value]); + } - /// - /// This function copies a boolean into a byte array - /// - public static void Write(this byte[] b, int offset, bool value) - { - Write(b, offset, [(byte)(value ? 1 : 0)]); - } + /// + /// This function copies a boolean into a byte array + /// + public static void Write(this byte[] b, int offset, bool value) + { + Write(b, offset, [(byte)(value ? 1 : 0)]); + } + + /// + /// This function copies a single precision float into a byte array + /// + public static void Write(this byte[] b, int offset, float value) + { + Write(b, offset, BitConverter.GetBytes(value)); + } - /// - /// This function copies a single precision float into a byte array - /// - public static void Write(this byte[] b, int offset, float value) + /// + /// This function copies a single precision float into a byte array + /// + public static void Write(this byte[] b, int offset, int value) + { + if (value > 255) { Write(b, offset, BitConverter.GetBytes(value)); } - - /// - /// This function copies a single precision float into a byte array - /// - public static void Write(this byte[] b, int offset, int value) + else { - if (value > 255) - { - Write(b, offset, BitConverter.GetBytes(value)); - } - else - { - Write(b, offset, (byte)value); - } + Write(b, offset, (byte)value); } + } - /// This function reads the values in a DataGridView control into a string array - public static List GetStringArray(this DataGridView dgv) - { - return (from DataGridViewRow r in dgv.Rows + /// This function reads the values in a DataGridView control into a string array + public static List GetStringArray(this DataGridView dgv) + { + return (from DataGridViewRow r in dgv.Rows where r.Cells[0].Value != null select r.Cells[0].Value).Cast().ToList(); - } + } - /// Returns the specified color as an array of bytes. - /// An array of bytes with length 3. - public static byte[] ToByte(this Color color) - { - return [color.R, color.G, color.B]; - } + /// Returns the specified color as an array of bytes. + /// An array of bytes with length 3. + public static byte[] ToByte(this Color color) + { + return [color.R, color.G, color.B]; + } - public static byte[] ToByte(this Vector4 vec) - { - var b = new List(); - b.AddRange(BitConverter.GetBytes(vec.X)); - b.AddRange(BitConverter.GetBytes(vec.Y)); - b.AddRange(BitConverter.GetBytes(vec.Z)); - b.AddRange(BitConverter.GetBytes(vec.W)); - return b.ToArray(); - } + public static byte[] ToByte(this Vector4 vec) + { + var b = new List(); + b.AddRange(BitConverter.GetBytes(vec.X)); + b.AddRange(BitConverter.GetBytes(vec.Y)); + b.AddRange(BitConverter.GetBytes(vec.Z)); + b.AddRange(BitConverter.GetBytes(vec.W)); + return b.ToArray(); + } - public static byte[] ToByte(this Vector3 vec) - { - var b = new List(); - b.AddRange(BitConverter.GetBytes(vec.X)); - b.AddRange(BitConverter.GetBytes(vec.Y)); - b.AddRange(BitConverter.GetBytes(vec.Z)); - return b.ToArray(); - } - - public static byte[] ToByte(this Vector2 vec) - { - var b = new List(); - b.AddRange(BitConverter.GetBytes(vec.X)); - b.AddRange(BitConverter.GetBytes(vec.Y)); - return b.ToArray(); - } + public static byte[] ToByte(this Vector3 vec) + { + var b = new List(); + b.AddRange(BitConverter.GetBytes(vec.X)); + b.AddRange(BitConverter.GetBytes(vec.Y)); + b.AddRange(BitConverter.GetBytes(vec.Z)); + return b.ToArray(); + } + + public static byte[] ToByte(this Vector2 vec) + { + var b = new List(); + b.AddRange(BitConverter.GetBytes(vec.X)); + b.AddRange(BitConverter.GetBytes(vec.Y)); + return b.ToArray(); } +} } \ No newline at end of file diff --git a/VBLauncher/GrpBrowser.cs b/VBLauncher/GrpBrowser.cs index adb1668..130b4da 100644 --- a/VBLauncher/GrpBrowser.cs +++ b/VBLauncher/GrpBrowser.cs @@ -47,10 +47,10 @@ internal struct F3RHTHeader internal struct Entry { - public int one; - public int number; - public int type; - public int offset; + public int one; + public int number; + public int type; + public int offset; public int pack; } @@ -84,14 +84,71 @@ internal struct Lump private readonly Dictionary packOffsetToIndex = new() { - {0, 0},{6,1},{16,2},{25,3},{32,4},{42,5},{50,6},{55,7},{63,8},{68,9},{74,10},{81,11},{87,12},{92,13},{97,14},{102,15},{107,16},{112,17},{117,18},{122,19},{127,20},{132,21},{137,22},{142,23} + { 0, 0 }, + { 6, 1 }, + { 16, 2 }, + { 25, 3 }, + { 32, 4 }, + { 42, 5 }, + { 50, 6 }, + { 55, 7 }, + { 63, 8 }, + { 68, 9 }, + { 74, 10 }, + { 81, 11 }, + { 87, 12 }, + { 92, 13 }, + { 97, 14 }, + { 102, 15 }, + { 107, 16 }, + { 112, 17 }, + { 117, 18 }, + { 122, 19 }, + { 127, 20 }, + { 132, 21 }, + { 137, 22 }, + { 142, 23 } }; private readonly Dictionary extensionMap = new() { - {1900, "psf"},{1600,"int"},{1700,"rle"},{1800,"itm"},{1500,"veg"},{1400,"crt"},{1300,"map"},{1100,"wav"},{1200,"amx"},{1000,"rtd"},{900,"rlz"},{800,"ini"}, - {600,"skl"},{700,"gr2"},{500,"skn"},{400,"8"},{300,"dlg"},{100,"model"},{200,"image"},{2900,"str"},{2800,"sst"},{2700,"use"},{2500,"arm"},{2600,"dor"}, - {2400,"wea"},{2300,"pce"},{2200,"sco"},{2000,"gsf"},{2100,"gls"},{3400,"fnt"},{3300,"spl"},{3200,"pro"},{3000,"enc"},{3100,"wmp"},{3500,"amo"},{3600,"con"},{3700,"tok"} + { 1900, "psf" }, + { 1600, "int" }, + { 1700, "rle" }, + { 1800, "itm" }, + { 1500, "veg" }, + { 1400, "crt" }, + { 1300, "map" }, + { 1100, "wav" }, + { 1200, "amx" }, + { 1000, "rtd" }, + { 900, "rlz" }, + { 800, "ini" }, + { 600, "skl" }, + { 700, "gr2" }, + { 500, "skn" }, + { 400, "8" }, + { 300, "dlg" }, + { 100, "model" }, + { 200, "image" }, + { 2900, "str" }, + { 2800, "sst" }, + { 2700, "use" }, + { 2500, "arm" }, + { 2600, "dor" }, + { 2400, "wea" }, + { 2300, "pce" }, + { 2200, "sco" }, + { 2000, "gsf" }, + { 2100, "gls" }, + { 3400, "fnt" }, + { 3300, "spl" }, + { 3200, "pro" }, + { 3000, "enc" }, + { 3100, "wmp" }, + { 3500, "amo" }, + { 3600, "con" }, + { 3700, "tok" } }; #endregion @@ -196,7 +253,7 @@ private string DetermineActualExtension(int filetype, byte[] buffer) ext = (buffer[0] == 'B' && buffer[1] == '3' && buffer[2] == 'D' && buffer[3] == ' ') ? "b3d" : "g3d"; else if (ext == "image") ext = (buffer[0] == 'B' && buffer[1] == 'M') ? "bmp" : "tga"; - + return ext; } @@ -732,9 +789,9 @@ private BitmapImage GetImageFromName(string name) { var i1 = i; foreach (var g in from ent in entries[i] - let g = localIndexToGlobal[i1][ent.number] - where filenames[g] == nne && GetExtension(ent.type) == "image" - select g) + let g = localIndexToGlobal[i1][ent.number] + where filenames[g] == nne && GetExtension(ent.type) == "image" + select g) { return TargaToBitmapImage(getFileBytes(g)); } diff --git a/VBLauncher/ModLoader.cs b/VBLauncher/ModLoader.cs index 374f6d9..9a2ccc1 100644 --- a/VBLauncher/ModLoader.cs +++ b/VBLauncher/ModLoader.cs @@ -40,8 +40,8 @@ public void LoadMods() var description = IniManager.Ini(ref iniData, "Info", "Description", IniManager.KeyType.Multiline); var version = IniManager.Ini(ref iniData, "Info", "Version"); var entries = (from ent in zip.Entries - where ent.Name.ToLower() != "mod.info" - select ent.Name).ToList(); + where ent.Name.ToLower() != "mod.info" + select ent.Name).ToList(); modList.Add(new ModInfo(mname, description, version, new FileInfo(file.FullName), entries)); break; } diff --git a/VBLauncher/Options.cs b/VBLauncher/Options.cs index 047b03b..f156fb6 100644 --- a/VBLauncher/Options.cs +++ b/VBLauncher/Options.cs @@ -259,22 +259,22 @@ private void ApplyChanges(object sender, EventArgs e) switch (APICB.SelectedIndex) { case 0: - { - File.Delete("d3d9.dll"); - File.Delete("d3d11.dll"); - File.Delete("dxgi.dll"); - File.Delete("wined3d.dll"); - File.WriteAllBytes("d3d8.dll", My.Resources.Resources.D3D8); - break; - } + { + File.Delete("d3d9.dll"); + File.Delete("d3d11.dll"); + File.Delete("dxgi.dll"); + File.Delete("wined3d.dll"); + File.WriteAllBytes("d3d8.dll", My.Resources.Resources.D3D8); + break; + } case 1: - { - File.Delete("d3d9.dll"); - File.Delete("wined3d.dll"); - File.WriteAllBytes("d3d11.dll", My.Resources.Resources.d3d11); - File.WriteAllBytes("dxgi.dll", My.Resources.Resources.dxgi); - break; - } + { + File.Delete("d3d9.dll"); + File.Delete("wined3d.dll"); + File.WriteAllBytes("d3d11.dll", My.Resources.Resources.d3d11); + File.WriteAllBytes("dxgi.dll", My.Resources.Resources.dxgi); + break; + } } IniManager.Ini(ref dgV2Conf, "DirectX", "Antialiasing", AAModes[AACB.SelectedIndex]); @@ -285,7 +285,7 @@ private void ApplyChanges(object sender, EventArgs e) IniManager.Ini(ref dgV2Conf, "GeneralExt", "FPSLimit", res.Hz.ToString()); IniManager.Ini(ref IniManager.F3Ini, "Graphics", "refresh", res.Hz.ToString()); var NewBinds = (from DataGridViewRow r in DataGridView1.Rows - select RowToStr(r)).ToList(); + select RowToStr(r)).ToList(); var SectionStart = Array.FindIndex(IniManager.F3Ini, x => x.StartsWith("[HotKeys]")); var SectionEnd = Array.FindIndex(IniManager.F3Ini, SectionStart + 1, x => x.StartsWith("[")) - 1; @@ -336,31 +336,31 @@ private void DataGridView1_CellContentClick(object sender, DataGridViewCellEvent { case 0: case 1: - { - Row = e.RowIndex; - DarkLabel1.Show(); - WantKey = true; - break; - } + { + Row = e.RowIndex; + DarkLabel1.Show(); + WantKey = true; + break; + } case 2: - { - DarkLabel1.Hide(); - WantKey = false; - break; - } + { + DarkLabel1.Hide(); + WantKey = false; + break; + } case 3: - { - if (ReferenceEquals(DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, DBNull.Value)) - DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "Up"; - DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = - Conversions.ToBoolean(Operators.ConditionalCompareObjectEqual( - DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, "Up", false)) - ? "Down" - : "Up"; - DarkLabel1.Hide(); - WantKey = false; - break; - } + { + if (ReferenceEquals(DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, DBNull.Value)) + DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "Up"; + DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = + Conversions.ToBoolean(Operators.ConditionalCompareObjectEqual( + DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value, "Up", false)) + ? "Down" + : "Up"; + DarkLabel1.Hide(); + WantKey = false; + break; + } } } @@ -393,32 +393,51 @@ private void DataGridView1_KeyDown(object sender, KeyEventArgs e) case Keys.ControlKey: case Keys.Menu: case Keys.ShiftKey: - { - break; - } + { + break; + } default: - { - if (WantKey) { - Modifier = e.Modifiers.ToString(); - Key = e.KeyCode.ToString(); - DataGridView1.Rows[Row].Cells[0].Value = ProperName.TryGetValue(Modifier, out var value) ? value : Modifier; - DataGridView1.Rows[Row].Cells[1].Value = ProperName.TryGetValue(Key, out var value1) ? value1 : Key; + if (WantKey) + { + Modifier = e.Modifiers.ToString(); + Key = e.KeyCode.ToString(); + DataGridView1.Rows[Row].Cells[0].Value = ProperName.TryGetValue(Modifier, out var value) ? value : Modifier; + DataGridView1.Rows[Row].Cells[1].Value = ProperName.TryGetValue(Key, out var value1) ? value1 : Key; + break; + } + break; } - - break; - } } } private Dictionary ProperName = new() { - { "D1", "1" }, { "D2", "2" }, { "D3", "3" }, { "D4", "4" }, { "D5", "5" }, { "D6", "6" }, { "D7", "7" }, - { "D8", "8" }, { "D9", "9" }, { "D0", "0" }, { "Control", "Ctrl" }, { "None", "" }, { "Oemtilde", "`" }, - { "Oemminus", "-" }, { "Oemplus", "+" }, { "OemOpenBrackets", "[" }, { "Oem6", "]" }, { "Oem5", @"\" }, - { "Oem1", ";" }, { "Oem7", "\"" }, { "Oemcomma", "," }, { "Oemperiod", "." }, { "OemQuestion", "/" } + { "D1", "1" }, + { "D2", "2" }, + { "D3", "3" }, + { "D4", "4" }, + { "D5", "5" }, + { "D6", "6" }, + { "D7", "7" }, + { "D8", "8" }, + { "D9", "9" }, + { "D0", "0" }, + { "Control", "Ctrl" }, + { "None", "" }, + { "Oemtilde", "`" }, + { "Oemminus", "-" }, + { "Oemplus", "+" }, + { "OemOpenBrackets", "[" }, + { "Oem6", "]" }, + { "Oem5", @"\" }, + { "Oem1", ";" }, + { "Oem7", "\"" }, + { "Oemcomma", "," }, + { "Oemperiod", "." }, + { "OemQuestion", "/" } }; } diff --git a/VBLauncher/VB3DLib/GrannyFormats.cs b/VBLauncher/VB3DLib/GrannyFormats.cs index 8616b28..0860b49 100644 --- a/VBLauncher/VB3DLib/GrannyFormats.cs +++ b/VBLauncher/VB3DLib/GrannyFormats.cs @@ -87,7 +87,7 @@ private static void ParseExporterInfo(ref file_info parsedFile, unm_file_info fi private static void ParseModels(ref file_info parsedFile, unm_file_info fileInfo) { parsedFile.Models = []; - for (var i = 0; i < fileInfo.ModelCount; i++) + for (var i = 0; i < fileInfo.ModelCount; i++) { var model = ReadFromPointerArray(fileInfo.Models, i); var parsedModel = new model @@ -136,7 +136,7 @@ private static List ParseCurve(unm_curve2 curve) for (var i = 0; i < curveData.KnotCount; i++) { var knot = ReadFromArray(curveData.Knots, i); - var control = new float[dimension+1]; + var control = new float[dimension + 1]; control[0] = knot; for (var j = 1; j <= dimension; j++) { @@ -150,7 +150,7 @@ private static List ParseCurve(unm_curve2 curve) return keyframes; } - + private static void ComputeBoneWorldTransforms(model parsedModel) { var bones = parsedModel.Skeleton.Bones; @@ -200,7 +200,7 @@ private static Matrix4x4 TransformToMatrix(transform t) t.ScaleShear[0][0], t.ScaleShear[0][1], t.ScaleShear[0][2], 0, t.ScaleShear[1][0], t.ScaleShear[1][1], t.ScaleShear[1][2], 0, t.ScaleShear[2][0], t.ScaleShear[2][1], t.ScaleShear[2][2], 0, - 0, 0, 0, 1 + 0, 0, 0, 1 ); var rotationMat = Matrix4x4.CreateFromQuaternion(t.Orientation); @@ -214,7 +214,7 @@ private static Matrix4x4 TransformToMatrix(transform t) return worldMat; } - + private static void AdjustTransformTrackCurves(transform_track tt) { // Orientation adjustments: @@ -942,7 +942,7 @@ public struct track_group public transform InitialPlacement; //TODO: is more needed? } - + public struct transform_track { public string Name; diff --git a/VBLauncher/VB3DLib/VanBurenFormats.cs b/VBLauncher/VB3DLib/VanBurenFormats.cs index 1424761..9ecb736 100644 --- a/VBLauncher/VB3DLib/VanBurenFormats.cs +++ b/VBLauncher/VB3DLib/VanBurenFormats.cs @@ -19,7 +19,7 @@ public class B3DModel public List Vertex_Nodes = []; public string texName = ""; - + public List Txs = []; public List Materials = []; @@ -383,716 +383,718 @@ public TMaterial_Data(BinaryReader f, B3DModel b3d) var b = f.ReadInt32(); var c = f.ReadInt32(); b3d.Model_Faces_Index.Add([b, a, c]); - b3d.Model_Faces_Mats.Add(b3d.Txs.Count); - } + b3d.Model_Faces_Mats.Add(b3d.Txs.Count); + } for (uint i = 1; i <= kk; i++) { Unknown2 = f.ReadByte(); } - } + } - public void print() - { - Console.Write("(TMaterial_Data Name:\""); - Console.Write(Name); - Console.Write("\" Mtl_ID:\""); - Console.Write(Mtl_ID); - Console.Write($"\" Unknown1:{Unknown1} BLEND_STATE:\""); - Console.Write(BLEND_STATE); - Console.Write("\" MATERIAL_TYPE:\""); - Console.Write(MATERIAL_TYPE); - Console.Write($"\" Unknown2:{Unknown2} Zone:\""); - Console.Write(Zone); - Console.WriteLine($"\" Unknown3:{Unknown3})"); - } + public void print() + { + Console.Write("(TMaterial_Data Name:\""); + Console.Write(Name); + Console.Write("\" Mtl_ID:\""); + Console.Write(Mtl_ID); + Console.Write($"\" Unknown1:{Unknown1} BLEND_STATE:\""); + Console.Write(BLEND_STATE); + Console.Write("\" MATERIAL_TYPE:\""); + Console.Write(MATERIAL_TYPE); + Console.Write($"\" Unknown2:{Unknown2} Zone:\""); + Console.Write(Zone); + Console.WriteLine($"\" Unknown3:{Unknown3})"); + } +} + +public struct TVertex_Node +{ + public int Unknown1; + public int Unknown2; + public int VertexTypeFlag; + public int NumberVerts; + public int SizeOfVerts; + public List Unknown3; + public int IsBones; + public int BonesPerVert; + public int NumberMaterial; + public List Vert_Bones_Data; + + public TVertex_Node(BinaryReader f, B3DModel b3d) + { + Unknown3 = []; + Vert_Bones_Data = []; + //Console.WriteLine("TVertex_Node"); + Unknown1 = f.ReadByte(); + Unknown2 = f.ReadByte(); + Console.WriteLine($"VertNode U1 {Unknown1} U2 {Unknown2}"); + + if (b3d.FormatVer == 0) + { + VertexTypeFlag = f.ReadByte(); + b3d.Vertex_Type_Flag = VertexTypeFlag; + } + else + { + b3d.Vertex_Type_Flag = 0; } - public struct TVertex_Node + NumberVerts = f.ReadInt32(); + Console.WriteLine($"Vertex count - {NumberVerts}"); + Console.WriteLine($"Vertex_Type_Flag - {VertexTypeFlag}"); + if (b3d.Vertex_Type_Flag == 1) { - public int Unknown1; - public int Unknown2; - public int VertexTypeFlag; - public int NumberVerts; - public int SizeOfVerts; - public List Unknown3; - public int IsBones; - public int BonesPerVert; - public int NumberMaterial; - public List Vert_Bones_Data; - - public TVertex_Node(BinaryReader f, B3DModel b3d) + SizeOfVerts = f.ReadInt32(); + Console.WriteLine($"SizeOfVerts - {SizeOfVerts}"); + for (var i = 0; i < NumberVerts; i++) { - Unknown3 = []; - Vert_Bones_Data = []; - //Console.WriteLine("TVertex_Node"); - Unknown1 = f.ReadByte(); - Unknown2 = f.ReadByte(); - Console.WriteLine($"VertNode U1 {Unknown1} U2 {Unknown2}"); - - if (b3d.FormatVer == 0) - { - VertexTypeFlag = f.ReadByte(); - b3d.Vertex_Type_Flag = VertexTypeFlag; - } - else - { - b3d.Vertex_Type_Flag = 0; - } - - NumberVerts = f.ReadInt32(); - Console.WriteLine($"Vertex count - {NumberVerts}"); - Console.WriteLine($"Vertex_Type_Flag - {VertexTypeFlag}"); - if (b3d.Vertex_Type_Flag == 1) - { - SizeOfVerts = f.ReadInt32(); - Console.WriteLine($"SizeOfVerts - {SizeOfVerts}"); - for (var i = 0; i < NumberVerts; i++) - { - var Vertex44 = new TVertex44(f, b3d); - } - - for (var i = 0; i < 6; i++) - { - Unknown3.Add(f.ReadSingle()); - } - - IsBones = f.ReadByte(); - - if (IsBones == 1) - { - BonesPerVert = f.ReadInt32(); - Console.WriteLine($"BonesPerVert - {BonesPerVert}"); - for (var i = 0; i < NumberVerts * BonesPerVert; i++) - { - var VBD = new TVert_Bones_Data(f); - Vert_Bones_Data.Add(VBD); - } - } - - NumberMaterial = f.ReadInt32(); - Console.WriteLine($"NumberMaterial - {NumberMaterial}"); - for (var i = 0; i < NumberMaterial; i++) - { - var MD = new TMaterial_Data44(f, b3d); - MD.print(); - } - - for (var i = 0; i < NumberMaterial; i++) - { - StringRead(f); - } - - var Mat_list = new List(); - - var NumVert = 0; - var NumTri = 0; - - for (var i = 0; i < NumberMaterial; i++) - { - var a = f.ReadInt32(); - Mat_list.Add(a); - } + var Vertex44 = new TVertex44(f, b3d); + } - for (var i = 0; i < NumberMaterial; i++) - { - var a = f.ReadInt32(); - NumVert += a; - } + for (var i = 0; i < 6; i++) + { + Unknown3.Add(f.ReadSingle()); + } - Console.WriteLine("NumVert"); - Console.WriteLine(NumVert); - Console.WriteLine("NumTri"); - Console.WriteLine(NumTri); + IsBones = f.ReadByte(); - for (var j = 0; j < NumberMaterial; j++) - { - for (var i = 0; i < (Mat_list[j] / 3); i++) - { - int a = f.ReadUInt16(); - int b = f.ReadUInt16(); - int c = f.ReadUInt16(); - b3d.Model_Faces_Index.Add([c, b, a]); - b3d.Model_Faces_Mats.Add(j); - } - } - } - else + if (IsBones == 1) + { + BonesPerVert = f.ReadInt32(); + Console.WriteLine($"BonesPerVert - {BonesPerVert}"); + for (var i = 0; i < NumberVerts * BonesPerVert; i++) { - for (var i = 0; i < NumberVerts; i++) - { - var Vertex64 = new TVertex64(f, b3d); - } - - Console.WriteLine(f.BaseStream.Position); - - NumberMaterial = f.ReadInt32(); - Console.WriteLine($"NumberMaterial - {NumberMaterial}"); - for (var i = 0; i < NumberMaterial; i++) - { - var MD = new TMaterial_Data(f, b3d); - MD.print(); - } + var VBD = new TVert_Bones_Data(f); + Vert_Bones_Data.Add(VBD); } } - } - public struct TBone - { - public char[] Name; - public ushort Unknown1; - public byte Flag; - public Vector3 Translation; - public Quaternion Rotation; + NumberMaterial = f.ReadInt32(); + Console.WriteLine($"NumberMaterial - {NumberMaterial}"); + for (var i = 0; i < NumberMaterial; i++) + { + var MD = new TMaterial_Data44(f, b3d); + MD.print(); + } - public TBone(BinaryReader reader) + for (var i = 0; i < NumberMaterial; i++) { - //Console.WriteLine("TBone"); - Name = StringRead(reader); - Unknown1 = reader.ReadUInt16(); - Flag = reader.ReadByte(); + StringRead(f); + } - if (Flag != 0) - { - Translation.X = reader.ReadSingle(); - Translation.Z = reader.ReadSingle(); - Translation.Y = reader.ReadSingle(); + var Mat_list = new List(); - if (Flag == 3) - { - Rotation.X = reader.ReadSingle(); - Rotation.Z = reader.ReadSingle(); - Rotation.Y = reader.ReadSingle(); - Rotation.W = reader.ReadSingle(); - } + var NumVert = 0; + var NumTri = 0; - if (Flag == 2) - { - reader.ReadSingle(); - } - } + for (var i = 0; i < NumberMaterial; i++) + { + var a = f.ReadInt32(); + Mat_list.Add(a); } - public void print() + for (var i = 0; i < NumberMaterial; i++) { - Console.Write("(TBone Name:\""); - Console.Write(Name); - Console.WriteLine( - $"\" Unknown1:{Unknown1} Flag:{Flag} Translation:[{Translation.X} {Translation.Y} {Translation.Z}] Rotation:(quat {Rotation.X} {Rotation.Y} {Rotation.Z} {Rotation.W}))"); + var a = f.ReadInt32(); + NumVert += a; } - } - public class TColor - { - public float r; - public float g; - public float b; - public float a; + Console.WriteLine("NumVert"); + Console.WriteLine(NumVert); + Console.WriteLine("NumTri"); + Console.WriteLine(NumTri); - public TColor(BinaryReader f) + for (var j = 0; j < NumberMaterial; j++) { - r = f.ReadSingle(); - g = f.ReadSingle(); - b = f.ReadSingle(); - a = f.ReadSingle(); - Console.WriteLine($"TColor: {r} {g} {b} {a}"); - } + for (var i = 0; i < (Mat_list[j] / 3); i++) + { + int a = f.ReadUInt16(); + int b = f.ReadUInt16(); + int c = f.ReadUInt16(); + b3d.Model_Faces_Index.Add([c, b, a]); + b3d.Model_Faces_Mats.Add(j); } + } +} + else +{ + for (var i = 0; i < NumberVerts; i++) + { + var Vertex64 = new TVertex64(f, b3d); + } - public struct TMater - { - public TColor Ambient; - public TColor Diffuse; - public TColor Emissive; - public TColor Specular; - public float Shininess; - public float Alpha; - - public TMater(BinaryReader f) - { - Console.WriteLine("TMater"); - Ambient = new TColor(f); - Diffuse = new TColor(f); - Emissive = new TColor(f); - Specular = new TColor(f); - Shininess = f.ReadSingle(); - Alpha = f.ReadSingle(); + Console.WriteLine(f.BaseStream.Position); + + NumberMaterial = f.ReadInt32(); + Console.WriteLine($"NumberMaterial - {NumberMaterial}"); + for (var i = 0; i < NumberMaterial; i++) + { + var MD = new TMaterial_Data(f, b3d); + MD.print(); + } +} } } - public class TMaterials + public struct TBone +{ + public char[] Name; + public ushort Unknown1; + public byte Flag; + public Vector3 Translation; + public Quaternion Rotation; + + public TBone(BinaryReader reader) + { + //Console.WriteLine("TBone"); + Name = StringRead(reader); + Unknown1 = reader.ReadUInt16(); + Flag = reader.ReadByte(); + + if (Flag != 0) { - public char[] Mtl_ID; - public char[] Name; - public TMater Mater; - public char[] BLEND_STATE; - public char[] MATERIAL_TYPE; - public int Flag_1; - public int Flag_2; + Translation.X = reader.ReadSingle(); + Translation.Z = reader.ReadSingle(); + Translation.Y = reader.ReadSingle(); - public TMaterials(BinaryReader f) + if (Flag == 3) { - //Console.WriteLine("TMaterials"); - Mtl_ID = StringRead(f); - Name = StringRead(f); - Mater = new TMater(f); - BLEND_STATE = StringRead(f); - MATERIAL_TYPE = StringRead(f); - Flag_1 = f.ReadInt32(); - Flag_2 = f.ReadInt32(); + Rotation.X = reader.ReadSingle(); + Rotation.Z = reader.ReadSingle(); + Rotation.Y = reader.ReadSingle(); + Rotation.W = reader.ReadSingle(); } - public void print() + if (Flag == 2) { - Console.Write("(TMaterials Mtl_ID:\""); - Console.Write(Mtl_ID); - Console.Write("\" Name:\""); - Console.Write(Name); - Console.Write("\" BLEND_STATE:\""); - Console.Write(BLEND_STATE); - Console.Write("\" MATERIAL_TYPE:\""); - Console.Write(MATERIAL_TYPE); - Console.WriteLine($"\" Flag_1:{Flag_1} Flag_2:{Flag_2})"); + reader.ReadSingle(); } } + } - public struct TTextures - { - public byte Unknown1; - public char[] Name; - public char[] FileName; - public uint Width; - public uint Height; + public void print() + { + Console.Write("(TBone Name:\""); + Console.Write(Name); + Console.WriteLine( + $"\" Unknown1:{Unknown1} Flag:{Flag} Translation:[{Translation.X} {Translation.Y} {Translation.Z}] Rotation:(quat {Rotation.X} {Rotation.Y} {Rotation.Z} {Rotation.W}))"); + } +} - public TTextures(BinaryReader f, B3DModel b3d) - { - //Console.WriteLine("TTextures"); - Unknown1 = f.ReadByte(); - Name = StringRead(f); - if (string.IsNullOrEmpty(b3d.texName)) {b3d.texName = new string(Name);} - FileName = StringRead(f); - Width = f.ReadUInt32(); - Height = f.ReadUInt32(); - } +public class TColor +{ + public float r; + public float g; + public float b; + public float a; - public void print() - { - Console.Write("(TTextures Unknown1:{Unknown1} Name:\""); - Console.Write(Name); - Console.Write("\" FileName:\""); - Console.Write(FileName); - Console.WriteLine($"\" Width:{Width} Height:{Height})"); - } - } + public TColor(BinaryReader f) + { + r = f.ReadSingle(); + g = f.ReadSingle(); + b = f.ReadSingle(); + a = f.ReadSingle(); + Console.WriteLine($"TColor: {r} {g} {b} {a}"); + } +} - public class TNodes - { - public byte Unknown1; //: byte; - public char[] Name; //: TCharArray; +public struct TMater +{ + public TColor Ambient; + public TColor Diffuse; + public TColor Emissive; + public TColor Specular; + public float Shininess; + public float Alpha; + + public TMater(BinaryReader f) + { + Console.WriteLine("TMater"); + Ambient = new TColor(f); + Diffuse = new TColor(f); + Emissive = new TColor(f); + Specular = new TColor(f); + Shininess = f.ReadSingle(); + Alpha = f.ReadSingle(); + } +} - public TNodes(BinaryReader f) - { - //Console.WriteLine("TNodes"); - Unknown1 = f.ReadByte(); - Name = StringRead(f); - } +public class TMaterials +{ + public char[] Mtl_ID; + public char[] Name; + public TMater Mater; + public char[] BLEND_STATE; + public char[] MATERIAL_TYPE; + public int Flag_1; + public int Flag_2; + + public TMaterials(BinaryReader f) + { + //Console.WriteLine("TMaterials"); + Mtl_ID = StringRead(f); + Name = StringRead(f); + Mater = new TMater(f); + BLEND_STATE = StringRead(f); + MATERIAL_TYPE = StringRead(f); + Flag_1 = f.ReadInt32(); + Flag_2 = f.ReadInt32(); + } - public void print() - { - Console.Write($"(TNodes Unknown1:{Unknown1} Name:\""); - Console.Write(Name); - Console.WriteLine("\")"); - } - } + public void print() + { + Console.Write("(TMaterials Mtl_ID:\""); + Console.Write(Mtl_ID); + Console.Write("\" Name:\""); + Console.Write(Name); + Console.Write("\" BLEND_STATE:\""); + Console.Write(BLEND_STATE); + Console.Write("\" MATERIAL_TYPE:\""); + Console.Write(MATERIAL_TYPE); + Console.WriteLine($"\" Flag_1:{Flag_1} Flag_2:{Flag_2})"); + } +} - public struct TMat_Data - { - public byte[] Unknown1; // array[0..2]of byte; - public char[] Name; // TCharArray; - public uint TextureOn; // intword; - public char[] Texture; // TCharArray; - public uint Unknown3; // intword; - public byte Unknown4; // byte; - public uint NumOfPoints; // intword; - - public TMat_Data(BinaryReader f) - { - //Console.WriteLine("TMat_Data"); - Unknown1 = f.ReadBytes(3); - Name = StringRead(f); - Console.WriteLine(Name); - TextureOn = f.ReadUInt32(); - if (TextureOn != 0) Texture = StringRead(f); - Unknown3 = f.ReadUInt32(); - Unknown4 = f.ReadByte(); - NumOfPoints = f.ReadUInt32(); - Console.WriteLine(NumOfPoints); - } - } +public struct TTextures +{ + public byte Unknown1; + public char[] Name; + public char[] FileName; + public uint Width; + public uint Height; - public struct TMaterial_Node - { - public uint NumberMaterialNodes; //: intword; - public byte Unknown1; //: byte; + public TTextures(BinaryReader f, B3DModel b3d) + { + //Console.WriteLine("TTextures"); + Unknown1 = f.ReadByte(); + Name = StringRead(f); + if (string.IsNullOrEmpty(b3d.texName)) { b3d.texName = new string(Name); } + FileName = StringRead(f); + Width = f.ReadUInt32(); + Height = f.ReadUInt32(); + } - public TMaterial_Node(BinaryReader f) - { - //Console.WriteLine("TMaterial_Node"); - NumberMaterialNodes = f.ReadUInt32(); - Unknown1 = f.ReadByte(); //Unknown4 in maxscript? somehow? idfk - Console.WriteLine($"MaterialNode - NumberMaterialNodes = {NumberMaterialNodes}"); - } - } + public void print() + { + Console.Write("(TTextures Unknown1:{Unknown1} Name:\""); + Console.Write(Name); + Console.Write("\" FileName:\""); + Console.Write(FileName); + Console.WriteLine($"\" Width:{Width} Height:{Height})"); + } +} + +public class TNodes +{ + public byte Unknown1; //: byte; + public char[] Name; //: TCharArray; + + public TNodes(BinaryReader f) + { + //Console.WriteLine("TNodes"); + Unknown1 = f.ReadByte(); + Name = StringRead(f); + } + + public void print() + { + Console.Write($"(TNodes Unknown1:{Unknown1} Name:\""); + Console.Write(Name); + Console.WriteLine("\")"); + } +} + +public struct TMat_Data +{ + public byte[] Unknown1; // array[0..2]of byte; + public char[] Name; // TCharArray; + public uint TextureOn; // intword; + public char[] Texture; // TCharArray; + public uint Unknown3; // intword; + public byte Unknown4; // byte; + public uint NumOfPoints; // intword; + + public TMat_Data(BinaryReader f) + { + //Console.WriteLine("TMat_Data"); + Unknown1 = f.ReadBytes(3); + Name = StringRead(f); + Console.WriteLine(Name); + TextureOn = f.ReadUInt32(); + if (TextureOn != 0) Texture = StringRead(f); + Unknown3 = f.ReadUInt32(); + Unknown4 = f.ReadByte(); + NumOfPoints = f.ReadUInt32(); + Console.WriteLine(NumOfPoints); + } +} + +public struct TMaterial_Node +{ + public uint NumberMaterialNodes; //: intword; + public byte Unknown1; //: byte; + + public TMaterial_Node(BinaryReader f) + { + //Console.WriteLine("TMaterial_Node"); + NumberMaterialNodes = f.ReadUInt32(); + Unknown1 = f.ReadByte(); //Unknown4 in maxscript? somehow? idfk + Console.WriteLine($"MaterialNode - NumberMaterialNodes = {NumberMaterialNodes}"); + } +} } public class G3DModel +{ + public List Model_Vertex_Position = []; + public List Model_Faces_Index = []; + public List Model_Vertex_Texcoords = []; + + public G3DModel(string path) { - public List Model_Vertex_Position = []; - public List Model_Faces_Index = []; - public List Model_Vertex_Texcoords = []; + var s = File.ReadAllLines(path); + ReadG3D(s); + } - public G3DModel(string path) - { - var s = File.ReadAllLines(path); - ReadG3D(s); - } + public G3DModel(byte[] file) + { + var s = Encoding.UTF8.GetString(file); + // split into array at every CrLf + s = s.Replace("\r\n", "\n"); + var sa = s.Split('\n'); + ReadG3D(sa); + } - public G3DModel(byte[] file) + // there's only one so a lot of this will be hardcoded + // if you want to fix it, be my guest. + // if not, it works so i don't care. + private void ReadG3D(string[] f) + { + for (var i = 73; i < 3645; i++) { - var s = Encoding.UTF8.GetString(file); - // split into array at every CrLf - s = s.Replace("\r\n", "\n"); - var sa = s.Split('\n'); - ReadG3D(sa); + //example line + // Vertex{ Coordinate(0 565 36) Normal(0 -264 989) Color(586 80 80 512) TexCoord(156 141) Bone(7 1.000000) } + var x = f[i].Split(" Vertex{ Coordinate(")[1].Split(' ')[0]; + var y = f[i].Split(" Vertex{ Coordinate(")[1].Split(' ')[1]; + var z = f[i].Split(" Vertex{ Coordinate(")[1].Split(' ')[2].Split(')')[0]; + Model_Vertex_Position.Add(new Vector3(float.Parse(x), float.Parse(y), float.Parse(z))); + var u = f[i].Split("TexCoord(")[1].Split(' ')[0]; + var v = f[i].Split("TexCoord(")[1].Split(' ')[1].Split(')')[0]; + Model_Vertex_Texcoords.Add(new Vector2(float.Parse(u) / 1024.0f, float.Parse(v) / 1024.0f)); //divide by 1024 to normalize UV } - // there's only one so a lot of this will be hardcoded - // if you want to fix it, be my guest. - // if not, it works so i don't care. - private void ReadG3D(string[] f) + var tmpList = new List(); + var skipLine = false; + + for (var i = 3648; i < 4123; i++) { - for (var i = 73; i < 3645; i++) + //example lines + // Triangles{Index( 2976 2977 2978 2979 2976 2978 2980 2981 2982 2983 2981 2980 2984 2985 2986 2987 2988 2989 2990 2987 2989 2991 2992 2993 2993 2994 2995 2996 2997 2998 2999 3000 + // 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3009 3008 3012 2999 3013 2987 2995 2988 3014 3015 3016 3015 3017 3016 3018 3019 3020 2994 3019 3018 3021 + // 3449 3446 ) Edge( 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 + var s = f[i]; + if (s.StartsWith(" Triangles{Index( ")) { - //example line - // Vertex{ Coordinate(0 565 36) Normal(0 -264 989) Color(586 80 80 512) TexCoord(156 141) Bone(7 1.000000) } - var x = f[i].Split(" Vertex{ Coordinate(")[1].Split(' ')[0]; - var y = f[i].Split(" Vertex{ Coordinate(")[1].Split(' ')[1]; - var z = f[i].Split(" Vertex{ Coordinate(")[1].Split(' ')[2].Split(')')[0]; - Model_Vertex_Position.Add(new Vector3(float.Parse(x), float.Parse(y), float.Parse(z))); - var u = f[i].Split("TexCoord(")[1].Split(' ')[0]; - var v = f[i].Split("TexCoord(")[1].Split(' ')[1].Split(')')[0]; - Model_Vertex_Texcoords.Add(new Vector2(float.Parse(u) / 1024.0f, float.Parse(v) / 1024.0f)); //divide by 1024 to normalize UV + skipLine = false; + tmpList.AddRange(from ss in s.Split(" Triangles{Index( ")[1].Split(" ") + where !string.IsNullOrEmpty(ss) + select int.Parse(ss)); } - - var tmpList = new List(); - var skipLine = false; - - for (var i = 3648; i < 4123; i++) + else if (!skipLine) { - //example lines - // Triangles{Index( 2976 2977 2978 2979 2976 2978 2980 2981 2982 2983 2981 2980 2984 2985 2986 2987 2988 2989 2990 2987 2989 2991 2992 2993 2993 2994 2995 2996 2997 2998 2999 3000 - // 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3009 3008 3012 2999 3013 2987 2995 2988 3014 3015 3016 3015 3017 3016 3018 3019 3020 2994 3019 3018 3021 - // 3449 3446 ) Edge( 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - var s = f[i]; - if (s.StartsWith(" Triangles{Index( ")) + if (s.Contains("Edge")) { - skipLine = false; - tmpList.AddRange(from ss in s.Split(" Triangles{Index( ")[1].Split(" ") - where !string.IsNullOrEmpty(ss) select int.Parse(ss)); - } - else if (!skipLine) - { - if (s.Contains("Edge")) - { - skipLine = true; - s = s.Split(" ) Edge( ")[0]; - } - tmpList.AddRange(from ss in s.Split(" ") - where !string.IsNullOrEmpty(ss) select int.Parse(ss)); + skipLine = true; + s = s.Split(" ) Edge( ")[0]; } - } - //split tmplist into groups of 3 and add to faces - for (var i = 0; i < tmpList.Count; i += 3) - { - Model_Faces_Index.Add([tmpList[i], tmpList[i + 1], tmpList[i + 2]]); + tmpList.AddRange(from ss in s.Split(" ") + where !string.IsNullOrEmpty(ss) + select int.Parse(ss)); } } + //split tmplist into groups of 3 and add to faces + for (var i = 0; i < tmpList.Count; i += 3) + { + Model_Faces_Index.Add([tmpList[i], tmpList[i + 1], tmpList[i + 2]]); + } +} } public class _8Model - { - public string MapName = "defaultName"; +{ + public string MapName = "defaultName"; - public List GVP = []; // vertex position - public List GVN = []; // vertex normal - public List GVD = []; // vertex diffuse color - public List GVT = []; // texture coords - public List GVL = []; // lightmap coords + public List GVP = []; // vertex position + public List GVN = []; // vertex normal + public List GVD = []; // vertex diffuse color + public List GVT = []; // texture coords + public List GVL = []; // lightmap coords - public List IDX = []; // face indexes - public List MDX = []; // mat index - public List MAT = []; // materials + public List IDX = []; // face indexes + public List MDX = []; // mat index + public List MAT = []; // materials - public int buffer_index; - public List buffer_offset = []; + public int buffer_index; + public List buffer_offset = []; - public int Flag = 1; + public int Flag = 1; - public _8Model(string path, bool flgs) - { - Flag = flgs ? 4 : 1; + public _8Model(string path, bool flgs) + { + Flag = flgs ? 4 : 1; - var f = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read)); - ReadTREE_Data(f); - } + var f = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read)); + ReadTREE_Data(f); + } - public _8Model(byte[] file, bool flgs) - { - Flag = flgs ? 4 : 1; - GVP = []; + public _8Model(byte[] file, bool flgs) + { + Flag = flgs ? 4 : 1; + GVP = []; - GVN = []; - GVD = []; - GVT = []; - GVL = []; + GVN = []; + GVD = []; + GVT = []; + GVL = []; - IDX = []; - MDX = []; - MAT = []; + IDX = []; + MDX = []; + MAT = []; - buffer_index = 0; - buffer_offset = []; + buffer_index = 0; + buffer_offset = []; - var f = new BinaryReader(new MemoryStream(file)); - ReadTREE_Data(f); - } + var f = new BinaryReader(new MemoryStream(file)); + ReadTREE_Data(f); + } - public static string String4Read(BinaryReader f) + public static string String4Read(BinaryReader f) + { + var s = new byte[4]; + for (var i = 0; i < 4; ++i) { - var s = new byte[4]; - for (var i = 0; i < 4; ++i) - { - var t = f.BaseStream.Position; - s[i] = f.ReadByte(); - } - - try - { - return Encoding.ASCII.GetString(s); - } - catch - { - Console.WriteLine("ERRO"); - return " "; - } + var t = f.BaseStream.Position; + s[i] = f.ReadByte(); } - public struct TSectionHeader + try { - public string id; // name - public int size; - - public TSectionHeader(BinaryReader f) - { - id = String4Read(f); - size = f.ReadInt32(); - } + return Encoding.ASCII.GetString(s); } - - public struct BitmapTexture + catch { - public string FileName; - public int AlphaSource; + Console.WriteLine("ERRO"); + return " "; } + } - public static bool IsHeader(string s) - { - return s switch - { - "NODE" or "LEAF" or "INFO" or "IDXD" or "IDXS" or "FLGS" or "TREE" or "LVL0" or "XYZ " or "MATR" - or "MATD" or "TXTD" or "VTXD" or "VTXB" or "TXUV" or "LMUV" or "DIFU" or "NRML" or "LVLD" - or "HEAD" or "8TRE" or "LGTD" or "LGTR" => true, - _ => false, - }; - } + public struct TSectionHeader + { + public string id; // name + public int size; - public void ReadTREE_Data(BinaryReader f) + public TSectionHeader(BinaryReader f) { - ReadBlock(f, 0); + id = String4Read(f); + size = f.ReadInt32(); } + } - public int ReadBlock(BinaryReader f, int size) + public struct BitmapTexture + { + public string FileName; + public int AlphaSource; + } + + public static bool IsHeader(string s) + { + return s switch { - var header = new TSectionHeader(f); + "NODE" or "LEAF" or "INFO" or "IDXD" or "IDXS" or "FLGS" or "TREE" or "LVL0" or "XYZ " or "MATR" + or "MATD" or "TXTD" or "VTXD" or "VTXB" or "TXUV" or "LMUV" or "DIFU" or "NRML" or "LVLD" + or "HEAD" or "8TRE" or "LGTD" or "LGTR" => true, + _ => false, + }; + } - Console.WriteLine(header.id); + public void ReadTREE_Data(BinaryReader f) + { + ReadBlock(f, 0); + } - switch (header.id) - { - case "FLGS": - f.BaseStream.Seek(header.size * Flag, SeekOrigin.Current); - return 0; + public int ReadBlock(BinaryReader f, int size) + { + var header = new TSectionHeader(f); - case "IDXD": - f.BaseStream.Seek(-16, SeekOrigin.Current); - var t = f.ReadInt32(); - if (t >= 0 && t <= buffer_offset.Count - 1) // maybe if (t >= 1 && t <= buffer_offset.Count) - buffer_index = t; - f.BaseStream.Seek(12, SeekOrigin.Current); - break; + Console.WriteLine(header.id); + + switch (header.id) + { + case "FLGS": + f.BaseStream.Seek(header.size * Flag, SeekOrigin.Current); + return 0; + + case "IDXD": + f.BaseStream.Seek(-16, SeekOrigin.Current); + var t = f.ReadInt32(); + if (t >= 0 && t <= buffer_offset.Count - 1) // maybe if (t >= 1 && t <= buffer_offset.Count) + buffer_index = t; + f.BaseStream.Seek(12, SeekOrigin.Current); + break; + + case "TXTD": + Console.WriteLine(f.ReadInt32()); + Console.WriteLine(f.ReadInt32()); + break; + + case "TXUV": + { + for (var i = 1; i <= header.size / 8; i++) + { + var u = f.ReadSingle(); + var v = f.ReadSingle(); + GVT.Add(new Vector2(u, v)); + } - case "TXTD": - Console.WriteLine(f.ReadInt32()); - Console.WriteLine(f.ReadInt32()); break; + } + //case "LMUV": + //{ + // for (int i = 1; i <= header.size / 8; i++) + // { + // float u = f.ReadSingle(); + // float v = f.ReadSingle(); + // GVL.Add(new Vector2(u, v)); + // } + // + // break; + //} + case "TXTR": + { + var s = ""; + for (var i = 1; i <= header.size; i++) + s += f.ReadChar(); - case "TXUV": - { - for (var i = 1; i <= header.size / 8; i++) - { - var u = f.ReadSingle(); - var v = f.ReadSingle(); - GVT.Add(new Vector2(u, v)); - } + if (s.IndexOf("ctx", StringComparison.Ordinal) != -1) return 0; - break; - } - //case "LMUV": - //{ - // for (int i = 1; i <= header.size / 8; i++) - // { - // float u = f.ReadSingle(); - // float v = f.ReadSingle(); - // GVL.Add(new Vector2(u, v)); - // } - // - // break; - //} - case "TXTR": + var tm = new BitmapTexture { - var s = ""; - for (var i = 1; i <= header.size; i++) - s += f.ReadChar(); + AlphaSource = 2, + FileName = s + }; + Console.WriteLine(s); + MAT.Add(tm); - if (s.IndexOf("ctx", StringComparison.Ordinal) != -1) return 0; + return 0; + } + case "IDXS": + { + var end = (f.BaseStream.Position) + header.size; + var m = 0; + var mp = 0; - var tm = new BitmapTexture + while ((f.BaseStream.Position + 12) < end) + { + var tmp = f.ReadUInt16(); + if (tmp == 0) { - AlphaSource = 2, - FileName = s - }; - Console.WriteLine(s); - MAT.Add(tm); + tmp = f.ReadUInt16(); + } - return 0; - } - case "IDXS": - { - var end = (f.BaseStream.Position) + header.size; - var m = 0; - var mp = 0; + if ((tmp & 0xFF00) == 0x8000) + { + f.ReadUInt16(); + var t1 = (f.ReadUInt16()) - 0x4000; + f.ReadUInt16(); + var t2 = f.ReadUInt16(); + m = t2; + } - while ((f.BaseStream.Position + 12) < end) + if ((tmp & 0xFF00) == 0x4000) { - var tmp = f.ReadUInt16(); - if (tmp == 0) - { - tmp = f.ReadUInt16(); - } - - if ((tmp & 0xFF00) == 0x8000) - { - f.ReadUInt16(); - var t1 = (f.ReadUInt16()) - 0x4000; - f.ReadUInt16(); - var t2 = f.ReadUInt16(); - m = t2; - } - - if ((tmp & 0xFF00) == 0x4000) - { - f.ReadUInt16(); - var t1 = f.ReadUInt16(); - m = t1; - } - - if ((tmp & 0xFF00) == 0) m = tmp; - - var sz = f.ReadUInt16(); - - for (var i = 1; i <= (sz / 3); i++) - { - var a = buffer_offset[buffer_index] + f.ReadUInt16(); - var b = buffer_offset[buffer_index] + f.ReadUInt16(); - var c = buffer_offset[buffer_index] + f.ReadUInt16(); - - IDX.Add([a, c, b]); - MDX.Add(m == 0 ? 0 : m); - } + f.ReadUInt16(); + var t1 = f.ReadUInt16(); + m = t1; } - f.BaseStream.Seek(end, SeekOrigin.Begin); - return 0; + if ((tmp & 0xFF00) == 0) m = tmp; + + var sz = f.ReadUInt16(); + + for (var i = 1; i <= (sz / 3); i++) + { + var a = buffer_offset[buffer_index] + f.ReadUInt16(); + var b = buffer_offset[buffer_index] + f.ReadUInt16(); + var c = buffer_offset[buffer_index] + f.ReadUInt16(); + + IDX.Add([a, c, b]); + MDX.Add(m == 0 ? 0 : m); } + } + + f.BaseStream.Seek(end, SeekOrigin.Begin); + return 0; + } case "VTXB": f.ReadInt32(); - header.size -= 4; - buffer_offset.Add(GVP.Count); - break; + header.size -= 4; + buffer_offset.Add(GVP.Count); + break; case "VTXD": //f.ReadInt32(); var rd = f.ReadByte(); - var gr = f.ReadByte(); - var bl = f.ReadByte(); - var al = f.ReadByte(); - GVD.Add(Color.FromArgb(al, rd, gr, bl)); - header.size -= 4; - break; + var gr = f.ReadByte(); + var bl = f.ReadByte(); + var al = f.ReadByte(); + GVD.Add(Color.FromArgb(al, rd, gr, bl)); + header.size -= 4; + break; case "XYZ ": { - for (var i = 1; i <= header.size / 12; i++) - { - var x = f.ReadSingle(); - var y = f.ReadSingle(); - var z = f.ReadSingle(); + for (var i = 1; i <= header.size / 12; i++) + { + var x = f.ReadSingle(); + var y = f.ReadSingle(); + var z = f.ReadSingle(); - GVP.Add(new Vector3(x, z, y)); - } + GVP.Add(new Vector3(x, z, y)); + } - return 0; - } + return 0; + } case "DIFU": var baits = new List(); - for (var i = 1; i <= header.size; i++) - { - baits.Add(f.ReadByte()); - } - File.WriteAllBytes("difu.bin", baits.ToArray()); - break; - } + for (var i = 1; i <= header.size; i++) + { + baits.Add(f.ReadByte()); + } + File.WriteAllBytes("difu.bin", baits.ToArray()); + break; + } if (IsHeader(header.id)) { var end = (f.BaseStream.Position + header.size); - while (f.BaseStream.Position < end) + while (f.BaseStream.Position