Created
July 14, 2019 16:21
-
-
Save pardeike/e600d1c2b9be811acd2b3f513ac7ce72 to your computer and use it in GitHub Desktop.
3D Rimworld Test Mod
This file contains hidden or 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
using Harmony; | |
using System.Reflection; | |
using UnityEngine; | |
using Verse; | |
namespace Test | |
{ | |
class TestMod : Mod | |
{ | |
public TestMod(ModContentPack content) : base(content) | |
{ | |
var harmony = HarmonyInstance.Create("net.pardeike.rimworld.mod.rimbattle"); | |
harmony.PatchAll(Assembly.GetExecutingAssembly()); | |
} | |
public override void DoSettingsWindowContents(Rect inRect) | |
{ | |
Settings.DoWindowContents(inRect); | |
} | |
public override string SettingsCategory() | |
{ | |
return "Test"; | |
} | |
} | |
[HarmonyPatch(typeof(CameraDriver))] | |
[HarmonyPatch("MyCamera", MethodType.Getter)] | |
static class CameraDriver_MyCamera_Patch | |
{ | |
static void Prefix(out Camera __state, Camera ___cachedCamera) | |
{ | |
__state = ___cachedCamera; | |
} | |
static void Postfix(Camera __state, Camera ___cachedCamera) | |
{ | |
if (__state != null) | |
return; | |
Log.Warning("Changing camera"); | |
___cachedCamera.orthographic = false; | |
___cachedCamera.fieldOfView = 40f; | |
___cachedCamera.nearClipPlane = 0.1f; | |
___cachedCamera.farClipPlane = 10000f; | |
} | |
} | |
[HarmonyPatch(typeof(CameraDriver))] | |
[HarmonyPatch("CurrentViewRect", MethodType.Getter)] | |
static class CameraDriver_CurrentViewRect_Patch | |
{ | |
static bool Prefix(ref CellRect __result) | |
{ | |
__result = new CellRect(0, 0, 249, 249); | |
return false; | |
} | |
} | |
[HarmonyPatch(typeof(CameraDriver))] | |
[HarmonyPatch("ApplyPositionToGameObject")] | |
static class CameraDriver_ApplyPositionToGameObject_Patch | |
{ | |
static void Postfix(Camera ___cachedCamera) | |
{ | |
var a = GenMath.LerpDoubleClamped(15f, 65f, 0f, 180f, ___cachedCamera.transform.position.y); | |
Log.Warning("" + ___cachedCamera.transform.position.y + " " + a); | |
___cachedCamera.transform.rotation = Quaternion.Euler(a, 0, 0); | |
} | |
} | |
[HarmonyPatch(typeof(Graphics))] | |
[HarmonyPatch("DrawMesh", new[] { typeof(Mesh), typeof(Vector3), typeof(Quaternion), typeof(Material), typeof(int) })] | |
static class Graphics_DrawMesh_Patch | |
{ | |
static Vector3 RotateAroundPoint(Vector3 point, Vector3 pivot, Quaternion angle) | |
{ | |
var finalPos = point - pivot; | |
finalPos = angle * finalPos; | |
finalPos += pivot; | |
return finalPos; | |
} | |
static void Prefix(ref Vector3 position, ref Quaternion rotation, ref int layer) | |
{ | |
rotation = Quaternion.Euler(60, 0, 0); | |
var off = new Vector3(0f, 0f, 0f); | |
position = RotateAroundPoint(position + off, new Vector3(125f, 0f, 125f) + off, Quaternion.Euler(60, 0, 0)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment