-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v2.2.1 has rewritten logic for dots and labels and works correctly wi…
…th vanilla animal name settings
- Loading branch information
Showing
8 changed files
with
274 additions
and
231 deletions.
There are no files selected for viewing
Binary file not shown.
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,39 @@ | ||
using HarmonyLib; | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using UnityEngine; | ||
using Verse; | ||
|
||
namespace CameraPlus | ||
{ | ||
class CameraDelegates | ||
{ | ||
public Func<Pawn, Color[]> GetCameraColors = null; | ||
public Func<Pawn, Texture2D[]> GetCameraMarkers = null; | ||
|
||
static MethodInfo GetMethod(Pawn pawn, string name) | ||
{ | ||
return pawn.GetType().Assembly | ||
.GetType("CameraPlusSupport.Methods", false)? | ||
.GetMethod(name, AccessTools.all); | ||
} | ||
|
||
public CameraDelegates(Pawn pawn) | ||
{ | ||
var m_GetCameraColors = GetMethod(pawn, "GetCameraPlusColors"); | ||
if (m_GetCameraColors != null) | ||
{ | ||
var funcType = Expression.GetFuncType(new[] { typeof(Pawn), typeof(Color[]) }); | ||
GetCameraColors = (Func<Pawn, Color[]>)Delegate.CreateDelegate(funcType, m_GetCameraColors); | ||
} | ||
|
||
var m_GetCameraTextures = GetMethod(pawn, "GetCameraPlusMarkers"); | ||
if (m_GetCameraTextures != null) | ||
{ | ||
var funcType = Expression.GetFuncType(new[] { typeof(Pawn), typeof(Texture2D[]) }); | ||
GetCameraMarkers = (Func<Pawn, Texture2D[]>)Delegate.CreateDelegate(funcType, m_GetCameraTextures); | ||
} | ||
} | ||
} | ||
} |
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,43 @@ | ||
using System; | ||
using UnityEngine; | ||
using Verse; | ||
|
||
namespace CameraPlus | ||
{ | ||
static class Extensions | ||
{ | ||
public static void Slider(this Listing_Standard list, ref int value, int min, int max, Func<string> label) | ||
{ | ||
float f = value; | ||
var h = HorizontalSlider(list.GetRect(22f), ref f, min, max, label == null ? null : label(), 1f); | ||
value = (int)f; | ||
list.Gap(h); | ||
} | ||
|
||
public static void Slider(this Listing_Standard list, ref float value, float min, float max, Func<string> label, float roundTo = -1f) | ||
{ | ||
var rect = list.GetRect(22f); | ||
var h = HorizontalSlider(rect, ref value, min, max, label == null ? null : label(), roundTo); | ||
list.Gap(h); | ||
} | ||
|
||
public static float HorizontalSlider(Rect rect, ref float value, float leftValue, float rightValue, string label = null, float roundTo = -1f) | ||
{ | ||
if (label != null) | ||
{ | ||
var anchor = Text.Anchor; | ||
var font = Text.Font; | ||
Text.Font = GameFont.Tiny; | ||
Text.Anchor = TextAnchor.UpperLeft; | ||
Widgets.Label(rect, label); | ||
Text.Anchor = anchor; | ||
Text.Font = font; | ||
rect.y += 18f; | ||
} | ||
value = GUI.HorizontalSlider(rect, value, leftValue, rightValue); | ||
if (roundTo > 0f) | ||
value = Mathf.RoundToInt(value / roundTo) * roundTo; | ||
return 4f + label != null ? 18f : 0f; | ||
} | ||
} | ||
} |
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,49 @@ | ||
using HarmonyLib; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using Verse; | ||
|
||
namespace CameraPlus | ||
{ | ||
[HarmonyPatch] | ||
static class ReversePatches | ||
{ | ||
// mostly copied from the logic in the beginning od PawnUIOverlay.DrawPawnGUIOverlay | ||
// | ||
[HarmonyReversePatch(HarmonyReversePatchType.Original)] | ||
[HarmonyPatch(typeof(PawnUIOverlay), nameof(PawnUIOverlay.DrawPawnGUIOverlay))] | ||
public static bool PerformsDrawPawnGUIOverlay(PawnUIOverlay me) | ||
{ | ||
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
var mLabelDrawPosFor = SymbolExtensions.GetMethodInfo(() => GenMapUI.LabelDrawPosFor(null, 0f)); | ||
|
||
var list = instructions.ToList(); | ||
var idx = list.FirstIndexOf(code => code.Calls(mLabelDrawPosFor)); | ||
if (idx < 3 || idx >= list.Count) throw new AmbiguousMatchException("Cannot find GenMapUI.LabelDrawPosFor in PawnUIOverlay.DrawPawnGUIOverlay"); | ||
idx -= 3; | ||
var endLabels = list[idx].labels; | ||
list.RemoveRange(idx, list.Count - idx); | ||
|
||
foreach (var code in list) | ||
{ | ||
if (code.opcode == OpCodes.Ret) | ||
{ | ||
var labels = code.labels; | ||
yield return new CodeInstruction(OpCodes.Ldc_I4_0) { labels = labels }; | ||
yield return new CodeInstruction(OpCodes.Ret); | ||
} | ||
else | ||
yield return code; | ||
} | ||
yield return new CodeInstruction(OpCodes.Ldc_I4_1) { labels = endLabels }; | ||
yield return new CodeInstruction(OpCodes.Ret); | ||
} | ||
|
||
_ = Transpiler(default); | ||
try { _ = me; return default; } finally { } | ||
} | ||
} | ||
} |
Oops, something went wrong.