Skip to content

Commit a8dd32d

Browse files
committed
Big changes to the handling of messages and the levels of information. Added a feature to outright quiet message boxes and now takes into account Nutaku store directory movements.
1 parent db11934 commit a8dd32d

7 files changed

Lines changed: 133 additions & 64 deletions

File tree

ExtendedErrorHandling/ErrorTexturePlaceholder.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ internal static class ErrorTexturePlaceholder
1313
internal static Dictionary<string, string> RawImages;
1414

1515
private const string MissingTex =
16-
"iVBORw0KGgoAAAANSUhEUgAAAfQAAAH0BAMAAAA5+MK5AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv" +
17-
"8YQUAAAAwUExURQAAAP8A3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAI" +
18-
"/r1v0AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAJ3SURBVHja7c8xEQAgAMQwLODfLIeNbzp1zbm/86sdO" +
19-
"jo6Ojo6+hC97kdHR0dHR0efuKY6CUZHR0dHR1+m1/3o6Ojo6OjoE9dUJ8Ho6Ojo6OjL9LofHR0dHR0d" +
20-
"feKa6iQYHR0dHR19mV73o6Ojo6Ojo09cU50Eo6Ojo6OjL9PrfnR0dHR0dPSJa6qTYHR0dHR09GV63Y+" +
21-
"Ojo6Ojo4+cU11EoyOjo6Ojr5Mr/vR0dHR0dHRJ66pToLR0dHR0dGX6XU/Ojo6Ojo6+sQ11UkwOjo6Oj" +
22-
"r6Mr3uR0dHR0dHR5+4pjoJRkdHR0dHX6bX/ejo6Ojo6OgT11Qnwejo6Ojo6Mv0uh8dHR0dHR194prqJ" +
23-
"BgdHR0dHX2ZXvejo6Ojo6OjT1xTnQSjo6Ojo6Mv0+t+dHR0dHR09IlrqpNgdHR0dHT0ZXrdj46Ojo6O" +
24-
"jj5xTXUSjI6Ojo6Ovkyv+9HR0dHR0dEnrqlOgtHR0dHR0ZfpdT86Ojo6Ojr6xDXVSTA6Oj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jT1xTnQSjo6Ojo6Mv0+t+dHR0dHR09IlrqpNgdHR0dHT0ZXrdj46Ojo6O" +
24+
"jj5xTXUSjI6Ojo6Ovkyv+9HR0dHR0dEnrqlOgtHR0dHR0ZfpdT86Ojo6Ojr6xDXVSTA6Ojo6Ovoyve5" +
25+
"HR0dHR0dHn7imOglGR0dHR0dfptf96Ojo6Ojo6BPXVCfB6Ojo6Ojoy/S6Hx0dHR0dHX3imuokGB0dHR" +
26+
"0dfZle96Ojo6Ojo6NPXFOdBKOjo6Ojoy/T6350dHR0dHT0iWuqk2B0dHR0dPRlet2Pjo6Ojo6OPnFNd" +
27+
"RKMjo6Ojo6+TK/70dHR0dHR0SeuqU6C0dHR0dHRl+l1Pzo6Ojo6OvrENdVJMDo6Ojo6+jK97kdHR0dH" +
28+
"R0efuKY6CUZHR0dHR1+m1/3o6Ojo6OjoE9dUJ8Ho6Ojo6OjL9LofHR0dHR0dfeKa6iQYHR0dHR19mV7" +
29+
"3o6Ojb9+9DzgHN1XYvWlQAAAAAElFTkSuQmCC";
3030

3131
private static readonly TextureResource MissingTextureResource = new TextureResource(1, 1, TextureFormat.ARGB32, new Rect[0], Convert.FromBase64String(MissingTex));
3232

