Skip to content

Commit

Permalink
v2.0.2 fixes Issue #12
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Jun 21, 2020
1 parent dc312bf commit 26728be
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 115 deletions.
2 changes: 1 addition & 1 deletion 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>net.pardeike.rimworld.mod.cameraplus</identifier>
<version>2.0.1.10</version>
<version>2.0.2.0</version>
<targetVersions>
<li>1.0.0</li>
<li>1.1.0</li>
Expand Down
2 changes: 1 addition & 1 deletion About/ModSync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ModSyncNinjaData>
<ID>d47b5c8c-3f08-4ab6-8d0a-bc67e509d15c</ID>
<ModName>Camera+</ModName>
<Version>2.0.1.10</Version>
<Version>2.0.2.0</Version>
<SaveBreaking>False</SaveBreaking>
<Host name="Github">
<Owner>pardeike</Owner>
Expand Down
125 changes: 15 additions & 110 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class CameraPlusMain : Mod
public static CameraPlusSettings Settings;
public static float orthographicSize = -1f;

// for other mods: set temporarily to true to skip any hiding
public static bool renderEverything = false;

public CameraPlusMain(ModContentPack content) : base(content)
{
Settings = GetSettings<CameraPlusSettings>();
Expand Down Expand Up @@ -92,13 +95,6 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
if (found == false)
Log.Error("Cannot find field Stdfld rootSize in CameraDriver.Update");
}

/*static void Postfix(CameraDriver __instance)
{
if (CameraPlusMain.Settings.stickyMiddleMouse)
if (Refs.desiredDollyRaw(__instance) != Vector2.zero)
Refs.velocity(__instance) = Vector3.zero;
}*/
}

[HarmonyPatch(typeof(TimeControls))]
Expand All @@ -122,99 +118,16 @@ static void Postfix(ref Vector2 __result)
}
}

/*
[HarmonyPatch(typeof(CameraDriver))]
[HarmonyPatch("CameraDriverOnGUI")]
static class CameraDriver_CameraDriverOnGUI_Patch
{
static Vector2 dummy;
static readonly MethodInfo m_Patch = SymbolExtensions.GetMethodInfo(() => Patch(null, ref dummy, ref dummy));
static void Patch(CameraDriver cameraDriver, ref Vector2 desiredDollyRaw, ref Vector2 desiredDolly)
{
if (desiredDollyRaw != Vector2.zero)
{
var factor = CameraDriver.HitchReduceFactor;
if (desiredDollyRaw != Vector2.zero)
factor = 1 / RealTime.deltaTime / 60f;
desiredDollyRaw *= factor;
desiredDollyRaw.x *= -1f;
desiredDolly += desiredDollyRaw * cameraDriver.config.dollyRateScreenEdge;
// done in postfix for CameraDriver.Update()
// desiredDollyRaw = Vector2.zero;
}
}
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var list = instructions.ToList();
list.InsertRange(0, new CodeInstruction[]
{
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Call, Refs.p_get_zero),
new CodeInstruction(OpCodes.Stfld, Refs.f_desiredDollyRaw)
}
);
var found = false;
for (var i = 0; i < list.Count - 4; i++)
{
if (list[i].opcode != OpCodes.Ldarg_0)
continue;
var start = i;
if (list[i + 1].LoadsField(Refs.f_desiredDollyRaw) == false)
continue;
if (list[i + 2].Calls(Refs.p_get_zero) == false)
continue;
if (list[i + 3].Calls(Refs.m_op_Inequality) == false)
continue;
i += 4;
while (list[i].opcode != OpCodes.Brfalse && list[i].opcode != OpCodes.Brfalse_S && i < list.Count - 1)
i++;
if (list[i].opcode != OpCodes.Brfalse && list[i].opcode != OpCodes.Brfalse_S)
continue;
var jumpLabel = (Label)list[i].operand;
var j = list.FindIndex(start, instr => instr.labels.Contains(jumpLabel));
if (j == -1)
continue;
_ = list[j].labels.Remove(jumpLabel);
var labels = list[start].labels;
var blocks = list[start].blocks;
list.RemoveRange(start, j - start);
var callPatchInstructions = new CodeInstruction[]
{
new CodeInstruction(OpCodes.Ldarg_0) { labels = labels, blocks = blocks },
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldflda, Refs.f_desiredDollyRaw),
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldflda, Refs.f_desiredDolly),
new CodeInstruction(OpCodes.Call, m_Patch)
};
list.InsertRange(start, callPatchInstructions);
found = true;
break;
}
if (found == false)
Log.Error("Cannot find and replace last if() in CameraDriver.OnGUI");
return list.AsEnumerable();
}
}
*/

[HarmonyPatch(typeof(MoteMaker))]
[HarmonyPatch("ThrowText")]
[HarmonyPatch(new Type[] { typeof(Vector3), typeof(Map), typeof(string), typeof(Color), typeof(float) })]
static class MoteMaker_ThrowText_Patch
{
static bool Prefix(Vector3 loc)
{
if (CameraPlusMain.renderEverything)
return true;

if (CameraPlusMain.Settings.hideNamesWhenZoomedOut == false)
return true;

Expand All @@ -237,6 +150,9 @@ static class PawnRenderer_RenderPawnAt_Patch
[HarmonyPriority(10000)]
static bool Prefix(Pawn ___pawn)
{
if (CameraPlusMain.renderEverything)
return true;

var cameraDelegate = Tools.GetCachedCameraDelegate(___pawn);
if (cameraDelegate.GetCameraColors == null)
{
Expand Down Expand Up @@ -271,6 +187,9 @@ static class GenMapUI_DrawPawnLabel_Patch
[HarmonyPriority(10000)]
public static bool Prefix(Pawn pawn, float truncateToWidth)
{
if (CameraPlusMain.renderEverything)
return true;

if (truncateToWidth != 9999f)
return true; // use label

Expand Down Expand Up @@ -336,6 +255,9 @@ static GameFont GetAdaptedGameFont(float rootSize)
[HarmonyPriority(10000)]
public static bool Prefix(Vector2 screenPos)
{
if (CameraPlusMain.renderEverything)
return true;

Tools.ShouldShowLabel(screenPos, false, out var showLabel, out _);
return showLabel;
}
Expand Down Expand Up @@ -424,23 +346,6 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
}
}

/* increase clipping distance
//
[HarmonyPatch(typeof(CameraDriver))]
[HarmonyPatch("Awake")]
static class CameraDriver_Awake_Patch
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
foreach (var instruction in instructions)
{
if (instruction.opcode == OpCodes.Ldc_R4)
instruction.operand = CameraPlusSettings.farOutHeight + 5;
yield return instruction;
}
}
}*/

// here, we basically add a "var lerpedRootSize = Main.LerpRootSize(this.rootSize);" to
// the beginning of this method and replace every "this.rootSize" witn "lerpedRootSize"
//
Expand Down
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@

[assembly: Guid("b0d46bb5-08ff-4e04-9efd-3e32e38a9cc2")]

[assembly: AssemblyVersion("2.0.1.10")]
[assembly: AssemblyFileVersion("2.0.1.10")]
[assembly: AssemblyVersion("2.0.2.0")]
[assembly: AssemblyFileVersion("2.0.2.0")]
5 changes: 4 additions & 1 deletion Source/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ public static void HandleHotkeys()
return;

var map = Find.CurrentMap;
var cameraDriver = Find.CameraDriver;
if (map == null)
return;

var savedViews = map.GetComponent<SavedViews>();

m1 = settings.cameraSettingsLoad[0];
Expand All @@ -459,6 +461,7 @@ public static void HandleHotkeys()
if (m1 == KeyCode.None || Input.GetKey(m1))
if (m2 == KeyCode.None || Input.GetKey(m2))
{
var cameraDriver = Find.CameraDriver;
savedViews.views[numKey - 1] = new RememberedCameraPos(map)
{
rootPos = Refs.rootPos(cameraDriver),
Expand Down
Binary file modified v1.1/Assemblies/CameraPlus.dll
Binary file not shown.

0 comments on commit 26728be

Please sign in to comment.