-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixes.cs
More file actions
54 lines (46 loc) · 1.88 KB
/
Fixes.cs
File metadata and controls
54 lines (46 loc) · 1.88 KB
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
using HarmonyLib;
using Sunless.Game.Data.BaseClasses;
using Sunless.Game.Data;
using FailBetter.Core;
using System.Reflection;
namespace SDLS
{
internal static class Fixes
{
public static void DoMiscFixes()
{
Harmony.CreateAndPatchAll(typeof(BaseCollectionRepositoryGetPatch));
}
[HarmonyPatch]
private static class BaseCollectionRepositoryGetPatch
{
private static MethodBase TargetMethod() // I do not understand this
{
return typeof(BaseCollectionRepository<,>)
.MakeGenericType(typeof(int), typeof(Quality))
.GetMethod("Get", [typeof(int)]);
}
private static bool Prefix(int id, ref object __result, object __instance)
{
var instance = __instance as BaseCollectionRepository<int, Quality>;
RepositoryManager.Instance.Initialise();
if (instance.Entities.TryGetValue(id, out Quality output))
{
__result = output;
return false;
}
Plugin.Log($"{id} not found, creating a placeholder.");
// Create placeholder Quality
var result = JSON.Deserialize<Quality>(JSON.ReadInternalJson("qualities"));
// Give it some defaults
result.Name = $"Quality {id}";
result.Description = $"This quality was part of a mod that is no longer installed.\r\n{nameof(SDLS)} has replaced it to keep your save from being corrupted.";
result.Id = id;
result.Category = FailBetter.Core.Enums.Category.Curiosity;
result.Nature = FailBetter.Core.Enums.Nature.Thing;
__result = result;
return false; // Skip original method
}
}
}
}