Skip to content

Commit

Permalink
Some stashed changes already applied.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottermandias committed Nov 21, 2024
1 parent f2bdaf1 commit ee48ea0
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 23 deletions.
1 change: 1 addition & 0 deletions Penumbra/Collections/ModCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public string AnonymizedName
public int ChangeCounter { get; private set; }

public uint ImcChangeCounter { get; set; }
public uint AtchChangeCounter { get; set; }

/// <summary> Increment the number of changes in the effective file list. </summary>
public int IncrementCounter()
Expand Down
8 changes: 4 additions & 4 deletions Penumbra/Interop/Hooks/ResourceLoading/ResourceLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ public unsafe class ResourceLoader : IDisposable, IService
{
private readonly ResourceService _resources;
private readonly FileReadService _fileReadService;
private readonly TexMdlScdService _texMdlScdService;
private readonly RsfService _rsfService;
private readonly PapHandler _papHandler;
private readonly Configuration _config;

private ResolveData _resolvedData = ResolveData.Invalid;
public event Action<Utf8GamePath, FullPath?, ResolveData>? PapRequested;

public ResourceLoader(ResourceService resources, FileReadService fileReadService, TexMdlScdService texMdlScdService, Configuration config)
public ResourceLoader(ResourceService resources, FileReadService fileReadService, RsfService rsfService, Configuration config)
{
_resources = resources;
_fileReadService = fileReadService;
_texMdlScdService = texMdlScdService;
_rsfService = rsfService;
_config = config;
ResetResolvePath();

Expand Down Expand Up @@ -140,7 +140,7 @@ private void ResourceHandler(ref ResourceCategory category, ref ResourceType typ
return;
}

_texMdlScdService.AddCrc(type, resolvedPath);
_rsfService.AddCrc(type, resolvedPath);
// Replace the hash and path with the correct one for the replacement.
hash = ComputeHash(resolvedPath.Value.InternalName, parameters);
var oldPath = path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Penumbra.Interop.Hooks.ResourceLoading;

public unsafe class TexMdlScdService : IDisposable, IRequiredService
public unsafe class RsfService : IDisposable, IRequiredService
{
/// <summary>
/// We need to be able to obtain the requested LoD level.
Expand Down Expand Up @@ -43,7 +43,7 @@ public byte GetLod(TextureResourceHandle* handle)

private readonly LodService _lodService;

public TexMdlScdService(IGameInteropProvider interop)
public RsfService(IGameInteropProvider interop)
{
interop.InitializeFromAttributes(this);
_lodService = new LodService(interop);
Expand Down
5 changes: 5 additions & 0 deletions Penumbra/Interop/PathResolving/PathDataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public static FullPath CreateTmb(CiByteString path, ModCollection collection)
public static FullPath CreateAvfx(CiByteString path, ModCollection collection)
=> CreateBase(path, collection);

/// <summary> Create the encoding path for an ATCH file. </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static FullPath CreateAtch(CiByteString path, ModCollection collection)
=> new($"|{collection.LocalId.Id}_{collection.AtchChangeCounter}_{DiscriminatorString}|{path}");

/// <summary> Create the encoding path for a MTRL file. </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static FullPath CreateMtrl(CiByteString path, ModCollection collection, Utf8GamePath originalPath)
Expand Down
3 changes: 2 additions & 1 deletion Penumbra/Interop/Processing/ImcFilePostProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Dalamud.Game.ClientState.JobGauge.Types;
using Penumbra.Api.Enums;
using Penumbra.Collections.Manager;
using Penumbra.Interop.PathResolving;
Expand All @@ -24,7 +25,7 @@ public unsafe void PostProcess(ResourceHandle* resource, CiByteString originalGa
return;

file.Replace(resource);
Penumbra.Log.Information(
Penumbra.Log.Verbose(
$"[ResourceLoader] Loaded {originalGamePath} from file and replaced with IMC from collection {collection.AnonymizedName}.");
}
}
14 changes: 11 additions & 3 deletions Penumbra/UI/ResourceWatcher/Record.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Penumbra.Enums;
using Penumbra.Interop.Structs;
using Penumbra.String;
using Penumbra.String.Classes;

namespace Penumbra.UI.ResourceWatcher;

Expand All @@ -24,14 +25,16 @@ internal unsafe struct Record
public ModCollection? Collection;
public ResourceHandle* Handle;
public ResourceTypeFlag ResourceType;
public ResourceCategoryFlag Category;
public ulong Crc64;
public uint RefCount;
public ResourceCategoryFlag Category;
public RecordType RecordType;
public OptionalBool Synchronously;
public OptionalBool ReturnValue;
public OptionalBool CustomLoad;
public LoadState LoadState;


public static Record CreateRequest(CiByteString path, bool sync)
=> new()
{
Expand All @@ -49,6 +52,7 @@ public static Record CreateRequest(CiByteString path, bool sync)
CustomLoad = OptionalBool.Null,
AssociatedGameObject = string.Empty,
LoadState = LoadState.None,
Crc64 = 0,
};

public static Record CreateDefaultLoad(CiByteString path, ResourceHandle* handle, ModCollection collection, string associatedGameObject)
Expand All @@ -70,15 +74,16 @@ public static Record CreateDefaultLoad(CiByteString path, ResourceHandle* handle
CustomLoad = false,
AssociatedGameObject = associatedGameObject,
LoadState = handle->LoadState,
Crc64 = 0,
};
}

public static Record CreateLoad(CiByteString path, CiByteString originalPath, ResourceHandle* handle, ModCollection collection,
public static Record CreateLoad(FullPath path, CiByteString originalPath, ResourceHandle* handle, ModCollection collection,
string associatedGameObject)
=> new()
{
Time = DateTime.UtcNow,
Path = path.IsOwned ? path : path.Clone(),
Path = path.InternalName.IsOwned ? path.InternalName : path.InternalName.Clone(),
OriginalPath = originalPath.IsOwned ? originalPath : originalPath.Clone(),
Collection = collection,
Handle = handle,
Expand All @@ -91,6 +96,7 @@ public static Record CreateLoad(CiByteString path, CiByteString originalPath, Re
CustomLoad = true,
AssociatedGameObject = associatedGameObject,
LoadState = handle->LoadState,
Crc64 = path.Crc64,
};

public static Record CreateDestruction(ResourceHandle* handle)
Expand All @@ -112,6 +118,7 @@ public static Record CreateDestruction(ResourceHandle* handle)
CustomLoad = OptionalBool.Null,
AssociatedGameObject = string.Empty,
LoadState = handle->LoadState,
Crc64 = 0,
};
}

Expand All @@ -132,5 +139,6 @@ public static Record CreateFileLoad(CiByteString path, ResourceHandle* handle, b
CustomLoad = custom,
AssociatedGameObject = string.Empty,
LoadState = handle->LoadState,
Crc64 = 0,
};
}
2 changes: 1 addition & 1 deletion Penumbra/UI/ResourceWatcher/ResourceWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private unsafe void OnResourceLoaded(ResourceHandle* handle, Utf8GamePath path,

var record = manipulatedPath == null
? Record.CreateDefaultLoad(path.Path, handle, data.ModCollection, Name(data))
: Record.CreateLoad(manipulatedPath.Value.InternalName, path.Path, handle, data.ModCollection, Name(data));
: Record.CreateLoad(manipulatedPath.Value, path.Path, handle, data.ModCollection, Name(data));
if (!_ephemeral.OnlyAddMatchingResources || _table.WouldBeVisible(record))
_newRecords.Enqueue(record);
}
Expand Down
18 changes: 17 additions & 1 deletion Penumbra/UI/ResourceWatcher/ResourceWatcherTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public ResourceWatcherTable(EphemeralConfig config, IReadOnlyCollection<Record>
new HandleColumn { Label = "Resource" },
new LoadStateColumn { Label = "State" },
new RefCountColumn { Label = "#Ref" },
new DateColumn { Label = "Time" }
new DateColumn { Label = "Time" },
new Crc64Column { Label = "Crc64" }
)
{ }

Expand Down Expand Up @@ -144,6 +145,21 @@ public override void DrawColumn(Record item, int _)
=> ImGui.TextUnformatted($"{item.Time.ToLongTimeString()}.{item.Time.Millisecond:D4}");
}

private sealed class Crc64Column : ColumnString<Record>
{
public override float Width
=> UiBuilder.MonoFont.GetCharAdvance('0') * 17;

public override unsafe string ToName(Record item)
=> item.Crc64 != 0 ? $"{item.Crc64:X16}" : string.Empty;

public override unsafe void DrawColumn(Record item, int _)
{
using var font = ImRaii.PushFont(UiBuilder.MonoFont, item.Handle != null);
ImUtf8.Text(ToName(item));
}
}


private sealed class CollectionColumn : ColumnString<Record>
{
Expand Down
15 changes: 8 additions & 7 deletions Penumbra/UI/Tabs/Debug/AtchDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OtterGui;
using OtterGui.Text;
using Penumbra.GameData.Files;
using Penumbra.GameData.Files.AtchStructs;

namespace Penumbra.UI.Tabs.Debug;

Expand All @@ -18,27 +19,27 @@ public static void Draw(AtchFile file)
ImGui.SameLine();
using (ImUtf8.Group())
{
ImUtf8.Text($"{file.Entries.Count}");
if (file.Entries.Count == 0)
ImUtf8.Text($"{file.Points.Count}");
if (file.Points.Count == 0)
{
ImUtf8.Text("0"u8);
return;
}

ImUtf8.Text($"{file.Entries[0].States.Count}");
ImUtf8.Text($"{file.Points[0].Entries.Length}");
}

foreach (var (entry, index) in file.Entries.WithIndex())
foreach (var (entry, index) in file.Points.WithIndex())
{
using var id = ImUtf8.PushId(index);
using var tree = ImUtf8.TreeNode($"{index:D3}: {entry.Name.Span}");
using var tree = ImUtf8.TreeNode($"{index:D3}: {entry.Type.ToName()}");
if (tree)
{
ImUtf8.TreeNode(entry.Accessory ? "Accessory"u8 : "Weapon"u8, ImGuiTreeNodeFlags.Bullet | ImGuiTreeNodeFlags.Leaf).Dispose();
foreach (var (state, i) in entry.States.WithIndex())
foreach (var (state, i) in entry.Entries.WithIndex())
{
id.Push(i);
using var t = ImUtf8.TreeNode(state.Bone.Span);
using var t = ImUtf8.TreeNode(state.Bone);
if (t)
{
ImUtf8.TreeNode($"Scale: {state.Scale}", ImGuiTreeNodeFlags.Bullet | ImGuiTreeNodeFlags.Leaf).Dispose();
Expand Down
8 changes: 4 additions & 4 deletions Penumbra/UI/Tabs/Debug/DebugTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class DebugTab : Window, ITab, IUiService
private readonly CrashHandlerPanel _crashHandlerPanel;
private readonly TexHeaderDrawer _texHeaderDrawer;
private readonly HookOverrideDrawer _hookOverrides;
private readonly TexMdlScdService _texMdlScdService;
private readonly RsfService _rsfService;

public DebugTab(PerformanceTracker performance, Configuration config, CollectionManager collectionManager, ObjectManager objects,
IClientState clientState, IDataManager dataManager,
Expand All @@ -115,7 +115,7 @@ public DebugTab(PerformanceTracker performance, Configuration config, Collection
CutsceneService cutsceneService, ModImportManager modImporter, ImportPopup importPopup, FrameworkManager framework,
TextureManager textureManager, ShaderReplacementFixer shaderReplacementFixer, RedrawService redraws, DictEmote emotes,
Diagnostics diagnostics, IpcTester ipcTester, CrashHandlerPanel crashHandlerPanel, TexHeaderDrawer texHeaderDrawer,
HookOverrideDrawer hookOverrides, TexMdlScdService texMdlScdService)
HookOverrideDrawer hookOverrides, RsfService rsfService)
: base("Penumbra Debug Window", ImGuiWindowFlags.NoCollapse)
{
IsOpen = true;
Expand Down Expand Up @@ -153,7 +153,7 @@ public DebugTab(PerformanceTracker performance, Configuration config, Collection
_crashHandlerPanel = crashHandlerPanel;
_texHeaderDrawer = texHeaderDrawer;
_hookOverrides = hookOverrides;
_texMdlScdService = texMdlScdService;
_rsfService = rsfService;
_objects = objects;
_clientState = clientState;
_dataManager = dataManager;
Expand Down Expand Up @@ -1087,7 +1087,7 @@ private unsafe void DrawCrcCache()
ImUtf8.TableSetupColumn("Type"u8, ImGuiTableColumnFlags.WidthFixed, 5 * UiBuilder.MonoFont.GetCharAdvance('0'));
ImGui.TableHeadersRow();

foreach (var (hash, type) in _texMdlScdService.CustomCache)
foreach (var (hash, type) in _rsfService.CustomCache)
{
ImGui.TableNextColumn();
ImUtf8.Text($"{hash:X16}");
Expand Down

0 comments on commit ee48ea0

Please sign in to comment.