From 062621fac073dd6c004386a8897858cc3f8c411f Mon Sep 17 00:00:00 2001 From: Devyn Myers Date: Sun, 13 Feb 2022 16:09:25 -0500 Subject: [PATCH] Fixed some tag search bugs, and added unlock support to old spawner --- .../ObjectTemplates/UnlockedItemSaveData.cs | 19 ++++ Scripts/OtherLoader.cs | 16 +++- Scripts/Patches/ItemSpawnerPatch.cs | 96 +++++++++++++++++++ Scripts/Patches/ItemSpawnerV2Patch.cs | 37 ++++--- 4 files changed, 147 insertions(+), 21 deletions(-) diff --git a/Scripts/ObjectTemplates/UnlockedItemSaveData.cs b/Scripts/ObjectTemplates/UnlockedItemSaveData.cs index d044acb..591bb53 100644 --- a/Scripts/ObjectTemplates/UnlockedItemSaveData.cs +++ b/Scripts/ObjectTemplates/UnlockedItemSaveData.cs @@ -9,8 +9,21 @@ public class UnlockedItemSaveData { public bool UnlockAll = false; public bool AutoUnlockNonRewards = true; + public ItemUnlockMode UnlockMode; public List UnlockedItemIDs = new List(); + public UnlockedItemSaveData() { } + + public UnlockedItemSaveData(ItemUnlockMode unlockMode) + { + UnlockMode = unlockMode; + + if(unlockMode == ItemUnlockMode.Unlockathon) + { + AutoUnlockNonRewards = false; + } + } + public bool IsItemUnlocked(string itemID) { return UnlockAll || UnlockedItemIDs.Contains(itemID); @@ -27,4 +40,10 @@ public bool UnlockItem(string itemID) return false; } } + + public enum ItemUnlockMode + { + Normal, + Unlockathon + } } diff --git a/Scripts/OtherLoader.cs b/Scripts/OtherLoader.cs index 80bde04..3416eb9 100644 --- a/Scripts/OtherLoader.cs +++ b/Scripts/OtherLoader.cs @@ -41,6 +41,7 @@ public class OtherLoader : StratumPlugin public static ConfigEntry EnableLogging; public static ConfigEntry LogLoading; public static ConfigEntry AddUnloadButton; + public static ConfigEntry UnlockMode; public static int MaxActiveLoaders = 0; @@ -120,6 +121,13 @@ private void LoadConfigFile() "When true, and sodalite is installed, you'll have a wristmenu button that unloads all modded asset bundles for testing" ); + UnlockMode = Config.Bind( + "General", + "UnlockMode", + ItemUnlockMode.Normal, + "When set to Unlockathon, all items will start out locked, and you must unlock items by finding them in game" + ); + MaxActiveLoaders = MaxActiveLoadersConfig.Value; } @@ -134,7 +142,8 @@ private void InitUnlockSaveData() if (!File.Exists(UnlockedItemSaveDataPath)) { - UnlockSaveData = new UnlockedItemSaveData(); + UnlockSaveData = new UnlockedItemSaveData(UnlockMode.Value); + SaveUnlockedItemsData(); } @@ -151,6 +160,11 @@ public static void LoadUnlockedItemsData() { string unlockJson = File.ReadAllText(UnlockedItemSaveDataPath); UnlockSaveData = JsonConvert.DeserializeObject(unlockJson); + + if(UnlockSaveData.UnlockMode != UnlockMode.Value) + { + UnlockSaveData = new UnlockedItemSaveData(UnlockMode.Value); + } } catch (Exception ex) { diff --git a/Scripts/Patches/ItemSpawnerPatch.cs b/Scripts/Patches/ItemSpawnerPatch.cs index d9ea37e..c2050a6 100644 --- a/Scripts/Patches/ItemSpawnerPatch.cs +++ b/Scripts/Patches/ItemSpawnerPatch.cs @@ -234,6 +234,102 @@ private static bool DrawTilesCategoryPatch(ItemSpawnerID.EItemCategory Category, } + [HarmonyPatch(typeof(ItemSpawnerUI), "Draw_Tiles_SubCategory")] + [HarmonyPrefix] + private static bool DrawTilesSubCategoryPatch(ItemSpawnerID.ESubCategory SubCategory, ItemSpawnerUI __instance) + { + int num = 0; + bool sandboxMode = !GM.CurrentSceneSettings.UsesUnlockSystem; + List availableInSubCategory = IM.GetAvailableInSubCategory(SubCategory); + + for (int i = __instance.m_curPage * 10; i < availableInSubCategory.Count; i++) + { + if (num < Mathf.Min(10 + __instance.m_curPage * 10, 10)) + { + + //Handle the case where the item is not unlocked globally + if(availableInSubCategory[i].MainObject != null && + !OtherLoader.UnlockSaveData.IsItemUnlocked(availableInSubCategory[i].MainObject.ItemID)) + { + __instance.Tiles_SelectionPage[num].gameObject.SetActive(true); + __instance.Tiles_SelectionPage[num].Image.sprite = OtherLoader.LockIcon; + __instance.Tiles_SelectionPage[num].Text.text = "???"; + __instance.Tiles_SelectionPage[num].Item = availableInSubCategory[i]; + + __instance.Tiles_SelectionPage[num].IsSpawnable = false; + __instance.Tiles_SelectionPage[num].LockedCorner.gameObject.SetActive(false); + + } + + //If item is unlocked globally, just perform normal logic + else + { + __instance.Tiles_SelectionPage[num].gameObject.SetActive(true); + __instance.Tiles_SelectionPage[num].Image.sprite = availableInSubCategory[i].Sprite; + __instance.Tiles_SelectionPage[num].Text.text = availableInSubCategory[i].DisplayName; + __instance.Tiles_SelectionPage[num].Item = availableInSubCategory[i]; + + if (GM.Omni.OmniUnlocks.IsEquipmentUnlocked(__instance.Tiles_SelectionPage[num].Item, sandboxMode)) + { + __instance.Tiles_SelectionPage[num].IsSpawnable = true; + __instance.Tiles_SelectionPage[num].LockedCorner.gameObject.SetActive(false); + } + else + { + __instance.Tiles_SelectionPage[num].IsSpawnable = false; + __instance.Tiles_SelectionPage[num].LockedCorner.gameObject.SetActive(true); + } + } + + num++; + } + } + for (int j = num; j < __instance.Tiles_SelectionPage.Length; j++) + { + __instance.Tiles_SelectionPage[j].gameObject.SetActive(false); + } + + return false; + } + + + + [HarmonyPatch(typeof(ItemSpawnerUI), "ButtonPress_SelectionTile")] + [HarmonyPrefix] + private static bool SelectTilePatch(int i, ItemSpawnerUI __instance) + { + if (__instance.refireTick > 0f) + { + return false; + } + __instance.ButtonPress(0); + switch (__instance.m_curMode) + { + case ItemSpawnerUI.ItemSpawnerPageMode.Home: + __instance.m_curCategory = __instance.Tiles_SelectionPage[i].Category; + __instance.SetMode_Category(); + break; + case ItemSpawnerUI.ItemSpawnerPageMode.Category: + __instance.m_curSubCategory = __instance.Tiles_SelectionPage[i].SubCategory; + __instance.SetMode_SubCategory(); + break; + case ItemSpawnerUI.ItemSpawnerPageMode.SubCategory: + + if(__instance.Tiles_SelectionPage[i].Item.MainObject != null && + OtherLoader.UnlockSaveData.IsItemUnlocked(__instance.Tiles_SelectionPage[i].Item.MainObject.ItemID)) + { + __instance.m_curID = __instance.Tiles_SelectionPage[i].Item; + __instance.m_IDSelectedForSpawn = __instance.Tiles_SelectionPage[i].Item; + __instance.SetMode_Details(); + } + + break; + } + + return false; + } + + [HarmonyPatch(typeof(ItemSpawnerUI), "ButtonPress_Next")] [HarmonyPrefix] diff --git a/Scripts/Patches/ItemSpawnerV2Patch.cs b/Scripts/Patches/ItemSpawnerV2Patch.cs index cba1794..4962e89 100644 --- a/Scripts/Patches/ItemSpawnerV2Patch.cs +++ b/Scripts/Patches/ItemSpawnerV2Patch.cs @@ -729,6 +729,15 @@ private static bool RedrawListPatch(ItemSpawnerV2 __instance) private static Dictionary GetEntryPairsFromQuery(List itemIDs, Dictionary> tagQuery) { + /* + OtherLogger.Log("Performing Tag Saerch!", OtherLogger.LogType.General); + + foreach (KeyValuePair> pair in tagQuery) + { + OtherLogger.Log("Tag Type: " + pair.Key.ToString() + ", Values: " + String.Join(",", pair.Value.ToArray()), OtherLogger.LogType.General); + } + */ + //Create a dictionary and populate it with items that have an FVRObject and a spawner entry Dictionary entryDic = new Dictionary(); for (int i = 0; i < itemIDs.Count; i++) @@ -768,8 +777,6 @@ private static Dictionary GetEntryPairsFromQuery(Li else if (item.Category == FVRObject.ObjectCategory.Attachment && !ShouldIncludeAttachment(item, tagQuery)) continue; - else if (item.Category == FVRObject.ObjectCategory.Magazine && !ShouldIncludeMagazine(item, tagQuery)) continue; - entryDic[item] = entry; } @@ -787,6 +794,14 @@ private static bool ShouldIncludeGeneral(FVRObject item, ItemSpawnerEntry entry, if (tagQuery[TagType.ModTag].Count > 0 && !entry.ModTags.Any(o => tagQuery[TagType.ModTag].Contains(o.ToString()))) return false; + if (tagQuery[TagType.Caliber].Count > 0 && (!item.UsesRoundTypeFlag || !tagQuery[TagType.Caliber].Contains(item.RoundType.ToString()))) return false; + + if (tagQuery[TagType.MagazineType].Count > 0 && !tagQuery[TagType.MagazineType].Contains(item.MagazineType.ToString())) return false; + + if (tagQuery[TagType.CountryOfOrigin].Count > 0 && !tagQuery[TagType.CountryOfOrigin].Contains(item.TagFirearmCountryOfOrigin.ToString())) return false; + + if (tagQuery[TagType.IntroductionYear].Count > 0 && !tagQuery[TagType.IntroductionYear].Contains(item.TagFirearmFirstYear.ToString())) return false; + return true; } @@ -798,14 +813,6 @@ private static bool ShouldIncludeFirearm(FVRObject item, Dictionary 0 && !tagQuery[TagType.RoundClass].Contains(item.TagFirearmRoundPower.ToString())) return false; - if (tagQuery[TagType.CountryOfOrigin].Count > 0 && !tagQuery[TagType.CountryOfOrigin].Contains(item.TagFirearmCountryOfOrigin.ToString())) return false; - - if (tagQuery[TagType.IntroductionYear].Count > 0 && !tagQuery[TagType.IntroductionYear].Contains(item.TagFirearmFirstYear.ToString())) return false; - - if (tagQuery[TagType.MagazineType].Count > 0 && !tagQuery[TagType.MagazineType].Contains(item.MagazineType.ToString())) return false; - - if (tagQuery[TagType.Caliber].Count > 0 && (!item.UsesRoundTypeFlag || !tagQuery[TagType.Caliber].Contains(item.RoundType.ToString()))) return false; - if (tagQuery[TagType.FiringMode].Count > 0 && !item.TagFirearmFiringModes.Any(o => tagQuery[TagType.FiringMode].Contains(o.ToString()))) return false; if (tagQuery[TagType.FeedOption].Count > 0 && !item.TagFirearmFeedOption.Any(o => tagQuery[TagType.FeedOption].Contains(o.ToString()))) return false; @@ -815,7 +822,6 @@ private static bool ShouldIncludeFirearm(FVRObject item, Dictionary> tagQuery) { if (tagQuery[TagType.AttachmentFeature].Count > 0 && !tagQuery[TagType.AttachmentFeature].Contains(item.TagAttachmentFeature.ToString())) return false; @@ -826,15 +832,6 @@ private static bool ShouldIncludeAttachment(FVRObject item, Dictionary> tagQuery) - { - if (tagQuery[TagType.MagazineType].Count > 0 && !tagQuery[TagType.MagazineType].Contains(item.MagazineType.ToString())) return false; - - return true; - } - - -