diff --git a/Assets/MeatKit/BuildProfile.asset b/Assets/MeatKit/BuildProfile.asset index eec7587..afcbe6f 100644 --- a/Assets/MeatKit/BuildProfile.asset +++ b/Assets/MeatKit/BuildProfile.asset @@ -13,7 +13,7 @@ MonoBehaviour: m_EditorClassIdentifier: PackageName: TNH_Quality_of_Life_Improvements Author: muskit - Version: 1.0.1 + Version: 1.1.0 Icon: {fileID: 2800000, guid: 785b7946398f5314b95bf593d2d77d67, type: 3} ReadMe: {fileID: 102900000, guid: ab1d6dea017447a48ac348db588a6f35, type: 3} WebsiteURL: https://github.com/muskit/TNH-Quality-of-Life-Improvements diff --git a/Assets/MeatKit/MeatKitPlugin.cs b/Assets/MeatKit/MeatKitPlugin.cs index 88c6a61..1bbc749 100644 --- a/Assets/MeatKit/MeatKitPlugin.cs +++ b/Assets/MeatKit/MeatKitPlugin.cs @@ -1,4 +1,5 @@ #if H3VR_IMPORTED +using HarmonyLib; using System.IO; using System.Reflection; using BepInEx; @@ -42,10 +43,11 @@ public class MeatKitPlugin : BaseUnityPlugin private static InPlay instance; - private LeaderboardPlayerCountPatch lpc; private bool lpcModGone = false; private float lpcModSearchTimeEnd; + private Harmony harmony; + private void SceneChanged(Scene from, Scene to) { //Logger.LogInfo(string.Format("scene chg: {0} --> {1}", from.name, to.name)); @@ -63,6 +65,11 @@ public class MeatKitPlugin : BaseUnityPlugin } } + public MeatKitPlugin(): base() + { + harmony = new Harmony("muskit.TNHQualityOfLifeImprovements"); + } + private void Awake() { // load asset bundle @@ -96,11 +103,17 @@ public class MeatKitPlugin : BaseUnityPlugin true, "Shows how many holds the player has completed by their radar hand."); + // patch KillAll code (only acts w/ health crystals) + TimedHealthCrystalPatch.Patch(harmony); + // patch leaderboard code if (cfgShowLPC.Value) - lpc = new LeaderboardPlayerCountPatch(); + LeaderboardPlayerCountPatch.Patch(harmony); + + if(cfgShowHolds.Value) + HoldCounter.Patch(harmony); - // give 120 seconds to search for old mod + // give 120 seconds to search for old mod, which we want to kill lpcModSearchTimeEnd = Time.realtimeSinceStartup + 120; } // DO NOT EDIT. diff --git a/Assets/README.md b/Assets/README.md index f1f38c3..3083209 100644 --- a/Assets/README.md +++ b/Assets/README.md @@ -12,12 +12,15 @@ Enable/disable these features in your mod manager's *Config editor*. For any issues/ideas, please create an issue on the GitHub repo (linked on Thunderstore page). ## Changelog +1.1.0 +* Added Health Crystals expiration indicator + 1.0.1 -* Fixed the in-play improvements only applying in Classic Hallways map (whoops!!) +* Fixed the in-play improvements only applying to Classic Hallways map (whoops!!) * Added option to enable/disable showing player count of online leaderboards * Added option to enable/disable HP text opacity/shadow change * (Surprisingly, the HP text normally doesn't have full opacity) -* Searching for TNH Leaderboards Player Count now stops after 120s +* Searching for the deprecated TNH Leaderboards Player Count mod to kill now stops after 120s 1.0.0 diff --git a/Assets/_Prefabs/HealthCrystalTimer.prefab b/Assets/_Prefabs/HealthCrystalTimer.prefab new file mode 100644 index 0000000..2f90aec --- /dev/null +++ b/Assets/_Prefabs/HealthCrystalTimer.prefab @@ -0,0 +1,187 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 1634027973393822} + m_IsPrefabParent: 1 +--- !u!1 &1475934434838188 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 224853189626207054} + - component: {fileID: 222684863573680672} + - component: {fileID: 114673309682266402} + m_Layer: 5 + m_Name: Image + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!1 &1634027973393822 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 224077453978722080} + - component: {fileID: 223544683124447678} + - component: {fileID: 114094006499494552} + - component: {fileID: 114774830210974956} + - component: {fileID: 114654661998195444} + m_Layer: 5 + m_Name: HealthCrystalTimer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &114094006499494552 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1634027973393822} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_UiScaleMode: 0 + m_ReferencePixelsPerUnit: 100 + m_ScaleFactor: 1 + m_ReferenceResolution: {x: 800, y: 600} + m_ScreenMatchMode: 0 + m_MatchWidthOrHeight: 0 + m_PhysicalUnit: 3 + m_FallbackScreenDPI: 96 + m_DefaultSpriteDPI: 96 + m_DynamicPixelsPerUnit: 1 +--- !u!114 &114654661998195444 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1634027973393822} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c0cc182175a3417499d53e43378f028c, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &114673309682266402 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1475934434838188} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_Sprite: {fileID: 21300000, guid: 3677786155d617b4cb39bf42eddd24ad, type: 3} + m_Type: 3 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 0 + m_FillOrigin: 2 +--- !u!114 &114774830210974956 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1634027973393822} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 1301386320, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_IgnoreReversedGraphics: 1 + m_BlockingObjects: 0 + m_BlockingMask: + serializedVersion: 2 + m_Bits: 4294967295 +--- !u!222 &222684863573680672 +CanvasRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1475934434838188} +--- !u!223 &223544683124447678 +Canvas: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1634027973393822} + m_Enabled: 1 + serializedVersion: 3 + m_RenderMode: 2 + m_Camera: {fileID: 0} + m_PlaneDistance: 100 + m_PixelPerfect: 0 + m_ReceivesEvents: 1 + m_OverrideSorting: 0 + m_OverridePixelPerfect: 0 + m_SortingBucketNormalizedSize: 0 + m_AdditionalShaderChannelsFlag: 0 + m_SortingLayerID: 0 + m_SortingOrder: 0 + m_TargetDisplay: 0 +--- !u!224 &224077453978722080 +RectTransform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1634027973393822} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 224853189626207054} + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 574, y: 308.5} + m_SizeDelta: {x: 468, y: 472} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!224 &224853189626207054 +RectTransform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1475934434838188} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 224077453978722080} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 468, y: 472} + m_Pivot: {x: 0.5, y: 0.5} diff --git a/Assets/_Prefabs/HealthCrystalTimer.prefab.meta b/Assets/_Prefabs/HealthCrystalTimer.prefab.meta new file mode 100644 index 0000000..5f1abd6 --- /dev/null +++ b/Assets/_Prefabs/HealthCrystalTimer.prefab.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: a97af7648bcd6394b867989bf8fb9ed0 +timeCreated: 1643099434 +licenseType: Free +NativeFormatImporter: + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Prefabs/HoldCounter.prefab b/Assets/_Prefabs/HoldCounter.prefab index 8e771c3..95ba49b 100644 --- a/Assets/_Prefabs/HoldCounter.prefab +++ b/Assets/_Prefabs/HoldCounter.prefab @@ -66,6 +66,24 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 +--- !u!1 &1774018057659698 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 224420167260936368} + - component: {fileID: 222388691975761020} + - component: {fileID: 114828117127462556} + - component: {fileID: 114042133408737726} + m_Layer: 5 + m_Name: Text (2) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 --- !u!114 &114032145135548160 MonoBehaviour: m_ObjectHideFlags: 1 @@ -99,6 +117,20 @@ MonoBehaviour: m_VerticalOverflow: 0 m_LineSpacing: 1 m_Text: HOLDS COMPLETED +--- !u!114 &114042133408737726 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1774018057659698} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 1573420865, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_EffectColor: {r: 0, g: 0, b: 0, a: 0.734} + m_EffectDistance: {x: 3.5, y: -3.5} + m_UseGraphicAlpha: 1 --- !u!114 &114133878122943296 MonoBehaviour: m_ObjectHideFlags: 1 @@ -192,6 +224,39 @@ MonoBehaviour: m_VerticalOverflow: 0 m_LineSpacing: 1 m_Text: "-1 / \u221E" +--- !u!114 &114828117127462556 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1774018057659698} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_FontData: + m_Font: {fileID: 12800000, guid: 05d48c500227c8a4bbb7c02e3ccbb0b3, type: 3} + m_FontSize: 26 + m_FontStyle: 0 + m_BestFit: 1 + m_MinSize: 10 + m_MaxSize: 100 + m_Alignment: 7 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: 0 0 --- !u!114 &114972162530505676 MonoBehaviour: m_ObjectHideFlags: 1 @@ -208,6 +273,12 @@ MonoBehaviour: m_BlockingMask: serializedVersion: 2 m_Bits: 4294967295 +--- !u!222 &222388691975761020 +CanvasRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1774018057659698} --- !u!222 &222541359112789466 CanvasRenderer: m_ObjectHideFlags: 1 @@ -255,8 +326,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: -45} - m_SizeDelta: {x: 0, y: -90} + m_AnchoredPosition: {x: 0, y: -12.550003} + m_SizeDelta: {x: 0, y: -100.3} m_Pivot: {x: 0.5, y: 0.5} --- !u!224 &224364969672532764 RectTransform: @@ -276,6 +347,24 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 105.9} m_SizeDelta: {x: 0, y: -211.8} m_Pivot: {x: 0.5, y: 0.5} +--- !u!224 &224420167260936368 +RectTransform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1774018057659698} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 224724389550513542} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0} + m_AnchorMax: {x: 0.5, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 308.5, y: 64.57} + m_Pivot: {x: 0.5, y: 0} --- !u!224 &224724389550513542 RectTransform: m_ObjectHideFlags: 1 @@ -288,6 +377,7 @@ RectTransform: m_Children: - {fileID: 224364969672532764} - {fileID: 224142695019321682} + - {fileID: 224420167260936368} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} diff --git a/Assets/_Prefabs/PlayerCount_LoadingText.prefab b/Assets/_Prefabs/PlayerCount_LoadingText.prefab index 9b01004..b3c4779 100644 --- a/Assets/_Prefabs/PlayerCount_LoadingText.prefab +++ b/Assets/_Prefabs/PlayerCount_LoadingText.prefab @@ -113,9 +113,9 @@ MonoBehaviour: m_AlignByGeometry: 0 m_RichText: 1 m_HorizontalOverflow: 0 - m_VerticalOverflow: 0 + m_VerticalOverflow: 1 m_LineSpacing: 1 - m_Text: LOADING PLAYER COUNT + m_Text: RETRIEVING PLAYER COUNT --- !u!222 &222658238543524802 CanvasRenderer: m_ObjectHideFlags: 1 diff --git a/Assets/_Prefabs/Store.asset b/Assets/_Prefabs/Store.asset index 9274818..629e3d0 100644 --- a/Assets/_Prefabs/Store.asset +++ b/Assets/_Prefabs/Store.asset @@ -16,3 +16,4 @@ MonoBehaviour: - {fileID: 1428988585174978, guid: c034a3fdd4eaa554bb81a9a202bf37dd, type: 2} - {fileID: 1421894940388160, guid: 2e88fb286dba59a45b49fb0ae7d9449b, type: 2} - {fileID: 1395656030192232, guid: 6085354c72844664589bb5f21f9872b1, type: 2} + - {fileID: 1634027973393822, guid: a97af7648bcd6394b867989bf8fb9ed0, type: 2} diff --git a/Assets/_Scripts/HoldCounter.cs b/Assets/_Scripts/HoldCounter.cs index 2661bca..f27a649 100644 --- a/Assets/_Scripts/HoldCounter.cs +++ b/Assets/_Scripts/HoldCounter.cs @@ -1,5 +1,5 @@ -using System.Collections; -using System.Collections.Generic; +using System.Reflection; +using HarmonyLib; using UnityEngine; using UnityEngine.UI; using FistVR; @@ -8,37 +8,62 @@ namespace TNHQoLImprovements { public class HoldCounter : MonoBehaviour { + private Text lblHoldCount; + private Text lblWinLose; + + public static int[] winLose = { -1, 1 }; + public const string WIN_LOSE_TEXT = "{0} {1}"; + + private void OnDeath(bool _) { Debug.Log("I died!"); + // TODO: bind stats to controller hand } - // TODO: lose counter. patch postfix FistVR.TNH_Manager.HoldPointCompleted - private void OnHoldLose() + // TODO: win/lose counter. patch postfix FistVR.TNH_Manager.HoldPointCompleted + public static void Patch(Harmony harmony) { - + var original = typeof(TNH_Manager).GetMethod("HoldPointCompleted", BindingFlags.Public | BindingFlags.Instance); + var patch = typeof(HoldCounter).GetMethod("OnHoldEnd"); + Debug.Log(string.Format("Original: {0} // Patch: {1}", original, patch)); + harmony.Patch(original, postfix: new HarmonyMethod(patch)); + } + public static void OnHoldEnd(TNH_HoldPoint p, bool success) + { + if (success) + winLose[0]++; + else + winLose[1]++; } void Start() { - //transform.parent = GameObject.Find("_NewTAHReticle/TAHReticle_HealthBar").transform; - transform.parent = FindObjectOfType().transform.GetChild(3); transform.localPosition = new Vector3(-1f, 0, -.5f); transform.localRotation = Quaternion.Euler(90, 0, 0); transform.localScale = new Vector3(0.002f, 0.002f, 0.002f); + lblHoldCount = transform.GetChild(1).GetComponent(); + lblWinLose = transform.GetChild(2).GetComponent(); + + winLose[0] = 0; + winLose[1] = 0; + FindObjectOfType().PlayerDeathEvent += OnDeath; } void Update() { + // Total hold count string display = ""; if (InPlay.tnhManager.ProgressionMode == TNHSetting_ProgressionType.Marathon) display = InPlay.tnhManager.m_level.ToString() + " / ∞"; else display = string.Format("{0} / {1}", InPlay.tnhManager.m_level, InPlay.tnhManager.m_maxLevels); + lblHoldCount.text = display; - transform.GetChild(1).GetComponent().text = display; + // Win/Lost holds + lblWinLose.text = string.Format(WIN_LOSE_TEXT, winLose[0], winLose[1]); } } } \ No newline at end of file diff --git a/Assets/_Scripts/InPlay.cs b/Assets/_Scripts/InPlay.cs index 7ec7d97..ec0053f 100644 --- a/Assets/_Scripts/InPlay.cs +++ b/Assets/_Scripts/InPlay.cs @@ -11,10 +11,8 @@ namespace TNHQoLImprovements public class InPlay : MonoBehaviour { private GameObject gObjHUD; - private GameObject gObjTokens; public static TNH_Manager tnhManager; - #region INITIALIZATION void ImproveHPTextReadability() { var canvas = gObjHUD.GetComponent(); @@ -60,10 +58,9 @@ namespace TNHQoLImprovements if(MeatKitPlugin.cfgShowHPBackground.Value || MeatKitPlugin.cfgSolidifyHPText.Value) ImproveHPTextReadability(); if (MeatKitPlugin.cfgShowTokens.Value) - Instantiate(MeatKitPlugin.bundle.LoadAsset("TokenCounter")); + Instantiate(MeatKitPlugin.bundle.LoadAsset("TokenCounter"), FindObjectOfType().transform.GetChild(3)); if (MeatKitPlugin.cfgShowHolds.Value) - Instantiate(MeatKitPlugin.bundle.LoadAsset("HoldCounter")); + Instantiate(MeatKitPlugin.bundle.LoadAsset("HoldCounter"), FindObjectOfType().transform.GetChild(3)); } - #endregion } } \ No newline at end of file diff --git a/Assets/_Scripts/LeaderboardPlayerCount.cs b/Assets/_Scripts/LeaderboardPlayerCount.cs index 75915aa..428f8c6 100644 --- a/Assets/_Scripts/LeaderboardPlayerCount.cs +++ b/Assets/_Scripts/LeaderboardPlayerCount.cs @@ -15,22 +15,13 @@ namespace TNHQoLImprovements private bool tnhTweakerInstalled = false; private string curID; + private string loadingStr; private TNH_ScoreDisplay scoreDisplay; private Text lblGlobalScores; private GameObject gObjLoading; #region INITIALIZATION - // public void Start() - // { - // Debug.Log("--- Installed BepInEx Plugins ---"); - // foreach (var plugin in Chainloader.PluginInfos) - // { - // Debug.Log(plugin.Key); - // } - // Debug.Log("--- End Plugins ---"); - //} - public void Init(TNH_ScoreDisplay tnhScore, Text scoreLabel, GameObject gObjLoading) { if (initialized) @@ -41,12 +32,13 @@ namespace TNHQoLImprovements this.lblGlobalScores.resizeTextForBestFit = true; this.lblGlobalScores.horizontalOverflow = HorizontalWrapMode.Overflow; this.gObjLoading = gObjLoading; + loadingStr = gObjLoading.GetComponentInChildren().text; var loadedAssemblies = System.AppDomain.CurrentDomain.GetAssemblies(); if (Array.Exists(loadedAssemblies, x => x.GetName().Name == "TakeAndHoldTweaker")) { tnhTweakerInstalled = true; - this.gObjLoading.transform.GetChild(0).GetComponent().text = "Online leaderboards player count is incompatible with TNHTweaker."; + this.gObjLoading.transform.GetChild(0).GetComponent().text = "Online player count is incompatible with TNHTweaker."; this.gObjLoading.SetActive(true); } @@ -66,23 +58,31 @@ namespace TNHQoLImprovements } private void UpdatePlayerCountDisplay(string id) - { - try - { - string playerCountText = Steamworks.SteamUserStats - .GetLeaderboardEntryCount(HighScoreManager.Leaderboards[id]) - .ToString("N0"); - lblGlobalScores.text = "Global Scores: (" + playerCountText + " players)"; - curID = id; + { + try + { + string playerCountText = Steamworks.SteamUserStats + .GetLeaderboardEntryCount(HighScoreManager.Leaderboards[id]) + .ToString("N0"); + + lblGlobalScores.text = "Global Scores: (" + playerCountText + " players)"; + curID = id; gObjLoading.SetActive(false); - } - catch (KeyNotFoundException e) - { - lblGlobalScores.text = "Global Scores:"; + } + catch (KeyNotFoundException e) + { + lblGlobalScores.text = "Global Scores:"; + gObjLoading.GetComponentInChildren().text = loadingStr; gObjLoading.SetActive(true); - curID = null; + curID = null; + } + catch (Exception e) + { + gObjLoading.GetComponentInChildren().text = string.Format("Unknown error occured trying to retrieve online player count.\n\n" + + "{0}", e); + gObjLoading.SetActive(true); } - } - } + } + } #endregion } \ No newline at end of file diff --git a/Assets/_Scripts/LeaderboardPlayerCountPatch.cs b/Assets/_Scripts/LeaderboardPlayerCountPatch.cs index e8d5dc7..e04f187 100644 --- a/Assets/_Scripts/LeaderboardPlayerCountPatch.cs +++ b/Assets/_Scripts/LeaderboardPlayerCountPatch.cs @@ -1,25 +1,24 @@ -using HarmonyLib; +using System.Reflection; +using HarmonyLib; using UnityEngine; using UnityEngine.UI; using FistVR; namespace TNHQoLImprovements { - [HarmonyPatch] - public class LeaderboardPlayerCountPatch + public static class LeaderboardPlayerCountPatch { - Harmony harmony; private static GameObject gObjLoading; private static Text uiGlobalText; - public LeaderboardPlayerCountPatch() + public static void Patch(Harmony harmony) { - harmony = new Harmony("me.muskit.TNHQualityOfLifeImprovements.LeaderboardPlayerCount"); - harmony.PatchAll(); + var original = typeof(TNH_ScoreDisplay).GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Instance); + var newfunc = typeof(LeaderboardPlayerCountPatch).GetMethod("Setup"); + + harmony.Patch(original, postfix: new HarmonyMethod(newfunc)); } - [HarmonyPostfix] - [HarmonyPatch(typeof(TNH_ScoreDisplay), "Start")] public static void Setup(TNH_ScoreDisplay __instance) { GameObject gObjLeaderboard = null; diff --git a/Assets/_Scripts/MeshRendererFlicker.cs b/Assets/_Scripts/MeshRendererFlicker.cs new file mode 100644 index 0000000..78af9c1 --- /dev/null +++ b/Assets/_Scripts/MeshRendererFlicker.cs @@ -0,0 +1,64 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace TNHQoLImprovements +{ + /// + /// Flash attached MeshRenderer the timer runs out. + /// + public class MeshRendererFlicker : MonoBehaviour + { + private bool initialized = false; + + private float beginTime; + private float onLength; + private float offLength; + private float stateChangeTime = 0; + private bool visible = true; + + private MeshRenderer mesh; + + void Start() + { + mesh = GetComponent(); + } + + public void Init(float interval, float onToOffRatio = 0.5f, float beginAfter = 0) + { + beginTime = Time.time + beginAfter; + onLength = interval * onToOffRatio; + offLength = interval * (1 - onToOffRatio); + + initialized = true; + } + + void Update() + { + if (!initialized || Time.time < beginTime) + return; + + if (Time.time >= stateChangeTime) + { + visible = !visible; + mesh.enabled = visible; + + if (visible) // set time to stay on + { + stateChangeTime = Time.time + onLength; + } + else // set time to stay off + { + stateChangeTime = Time.time + offLength; + } + } + + //if (Time.time >= stateChangeTime) + // { + // stateChangeTime = Time.time + interval; + // visible = !visible; + // mesh.enabled = visible; + // } + } + } +} \ No newline at end of file diff --git a/Assets/_Scripts/MeshRendererFlicker.cs.meta b/Assets/_Scripts/MeshRendererFlicker.cs.meta new file mode 100644 index 0000000..40b93e3 --- /dev/null +++ b/Assets/_Scripts/MeshRendererFlicker.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 41ced368c613e2444bdbb07051989499 +timeCreated: 1643160950 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/TimedHealthCrystalPatch.cs b/Assets/_Scripts/TimedHealthCrystalPatch.cs new file mode 100644 index 0000000..b669c73 --- /dev/null +++ b/Assets/_Scripts/TimedHealthCrystalPatch.cs @@ -0,0 +1,57 @@ +using System.Reflection; +using HarmonyLib; +using UnityEngine; +using FistVR; + +namespace TNHQoLImprovements +{ + /// + /// If KillAfter is attached to a HealthCrystal, show visual representation of expiration. + /// + public static class TimedHealthCrystalPatch + { + private static GameObject timerAsset; + public const int VISUAL_APPROACH = 2; + + public static void Patch(Harmony harmony) + { + timerAsset = MeatKitPlugin.bundle.LoadAsset("HealthCrystalTimer"); + + var original = typeof(KillAfter).GetMethod("Start", BindingFlags.NonPublic | BindingFlags.Instance); + var newfunc = typeof(TimedHealthCrystalPatch).GetMethod("Setup"); + + harmony.Patch(original, postfix: new HarmonyMethod(newfunc)); + } + + public static void Setup(KillAfter __instance) + { + // only work with Health Crystals + if (__instance.transform.GetComponentInChildren() == null) + return; + + Debug.Log("KillAfter will expire in " + __instance.DieTime + " seconds."); + + GameObject timer; + Transform healthCrystal = __instance.transform.Find("HealthCrystal"); + switch (VISUAL_APPROACH) + { + case 0: // ring above + timer = GameObject.Instantiate(timerAsset, healthCrystal); + timer.GetComponent().Init(__instance.DieTime); + timer.transform.localScale = new Vector2(0.001f, 0.001f); + timer.transform.localPosition = new Vector3(0, .9f, 0); + break; + case 1: // ring around + timer = GameObject.Instantiate(timerAsset, healthCrystal); + timer.GetComponent().Init(__instance.DieTime); + timer.transform.localScale = new Vector2(0.0035f, 0.0035f); + timer.transform.localPosition = Vector3.zero; + break; + case 2: // flashing crystal + var flicker = healthCrystal.gameObject.AddComponent(); + flicker.Init(.4f, 0.6f, __instance.DieTime - 3f); + break; + } + } + } +} \ No newline at end of file diff --git a/Assets/_Scripts/TimedHealthCrystalPatch.cs.meta b/Assets/_Scripts/TimedHealthCrystalPatch.cs.meta new file mode 100644 index 0000000..24195a5 --- /dev/null +++ b/Assets/_Scripts/TimedHealthCrystalPatch.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: e2d8d57a4a90c704da061837b5f7b16a +timeCreated: 1643082249 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Scripts/TokenCounter.cs b/Assets/_Scripts/TokenCounter.cs index 6db66b6..28d6f17 100644 --- a/Assets/_Scripts/TokenCounter.cs +++ b/Assets/_Scripts/TokenCounter.cs @@ -9,8 +9,6 @@ namespace TNHQoLImprovements { void Start() { - //transform.parent = GameObject.Find("_NewTAHReticle/TAHReticle_HealthBar").transform; - transform.parent = FindObjectOfType().transform.GetChild(3); transform.localPosition = new Vector3(1, 0, -.5f); transform.localRotation = Quaternion.Euler(90, 0, 0); transform.localScale = new Vector3(0.002f, 0.002f, 0.002f); diff --git a/Assets/_Scripts/UIRingTimer.cs b/Assets/_Scripts/UIRingTimer.cs new file mode 100644 index 0000000..2466d81 --- /dev/null +++ b/Assets/_Scripts/UIRingTimer.cs @@ -0,0 +1,33 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class UIRingTimer : MonoBehaviour { + + private bool initialized = false; + private float endTime; + private float length; + + private Image ringImg; + + private void Start() + { + ringImg = GetComponentInChildren(); + } + + public void Init(float timeInSeconds) + { + length = timeInSeconds; + endTime = Time.time + length; + initialized = true; + } + + void Update () { + if (!initialized) + return; + + float amount = (endTime - Time.time) / length; + ringImg.fillAmount = Mathf.Clamp01(amount); + } +} diff --git a/Assets/_Scripts/UIRingTimer.cs.meta b/Assets/_Scripts/UIRingTimer.cs.meta new file mode 100644 index 0000000..77e7b1a --- /dev/null +++ b/Assets/_Scripts/UIRingTimer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c0cc182175a3417499d53e43378f028c +timeCreated: 1643099834 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Textures.meta b/Assets/_Textures.meta new file mode 100644 index 0000000..bff12f7 --- /dev/null +++ b/Assets/_Textures.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 202273f3dee1d244dbfc63238c672310 +folderAsset: yes +timeCreated: 1643099086 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_Textures/White Ring.png b/Assets/_Textures/White Ring.png new file mode 100644 index 0000000..dbfb81a Binary files /dev/null and b/Assets/_Textures/White Ring.png differ diff --git a/Assets/_Textures/White Ring.png.meta b/Assets/_Textures/White Ring.png.meta new file mode 100644 index 0000000..efdd098 --- /dev/null +++ b/Assets/_Textures/White Ring.png.meta @@ -0,0 +1,76 @@ +fileFormatVersion: 2 +guid: 3677786155d617b4cb39bf42eddd24ad +timeCreated: 1643099089 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 4 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + filterMode: -1 + aniso: -1 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Standalone + maxTextureSize: 2048 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: