private void Awake()
        {
            LoadConfigFile();

            Harmony.CreateAndPatchAll(typeof(OtherLoader));
            Harmony.CreateAndPatchAll(typeof(ItemSpawnerPatch));
            Harmony.CreateAndPatchAll(typeof(ItemSpawnerV2Patch));
            Harmony.CreateAndPatchAll(typeof(QuickbeltPanelPatch));

            OtherLogger.Init(EnableLogging.Value, LogLoading.Value);

            if (AddUnloadButton.Value)
            {
                AddUnloadWristMenuButton();
            }

            coroutineStarter = StartCoroutine;
        }
Beispiel #2
0
        private void LoadMechanicalAccuracyEntries(UnityEngine.Object[] allAssets)
        {
            foreach (FVRFireArmMechanicalAccuracyChart chart in allAssets)
            {
                foreach (FVRFireArmMechanicalAccuracyChart.MechanicalAccuracyEntry entry in chart.Entries)
                {
                    OtherLogger.Log("Loading new mechanical accuracy entry: " + entry.Class, OtherLogger.LogType.Loading);

                    if (!AM.SMechanicalAccuracyDic.ContainsKey(entry.Class))
                    {
                        AM.SMechanicalAccuracyDic.Add(entry.Class, entry);
                    }
                    else
                    {
                        OtherLogger.LogError("Duplicate mechanical accuracy class found, will not use one of them! Make sure you're using unique mechanical accuracy classes!");
                    }
                }
            }
        }
Beispiel #3
0
        public void LoadLegacyAssets(CoroutineStarter starter)
        {
            if (!Directory.Exists(OtherLoader.MainLegacyDirectory))
            {
                Directory.CreateDirectory(OtherLoader.MainLegacyDirectory);
            }

            OtherLogger.Log("Plugins folder found (" + Paths.PluginPath + ")", OtherLogger.LogType.General);

            List <string> legacyPaths = Directory.GetDirectories(Paths.PluginPath, "LegacyVirtualObjects", SearchOption.AllDirectories).ToList();

            legacyPaths.Add(OtherLoader.MainLegacyDirectory);

            foreach (string legacyPath in legacyPaths)
            {
                OtherLogger.Log("Legacy folder found (" + legacyPath + ")", OtherLogger.LogType.General);

                foreach (string bundlePath in Directory.GetFiles(legacyPath, "*", SearchOption.AllDirectories))
                {
                    //Only allow files without file extensions to be loaded (assumed to be an asset bundle)
                    if (Path.GetFileName(bundlePath) != Path.GetFileNameWithoutExtension(bundlePath))
                    {
                        continue;
                    }

                    string bundleID = bundlePath.Replace(Path.GetFileName(bundlePath), "") + " : " + Path.GetFileName(bundlePath);

                    IEnumerator routine = LoadAssetsFromPathAsync(bundlePath, bundleID, "", new string[] { }, LoadOrderType.LoadUnordered, true).TryCatch <Exception>(e =>
                    {
                        OtherLogger.LogError("Failed to load mod (" + bundleID + ")");
                        OtherLogger.LogError(e.ToString());
                        LoaderStatus.UpdateProgress(bundleID, 1);
                        LoaderStatus.RemoveActiveLoader(bundleID, true);
                    });

                    starter(routine);
                }
            }
        }
        private void UnloadAllModdedBundles()
        {
            foreach (string bundleID in ManagedBundles.Keys)
            {
                if (!AnvilManager.m_bundles.m_lookup.ContainsKey(bundleID))
                {
                    continue;
                }

                OtherLogger.Log("Unloading bundle: " + bundleID, OtherLogger.LogType.General);

                //Get the bundle container
                AnvilCallback <AssetBundle> bundleCallback = (AnvilCallback <AssetBundle>)AnvilManager.m_bundles.m_lookup[bundleID];

                //Remove Instances of this bundle from the anvil manager
                AnvilManager.m_bundles.m_loading.Remove(AnvilManager.m_bundles.m_lookup[bundleID]);
                AnvilManager.m_bundles.m_lookup.Remove(bundleID);

                //Unload the bundle
                bundleCallback.Result.Unload(false);
            }
        }
Beispiel #5
0
        public IEnumerator StartAssetLoadDirect(string folderPath, string bundleName, string guid, string[] dependancies, LoadOrderType loadOrder, bool allowUnload)
        {
            OtherLogger.Log("Direct Loading Bundle (" + bundleName + ")", OtherLogger.LogType.General);

            string      bundlePath = Path.Combine(folderPath, bundleName);
            string      lateName   = "late_" + bundleName;
            string      latePath   = Path.Combine(folderPath, lateName);
            string      bundleID   = bundlePath.Replace(bundleName, "") + " : " + bundleName;
            IEnumerator afterLoad  = null;

            if (File.Exists(latePath))
            {
                afterLoad = RegisterAssetLoadLate(latePath, lateName, loadOrder);
            }

            return(LoadAssetsFromPathAsync(bundlePath, bundleID, guid, dependancies, loadOrder, allowUnload, afterLoad).TryCatch(e =>
            {
                OtherLogger.LogError("Failed to load mod (" + bundleID + ")");
                OtherLogger.LogError(e.ToString());
                LoaderStatus.UpdateProgress(bundleID, 1);
                LoaderStatus.RemoveActiveLoader(bundleID, true);
            }));
        }
        private static bool StartPatch(ItemSpawnerUI __instance)
        {
            //Make sure previous data objects on this spawner are destroyed
            ItemSpawnerDataObject dupObject = __instance.gameObject.GetComponent <ItemSpawnerDataObject>();

            if (dupObject != null)
            {
                OtherLogger.Log("Destroying duplicated ItemSpawnerDataObject", OtherLogger.LogType.General);
                UnityEngine.Object.Destroy(dupObject);
            }

            //Somehow, an extra canvas is created when loaded by Atlas, so we must clear all previous canvases as well
            Transform dupCanvas = __instance.transform.Find("LoadingTextCanvas");

            if (dupCanvas != null)
            {
                OtherLogger.Log("Destroying duplicated progress canvas", OtherLogger.LogType.General);
                UnityEngine.Object.Destroy(dupCanvas.gameObject);
            }

            __instance.gameObject.AddComponent <ItemSpawnerDataObject>();

            return(true);
        }
Beispiel #7
0
        private static bool SimpleButtonPatch(ItemSpawnerV2 __instance, int i)
        {
            ItemSpawnerData data = __instance.GetComponent <ItemSpawnerData>();

            //If the entry that was selected has child entries, we should display the child entries
            if (OtherLoader.SpawnerEntriesByPath[data.VisibleEntries[i].EntryPath].childNodes.Count > 0)
            {
                data.CurrentPath   = data.VisibleEntries[i].EntryPath;
                data.CurrentDepth += 1;
                data.SavedPagePositions[__instance.PMode][data.CurrentDepth] = 0;

                __instance.RedrawSimpleCanvas();
            }

            else
            {
                OtherLogger.Log("Setting selected id to: " + data.VisibleEntries[i].MainObjectID, OtherLogger.LogType.General);

                __instance.SetSelectedID(data.VisibleEntries[i].MainObjectID);
                __instance.RedrawDetailsCanvas();
            }

            return(false);
        }
Beispiel #8
0
        private static bool RedrawSimplePatch(ItemSpawnerV2 __instance)
        {
            if (__instance.PMode == ItemSpawnerV2.PageMode.MainMenu)
            {
                return(false);
            }

            ItemSpawnerData data = __instance.GetComponent <ItemSpawnerData>();

            data.VisibleEntries.Clear();

            List <EntryNode> entries = OtherLoader.SpawnerEntriesByPath[data.CurrentPath].childNodes.Where(o => o.entry.IsDisplayedInMainEntry).ToList();

            OtherLogger.Log($"Got {entries.Count} entries for path: {data.CurrentPath}", OtherLogger.LogType.General);

            entries = entries.OrderBy(o => o.entry.DisplayName).OrderBy(o => o.entry.IsModded?1:0).OrderBy(o => o.childNodes.Count > 0?0:1).ToList();

            int currPage   = data.SavedPagePositions[__instance.PMode][data.CurrentDepth];
            int startIndex = currPage * __instance.IMG_SimpleTiles.Count;

            for (int i = 0; i < __instance.IMG_SimpleTiles.Count; i++)
            {
                if (startIndex + i < entries.Count)
                {
                    ItemSpawnerEntry entry = entries[startIndex + i].entry;
                    data.VisibleEntries.Add(entry);

                    __instance.IMG_SimpleTiles[i].gameObject.SetActive(true);
                    __instance.TXT_SimpleTiles[i].gameObject.SetActive(true);
                    __instance.IMG_SimpleTiles[i].sprite = entry.EntryIcon;
                    __instance.TXT_SimpleTiles[i].text   = entry.DisplayName;
                }
                else
                {
                    __instance.IMG_SimpleTiles[i].gameObject.SetActive(false);
                    __instance.TXT_SimpleTiles[i].gameObject.SetActive(false);
                }
            }

            int numPages = (int)Math.Ceiling((double)entries.Count / __instance.IMG_SimpleTiles.Count);

            OtherLogger.Log($"There are {numPages} pages for this entry", OtherLogger.LogType.General);

            __instance.TXT_SimpleTiles_PageNumber.text = (currPage + 1) + " / " + (numPages);
            __instance.TXT_SimpleTiles_Showing.text    =
                "Showing " +
                (currPage * __instance.IMG_SimpleTiles.Count) +
                " - " +
                (currPage * __instance.IMG_SimpleTiles.Count + data.VisibleEntries.Count) +
                " Of " +
                entries.Count;


            if (currPage > 0)
            {
                __instance.GO_SimpleTiles_PrevPage.SetActive(true);
            }
            else
            {
                __instance.GO_SimpleTiles_PrevPage.SetActive(false);
            }

            if (currPage < numPages - 1)
            {
                __instance.GO_SimpleTiles_NextPage.SetActive(true);
            }
            else
            {
                __instance.GO_SimpleTiles_NextPage.SetActive(false);
            }

            return(false);
        }
Beispiel #9
0
        private static bool RedrawDetailsCanvasPatch(ItemSpawnerV2 __instance)
        {
            OtherLogger.Log("Selected ID: " + __instance.m_selectedID, OtherLogger.LogType.General);

            //If there is no spawner entry for the selected ID, set everything to blank
            if (!OtherLoader.SpawnerEntriesByID.ContainsKey(__instance.m_selectedID))
            {
                return(true);
            }


            else
            {
                ItemSpawnerEntry entry = OtherLoader.SpawnerEntriesByID[__instance.m_selectedID];
                ItemSpawnerData  data  = __instance.GetComponent <ItemSpawnerData>();

                OtherLogger.Log("We found an entry for it!", OtherLogger.LogType.General);

                //First, fill activate some of the detail and populate it with info
                for (int l = 0; l < __instance.IM_FavButtons.Count; l++)
                {
                    __instance.IM_FavButtons[l].gameObject.SetActive(true);
                }

                __instance.IM_Detail.gameObject.SetActive(true);
                __instance.IM_Detail.sprite = entry.EntryIcon;
                __instance.TXT_Title.text   = entry.DisplayName;
                __instance.BTN_SpawnSelectedObject.SetActive(true);
                __instance.TXT_Detail.text = __instance.GetDetailText(__instance.m_selectedID);



                //Now get all the secondary entries
                List <ItemSpawnerEntry> secondaryEntries = new List <ItemSpawnerEntry>();
                for (int m = 0; m < entry.SecondaryObjectIDs.Count; m++)
                {
                    if (!OtherLoader.SpawnerEntriesByID.ContainsKey(entry.SecondaryObjectIDs[m]))
                    {
                        OtherLogger.LogWarning($"Secondary ID for ({entry.MainObjectID}) was not in entry dictionary! It will not appear! Secondary ID ({entry.SecondaryObjectIDs[m]})");
                        continue;
                    }

                    ItemSpawnerEntry secondary = OtherLoader.SpawnerEntriesByID[entry.SecondaryObjectIDs[m]];
                    if (!secondary.IsReward || GM.Rewards.RewardUnlocks.Rewards.Contains(secondary.MainObjectID))
                    {
                        secondaryEntries.Add(secondary);
                    }
                }


                //Now we create the secondaries page
                //Start by drawing the tiles
                data.VisibleSecondaryEntries.Clear();
                int startIndex = __instance.m_selectedIDRelatedPage * __instance.IM_DetailRelated.Count;
                for (int i = 0; i < __instance.IM_DetailRelated.Count; i++)
                {
                    if (startIndex + i < secondaryEntries.Count)
                    {
                        ItemSpawnerEntry secondaryEntry = secondaryEntries[startIndex + i];
                        data.VisibleSecondaryEntries.Add(secondaryEntry);

                        __instance.IM_DetailRelated[i].gameObject.SetActive(true);
                        __instance.IM_DetailRelated[i].sprite = secondaryEntry.EntryIcon;
                    }
                    else
                    {
                        __instance.IM_DetailRelated[i].gameObject.SetActive(false);
                    }
                }

                //Now handle the page selectors
                int numPages = (int)Math.Ceiling((double)secondaryEntries.Count / __instance.IM_DetailRelated.Count);
                __instance.TXT_DetailsRelatedPageNum.gameObject.SetActive(true);
                __instance.TXT_DetailsRelatedPageNum.text = (__instance.m_selectedIDRelatedPage + 1).ToString() + " / " + numPages.ToString();

                if (__instance.m_selectedIDRelatedPage > 0)
                {
                    __instance.BTN_DetailsRelatedPrevPage.SetActive(true);
                }
                else
                {
                    __instance.BTN_DetailsRelatedPrevPage.SetActive(false);
                }

                if (__instance.m_selectedIDRelatedPage < numPages - 1)
                {
                    __instance.BTN_DetailsRelatedNextPage.SetActive(true);
                }
                else
                {
                    __instance.BTN_DetailsRelatedNextPage.SetActive(false);
                }



                //Setup the tutorials panel
                for (int i = 0; i < __instance.BTNS_DetailTutorial.Count; i++)
                {
                    if (i < entry.TutorialBlockIDs.Count)
                    {
                        if (IM.TutorialBlockDic.ContainsKey(entry.TutorialBlockIDs[i]))
                        {
                            __instance.BTNS_DetailTutorial[i].gameObject.SetActive(true);
                            __instance.BTNS_DetailTutorial[i].text = IM.TutorialBlockDic[entry.TutorialBlockIDs[i]].Title;
                        }
                        else
                        {
                            __instance.BTNS_DetailTutorial[i].gameObject.SetActive(false);
                        }
                    }
                    else
                    {
                        __instance.BTNS_DetailTutorial[i].gameObject.SetActive(false);
                    }
                }



                //Setup the favorites icons
                for (int i = 0; i < __instance.IM_FavButtons.Count; i++)
                {
                    if (ManagerSingleton <IM> .Instance.ItemMetaDic.ContainsKey(__instance.m_selectedID) && ManagerSingleton <IM> .Instance.ItemMetaDic[__instance.m_selectedID].ContainsKey(TagType.Favorites) && ManagerSingleton <IM> .Instance.ItemMetaDic[__instance.m_selectedID][TagType.Favorites].Contains(__instance.FaveTags[i]))
                    {
                        __instance.IM_FavButtons[i].sprite = __instance.IM_FavButton_Faved[i];
                    }
                    else
                    {
                        __instance.IM_FavButtons[i].sprite = __instance.IM_FavButton_UnFaved[i];
                    }
                }
            }


            return(false);
        }
Beispiel #10
0
        private static bool DetailTextPatch(ItemSpawnerV2 __instance, string id, ref string __result)
        {
            FVRObject fvrObj;
            string    spawnerCat;
            string    spawnerSubcat;

            if (IM.Instance.SpawnerIDDic.ContainsKey(id))
            {
                OtherLogger.Log("Getting ID from spawnerID", OtherLogger.LogType.General);

                ItemSpawnerID spawnerID = IM.Instance.SpawnerIDDic[id];
                fvrObj = IM.OD[spawnerID.MainObject.ItemID];

                spawnerCat = spawnerID.Category.ToString();
                if (!Enum.IsDefined(typeof(ItemSpawnerID.EItemCategory), spawnerID.Category) && IM.CDefInfo.ContainsKey(spawnerID.Category))
                {
                    spawnerCat = IM.CDefInfo[spawnerID.Category].DisplayName;
                }

                spawnerSubcat = spawnerID.SubCategory.ToString();
                if (!Enum.IsDefined(typeof(ItemSpawnerID.ESubCategory), spawnerID.SubCategory) && IM.CDefSubInfo.ContainsKey(spawnerID.SubCategory))
                {
                    spawnerSubcat = IM.CDefSubInfo[spawnerID.SubCategory].DisplayName;
                }
            }

            else if (OtherLoader.SpawnerEntriesByID.ContainsKey(id))
            {
                OtherLogger.Log("Getting ID from otherloader", OtherLogger.LogType.General);

                spawnerCat    = "None";
                spawnerSubcat = "None";

                fvrObj = IM.OD[id];
            }

            else
            {
                OtherLogger.LogError($"The ItemID was not found to have spawner entry! ItemID: {id}");
                __result = "";
                return(false);
            }


            string text =
                "Spawner Category: " + spawnerCat + "\n" +
                "Spawner Subcategory: " + spawnerSubcat + "\n" +
                "Object Category: " + fvrObj.Category.ToString() + "\n" +
                "Set: " + fvrObj.TagSet.ToString() + "\n" +
                "Size: " + fvrObj.TagFirearmSize.ToString() + "\n" +
                "Era: " + fvrObj.TagEra.ToString() + "\n" +
                "Action: " + fvrObj.TagFirearmAction.ToString() + "\n" +
                "Round Power: " + fvrObj.TagFirearmRoundPower.ToString() + "\n" +
                "Country: " + fvrObj.TagFirearmCountryOfOrigin.ToString() + "\n" +
                "Introduction Year: " + fvrObj.TagFirearmFirstYear.ToString() + "\n" +
                "Magazine Type: " + fvrObj.MagazineType.ToString() + "\n" +
                "Round Type: " + fvrObj.RoundType.ToString() + "\n" +
                "Firing Modes: " + string.Join(",", fvrObj.TagFirearmFiringModes.Select(o => o.ToString()).ToArray()) + "\n" +
                "Feed Options: " + string.Join(",", fvrObj.TagFirearmFeedOption.Select(o => o.ToString()).ToArray()) + "\n" +
                "Mounts: " + string.Join(",", fvrObj.TagFirearmMounts.Select(o => o.ToString()).ToArray()) + "\n" +
                "Attachment Mount: " + fvrObj.TagAttachmentMount.ToString() + "\n" +
                "Attachment Feature: " + fvrObj.TagAttachmentFeature.ToString();

            __result = text;

            return(false);
        }
