Skip to content

Commit

Permalink
Merge pull request #271 from edbmods/develop
Browse files Browse the repository at this point in the history
Merge develop to master for 1.0.15
  • Loading branch information
edbmods authored Nov 18, 2019
2 parents 28c782e + 609adc6 commit 64aefba
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 8 deletions.
2 changes: 2 additions & 0 deletions EdBPrepareCarefully.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
<Reference Include="System.Xml.Linq" />
<Reference Include="Assembly-CSharp">
<HintPath>Libraries\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>Libraries\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.14")]
[assembly: AssemblyVersion("1.0.15")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
Expand Down
2 changes: 1 addition & 1 deletion Resources/About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

If you get a set of starting colonists that you like, save them as a preset so that you can start your game the same way next time.

[Version 1.0.14]
[Version 1.0.15]
</description>
</ModMetaData>
2 changes: 1 addition & 1 deletion Resources/About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>EdBPrepareCarefully</identifier>
<version>1.0.14</version>
<version>1.0.15</version>
<loadAfter>
<li>Core</li>
<li>HugsLib</li>
Expand Down
9 changes: 9 additions & 0 deletions Resources/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
_____________________________________________________________________________

Version 1.0.15
_____________________________________________________________________________

- Better error handling when loading the classes needed to add the
Prepare Carefully button to the character configuration screen.
- Fix for alien hair color swatches

_____________________________________________________________________________

Version 1.0.14
Expand Down
8 changes: 4 additions & 4 deletions Source/HarmonyPatches.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Harmony;
using Harmony;
using RimWorld;
using System;
using System.Collections.Generic;
Expand All @@ -15,8 +15,8 @@ namespace EdB.PrepareCarefully {
internal class HarmonyPatches {
static HarmonyPatches() {
try {
Type pageConfigureStartingPawnsType = AccessTools.TypeByName("RimWorld.Page_ConfigureStartingPawns");
Type gameType = AccessTools.TypeByName("Verse.Game");
Type pageConfigureStartingPawnsType = ReflectionUtil.TypeByName("RimWorld.Page_ConfigureStartingPawns");
Type gameType = ReflectionUtil.TypeByName("Verse.Game");
HarmonyInstance harmony = HarmonyInstance.Create("EdB.PrepareCarefully");
if (pageConfigureStartingPawnsType != null) {
if (harmony.Patch(pageConfigureStartingPawnsType.GetMethod("PreOpen"),
Expand All @@ -41,7 +41,7 @@ static HarmonyPatches() {
}
}
else {
Log.Warning("Could not modify the game initilization routine as needed for Prepare Carefully. Could not find the required type.");
Log.Warning("Could not modify the game initialization routine as needed for Prepare Carefully. Could not find the required type.");
}
}
catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion Source/ProviderAlienRaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected AlienRace InitializeAlienRace(ThingDef raceDef) {
object hairColorGeneratorValue = GetFieldValue(raceDef, alienPartGeneratorObject, "alienhaircolorgen", true);
ColorGenerator hairColorGenerator = hairColorGeneratorValue as ColorGenerator;
if (hairColorGenerator != null) {
result.HairColors = primaryGenerator.GetColorList();
result.HairColors = hairColorGenerator.GetColorList();
}
else {
result.HairColors = null;
Expand Down
5 changes: 5 additions & 0 deletions Source/ProviderHair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ protected OptionsHair InitializeHairs(ThingDef raceDef) {
})) {
result.AddHair(hairDef);
}

if (alienRace.HairColors != null) {
result.Colors = alienRace.HairColors.ToList();
}

result.Sort();
return result;
}
Expand Down
53 changes: 53 additions & 0 deletions Source/ReflectionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,58 @@ public static void SetPublicField(object target, string name, object value) {
info.SetValue(target, value);
}
}


// Similar to Harmony's AccessTools.TypeByName() but with error handling around Assembly.GetTypes() to avoid
// issues with bad assemblies.
public static Type TypeByName(string name) {
Type type = null;
try {
type = Type.GetType(name, false);
}
catch (Exception) {
Log.Warning("Prepare Carefully encountered an error when trying to get type {" + name + "} using Type.GetType(name)");
}
if (type != null) {
return type;
}
Assembly[] assemblies = null;
try {
assemblies = AppDomain.CurrentDomain.GetAssemblies();
}
catch (Exception) {
Log.Warning("Prepare Carefully encountered an error when trying to get the list of available assemblies");
return null;
}
foreach (var assembly in assemblies) {
try {
Type[] types = assembly.GetTypes();
type = types.FirstOrDefault(x => x.FullName == name);
if (type != null) {
return type;
}
else {
type = types.FirstOrDefault(x => x.Name == name);
}
if (type != null) {
return type;
}
}
catch (Exception) {
String assemblyNameAsString = "Unknown assembly";
try {
var assemblyName = assembly.GetName();
assemblyNameAsString = assemblyName.Name;
}
catch {
Log.Warning("Prepare Carefully ran into an error when trying to get an assembly name");
}
Log.Warning("Prepare Carefully was searching for the class {" + name + "}, but there was an error when getting the list of types "
+ "from the assembly {" + assemblyNameAsString + "}. Something might be broken in the mod to which that assembly belongs. "
+ "Skipping it to continue the search in the rest of the assemblies.");
}
}
return null;
}
}
}

0 comments on commit 64aefba

Please sign in to comment.