diff --git a/Assemblies/AlienRace.dll b/Assemblies/AlienRace.dll index ccf5497a..fae95184 100644 Binary files a/Assemblies/AlienRace.dll and b/Assemblies/AlienRace.dll differ diff --git a/Source/AlienRace/AlienRace/BackstoryDef.cs b/Source/AlienRace/AlienRace/BackstoryDef.cs index 7c43e893..0a1fedce 100644 --- a/Source/AlienRace/AlienRace/BackstoryDef.cs +++ b/Source/AlienRace/AlienRace/BackstoryDef.cs @@ -32,6 +32,7 @@ public class BackstoryDef : Def public IntRange bioAgeRange; public IntRange chronoAgeRange; public List forcedItems = new List(); + public Backstory backstory; public bool CommonalityApproved(Gender g) => Rand.Range(min: 0, max: 100) < (g == Gender.Female ? this.femaleCommonality : this.maleCommonality); @@ -45,14 +46,10 @@ public override void ResolveReferences() base.ResolveReferences(); - if (!this.addToDatabase || BackstoryDatabase.allBackstories.ContainsKey(key: this.defName) || this.title.NullOrEmpty() || this.spawnCategories.NullOrEmpty()) - { - return; - } + if (!this.addToDatabase || BackstoryDatabase.allBackstories.ContainsKey(key: this.defName) || this.title.NullOrEmpty() || this.spawnCategories.NullOrEmpty()) return; - Backstory b = new Backstory() + this.backstory = new Backstory { - baseDesc = this.baseDescription.NullOrEmpty() ? "Empty." : this.baseDescription, bodyTypeGlobal = this.bodyTypeGlobal, bodyTypeFemale = this.bodyTypeFemale, bodyTypeMale = this.bodyTypeMale, @@ -82,24 +79,29 @@ public override void ResolveReferences() })() }; - b.SetTitle(newTitle: this.title); - b.SetTitleShort(newTitleShort: this.titleShort.NullOrEmpty() ? b.Title : this.titleShort); - - b.ResolveReferences(); - b.PostLoad(); + UpdateTranslateableFields(bs: this); + + this.backstory.ResolveReferences(); + this.backstory.PostLoad(); - b.identifier = this.defName; + this.backstory.identifier = this.defName; IEnumerable errors; - if (!(errors = b.ConfigErrors(ignoreNoSpawnCategories: false)).Any()) - { - BackstoryDatabase.AddBackstory(bs: b); - } else - { + if (!(errors = this.backstory.ConfigErrors(ignoreNoSpawnCategories: false)).Any()) + BackstoryDatabase.AddBackstory(bs: this.backstory); + else Log.Error(text: this.defName + " has errors:\n" + string.Join(separator: "\n", value: errors.ToArray())); - } } + internal static void UpdateTranslateableFields(BackstoryDef bs) + { + bs.backstory.baseDesc = bs.baseDescription.NullOrEmpty() ? "Empty." : bs.baseDescription; + bs.backstory.SetTitle(newTitle: bs.title); + bs.backstory.SetTitleShort(newTitleShort: bs.titleShort.NullOrEmpty() ? bs.backstory.Title : bs.titleShort); + } + + + public struct BackstoryDefSkillListItem { #pragma warning disable CS0649 diff --git a/Source/AlienRace/AlienRace/HarmonyPatches.cs b/Source/AlienRace/AlienRace/HarmonyPatches.cs index 0c30e018..4f8d0166 100644 --- a/Source/AlienRace/AlienRace/HarmonyPatches.cs +++ b/Source/AlienRace/AlienRace/HarmonyPatches.cs @@ -236,8 +236,6 @@ static HarmonyPatches() { - //DateTime time = DateTime.Now; - FieldInfo bodyInfo = AccessTools.Field(type: typeof(RaceProperties), name: nameof(RaceProperties.body)); ILGenerator ilg = new DynamicMethod(name: "ScanMethod", returnType: typeof(int), parameterTypes: Type.EmptyTypes).GetILGenerator(); foreach (MethodInfo mi in LoadedModManager.RunningMods.Where(predicate: mcp => mcp.LoadedAnyAssembly) @@ -256,13 +254,19 @@ static HarmonyPatches() harmony.Patch(original: mi, prefix: null, postfix: null, transpiler: new HarmonyMethod(type: patchType, name: nameof(BodyReferenceTranspiler))); } } - Log.Message( - text: + + Log.Message(text: $"Alien race successfully completed {harmony.GetPatchedMethods().Select(selector: mb => harmony.GetPatchInfo(method: mb)).SelectMany(selector: p => p.Prefixes.Concat(second: p.Postfixes).Concat(second: p.Transpilers)).Count(predicate: p => p.owner == harmony.Id)} patches with harmony."); DefDatabase.GetNamed(defName: "Shaved").hairTags.Add(item: "alienNoHair"); // needed because..... the original idea doesn't work and I spend enough time finding a good solution + + foreach (BackstoryDef bd in DefDatabase.AllDefs) + { + BackstoryDef.UpdateTranslateableFields(bs: bd); + } } - public static IEnumerable BodyReferenceTranspiler(IEnumerable instructions) { + public static IEnumerable BodyReferenceTranspiler(IEnumerable instructions) + { FieldInfo bodyInfo = AccessTools.Field(type: typeof(RaceProperties), name: nameof(RaceProperties.body)); FieldInfo propsInfo = AccessTools.Field(type: typeof(ThingDef), name: nameof(ThingDef.race));