Beispiel #11
0
        private void LoadBulletData(UnityEngine.Object[] allAssets)
        {
            foreach (FVRFireArmRoundDisplayData data in allAssets)
            {
                if (data == null)
                {
                    continue;
                }

                OtherLogger.Log("Loading ammo type: " + data.Type, OtherLogger.LogType.Loading);

                if (!AM.STypeDic.ContainsKey(data.Type))
                {
                    OtherLogger.Log("This is a new ammo type! Adding it to dictionary", OtherLogger.LogType.Loading);
                    AM.STypeDic.Add(data.Type, new Dictionary <FireArmRoundClass, FVRFireArmRoundDisplayData.DisplayDataClass>());
                }
                else
                {
                    OtherLogger.Log("This is an existing ammo type, will add subclasses to this type", OtherLogger.LogType.Loading);
                }

                if (!AM.STypeList.Contains(data.Type))
                {
                    AM.STypeList.Add(data.Type);
                }

                if (!AM.SRoundDisplayDataDic.ContainsKey(data.Type))
                {
                    AM.SRoundDisplayDataDic.Add(data.Type, data);
                }

                //If this Display Data already exists, then we should add our classes to the existing display data class list
                else
                {
                    List <FVRFireArmRoundDisplayData.DisplayDataClass> classes = new List <FVRFireArmRoundDisplayData.DisplayDataClass>(AM.SRoundDisplayDataDic[data.Type].Classes);
                    classes.AddRange(data.Classes);
                    AM.SRoundDisplayDataDic[data.Type].Classes = classes.ToArray();
                }

                if (!AM.STypeClassLists.ContainsKey(data.Type))
                {
                    AM.STypeClassLists.Add(data.Type, new List <FireArmRoundClass>());
                }

                foreach (FVRFireArmRoundDisplayData.DisplayDataClass roundClass in data.Classes)
                {
                    OtherLogger.Log("Loading ammo class: " + roundClass.Class, OtherLogger.LogType.Loading);
                    if (!AM.STypeDic[data.Type].ContainsKey(roundClass.Class))
                    {
                        OtherLogger.Log("This is a new ammo class! Adding it to dictionary", OtherLogger.LogType.Loading);
                        AM.STypeDic[data.Type].Add(roundClass.Class, roundClass);
                    }
                    else
                    {
                        OtherLogger.LogError("Ammo class already exists for bullet type! Bullet will not be loaded! Type: " + data.Type + ", Class: " + roundClass.Class);
                        return;
                    }

                    if (!AM.STypeClassLists[data.Type].Contains(roundClass.Class))
                    {
                        AM.STypeClassLists[data.Type].Add(roundClass.Class);
                    }
                }
            }
        }
