-
Notifications
You must be signed in to change notification settings - Fork 0
/
PortraiturePlusFix.cs
58 lines (54 loc) · 2.07 KB
/
PortraiturePlusFix.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using HarmonyLib;
using Microsoft.Xna.Framework.Graphics;
using Portraiture;
using StardewModdingAPI;
using StardewValley;
using System.Reflection;
namespace PortraiturePlus
{
internal class PortraiturePlusFix
{
private static IMonitor _monitor = null!;
internal static void Initialize(IMonitor monitor)
{
_monitor = monitor;
}
internal static MethodInfo GetPortrait()
{
return AccessTools.Method("TextureLoader:getPortrait", new[]
{
typeof(NPC), typeof(Texture2D)
});
}
internal static MethodInfo LoadAllPortraits()
{
return AccessTools.Method("TextureLoader:loadAllPortraits");
}
internal static void loadAllPortraits_Postfix()
{
var folders = Traverse.Create(typeof(PortraitureMod).Assembly.GetType("Portraiture.TextureLoader")).Field<List<string>>("folders").Value;
var pTextures = Traverse.Create(typeof(PortraitureMod).Assembly.GetType("Portraiture.TextureLoader")).Field<Dictionary<string, Texture2D>>("pTextures").Value;
PortraiturePlusMod.AddContentPackTextures(folders, pTextures);
}
// ReSharper disable once InconsistentNaming
internal static bool getPortrait_Prefix(NPC npc, Texture2D tex, ref Texture2D? __result)
{
var folders = Traverse.Create(typeof(PortraitureMod).Assembly.GetType("Portraiture.TextureLoader")).Field<List<string>>("folders").Value;
var presets = Traverse.Create(typeof(PortraitureMod).Assembly.GetType("Portraiture.TextureLoader")).Field<PresetCollection>("presets").Value;
var activeFolder = Traverse.Create(typeof(PortraitureMod).Assembly.GetType("Portraiture.TextureLoader")).Field<int>("activeFolder").Value;
var pTextures = Traverse.Create(typeof(PortraitureMod).Assembly.GetType("Portraiture.TextureLoader")).Field<Dictionary<string, Texture2D>>("pTextures").Value;
if (folders is { Count: <= 0 })
return true;
try
{
__result = PortraiturePlusMod.GetPortrait(npc, tex, folders, presets, activeFolder, pTextures);
return false;
}
catch (Exception ex)
{
_monitor.Log($"Failed in {nameof(getPortrait_Prefix)}:\n{ex}", LogLevel.Error);
return true;
}
}
}
}