-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathPostDefFixer.cs
89 lines (82 loc) · 3.25 KB
/
PostDefFixer.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using Harmony;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;
namespace QEthics
{
[StaticConstructorOnStartup]
public static class PostDefFixer
{
static PostDefFixer()
{
//Add recipes to valid Genome Sequencing targets.
foreach (ThingDef def in DefDatabase<ThingDef>.AllDefs.Where(def => def.category == ThingCategory.Pawn))
{
if(def.GetModExtension<RaceExclusionProperties>() is RaceExclusionProperties props)
{
if(props.excludeThisRace)
{
GeneralCompatibility.excludedRaces.Add(def);
}
if(props.excludeTheseHediffs.Count > 0)
{
GeneralCompatibility.excludedHediffs.AddRange(props.excludeTheseHediffs);
}
}
if (def.IsValidGenomeSequencingTargetDef())
{
if(def.recipes == null)
{
def.recipes = new List<RecipeDef>();
}
if (def.recipes.Count > 0)
{
def.recipes.Insert(0, QERecipeDefOf.QE_GenomeSequencing);
}
else
{
def.recipes.Add(QERecipeDefOf.QE_GenomeSequencing);
}
}
if(def.IsValidBrainScanningDef())
{
if (def.recipes == null)
{
def.recipes = new List<RecipeDef>();
}
if (def.recipes.Count > 0)
{
def.recipes.Insert(0, QERecipeDefOf.QE_BrainScanning);
}
else
{
def.recipes.Add(QERecipeDefOf.QE_BrainScanning);
}
}
}
//Inject our own backstories.
foreach(BackstoryDef def in DefDatabase<BackstoryDef>.AllDefs)
{
Backstory backstory = new Backstory();
backstory.slot = def.slot;
backstory.title = def.title;
backstory.titleShort = def.titleShort;
backstory.titleFemale = def.titleFemale;
backstory.titleShortFemale = def.titleShortFemale;
backstory.baseDesc = def.baseDesc;
AccessTools.Field(typeof(Backstory), "bodyTypeFemale").SetValue(backstory, def.bodyTypeFemale);
AccessTools.Field(typeof(Backstory), "bodyTypeMale").SetValue(backstory, def.bodyTypeMale);
AccessTools.Field(typeof(Backstory), "bodyTypeGlobal").SetValue(backstory, def.bodyTypeGlobal);
backstory.spawnCategories.AddRange(def.spawnCategories);
backstory.PostLoad();
backstory.ResolveReferences();
BackstoryDatabase.AddBackstory(backstory);
def.identifier = backstory.identifier;
//Log.Message("'" + def.defName + "' identifier is '" + backstory.identifier + "'");
}
}
}
}