Skip to content

Commit

Permalink
Flagrum 1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kizari committed Feb 14, 2023
1 parent cae10e4 commit fde8b4d
Show file tree
Hide file tree
Showing 29 changed files with 740 additions and 284 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ Steamworks.NET.dll

# Jetbrains Rider data
.idea/
.run/

# Item ID Fixer project which is of little importance
ItemIdFixer/
Expand Down
15 changes: 7 additions & 8 deletions Flagrum.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
using System;
using System.IO;
using System.Linq;
using Flagrum.Core.Archive;
using Flagrum.Core.Utilities;
using Flagrum.Core.Utilities.Types;
using Flagrum.Web.Features.ModManager.Data;
using Flagrum.Web.Services;
using K4os.Compression.LZ4.Streams;

var profile = new ProfileService();
using var archive = new EbonyArchive(@$"{profile.GameDataDirectory}\level\dlc_ex\tera2\env\tb2_c_invisible - Copy.earc");
archive.RemoveFile("data://environment/world/curve/collision/area_tb2_malmalm_base_c.tcm");
archive.WriteToFile(@$"{profile.GameDataDirectory}\level\dlc_ex\tera2\env\tb2_c_invisible.earc", LuminousGame.FFXV);
return;

var fragment = new FmodFragment();
fragment.Read(@"C:\Users\Kieran\AppData\Local\Flagrum\earc\d52176d1-2d22-4311-be79-5ff8831976ed\2\2.ffg");

Expand Down Expand Up @@ -42,14 +49,6 @@
File.WriteAllBytes(@"C:\Users\Kieran\Downloads\hu000_000_inner_shirts_1001_b_h_EvilTerada.btex", btex);
return;

using var archive =
new EbonyArchive(
@"C:\Program Files (x86)\Steam\steamapps\common\FINAL FANTASY XV\datas\menu\first_ff\script\menuswfentry_first_ff.backup");
archive.WriteToFile(
@"C:\Program Files (x86)\Steam\steamapps\common\FINAL FANTASY XV\datas\menu\first_ff\script\menuswfentry_first_ff.earc",
LuminousGame.FFXV);
return;

//IndexingScripts.DumpUniqueRelativeExtensions();

// var path = @"C:\Users\Kieran\Downloads\nh02_000_player_vr.exml";
Expand Down
24 changes: 14 additions & 10 deletions Flagrum.Core/Archive/EbonyArchiveWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,26 @@ public void WriteToFile(string path, LuminousGame targetGame)
SerializeFileData(archiveStream, out var endOfFile);
_stream?.Dispose();

if (targetGame == LuminousGame.FFXV)
{
var headerStream = SerializeHeader();
archiveStream.Seek(0, SeekOrigin.Begin);
headerStream.CopyTo(archiveStream);
headerStream.Dispose();
}

var fileHeaderStream = SerializeFileHeaders();
archiveStream.Seek(EbonyArchiveHeader.Size, SeekOrigin.Begin);
fileHeaderStream.CopyTo(archiveStream);
fileHeaderStream.Dispose();

var headerStream = targetGame switch
if (targetGame == LuminousGame.Forspoken)
{
LuminousGame.FFXV => SerializeHeader(),
LuminousGame.Forspoken => SerializeHeaderWitch(archiveStream, endOfFile),
_ => throw new ArgumentOutOfRangeException(nameof(targetGame), targetGame,
$"Unsupported {nameof(LuminousGame)}")
};

archiveStream.Seek(0, SeekOrigin.Begin);
headerStream.CopyTo(archiveStream);
headerStream.Dispose();
var headerStream = SerializeHeaderWitch(archiveStream, endOfFile);
archiveStream.Seek(0, SeekOrigin.Begin);
headerStream.CopyTo(archiveStream);
headerStream.Dispose();
}

archiveStream.Seek(0, SeekOrigin.Begin);
using var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);
Expand Down
4 changes: 2 additions & 2 deletions Flagrum.Core/Gfxbin/Gmdl/MessagePack/GfxbinMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class GfxbinMesh : IMessagePackItem
public uint UnknownOffset { get; set; }
public uint UnknownSize { get; set; }
public ulong MaterialHash { get; set; }
public uint DrawPriorityOffset { get; set; }
public int DrawPriorityOffset { get; set; }
public bool Unknown7 { get; set; }
public bool Unknown8 { get; set; }
public float LodNear { get; set; }
Expand Down Expand Up @@ -124,7 +124,7 @@ public void Read(MessagePackReader reader)
}

