-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Null ref checking + placeholder code
v1.0.9.12 (June 1st, 2018) ===================== - Added more null reference checking and handling to PawnShields
- Loading branch information
Showing
16 changed files
with
772 additions
and
1,525 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2,088 changes: 607 additions & 1,481 deletions
2,088
Source/.idea/.idea.JecsTools/.idea/workspace.xml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
Source/AllModdingComponents/JecsTools/HarmonyPatches_GUI.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Reflection.Emit; | ||
using AbilityUser; | ||
using Harmony; | ||
using RimWorld; | ||
using UnityEngine; | ||
using Verse; | ||
using Verse.Sound; | ||
|
||
namespace JecsTools | ||
{ | ||
public static partial class HarmonyPatches | ||
{ | ||
private static bool drawButtonsPatched; | ||
|
||
public static void GUIPatches(HarmonyInstance harmony) | ||
{ | ||
//Allow fortitude to soak damage | ||
var type = typeof(HarmonyPatches); | ||
harmony.Patch(AccessTools.Method(typeof(DebugWindowsOpener), "DrawButtons"), null, | ||
null, new HarmonyMethod(type, nameof(DrawAdditionalButtons))); | ||
harmony.Patch(AccessTools.Method(typeof(MoteMaker), "MakeMoodThoughtBubble"), null, | ||
new HarmonyMethod(type, nameof(ToggleMoodThoughtBubble)), | ||
null); | ||
} | ||
|
||
public static void ToggleMoodThoughtBubble(Pawn pawn, Thought thought, ref MoteBubble __result) | ||
{ | ||
if (!bubblesEnabled) __result = null; | ||
} | ||
|
||
public static IEnumerable<CodeInstruction> DrawAdditionalButtons(IEnumerable<CodeInstruction> instructions) { | ||
var instructionsArr = instructions.ToArray(); | ||
var widgetRowIndex = TryGetLocalIndexOfConstructedObject(instructionsArr, typeof(WidgetRow)); | ||
foreach (var inst in instructionsArr) { | ||
if (!drawButtonsPatched && widgetRowIndex >= 0 && inst.opcode == OpCodes.Bne_Un) { | ||
yield return new CodeInstruction(OpCodes.Ldloc, widgetRowIndex); | ||
yield return new CodeInstruction(OpCodes.Call, ((Action<WidgetRow>)HarmonyPatches.DrawDebugToolbarButton).Method); | ||
drawButtonsPatched = true; | ||
} | ||
yield return inst; | ||
} | ||
} | ||
|
||
private static int TryGetLocalIndexOfConstructedObject(IEnumerable<CodeInstruction> instructions, Type constructedType, Type[] constructorParams = null) { | ||
var constructor = AccessTools.Constructor(constructedType, constructorParams); | ||
int localIndex = -1; | ||
if (constructor == null) { | ||
Log.Message($"Could not reflect constructor for type {constructedType}: {Environment.StackTrace}"); | ||
return localIndex; | ||
} | ||
CodeInstruction prevInstruction = null; | ||
foreach (var inst in instructions) { | ||
if (prevInstruction != null && prevInstruction.opcode == OpCodes.Newobj && constructor.Equals(prevInstruction.operand)) { | ||
if (inst.opcode == OpCodes.Stloc_0) { | ||
localIndex = 0; | ||
} else if (inst.opcode == OpCodes.Stloc_1) { | ||
localIndex = 1; | ||
} else if (inst.opcode == OpCodes.Stloc_2) { | ||
localIndex = 2; | ||
} else if (inst.opcode == OpCodes.Stloc_3) { | ||
localIndex = 3; | ||
} else if (inst.opcode == OpCodes.Stloc && inst.operand is int) { | ||
localIndex = (int)inst.operand; | ||
} | ||
if (localIndex >= 0) break; | ||
} | ||
prevInstruction = inst; | ||
} | ||
if (localIndex < 0) { | ||
Log.Message($"Could not determine local index for constructed type {constructedType}: {Environment.StackTrace}"); | ||
} | ||
return localIndex; | ||
} | ||
|
||
private static bool bubblesEnabled = true; | ||
internal static void DrawDebugToolbarButton(WidgetRow widgetRow) { | ||
if (Current.ProgramState == ProgramState.Playing) | ||
{ | ||
widgetRow.ToggleableIcon(ref bubblesEnabled, TexButton.quickstartIconTex, "Toggle thought/speech bubbles.", null, null); | ||
} | ||
} | ||
|
||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using UnityEngine; | ||
using Verse; | ||
|
||
namespace JecsTools | ||
{ | ||
[StaticConstructorOnStartup] | ||
internal class TexButton | ||
{ | ||
public static readonly Texture2D quickstartIconTex = ContentFinder<Texture2D>.Get("quickstartIcon"); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.