Skip to content

Commit fe4a046

Browse files
committed
Make ChatWarningService part of the MessageService.
1 parent f0c034c commit fe4a046

File tree

4 files changed

+32
-69
lines changed

4 files changed

+32
-69
lines changed

Penumbra/Interop/Processing/ShpkPathPreProcessor.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@
44
using Penumbra.GameData.Files;
55
using Penumbra.GameData.Files.Utility;
66
using Penumbra.Interop.Hooks.ResourceLoading;
7+
using Penumbra.Mods.Manager;
8+
using Penumbra.Services;
79
using Penumbra.String;
810
using Penumbra.String.Classes;
9-
using Penumbra.UI;
1011

1112
namespace Penumbra.Interop.Processing;
1213

1314
/// <summary>
1415
/// Path pre-processor for shader packages that reverts redirects to known invalid files, as bad ShPks can crash the game.
1516
/// </summary>
16-
public sealed class ShpkPathPreProcessor(ResourceManagerService resourceManager, ChatWarningService chatWarningService) : IPathPreProcessor
17+
public sealed class ShpkPathPreProcessor(ResourceManagerService resourceManager, MessageService messager, ModManager modManager)
18+
: IPathPreProcessor
1719
{
1820
public ResourceType Type
1921
=> ResourceType.Shpk;
2022

21-
public unsafe FullPath? PreProcess(ResolveData resolveData, CiByteString path, Utf8GamePath originalGamePath, bool nonDefault, FullPath? resolved)
23+
public unsafe FullPath? PreProcess(ResolveData resolveData, CiByteString path, Utf8GamePath originalGamePath, bool nonDefault,
24+
FullPath? resolved)
2225
{
23-
chatWarningService.CleanLastFileWarnings(false);
26+
messager.CleanTaggedMessages(false);
2427

2528
if (!resolved.HasValue)
2629
return null;
@@ -31,16 +34,16 @@ public ResourceType Type
3134
return resolvedPath;
3235

3336
// If the ShPk is already loaded, it means that it already passed the sanity check.
34-
var existingResource = resourceManager.FindResource(ResourceCategory.Shader, ResourceType.Shpk, unchecked((uint)resolvedPath.InternalName.Crc32));
37+
var existingResource =
38+
resourceManager.FindResource(ResourceCategory.Shader, ResourceType.Shpk, unchecked((uint)resolvedPath.InternalName.Crc32));
3539
if (existingResource != null)
3640
return resolvedPath;
3741

3842
var checkResult = SanityCheck(resolvedPath.FullName);
3943
if (checkResult == SanityCheckResult.Success)
4044
return resolvedPath;
4145

42-
Penumbra.Log.Warning($"Refusing to honor file redirection because of failed sanity check (result: {checkResult}). Original path: {originalGamePath} Redirected path: {resolvedPath}");
43-
chatWarningService.PrintFileWarning(resolvedPath.FullName, originalGamePath, WarningMessageComplement(checkResult));
46+
messager.PrintFileWarning(modManager, resolvedPath.FullName, originalGamePath, WarningMessageComplement(checkResult));
4447

4548
return null;
4649
}
@@ -49,8 +52,8 @@ private static SanityCheckResult SanityCheck(string path)
4952
{
5053
try
5154
{
52-
using var file = MmioMemoryManager.CreateFromFile(path);
53-
var bytes = file.GetSpan();
55+
using var file = MmioMemoryManager.CreateFromFile(path);
56+
var bytes = file.GetSpan();
5457

5558
return ShpkFile.FastIsLegacy(bytes)
5659
? SanityCheckResult.Legacy
@@ -69,9 +72,9 @@ private static SanityCheckResult SanityCheck(string path)
6972
private static string WarningMessageComplement(SanityCheckResult result)
7073
=> result switch
7174
{
72-
SanityCheckResult.IoError => "cannot read the modded file.",
73-
SanityCheckResult.NotFound => "the modded file does not exist.",
74-
SanityCheckResult.Legacy => "this mod is not compatible with Dawntrail. Get an updated version, if possible, or disable it.",
75+
SanityCheckResult.IoError => "Cannot read the modded file.",
76+
SanityCheckResult.NotFound => "The modded file does not exist.",
77+
SanityCheckResult.Legacy => "This mod is not compatible with Dawntrail. Get an updated version, if possible, or disable it.",
7578
_ => string.Empty,
7679
};
7780

Penumbra/Services/MessageService.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
using Dalamud.Game.Text.SeStringHandling;
33
using Dalamud.Game.Text.SeStringHandling.Payloads;
44
using Dalamud.Interface;
5+
using Dalamud.Interface.ImGuiNotification;
56
using Dalamud.Plugin.Services;
67
using Lumina.Excel.GeneratedSheets;
78
using OtterGui.Log;
89
using OtterGui.Services;
10+
using Penumbra.Mods.Manager;
11+
using Penumbra.String.Classes;
12+
using Notification = OtterGui.Classes.Notification;
913

1014
namespace Penumbra.Services;
1115

@@ -38,4 +42,16 @@ public void LinkItem(Item item)
3842
Message = payload,
3943
});
4044
}
45+
46+
public void PrintFileWarning(ModManager modManager, string fullPath, Utf8GamePath originalGamePath, string messageComplement)
47+
{
48+
// Don't warn for files managed by other plugins, or files we aren't sure about.
49+
if (!modManager.TryIdentifyPath(fullPath, out var mod, out _))
50+
return;
51+
52+
AddTaggedMessage($"{fullPath}.{messageComplement}",
53+
new Notification(
54+
$"Cowardly refusing to load replacement for {originalGamePath.Filename().ToString().ToLowerInvariant()} by {mod.Name}{(messageComplement.Length > 0 ? ":\n" : ".")}{messageComplement}",
55+
NotificationType.Warning, 10000));
56+
}
4157
}

Penumbra/UI/ChatWarningService.cs

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)