33-
[HarmonyPatch(typeof(ImportCM), "LoadTexture")]
33+
[HarmonyPatch(typeof(ImportCM), nameof(ImportCM.LoadTexture))]
3434
[HarmonyFinalizer]
3535
public static void HandleTextureFail(ref Exception __exception, ref TextureResource __result, string f_strFileName)
3636
{
@@ -68,15 +68,17 @@ public static void HandleTextureFail(ref Exception __exception, ref TextureResou
6868
if (__result == null)
6969
{
7070
ExtendedErrorHandling.PluginLogger.LogWarning($"[ImportCM.LoadTexture] Failed to load texture `{f_strFileName}`: ({__exception.GetType()}) {__exception.Message}");
71-
CornerMessage.DisplayMessage($"[fffd7a]Checkered Texture: Couldn't load {f_strFileName}[-]");
71+
CornerMessage.DisplayMessage(ExtendedErrorHandling.VerboseCornerMessages.Value
72+
? $"[f708e0]Texture load failed: {f_strFileName}![-]"
73+
: "[f708e0]Failed to load texture! See console...[-]");
7274

7375
__result = MissingTextureResource;
7476
}
7577

7678
__exception = null;
7779
}
7880

79-
[HarmonyPatch(typeof(ImportCM), "LoadTexture")]
81+
[HarmonyPatch(typeof(ImportCM), nameof(ImportCM.LoadTexture))]
8082
[HarmonyTranspiler]
8183
public static IEnumerable<CodeInstruction> CleanUpLoadFailMessages(IEnumerable<CodeInstruction> instructions)
8284
{

ExtendedErrorHandling/ExtendedErrorHandling.cs

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,72 +12,102 @@
1212

1313
namespace ExtendedErrorHandling
1414
{
15-
[BepInPlugin("ExtendedErrorHandling", "ExtendedErrorHandling", "1.6.1")]
15+
[BepInPlugin("ExtendedErrorHandling", "ExtendedErrorHandling", "1.7")]
1616
[BepInDependency("COM3D2.CornerMessage", BepInDependency.DependencyFlags.SoftDependency)]
1717
public class ExtendedErrorHandling : BaseUnityPlugin
1818
{
1919
internal static ExtendedErrorHandling Instance;
2020
internal static ManualLogSource PluginLogger => Instance.Logger;
21+
22+
internal static ConfigEntry<MessageBoxHandling> ConvertMessageBoxToCornerMessage;
23+
internal static ConfigEntry<bool> VerboseCornerMessages;
2124
internal static ConfigEntry<bool> LoadRawPng;
2225

2326
[UsedImplicitly]
2427
private void Awake()
2528
{
2629
Instance = this;
2730

28-
LoadRawPng = Config.Bind("General", "Load Raw Images (Experimental)", false, "When a .tex file can't be found, it will instead attempt to find a png file of the same name and load it in place. Not suggested, can increase memory usage.");
31+
ConvertMessageBoxToCornerMessage = Config.Bind("General", "Error Message Box Behavior",
32+
MessageBoxHandling.Default,
33+
"When the game encounters an error it considers fatal, it'll display a message box. Some users find this intrusive, this allows you to change the behavior.");
34+
VerboseCornerMessages = Config.Bind("General", "Verbose Corner Messages", false,
35+
"Corner messages will display more useful and complete information.");
2936

30-
CreateMissingFolders();
37+
LoadRawPng = Config.Bind("Extra", "Load Raw Images (Experimental)", false,
38+
"When a .tex file can't be found, it will instead attempt to find a png file of the same name and load it in place. Not suggested, can increase memory usage.");
3139

32-
CornerMessage.CornerMessageLoaded = BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey("COM3D2.CornerMessage");
40+
CornerMessage.CornerMessageLoaded =
41+
BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey("COM3D2.CornerMessage");
3342

43+
Harmony.CreateAndPatchAll(typeof(ExtendedErrorHandling));
3444
Harmony.CreateAndPatchAll(typeof(MenuItemRedundancy));
3545
Harmony.CreateAndPatchAll(typeof(PresetErrorHandling));
3646
Harmony.CreateAndPatchAll(typeof(Serialization));
3747
Harmony.CreateAndPatchAll(typeof(ErrorTexturePlaceholder));
48+
Harmony.CreateAndPatchAll(typeof(NDebugMod));
49+
50+
UnityEngine.SceneManagement.SceneManager.sceneLoaded += NDebugMod.DoOnTitleScreen;
51+
}
3852

39-
UnityEngine.SceneManagement.SceneManager.sceneLoaded += MenuItemRedundancy.DoOnTitleScreen;
53+
[HarmonyPatch(typeof(GameMain), nameof(GameMain.OnInitialize))]
54+
[HarmonyPostfix]
55+
private static void AfterOnInit()
56+
{
57+
CreateMissingFolders();
4058
}
4159

4260
public static void CreateMissingFolders()
4361
{
44-
var dirs = new[] { "Mod", "SaveData", "Preset", "MyRoom", "PhotoModeData", "ScreenShot", "Thumb" };
62+
TryCreateDirectory(Path.Combine(Paths.GameRootPath, "Mod"));
63+
64+
var dirs = new[] { "SaveData", "Preset", "MyRoom", "PhotoModeData", "ScreenShot", "Thumb" };
4565

4666
foreach (var s in dirs)
4767
{
48-
if (Directory.Exists(Paths.GameRootPath + $"\\{s}"))
68+
var dir = Path.Combine(GameMain.Instance.SerializeStorageManager.StoreDirectoryPath, s);
69+
TryCreateDirectory(dir);
70+
}
71+
72+
return;
73+
74+
void TryCreateDirectory(string s)
75+
{
76+
if (Directory.Exists(s))
4977
{
50-
continue;
78+
return;
5179
}
5280

5381
try
5482
{
55-
Directory.CreateDirectory(Paths.GameRootPath + $"\\{s}");
83+
Directory.CreateDirectory(s);
5684
}
5785
catch
5886
{
59-
PluginLogger.LogFatal($"We couldn't create the directory {Paths.GameRootPath}\\{s}. Please create it manually or you will have errors.");
87+
PluginLogger.LogFatal(
88+
$"We couldn't create the directory {s}. Please create it manually or you will have errors.");
6089
}
6190
}
6291
}
63-
}
64-
65-
//Classes for optional CornerMessage support. The segmentation of classes should prevent the TypeLoadException error when the dll isn't loaded.
66-
internal static class CornerMessage
67-
{
68-
internal static bool CornerMessageLoaded;
6992

70-
internal static void DisplayMessage(string mess, float dur = 6f)
93+
//Classes for optional CornerMessage support. The segmentation of classes should prevent the TypeLoadException error when the dll isn't loaded.
94+
internal static class CornerMessage
7195
{
72-
if (CornerMessageLoaded)
96+
internal static bool CornerMessageLoaded;
97+
98+
internal static void DisplayMessage(string mess, float dur = 6f)
7399
{
74-
TryCornerMessage.DisplayMessage(mess, dur);
100+
if (CornerMessageLoaded)
101+
{
102+
TryCornerMessage.DisplayMessage(mess, dur);
103+
}
75104
}
76-
}
77105

78-
internal static class TryCornerMessage
79-
{
80-
internal static void DisplayMessage(string mess, float dur) => COM3D2.CornerMessage.CornerMessage.DisplayMessage(mess, dur);
106+
internal static class TryCornerMessage
107+
{
108+
internal static void DisplayMessage(string mess, float dur) =>
109+
COM3D2.CornerMessage.CornerMessage.DisplayMessage(mess, dur);
110+
}
81111
}
82112
}
83113
}

ExtendedErrorHandling/ExtendedErrorHandling.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<Compile Include="ErrorTexturePlaceholder.cs" />
8282
<Compile Include="ExtendedErrorHandling.cs" />
8383
<Compile Include="MenuItemRedundancy.cs" />
84+
<Compile Include="NDebugMod.cs" />
8485
<Compile Include="PresetErrorHandling.cs" />
8586
<Compile Include="Properties\AssemblyInfo.cs" />
8687
<Compile Include="Serialization.cs" />

ExtendedErrorHandling/MenuItemRedundancy.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
using HarmonyLib;
22
using System;
3-
using UnityEngine.SceneManagement;
43

54
namespace ExtendedErrorHandling
65
{
76
internal static class MenuItemRedundancy
87
{
9-
//Awake is carried out before the game has even had time to load anything but the assembly. As a result, setting QuitWhenAssert false on awake has it being reverted moments later. Had to delay our own set.
10-
internal static void DoOnTitleScreen(Scene s, LoadSceneMode load)
11-
{
12-
if (!s.name.Equals("SceneTitle"))
13-
{
14-
return;
15-
}
16-
17-
NDebug.m_bQuitWhenAssert = false;
18-
SceneManager.sceneLoaded -= DoOnTitleScreen;
19-
}
20-
21-
[HarmonyPatch(typeof(Maid), "ProcItem")]
8+
[HarmonyPatch(typeof(Maid), nameof(Maid.ProcItem))]
229
[HarmonyPrefix]
2310
internal static void ErrorHandleMissingMenus(ref MaidProp __0)
2411
{
@@ -47,7 +34,7 @@ internal static void ErrorHandleMissingMenus(ref MaidProp __0)
4734
}
4835
}
4936

50-
[HarmonyPatch(typeof(Menu), "ProcScriptBin", typeof(Maid), typeof(byte[]), typeof(MaidProp), typeof(bool), typeof(SubProp))]
37+
[HarmonyPatch(typeof(Menu), nameof(Menu.ProcScriptBin), typeof(Maid), typeof(byte[]), typeof(MaidProp), typeof(bool), typeof(SubProp))]
5138
[HarmonyFinalizer]
5239
internal static Exception MaidPropErrorFix(Exception __exception, MaidProp mp)
5340
{
@@ -57,14 +44,17 @@ internal static Exception MaidPropErrorFix(Exception __exception, MaidProp mp)
5744
}
5845

5946
ExtendedErrorHandling.PluginLogger.LogError($"There was an exception while trying to read {mp.strFileName}");
60-
CornerMessage.DisplayMessage($"[ff4e33]Couldn't read {mp.strFileName}[-]");
47+
48+
CornerMessage.DisplayMessage(ExtendedErrorHandling.VerboseCornerMessages.Value
49+
? $"[ff4e33]Menu read failed: {mp.strFileName}.[-]"
50+
: "[ff4e33]Failed to read menu![-]");
6151

6252
return null;
6353
}
6454

65-
[HarmonyPatch(typeof(TBody), "MulTexSet")]
55+
[HarmonyPatch(typeof(TBody), nameof(TBody.MulTexSet))]
6656
[HarmonyPrefix]
67-
internal static void TattooLayerFixer(ref TBody __instance, ref string __0, ref int __3, string __4, SubProp f_SubProp)
57+
internal static void TattooLayerFixer(ref string __0, ref int __3, SubProp f_SubProp)
6858
{
6959
if (f_SubProp == null)
7060
{

ExtendedErrorHandling/NDebugMod.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using HarmonyLib;
2+
using UnityEngine.SceneManagement;
3+
4+
namespace ExtendedErrorHandling
5+
{
6+
public enum MessageBoxHandling
7+
{
8+
Default = 0,
9+
Disable = 1,
10+
NotifyInCorner = 2
11+
}
12+
public static class NDebugMod
13+
{
14+
//Awake is carried out before the game has even had time to load anything but the assembly. As a result, setting QuitWhenAssert false on awake has it being reverted moments later. Had to delay our own set.
15+
internal static void DoOnTitleScreen(Scene s, LoadSceneMode load)
16+
{
17+
if (!s.name.Equals("SceneTitle"))
18+
{
19+
return;
20+
}
21+
22+
NDebug.m_bQuitWhenAssert = false;
23+
SceneManager.sceneLoaded -= DoOnTitleScreen;
24+
}
25+
26+
[HarmonyPatch(typeof(NDebug), nameof(NDebug.MessageBox))]
27+
[HarmonyPrefix]
28+
public static bool MessageBoxToCorner(ref string f_strTitle, ref string f_strMsg)
29+
{
30+
switch (ExtendedErrorHandling.ConvertMessageBoxToCornerMessage.Value)
31+
{
32+
case MessageBoxHandling.Disable:
33+
return false;
34+
case MessageBoxHandling.NotifyInCorner when CornerMessage.CornerMessageLoaded:
35+
CornerMessage.DisplayMessage($"[ff4e33]{f_strTitle}: Check console...[-]");
36+
return false;
37+
case MessageBoxHandling.Default:
38+
default:
39+
return true;
40+
}
41+
}
42+
}
43+
}

ExtendedErrorHandling/PresetErrorHandling.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ExtendedErrorHandling
77
{
88
internal static class PresetErrorHandling
99
{
10-
[HarmonyPatch(typeof(CharacterMgr), "PresetLoad", typeof(BinaryReader), typeof(string))]
10+
[HarmonyPatch(typeof(CharacterMgr), nameof(CharacterMgr.PresetLoad), typeof(BinaryReader), typeof(string))]
1111
[HarmonyFinalizer]
1212
internal static Exception PresetLoadErrorFix(Exception __exception, string __1)
1313
{
@@ -17,13 +17,16 @@ internal static Exception PresetLoadErrorFix(Exception __exception, string __1)
1717
}
1818

1919
ExtendedErrorHandling.PluginLogger.LogError($"{__1} could not be loaded!!");
20-
CornerMessage.DisplayMessage($"[ff4e33]Preset Not Loaded: {__1}[-]");
20+
CornerMessage.DisplayMessage(ExtendedErrorHandling.VerboseCornerMessages.Value
21+
? $"[ff4e33]Preset load failed: {__1}[-]"
22+
: "[ff4e33]A preset failed to load...[-]");
23+
2124

2225
return null;
2326
}
2427

2528
//previous code is commented, it seemed to be pointless when a quick linq does the same.
26-
[HarmonyPatch(typeof(CharacterMgr), "PresetListLoad")]
29+
[HarmonyPatch(typeof(CharacterMgr), nameof(CharacterMgr.PresetListLoad))]
2730
[HarmonyPostfix]
2831
internal static void PresetListCleaner(ref List<CharacterMgr.Preset> __result)
2932
{

ExtendedErrorHandling/Serialization.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ExtendedErrorHandling
77
{
88
internal static class Serialization
99
{
10-
[HarmonyPatch(typeof(Maid), "GetProp", typeof(string))]
10+
[HarmonyPatch(typeof(Maid), nameof(Maid.GetProp), typeof(string))]
1111
[HarmonyPrefix]
1212
public static void GetPropStringFix(Maid __instance, ref string __0)
1313
{
@@ -17,14 +17,14 @@ public static void GetPropStringFix(Maid __instance, ref string __0)
1717
}
1818
}
1919

20-
[HarmonyPatch(typeof(CM3), "Init")]
20+
[HarmonyPatch(typeof(CM3), nameof(CM3.Init))]
2121
[HarmonyPrefix]
2222
public static void CM_dic_fix()
2323
{
2424
CM3.dicDelItem[MPN.null_mpn] = string.Empty;
2525
}
2626

27-
[HarmonyPatch(typeof(MaidProp), "Deserialize")]
27+
[HarmonyPatch(typeof(MaidProp), nameof(MaidProp.Deserialize))]
2828
[HarmonyTranspiler]
2929
public static IEnumerable<CodeInstruction> MaidPropDesFix(IEnumerable<CodeInstruction> instructions)
3030
{

0 commit comments

Comments
 (0)