Beispiel #12
0
        private void LoadSpawnerIDs(UnityEngine.Object[] allAssets)
        {
            foreach (ItemSpawnerID id in allAssets)
            {
                OtherLogger.Log("Adding Itemspawner ID! Category: " + id.Category + ", SubCategory: " + id.SubCategory, OtherLogger.LogType.Loading);

                //Try to set the main object of this ID as a secondary if the main is null (so that it gets tagged properly)
                if (id.MainObject == null && id.Secondaries.Length > 0)
                {
                    id.MainObject = id.Secondaries.Select(o => o.MainObject).FirstOrDefault(o => o != null);
                    if (id.MainObject == null)
                    {
                        OtherLogger.Log("Could not select a secondary object for ItemSpawnerID, it will not appear in spawner: Display Name: " + id.DisplayName, OtherLogger.LogType.Loading);
                    }
                    else
                    {
                        id.ItemID = id.MainObject.ItemID;
                    }
                }


                if (id.MainObject != null)
                {
                    if (id.UnlockCost == 0)
                    {
                        id.UnlockCost = id.MainObject.CreditCost;
                    }

                    IM.RegisterItemIntoMetaTagSystem(id);
                    if (!id.IsDisplayedInMainEntry)
                    {
                        HideItemFromCategories(id);
                    }
                }


                if (IM.CD.ContainsKey(id.Category) && IM.SCD.ContainsKey(id.SubCategory))
                {
                    IM.CD[id.Category].Add(id);
                    IM.SCD[id.SubCategory].Add(id);

                    if (!ManagerSingleton <IM> .Instance.SpawnerIDDic.ContainsKey(id.ItemID))
                    {
                        ManagerSingleton <IM> .Instance.SpawnerIDDic[id.ItemID] = id;

                        //Now we will try to convert this SpawnerID into a spawner entry
                        ItemSpawnerEntry SpawnerEntry = ScriptableObject.CreateInstance <ItemSpawnerEntry>();

                        //If the category is defined, we can try to add it based on what page it was given
                        if (Enum.IsDefined(typeof(ItemSpawnerID.EItemCategory), id.Category))
                        {
                            //TODO this should be done without having to loop through potentially all spawner entries, I bet this could become expensive
                            bool added = false;
                            foreach (KeyValuePair <ItemSpawnerV2.PageMode, List <string> > pageItems in IM.Instance.PageItemLists)
                            {
                                if (pageItems.Value.Contains(id.ItemID))
                                {
                                    OtherLogger.Log("Adding SpawnerID to spawner entry tree", OtherLogger.LogType.Loading);
                                    SpawnerEntry.LegacyPopulateFromID(pageItems.Key, id, true);
                                    PopulateEntryPaths(SpawnerEntry, id);
                                    added = true;

                                    break;
                                }
                            }

                            if (added)
                            {
                                continue;
                            }

                            //If we make it to this point, we failed to add the entry to the tree structure, but should still populate the entries data
                            OtherLogger.Log("ItemSpawnerID could not be converted for new spawner because of metadata issues! ItemID: " + id.ItemID, OtherLogger.LogType.Loading);
                            SpawnerEntry.LegacyPopulateFromID(ItemSpawnerV2.PageMode.Firearms, id, true);
                        }

                        //Otherwise, all custom category items go under the firearms page
                        else
                        {
                            OtherLogger.Log("Adding SpawnerID to spawner entry tree under custom category", OtherLogger.LogType.Loading);
                            SpawnerEntry.LegacyPopulateFromID(ItemSpawnerV2.PageMode.Firearms, id, true);
                            PopulateEntryPaths(SpawnerEntry, id);
                        }
                    }
                }

                else
                {
                    OtherLogger.LogError("ItemSpawnerID could not be added, because either the main category or subcategory were not loaded! Item will not appear in the itemspawner! Item Display Name: " + id.DisplayName);
                }
            }
        }
Beispiel #13
0
        private void LoadSpawnerCategories(UnityEngine.Object[] allAssets)
        {
            foreach (ItemSpawnerCategoryDefinitions newLoadedCats in allAssets)
            {
                foreach (ItemSpawnerCategoryDefinitions.Category newCategory in newLoadedCats.Categories)
                {
                    OtherLogger.Log("Loading New ItemSpawner Category! Name (" + newCategory.DisplayName + "), Value (" + newCategory.Cat + ")", OtherLogger.LogType.Loading);


                    //If the loaded categories already contains this new category, we want to add subcategories
                    if (IM.CDefs.Categories.Any(o => o.Cat == newCategory.Cat))
                    {
                        OtherLogger.Log("Category already exists! Adding subcategories", OtherLogger.LogType.Loading);

                        foreach (ItemSpawnerCategoryDefinitions.Category currentCat in IM.CDefs.Categories)
                        {
                            if (currentCat.Cat == newCategory.Cat)
                            {
                                foreach (ItemSpawnerCategoryDefinitions.SubCategory newSubCat in newCategory.Subcats)
                                {
                                    //Only add this new subcategory if it is unique
                                    if (!IM.CDefSubInfo.ContainsKey(newSubCat.Subcat))
                                    {
                                        OtherLogger.Log("Adding subcategory: " + newSubCat.DisplayName, OtherLogger.LogType.Loading);

                                        List <ItemSpawnerCategoryDefinitions.SubCategory> currSubCatList = currentCat.Subcats.ToList();
                                        currSubCatList.Add(newSubCat);
                                        currentCat.Subcats = currSubCatList.ToArray();

                                        IM.CDefSubs[currentCat.Cat].Add(newSubCat);

                                        if (!IM.CDefSubInfo.ContainsKey(newSubCat.Subcat))
                                        {
                                            IM.CDefSubInfo.Add(newSubCat.Subcat, newSubCat);
                                        }
                                        if (!IM.SCD.ContainsKey(newSubCat.Subcat))
                                        {
                                            IM.SCD.Add(newSubCat.Subcat, new List <ItemSpawnerID>());
                                        }
                                    }

                                    else
                                    {
                                        OtherLogger.LogWarning("SubCategory type is already being used, and SubCategory will not be added! Make sure your subcategory is using a unique type! SubCategory Type: " + newSubCat.Subcat);
                                    }
                                }
                            }
                        }
                    }

                    //If new category, we can just add the whole thing
                    else
                    {
                        OtherLogger.Log("This is a new primary category", OtherLogger.LogType.Loading);

                        List <ItemSpawnerCategoryDefinitions.Category> currentCatsList = IM.CDefs.Categories.ToList();
                        currentCatsList.Add(newCategory);
                        IM.CDefs.Categories = currentCatsList.ToArray();

                        OtherLogger.Log("Num CDefs: " + IM.CDefs.Categories.Length, OtherLogger.LogType.Loading);

                        if (!IM.CDefSubs.ContainsKey(newCategory.Cat))
                        {
                            IM.CDefSubs.Add(newCategory.Cat, new List <ItemSpawnerCategoryDefinitions.SubCategory>());
                        }
                        if (!IM.CDefInfo.ContainsKey(newCategory.Cat))
                        {
                            IM.CDefInfo.Add(newCategory.Cat, newCategory);
                        }
                        if (!IM.CD.ContainsKey(newCategory.Cat))
                        {
                            IM.CD.Add(newCategory.Cat, new List <ItemSpawnerID>());
                        }

                        foreach (ItemSpawnerCategoryDefinitions.SubCategory newSubCat in newCategory.Subcats)
                        {
                            IM.CDefSubs[newCategory.Cat].Add(newSubCat);

                            if (!IM.CDefSubInfo.ContainsKey(newSubCat.Subcat))
                            {
                                IM.CDefSubInfo.Add(newSubCat.Subcat, newSubCat);
                            }
                            if (!IM.SCD.ContainsKey(newSubCat.Subcat))
                            {
                                IM.SCD.Add(newSubCat.Subcat, new List <ItemSpawnerID>());
                            }
                        }
                    }
                }
            }
        }
Beispiel #14
0
        //Anatomy of a BundleID
        // [Mod Path] : [Bundle Name]
        // Combining these two gives you the path to the asset bundle


        public Empty LoadAssembly(FileSystemInfo handle)
        {
            OtherLogger.Log("Loading Assembly: " + handle.FullName, OtherLogger.LogType.Loading);
            Assembly.LoadFile(handle.FullName);
            return(new Empty());
        }
