From 439695b3ab4f119f2dabdbb30767d1b237033982 Mon Sep 17 00:00:00 2001 From: M'aiq Date: Fri, 18 Dec 2020 18:16:14 -0600 Subject: [PATCH] Customization & Mag Fixes -tons of ugly code to recolor various parts of the M1911Tactical -tons of ugly code to correct M1911Tactical & M1911Operator low cap mag position --- RemoveM1911TacRedDot.sln => Better1911.sln | 2 +- .../Better1911.csproj | 0 Better1911/Configs/Frame.cs | 19 ++ Better1911/Configs/GlowSights.cs | 21 ++ Better1911/Configs/Grips.cs | 18 ++ Better1911/Configs/GunCustomization.cs | 22 ++ Better1911/Configs/Magazine.cs | 22 ++ Better1911/Configs/Root.cs | 21 ++ Better1911/Configs/Shared.cs | 21 ++ Better1911/Configs/Slide.cs | 19 ++ Better1911/IConfig.cs | 13 + Better1911/Patches.cs | 225 ++++++++++++++++++ Better1911/Plugin.cs | 30 +++ Better1911/manifest.json | 15 ++ RemoveSillyDot/Plugin.cs | 29 --- RemoveSillyDot/manifest.json | 14 -- 16 files changed, 447 insertions(+), 44 deletions(-) rename RemoveM1911TacRedDot.sln => Better1911.sln (85%) rename RemoveSillyDot/RemoveM1911TacRedDot.csproj => Better1911/Better1911.csproj (100%) create mode 100644 Better1911/Configs/Frame.cs create mode 100644 Better1911/Configs/GlowSights.cs create mode 100644 Better1911/Configs/Grips.cs create mode 100644 Better1911/Configs/GunCustomization.cs create mode 100644 Better1911/Configs/Magazine.cs create mode 100644 Better1911/Configs/Root.cs create mode 100644 Better1911/Configs/Shared.cs create mode 100644 Better1911/Configs/Slide.cs create mode 100644 Better1911/IConfig.cs create mode 100644 Better1911/Patches.cs create mode 100644 Better1911/Plugin.cs create mode 100644 Better1911/manifest.json delete mode 100644 RemoveSillyDot/Plugin.cs delete mode 100644 RemoveSillyDot/manifest.json diff --git a/RemoveM1911TacRedDot.sln b/Better1911.sln similarity index 85% rename from RemoveM1911TacRedDot.sln rename to Better1911.sln index 6687106..4dfecb8 100644 --- a/RemoveM1911TacRedDot.sln +++ b/Better1911.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30608.117 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoveM1911TacRedDot", "RemoveSillyDot\RemoveM1911TacRedDot.csproj", "{686FBDC0-1DE3-4F58-82E1-915CD3AE3FF9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Better1911", "Better1911\Better1911.csproj", "{686FBDC0-1DE3-4F58-82E1-915CD3AE3FF9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/RemoveSillyDot/RemoveM1911TacRedDot.csproj b/Better1911/Better1911.csproj similarity index 100% rename from RemoveSillyDot/RemoveM1911TacRedDot.csproj rename to Better1911/Better1911.csproj diff --git a/Better1911/Configs/Frame.cs b/Better1911/Configs/Frame.cs new file mode 100644 index 0000000..dc2b764 --- /dev/null +++ b/Better1911/Configs/Frame.cs @@ -0,0 +1,19 @@ +using BepInEx.Configuration; +using UnityEngine; + +namespace Better1911.Configs +{ + public class FrameConfig : SharedConfigs + { + public FrameConfig(string section, ConfigFile config) + { + Color c = new Color32(0xFF, 0xFF, 0xFF, 0xFF); + Recolor = config.Bind(section, nameof(Recolor), c, "Color of the frame"); + Roughness = config.Bind(section, nameof(Roughness), 1f, "Roughness of the material. Decrease for a more mirrored finish."); + Metallic = config.Bind(section, nameof(Metallic), 1f, "Metallic value for the material. Decrease for a flatter more polymer look."); + NormalStrength = config.Bind(section, nameof(NormalStrength), 1f, "Strength of the normal maps. Increase this for a more rugged look or decrease for a smoother look."); + Specularity = config.Bind(section, nameof(Specularity), 0f, "Specularity for the material."); + RemoveTexture = config.Bind(section, nameof(RemoveTexture), false, "Enable to remove texture. This can allow cleaner finishes and better recoloring."); + } + } +} diff --git a/Better1911/Configs/GlowSights.cs b/Better1911/Configs/GlowSights.cs new file mode 100644 index 0000000..e4f5fb9 --- /dev/null +++ b/Better1911/Configs/GlowSights.cs @@ -0,0 +1,21 @@ +using BepInEx.Configuration; +using Color = UnityEngine.Color; + +namespace Better1911.Configs +{ + public class GlowSightsConfig + { + public ConfigEntry DisableGlowSights { get; } + public ConfigEntry CustomColor { get; } + public ConfigEntry RearColor { get; } + public ConfigEntry FrontColor { get; } + + public GlowSightsConfig(string section, ConfigFile config) + { + DisableGlowSights = config.Bind(section, nameof(DisableGlowSights), false, "Hide the glow sights"); + CustomColor = config.Bind(section, nameof(CustomColor), false, "Enable custom coloring of the glow sights"); + RearColor = config.Bind(section, nameof(RearColor), Color.blue, "Color of the rear glow sights"); + FrontColor = config.Bind(section, nameof(FrontColor), Color.yellow, "Color of the front glow sight"); + } + } +} diff --git a/Better1911/Configs/Grips.cs b/Better1911/Configs/Grips.cs new file mode 100644 index 0000000..01c797c --- /dev/null +++ b/Better1911/Configs/Grips.cs @@ -0,0 +1,18 @@ +using BepInEx.Configuration; +using UnityEngine; + +namespace Better1911.Configs +{ + public class GripsConfig : SharedConfigs + { + public GripsConfig(string section, ConfigFile config) + { + Color c = new Color32(0x1C, 0x1C, 0x1C, 0xFF); + Recolor = config.Bind(section, nameof(Recolor), c, "Color of the grips"); + Roughness = config.Bind(section, nameof(Roughness), 0.409f, "Roughness of the material. Decrease for a more mirrored finish."); + Metallic = config.Bind(section, nameof(Metallic), 0.489f, "Metallic value for the material. Decrease for a flatter more polymer look."); + NormalStrength = config.Bind(section, nameof(NormalStrength), 1f, "Strength of the normal maps. Increase this for a more rugged look or decrease for a smoother look."); + Specularity = config.Bind(section, nameof(Specularity), 0f, "Specularity for the material."); + } + } +} diff --git a/Better1911/Configs/GunCustomization.cs b/Better1911/Configs/GunCustomization.cs new file mode 100644 index 0000000..5d1b45f --- /dev/null +++ b/Better1911/Configs/GunCustomization.cs @@ -0,0 +1,22 @@ +using BepInEx.Configuration; + +namespace Better1911.Configs +{ + public class GunCustomizationConfig + { + public ConfigEntry CustomMaterials { get; } + + public FrameConfig Frame { get; } + public SlideConfig Slide { get; } + public GripsConfig Grips { get; } + + public GunCustomizationConfig(string section, ConfigFile config) + { + CustomMaterials = config.Bind(section, nameof(CustomMaterials), false, "Enable material editing"); + + Slide = new SlideConfig(nameof(Slide), config); + Frame = new FrameConfig(nameof(Frame), config); + Grips = new GripsConfig(nameof(Grips), config); + } + } +} diff --git a/Better1911/Configs/Magazine.cs b/Better1911/Configs/Magazine.cs new file mode 100644 index 0000000..ffcf137 --- /dev/null +++ b/Better1911/Configs/Magazine.cs @@ -0,0 +1,22 @@ +using BepInEx.Configuration; + +namespace Better1911.Configs +{ + public class MagazineConfig + { + public ConfigEntry FixMagPos { get; } + public ConfigEntry CustomMagazineMaterial { get; } + public MagazineConfig(string section, ConfigFile config) + { + FixMagPos = config.Bind(section, nameof(FixMagPos), true, "Attempts to fix the standard capacity magazine positions for M1911 Tactical & Operator"); + CustomMagazineMaterial = config.Bind(section, nameof(CustomMagazineMaterial), MagazineMaterial.Default, "Select Slide or Frame if you want your magazine material to match"); + } + + public enum MagazineMaterial + { + Default, + Slide, + Frame + } + } +} diff --git a/Better1911/Configs/Root.cs b/Better1911/Configs/Root.cs new file mode 100644 index 0000000..f4bdbba --- /dev/null +++ b/Better1911/Configs/Root.cs @@ -0,0 +1,21 @@ +using BepInEx.Configuration; + +namespace Better1911.Configs +{ + public class RootConfig + { + public ConfigEntry DisableRedDot { get; } + public GlowSightsConfig GlowSights { get; } + public GunCustomizationConfig GunCustomization { get; } + public MagazineConfig Magazine { get; } + + public RootConfig(ConfigFile config) + { + DisableRedDot = config.Bind("Red Dot", nameof(DisableRedDot), true, "Hide the red dot"); + + GlowSights = new GlowSightsConfig(nameof(GlowSights), config); + GunCustomization = new GunCustomizationConfig(nameof(GunCustomization), config); + Magazine = new MagazineConfig(nameof(Magazine), config); + } + } +} diff --git a/Better1911/Configs/Shared.cs b/Better1911/Configs/Shared.cs new file mode 100644 index 0000000..34100e8 --- /dev/null +++ b/Better1911/Configs/Shared.cs @@ -0,0 +1,21 @@ +using BepInEx.Configuration; +using UnityEngine; + +namespace Better1911.Configs +{ + public class SharedConfigs : IConfig + { + public ConfigEntry Recolor { get; set; } + public ConfigEntry Roughness { get; set; } + public ConfigEntry Metallic { get; set; } + public ConfigEntry NormalStrength { get; set; } + public ConfigEntry Specularity { get; set; } + public ConfigEntry RemoveTexture { get; set; } + + Color IConfig.Recolor => Recolor.Value; + float IConfig.Roughness => Roughness.Value; + float IConfig.Metallic => Metallic.Value; + float IConfig.NormalStrength => NormalStrength.Value; + float IConfig.Specularity => Specularity.Value; + } +} diff --git a/Better1911/Configs/Slide.cs b/Better1911/Configs/Slide.cs new file mode 100644 index 0000000..8e937e5 --- /dev/null +++ b/Better1911/Configs/Slide.cs @@ -0,0 +1,19 @@ +using BepInEx.Configuration; +using UnityEngine; + +namespace Better1911.Configs +{ + public class SlideConfig : SharedConfigs + { + public SlideConfig(string section, ConfigFile config) + { + Color c = new Color32(0xFF, 0xFF, 0xFF, 0xFF); + Recolor = config.Bind(section, nameof(Recolor), c, "Color of the slide"); + Roughness = config.Bind(section, nameof(Roughness), 1f, "Roughness of the material. Decrease for a more mirrored finish."); + Metallic = config.Bind(section, nameof(Metallic), 1f, "Metallic value for the material. Decrease for a flatter more polymer look."); + NormalStrength = config.Bind(section, nameof(NormalStrength), 1f, "Strength of the normal maps. Increase this for a more rugged look or decrease for a smoother look."); + Specularity = config.Bind(section, nameof(Specularity), 1f, "Specularity for the material."); + RemoveTexture = config.Bind(section, nameof(RemoveTexture), false, "Enable to remove texture. This can allow cleaner finishes and better recoloring."); + } + } +} diff --git a/Better1911/IConfig.cs b/Better1911/IConfig.cs new file mode 100644 index 0000000..dbbf9eb --- /dev/null +++ b/Better1911/IConfig.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +namespace Better1911 +{ + public interface IConfig + { + float Metallic { get; } + float NormalStrength { get; } + float Roughness { get; } + Color Recolor { get; } + float Specularity { get; } + } +} diff --git a/Better1911/Patches.cs b/Better1911/Patches.cs new file mode 100644 index 0000000..8764950 --- /dev/null +++ b/Better1911/Patches.cs @@ -0,0 +1,225 @@ +using FistVR; +using HarmonyLib; +using Better1911.Configs; +using UnityEngine; +using System; +using BepInEx.Configuration; + +namespace Better1911 +{ + internal class Patches + { + private static RootConfig Config => Plugin.Instance.Configs; + private static ConfigFile _cfg; + + private const string _tacMagID = "MagazineM1911Tactical"; + private const string _dilMagID = "MagazineM1911Dillinger"; + + public Patches(ConfigFile config) + { + _cfg = config; + } + + #region M1911Tactical Customization + + [HarmonyPatch(typeof(HandgunSlide), "Awake")] + [HarmonyPostfix] + private static void ChangeHandgun(HandgunSlide __instance) + { + var obj = __instance.Handgun.ObjectWrapper; + if (obj != null) + { + // M1911Operator is a lost cause + if (obj.ItemID == "M1911Tactical") + { + ReloadConfig(_cfg); + var slideTF = __instance.transform; + + // Red Dot + if (Config.DisableRedDot.Value) + { + slideTF.Find("Sight").gameObject.SetActive(false); + } + + // Glow Sights + var glowCfg = Config.GlowSights; + if (glowCfg.CustomColor.Value) + { + slideTF.Find("GlowSight (1)").GetComponent().material.SetColor("_Color", glowCfg.RearColor.Value); + slideTF.Find("GlowSight (2)").GetComponent().material.SetColor("_Color", glowCfg.RearColor.Value); + slideTF.Find("GlowSight (3)").GetComponent().material.SetColor("_Color", glowCfg.FrontColor.Value); + } + + // Gun Materials + var gunCfg = Config.GunCustomization; + if (gunCfg.CustomMaterials.Value) + { + var gun = slideTF.parent; + + // Frame + var frameMat = gun.transform.Find("Frame").GetComponent().material; + var frameCfg = gunCfg.Frame; + + if (frameCfg.RemoveTexture.Value) + { + frameMat.SetTexture("_MainTex", null); + } + + PaintComponent(frameMat, frameCfg); + + // Grip + var gripsMat = gun.transform.Find("Grips").GetComponent().material; + PaintComponent(gripsMat, gunCfg.Grips); + + // Slide + var slideMat = slideTF.Find("Slide").GetComponent().material; + var slideCfg = gunCfg.Slide; + + if (slideCfg.RemoveTexture.Value) + { + slideMat.SetTexture("_MainTex", null); + } + + PaintComponent(slideMat, slideCfg); + } + } + } + } + + #endregion + + #region Magazine Fix and Customization + + [HarmonyPatch(typeof(FVRFireArmMagazine), "Load")] + [HarmonyPostfix] + private static void Patch(FVRFireArmMagazine __instance) + { + if (Better1911(__instance.FireArm)) + { + ReloadConfig(_cfg); + var tf = __instance.transform; + var obj = __instance.ObjectWrapper; + + // Magic numbers to fix low cap mag pose/scale + if (FixPose(__instance)) + { + tf.localScale = new Vector3(1f, 1.07f, 1f); + tf.localPosition += new Vector3(0, -0.0052f, 0); + } + + // Magazine Materials + var cfg = Config.Magazine; + if (cfg.CustomMagazineMaterial.Value != MagazineConfig.MagazineMaterial.Default) + { + var viz = tf.Find("Viz"); + if (viz != null) + { + Material mat; + for (int i = 0; i < viz.childCount; i++) + { + var name = viz.GetChild(i).name.ToUpper(); + if (name.Contains("MAG") || name.Contains("GEO")) + { + mat = viz.GetChild(i).GetComponent().material; + + switch (cfg.CustomMagazineMaterial.Value) + { + case (MagazineConfig.MagazineMaterial.Frame): + PaintMag(mat, Config.GunCustomization.Frame, obj.ItemID); + break; + case (MagazineConfig.MagazineMaterial.Slide): + PaintMag(mat, Config.GunCustomization.Slide, obj.ItemID); + break; + default: + break; + } + + break; + } + } + } + } + } + } + + [HarmonyPatch(typeof(FVRFireArmMagazine), "Release")] + [HarmonyPrefix] + private static bool Unpatch(FVRFireArmMagazine __instance) + { + if (Better1911(__instance.FireArm) && FixPose(__instance)) + { + __instance.transform.localScale = new Vector3(1f, 1f, 1f); + } + return true; + } + + #endregion + + #region Helpers + + private static void ReloadConfig(ConfigFile config) + { + config.Reload(); + } + + private static void PaintMag(Material mat, IConfig config, string id) + { + if (id == _tacMagID) + { + mat.SetFloat("_Metal", config.Metallic); + mat.SetFloat("_BumpScale", config.NormalStrength); + mat.SetColor("_Color", config.Recolor); + mat.SetFloat("_Specularity", config.Specularity); + } + else + { + if (Config.GunCustomization.Frame.RemoveTexture.Value) + { + mat.SetTexture("_MainTex", null); + } + PaintComponent(mat, config); + } + } + + private static void PaintComponent(Material mat, IConfig config) + { + mat.SetFloat("_Metal", config.Metallic); + mat.SetFloat("_BumpScale", config.NormalStrength); + mat.SetFloat("_Roughness", config.Roughness); + mat.SetColor("_Color", config.Recolor); + mat.SetFloat("_Specularity", config.Specularity); + } + + private static bool Better1911(FVRFireArm gun) + { + var obj = gun.ObjectWrapper; + if (obj != null) + { + if (obj.ItemID == "M1911Tactical" || obj.ItemID == "M1911Operator") + { + return true; + } + } + return false; + } + + private static bool FixPose(FVRFireArmMagazine mag) + { + if(Config.Magazine.FixMagPos.Value) + { + var obj = mag.ObjectWrapper; + if (obj != null) + { + if (mag.m_capacity <= 9) + { + return true; + } + } + } + + return false; + } + + #endregion + } +} diff --git a/Better1911/Plugin.cs b/Better1911/Plugin.cs new file mode 100644 index 0000000..81f2f95 --- /dev/null +++ b/Better1911/Plugin.cs @@ -0,0 +1,30 @@ +using Deli; +using HarmonyLib; +using Better1911.Configs; +using UnityEngine.SceneManagement; +using BepInEx.Configuration; + +namespace Better1911 +{ + public class Plugin : DeliBehaviour + { + public static Plugin Instance { get; private set; } + + public RootConfig Configs { get; } + + private Patches _patches; + + public Plugin() + { + Instance = this; + + Configs = new RootConfig(Config); + _patches = new Patches(Config); + } + + private void Awake() + { + Harmony.CreateAndPatchAll(typeof(Patches)); + } + } +} diff --git a/Better1911/manifest.json b/Better1911/manifest.json new file mode 100644 index 0000000..e136d06 --- /dev/null +++ b/Better1911/manifest.json @@ -0,0 +1,15 @@ +{ + "guid": "better1911", + "version": "1.0.0", + "name": "Better1911", + "sourceUrl": "https://github.com/Maiq-The-Dude/RedDotRemoval", + "authors": [ + "M'aiq" + ], + "dependencies": { + "deli.core": "0.2.5" + }, + "runtime": { + "Better1911.dll": "assembly" + } +} diff --git a/RemoveSillyDot/Plugin.cs b/RemoveSillyDot/Plugin.cs deleted file mode 100644 index 79063f5..0000000 --- a/RemoveSillyDot/Plugin.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Deli; -using FistVR; -using HarmonyLib; - -namespace RemoveM1911TacRedDot -{ - public class Plugin : DeliBehaviour - { - [HarmonyPatch(typeof(HandgunSlide), "Awake")] - [HarmonyPostfix] - public static void SightRemove(HandgunSlide __instance) - { - var obj = __instance.Handgun.ObjectWrapper; - if (obj != null) - { - if (obj.ItemID == "M1911Tactical") - { - var slideTF = __instance.transform; - slideTF.Find("Sight").gameObject.SetActive(false); - } - } - } - - void Awake() - { - Harmony.CreateAndPatchAll(typeof(Plugin)); - } - } -} diff --git a/RemoveSillyDot/manifest.json b/RemoveSillyDot/manifest.json deleted file mode 100644 index b5ba08f..0000000 --- a/RemoveSillyDot/manifest.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "guid": "removem1911trd", - "version": "0.0.1", - "name": "RemoveM1911TacRedDot", - "authors": [ - "M'aiq" - ], - "dependencies": { - "deli.core": "0.2.5" - }, - "runtime": { - "RemoveM1911TacRedDot.dll": "assembly" - } -}