Skip to content

Commit

Permalink
Add controller icon override to hopefully address issues #7 and #16
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyall committed Aug 17, 2022
1 parent 2e604eb commit 26fa869
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
62 changes: 51 additions & 11 deletions RF5Fix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

using System;
using System.Collections.Generic;

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

namespace RF5Fix
{
Expand Down Expand Up @@ -37,6 +38,8 @@ public class RF5 : BasePlugin
public static ConfigEntry<float> fDesiredResolutionX;
public static ConfigEntry<float> fDesiredResolutionY;
public static ConfigEntry<int> iWindowMode;
public static ConfigEntry<bool> bControllerType;
public static ConfigEntry<string> sControllerType;

public override void Load()
{
Expand Down Expand Up @@ -99,6 +102,17 @@ public override void Load()
new ConfigDescription("Set desired mouse sensitivity.",
new AcceptableValueRange<int>(1, 9999)));

bControllerType = Config.Bind("Controller Icon Override",
"ControllerType.Override",
false, // Disable by default.
"Set to true to enable controller icon override.");

sControllerType = Config.Bind("Controller Icon Override",
"ControllerType",
"Xbox",
new ConfigDescription("Set desired controller icon type.",
new AcceptableValueList<string>("Xbox", "PS4", "PS5", "Switch")));

// Custom Resolution
bCustomResolution = Config.Bind("Set Custom Resolution",
"CustomResolution",
Expand All @@ -117,7 +131,7 @@ public override void Load()

iWindowMode = Config.Bind("Set Custom Resolution",
"WindowMode",
1,
(int)1,
new ConfigDescription("Set window mode. 1 = Fullscreen, 2 = Borderless, 3 = Windowed.",
new AcceptableValueRange<int>(1, 3)));

Expand Down Expand Up @@ -189,6 +203,12 @@ public override void Load()
Harmony.CreateAndPatchAll(typeof(FOVPatch));
}

// Run ControllerPatch
if (bControllerType.Value)
{
Harmony.CreateAndPatchAll(typeof(ControllerPatch));
}

// Run MiscellaneousPatch
Harmony.CreateAndPatchAll(typeof(MiscellaneousPatch));

Expand Down Expand Up @@ -348,17 +368,17 @@ public static void SkipIntroLogos(UILogoControl __instance)
[HarmonyPatch]
public class FOVPatch
{
static float NewAspectRatio = (float)Screen.width / Screen.height;
static float DefaultAspectRatio = (float)16 / 9;

static bool farmFOVHasRun = false;
static bool trackingFOVHasRun = false;
public static float NewAspectRatio = (float)Screen.width / Screen.height;
public static float DefaultAspectRatio = (float)16 / 9;
public static bool farmFOVHasRun = false;
public static bool trackingFOVHasRun = false;

// Adjust tracking camera FOV
// Indoor, outdoor, dungeon
[HarmonyPatch(typeof(PlayerTrackingCamera), nameof(PlayerTrackingCamera.Start))]
[HarmonyPostfix]
static void TrackingFOV(PlayerTrackingCamera __instance)
public static void TrackingFOV(PlayerTrackingCamera __instance)
{
// Only run this once
if (!trackingFOVHasRun)
Expand Down Expand Up @@ -481,6 +501,28 @@ public static bool SetCustomRes(ref int __0, ref int __1, ref BootOption.WindowM
}
}


[HarmonyPatch]
public class ControllerPatch
{
// Spoof RF5's steam input controller type
[HarmonyPatch(typeof(RF5SteamInput.SteamInputManager), nameof(RF5SteamInput.SteamInputManager.GetConnectingControllerType))]
[HarmonyPostfix]
public static void Glyphy(RF5SteamInput.SteamInputManager __instance, ref RF5SteamInput.SteamInputManager.ControllerType __result)
{
var controllerType = sControllerType.Value switch
{
"Xbox" => RF5SteamInput.SteamInputManager.ControllerType.Xbox,
"PS4" => RF5SteamInput.SteamInputManager.ControllerType.PS4,
"PS5" => RF5SteamInput.SteamInputManager.ControllerType.PS5,
"Switch" => RF5SteamInput.SteamInputManager.ControllerType.Switch,
_ => RF5SteamInput.SteamInputManager.ControllerType.Default,
};

__result = controllerType;
}
}

[HarmonyPatch]
public class MiscellaneousPatch
{
Expand Down Expand Up @@ -565,7 +607,6 @@ public static void AdjustSunMoonLight(Funly.SkyStudio.OrbitingBody __instance)
if (iShadowResolution.Value >= 64)
{
__instance.BodyLight.shadowCustomResolution = iShadowResolution.Value; // Default = ShadowQuality (i.e VeryHigh = 4096)
//Log.LogInfo($"Set light.shadowCustomResolution to {__instance.BodyLight.shadowCustomResolution}.");
}
}

Expand All @@ -577,7 +618,6 @@ public static void AdjustLightShadow(RealtimeBakeLight __instance)
if (iShadowResolution.Value >= 64)
{
__instance.Light.shadowCustomResolution = iShadowResolution.Value; // Default = ShadowQuality (i.e VeryHigh = 4096)
//Log.LogInfo($"Set RealtimeBakeLight.light.shadowCustomResolution to {__instance.Light.shadowCustomResolution}.");
}
}

Expand All @@ -597,7 +637,7 @@ public static void CampRenderTextureFix(CampMenuMain __instance)
float newHorizontalRes = Mathf.Floor(Screen.currentResolution.height * DefaultAspectRatio);
rt = new RenderTexture((int)newHorizontalRes, (int)Screen.currentResolution.height, 24, RenderTextureFormat.ARGB32);
rt.antiAliasing = QualitySettings.antiAliasing;

var UICam = UIMainManager.Instance.GetComponent<Camera>(UIMainManager.AttachId.UICamera);
UICam.targetTexture = rt;
UICam.Render();
Expand Down
2 changes: 1 addition & 1 deletion RF5Fix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>RF5Fix</AssemblyName>
<Description>RF5 Fix</Description>
<Version>0.1.3</Version>
<Version>0.1.4</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down

0 comments on commit 26fa869

Please sign in to comment.