MaterialHash = reader.Read<ulong>();
DrawPriorityOffset = reader.Read<uint>();
DrawPriorityOffset = reader.Read<int>();
Unknown7 = reader.Read<bool>();
Unknown8 = reader.Read<bool>();
LodNear = reader.Read<float>();
Expand Down
10 changes: 8 additions & 2 deletions Flagrum.Desktop/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Windows;
using System.Windows.Input;
using Flagrum.Web.Persistence;
using Flagrum.Web.Persistence.Configuration;
using Flagrum.Web.Persistence.Configuration.Entities;
using Flagrum.Web.Persistence.Entities;
using Flagrum.Web.Services;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -48,6 +50,10 @@ public App()
onAppUninstall: OnUninstall);

SetFileTypeAssociation();

// Migrate the configuration database if required
using var configuration = new ConfigurationDbContext();
configuration.Database.MigrateAsync().Wait();

// Migrate the database if required
Profile = new ProfileService();
Expand All @@ -62,8 +68,8 @@ public App()
var gamePath = context.GetString(StateKey.GamePath);
var binmodListPath = context.GetString(StateKey.BinmodListPath);

Profile.GamePath = gamePath;
Profile.BinmodListPath = binmodListPath;
Profile.Current.GamePath = gamePath;
Profile.Current.BinmodListPath = binmodListPath;

context.DeleteStateKey(StateKey.GamePath);
context.DeleteStateKey(StateKey.BinmodListPath);
Expand Down
9 changes: 5 additions & 4 deletions Flagrum.Desktop/Architecture/ViewportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ public class ViewportHelper
private readonly FlagrumDbContext _context;
private readonly MainViewModel _mainViewModel;
private ModelViewerTextureFidelity _fidelity;
private readonly ProfileService _profile;

public ViewportHelper(
MainViewModel mainViewModel)
public ViewportHelper(MainViewModel mainViewModel, ProfileService profileService)
{
_mainViewModel = mainViewModel;
_context = new FlagrumDbContext(new ProfileService());
_profile = profileService;
_context = new FlagrumDbContext(profileService);
}

public async Task ChangeModel(IAssetExplorerNode gmdlNode, AssetExplorerView view)
Expand Down Expand Up @@ -223,7 +224,7 @@ public async Task ChangeModel(IAssetExplorerNode gmdlNode, AssetExplorerView vie
var diffuse = GetDataByUri(diffuseUri, contextObject, view);
var normal = GetDataByUri(normalUri, contextObject, view);

var textureConverter = new TextureConverter(new ProfileService().Current.Type);
var textureConverter = new TextureConverter(_profile.Current.Type);

TextureModel? albedoMap = null;
TextureModel? normalMap = null;
Expand Down
4 changes: 2 additions & 2 deletions Flagrum.Desktop/Flagrum.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<ApplicationIcon>Resources\flagrum.ico</ApplicationIcon>
<DebugType>embedded</DebugType>
<AssemblyName>Flagrum</AssemblyName>
<AssemblyVersion>1.4.1</AssemblyVersion>
<FileVersion>1.4.1</FileVersion>
<AssemblyVersion>1.4.2</AssemblyVersion>
<FileVersion>1.4.2</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
25 changes: 16 additions & 9 deletions Flagrum.Desktop/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class MainViewModel : ObservableObject, IDisposable

public MainViewModel()
{
ViewportHelper = new ViewportHelper(this);
EffectsManager = new DefaultEffectsManager();
Camera = new PerspectiveCamera
{
Expand All @@ -54,20 +53,28 @@ public MainViewModel()
NearPlaneDistance = 0,
FarPlaneDistance = 10000
};
}

using var context = new FlagrumDbContext(new ProfileService());
public ProfileService ProfileService
{
set
{
using var context = new FlagrumDbContext(value);

var viewportRotateModifierKey = context.GetEnum<ModifierKeys>(StateKey.ViewportRotateModifierKey);
var viewportRotateMouseAction = context.GetEnum<MouseAction>(StateKey.ViewportRotateMouseAction);
_viewportRotateGesture = new MouseGesture(viewportRotateMouseAction, viewportRotateModifierKey);
var viewportRotateModifierKey = context.GetEnum<ModifierKeys>(StateKey.ViewportRotateModifierKey);
var viewportRotateMouseAction = context.GetEnum<MouseAction>(StateKey.ViewportRotateMouseAction);
_viewportRotateGesture = new MouseGesture(viewportRotateMouseAction, viewportRotateModifierKey);

var viewportPanModifierKey = context.GetEnum<ModifierKeys>(StateKey.ViewportPanModifierKey);
var viewportPanMouseAction = context.GetEnum<MouseAction>(StateKey.ViewportPanMouseAction);
_viewportPanGesture = new MouseGesture(viewportPanMouseAction, viewportPanModifierKey);
var viewportPanModifierKey = context.GetEnum<ModifierKeys>(StateKey.ViewportPanModifierKey);
var viewportPanMouseAction = context.GetEnum<MouseAction>(StateKey.ViewportPanMouseAction);
_viewportPanGesture = new MouseGesture(viewportPanMouseAction, viewportPanModifierKey);

ViewportHelper = new ViewportHelper(this, value);
}
}

public string HostPage => IOHelper.GetWebRoot() + "/index.html";
public ViewportHelper ViewportHelper { get; }
public ViewportHelper ViewportHelper { get; private set; }
public Viewport3DX Viewer { get; set; }
public AirspacePopup AirspacePopup { get; set; }
public string? FmodPath { get; set; }
Expand Down
1 change: 1 addition & 0 deletions Flagrum.Desktop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public MainWindow(ProfileService profileService, AppStateService appStateService
Closed += (_, _) => { (DataContext as IDisposable)?.Dispose(); };

((MainViewModel)DataContext).FmodPath = fmodPath;
((MainViewModel)DataContext).ProfileService = profileService;

try
{
Expand Down
51 changes: 31 additions & 20 deletions Flagrum.Web/Features/AssetExplorer/Base/ExplorerTreeRow.razor
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
@using Flagrum.Web.Features.AssetExplorer.Data
<div id="@Node.ElementId" @onclick="OnClick" class="row py-1 pr-2 transition-colors hover:bg-grey-700 select-none cursor-pointer @(AssetExplorer.FileList.CurrentNode.Path == Node.Path ? "bg-grey-800" : "")"
style="padding-left: @(Indent * 5)px">
@if (IsExpandable)
{
<span @onclick="Expand" @onclick:stopPropagation="true" @onclick:preventDefault="true"
class="material-icons text-sm">
@(Node.IsExpanded ? "expand_more" : "chevron_right")
</span>
}
else if (Node.Type == ExplorerItemType.Directory)
{
<div style="width: 14px;"></div>
}
else
{
<div style="width: 6px;"></div>
}
<span class="material-icons text-sm">@Node.Icon</span>
<span class="pl-2 flex-grow text-sm" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">@Node.Name</span>
</div>

<ContextMenuTrigger MenuId="assetExplorerMenu" @onmouseup="e => ContextMenuMouseUp(e, Node)">
<div id="@Node.ElementId" @onclick="OnClick" class="row py-1 pr-2 transition-colors hover:bg-grey-700 select-none cursor-pointer @(AssetExplorer.FileList.CurrentNode.Path == Node.Path ? "bg-grey-800" : "")"
style="padding-left: @(Indent * 5)px">
@if (IsExpandable)
{
<span @onclick="Expand" @onclick:stopPropagation="true" @onclick:preventDefault="true"
class="material-icons text-sm">
@(Node.IsExpanded ? "expand_more" : "chevron_right")
</span>
}
else if (Node.Type == ExplorerItemType.Directory)
{
<div style="width: 14px;"></div>
}
else
{
<div style="width: 6px;"></div>
}
<span class="material-icons text-sm">@Node.Icon</span>
<span class="pl-2 flex-grow text-sm" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">@Node.Name</span>
</div>
</ContextMenuTrigger>

@if (Node.IsExpanded)
{
Expand Down Expand Up @@ -53,4 +56,12 @@
Node.IsExpanded = !Node.IsExpanded;
StateHasChanged();
}

private void ContextMenuMouseUp(MouseEventArgs e, IAssetExplorerNode node)
{
if (e.Button == 2)
{
AssetExplorer.ContextNode = node;
}
}
}
12 changes: 1 addition & 11 deletions Flagrum.Web/Features/AssetExplorer/Base/ExplorerTreeView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

<CascadingValue Value="this">
<Virtualize Items="RootNode.Children.Where(n => n.Type == ExplorerItemType.Directory).ToList()" ItemSize="28" Context="node">
<ContextMenuTrigger MenuId="assetExplorerMenu" @onmouseup="e => ContextMenuMouseUp(e, node)">
<ExplorerTreeRow Node="node" Indent="2"/>
</ContextMenuTrigger>
<ExplorerTreeRow Node="node" Indent="2"/>
</Virtualize>
</CascadingValue>

Expand Down Expand Up @@ -67,12 +65,4 @@
}
}
}