Beispiel #15
0
        private IEnumerator LoadAssetsFromPathAsync(string path, string bundleID, string guid, string[] dependancies, LoadOrderType loadOrder, bool allowUnload, IEnumerator afterLoad = null)
        {
            //Start tracking this bundle and then wait a frame for everything else to be tracked
            LoaderStatus.TrackLoader(bundleID, loadOrder);
            yield return(null);

            //If there are many active loaders at once, we should wait our turn
            bool overTime = false;

            while (!LoaderStatus.CanOrderedModLoad(bundleID))
            {
                if (!overTime && Time.time - LoaderStatus.LastLoadEventTime > 30)
                {
                    OtherLogger.Log("Bundle has been waiting a long time to load! (" + bundleID + ")", OtherLogger.LogType.General);
                    LoaderStatus.PrintWaitingBundles(bundleID);
                    overTime = true;
                }

                yield return(null);
            }

            //Begin the loading process
            LoaderStatus.AddActiveLoader(bundleID);

            if (OtherLoader.LogLoading.Value)
            {
                OtherLogger.Log("Beginning async loading of asset bundle (" + bundleID + ")", OtherLogger.LogType.General);
            }


            //Load the bundle and apply it's contents
            float time = Time.time;

            LoaderStatus.UpdateProgress(bundleID, UnityEngine.Random.Range(.1f, .3f));

            AnvilCallback <AssetBundle> bundle = LoaderUtils.LoadAssetBundle(path);

            yield return(bundle);

            LoaderStatus.UpdateProgress(bundleID, 0.9f);

            yield return(ApplyLoadedAssetBundleAsync(bundle, bundleID).TryCatch(e =>
            {
                OtherLogger.LogError("Failed to load mod (" + bundleID + ")");
                OtherLogger.LogError(e.ToString());
                LoaderStatus.UpdateProgress(bundleID, 1);
                LoaderStatus.RemoveActiveLoader(bundleID, true);
            }));


            //Log that the bundle is loaded
            if (OtherLoader.LogLoading.Value)
            {
                OtherLogger.Log($"[{(Time.time - time).ToString("0.000")} s] Completed loading bundle ({bundleID})", OtherLogger.LogType.General);
            }
            else
            {
                OtherLogger.Log($"[{(Time.time - time).ToString("0.000")} s] Completed loading bundle ({LoaderUtils.GetBundleNameFromUniqueID(bundleID)})", OtherLogger.LogType.General);
            }



            if (allowUnload && OtherLoader.OptimizeMemory.Value)
            {
                OtherLogger.Log("Unloading asset bundle (Optimize Memory is true)", OtherLogger.LogType.Loading);
                bundle.Result.Unload(false);
            }
            else
            {
                AnvilManager.m_bundles.Add(bundleID, bundle);
            }

            OtherLoader.ManagedBundles.Add(bundleID, path);
            LoaderStatus.UpdateProgress(bundleID, 1);
            LoaderStatus.RemoveActiveLoader(bundleID, !(OtherLoader.OptimizeMemory.Value && allowUnload));

            if (afterLoad != null)
            {
                yield return(afterLoad);
            }
        }
        public void LegacyPopulateFromID(ItemSpawnerV2.PageMode Page, ItemSpawnerID ID, bool IsModded)
        {
            if (ID.MainObject != null)
            {
                MainObjectID = ID.MainObject.ItemID;
            }
            else
            {
                OtherLogger.LogWarning("ItemSpawnerID has a null MainObject! ItemID: " + ID.ItemID);
                MainObjectID = ID.ItemID;
            }

            if (IM.OD.ContainsKey(MainObjectID))
            {
                OtherLoader.SpawnerEntriesByID[MainObjectID] = this;
            }

            SpawnWithIDs = new List <string>();
            if (ID.SecondObject != null)
            {
                SpawnWithIDs.Add(ID.SecondObject.ItemID);
            }


            //Add secondary items to entry, being careful of null values!
            SecondaryObjectIDs = new List <string>();
            foreach (ItemSpawnerID secondary in ID.Secondaries)
            {
                if (secondary != null && secondary.MainObject != null)
                {
                    SecondaryObjectIDs.Add(secondary.MainObject.ItemID);
                }
                else if (secondary == null)
                {
                    OtherLogger.LogWarning("Failed to add secondary to item (" + MainObjectID + ") due to secondary item being null!");
                }
                else
                {
                    OtherLogger.LogWarning("Failed to add secondary to item (" + MainObjectID + ") due to null MainObject!, Secondary display name: " + secondary.DisplayName);
                }
            }

            if (ID.Secondaries_ByStringID != null)
            {
                SecondaryObjectIDs.AddRange(ID.Secondaries_ByStringID);
            }


            EntryPath   = CreatePath(Page, ID);
            EntryIcon   = ID.Sprite;
            DisplayName = ID.DisplayName;

            IsDisplayedInMainEntry = ID.IsDisplayedInMainEntry;
            UsesLargeSpawnPad      = ID.UsesLargeSpawnPad;
            this.IsModded          = IsModded;

            TutorialBlockIDs = new List <string>();
            TutorialBlockIDs.AddRange(ID.TutorialBlocks);

            ModTags = new List <string>();
            ModTags.AddRange(ID.ModTags);
        }