private void ContextMenuMouseUp(MouseEventArgs e, IAssetExplorerNode node)
{
if (e.Button == 2)
{
AssetExplorer.ContextNode = node;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@
{
// Process high resolution textures
var highTexturePackUri = material.HighTexturePackAsset.Replace(".htpk", ".autoext");
var highMaterial = ProcessHighTextures(material, highTexturePackUri, textures, false);
var highMaterial = ProcessHighTextures(material, highTexturePackUri, texturesDirectory, textures, false);
if (highMaterial.Length > 0)
{
highMaterials.Add(highTexturePackUri, highMaterial);
}

// Attempt to process 4K texture pack
highTexturePackUri = highTexturePackUri.Insert(highTexturePackUri.LastIndexOf('.'), "2");
highMaterial = ProcessHighTextures(material, highTexturePackUri, highTextures, true);
highMaterial = ProcessHighTextures(material, highTexturePackUri, highImagesDirectory, highTextures, true);
if (highMaterial.Length > 0)
{
highMaterials.Add(highTexturePackUri, highMaterial);
Expand Down Expand Up @@ -188,7 +188,7 @@
});
}

private byte[] ProcessHighTextures(Material material, string highTexturePackUri, Dictionary<string, byte[]> textures, bool is4K)
private byte[] ProcessHighTextures(Material material, string highTexturePackUri, string directory, Dictionary<string, byte[]> textures, bool is4K)
{
byte[] highTexturePack = null;
if (Context.ArchiveExistsForUri(highTexturePackUri))
Expand Down Expand Up @@ -237,7 +237,7 @@

if (textureData.Length > 0)
{
new TextureConverter(Profile.Current.Type).ExportTexture(highTexture, (ImageFormat)Extension, textureData);
ConvertTexture(highTexture, directory, textureData);
textures.Add(highTexture, null);
}
}
Expand Down
22 changes: 21 additions & 1 deletion Flagrum.Web/Features/ModManager/ModCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@using Flagrum.Core.Archive
@using Flagrum.Core.Utilities.Types
@using Flagrum.Web.Features.ModManager.Data
@using Flagrum.Web.Features.ModManager.Modals
@inherits ModComponentBase

@inject NavigationManager Navigation
Expand Down Expand Up @@ -64,11 +65,15 @@
</div>

<AlertModal @ref="Alert"/>
<CascadingValue Value="this">
<CorruptionModal @ref="CorruptionModal"/>
</CascadingValue>

@code
{
private AlertModal Alert { get; set; }
private long Timestamp { get; set; }
private CorruptionModal CorruptionModal { get; set; }

[CascadingParameter]
public Index Parent { get; set; }
Expand Down Expand Up @@ -159,7 +164,20 @@
private async Task Disable()
{
await InvokeAsync(() => Parent.SetLoading(true, "DisablingMod"));
await Task.Run(async () => await ModManagerService.DisableMod(Mod.Id));

await Task.Run(() =>
{
try
{
ModManagerService.DisableMod(Mod.Id);
}
catch (Exception exception)
{
Logger.LogError(exception, "Failed to disable mod due to exception");
InvokeAsync(() => CorruptionModal.Open(Mod.Id));
}
});

await InvokeAsync(() => Parent.SetLoading(false));
}

Expand Down Expand Up @@ -229,4 +247,6 @@
{
Parent.ShowReadme(Mod.Readme);
}

public void CallModListStateHasChanged() => Parent.CallStateHasChanged();
}
Loading

0 comments on commit fde8b4d

Please sign in to comment.