Ejemplo n.º 1
0
        private static bool SpawnItemDetails(ItemSpawnerV2 __instance)
        {
            OtherLogger.Log("Trying to spawn: " + __instance.m_selectedID, OtherLogger.LogType.General);

            //If the selected item has a spawner entry, use that
            if (OtherLoader.SpawnerEntriesByID.ContainsKey(__instance.m_selectedID))
            {
                OtherLogger.Log("Using normal spawn", OtherLogger.LogType.General);

                __instance.Boop(1);
                AnvilManager.Run(SpawnItems(__instance, OtherLoader.SpawnerEntriesByID[__instance.m_selectedID]));
            }

            //Otherwise try to use legacy spawner ID
            else if (IM.HasSpawnedID(__instance.m_selectedID))
            {
                OtherLogger.Log("Using legacy spawn", OtherLogger.LogType.General);

                return(true);
            }

            else
            {
                __instance.Boop(2);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public void PurchaseAmmoButton()
        {
            if (detectedFirearm == null || original.M.GetNumTokens() < PanelCost)
            {
                SM.PlayCoreSound(FVRPooledAudioType.UIChirp, original.AudEvent_Fail, transform.position);
                return;
            }

            else
            {
                SM.PlayCoreSound(FVRPooledAudioType.UIChirp, original.AudEvent_Spawn, transform.position);
                original.M.SubtractTokens(PanelCost);
                original.M.Increment(10, false);

                FVRObject.OTagFirearmRoundPower roundPower = AM.GetRoundPower(detectedFirearm.RoundType);
                int numSpawned = GetRoundsToSpawn(roundPower);

                TNHTweakerLogger.Log("Compatible rounds count for " + detectedFirearm.ObjectWrapper.ItemID + ": " + IM.OD[detectedFirearm.ObjectWrapper.ItemID].CompatibleSingleRounds.Count, TNHTweakerLogger.LogType.General);

                CustomCharacter        character      = LoadedTemplateManager.LoadedCharactersDict[original.M.C];
                MagazineBlacklistEntry blacklistEntry = null;
                if (character.GetMagazineBlacklist().ContainsKey(detectedFirearm.ObjectWrapper.ItemID))
                {
                    blacklistEntry = character.GetMagazineBlacklist()[detectedFirearm.ObjectWrapper.ItemID];
                }

                FVRObject compatibleRound = FirearmUtils.GetCompatibleRounds(detectedFirearm.ObjectWrapper, character.ValidAmmoEras, character.ValidAmmoSets, character.GlobalAmmoBlacklist, blacklistEntry).GetRandom();

                AnvilManager.Run(SpawnRounds(compatibleRound, numSpawned));

                detectedFirearm = null;
                UpdateIcons();
            }
        }
Ejemplo n.º 3
0
        public static void IM_GenerateItemDBs(GM __instance)
        {
            Uri StreamingAssetsUri = new Uri(Application.streamingAssetsPath + "\\dummy");

            Logger.LogDebug(Application.streamingAssetsPath + "\\dummy");
            foreach (string file in Directory.GetFiles(Paths.GameRootPath + @"\VirtualObjects", "*", SearchOption.AllDirectories))
            {
                if (Path.GetFileName(file) != Path.GetFileNameWithoutExtension(file) || Path.GetFileName(file).Contains("VirtualObjects"))
                {
                    continue;
                }

                string relativeFile = StreamingAssetsUri.MakeRelativeUri(new Uri(file)).ToString();

                AnvilCallback <AssetBundle> bundle = AnvilManager.GetBundleAsync(relativeFile);
                bundle.AddCallback(delegate
                {
                    if (bundle.Result != null)
                    {
                        Logger.Log(LogLevel.Info, $"Injecting FVRObject(s) and ItemSpawnerID(s) from {Path.GetFileName(file)}");

                        foreach (FVRObject fvrObj in bundle.Result.LoadAllAssets <FVRObject>())
                        {
                            //allows the original bundle path to be ignored, a bit cursed
                            FieldInfo anvilPrefab = AccessTools.Field(typeof(FVRObject), "m_anvilPrefab");
                            AssetID original      = (AssetID)anvilPrefab.GetValue(fvrObj);
                            original.Bundle       = relativeFile;
                            anvilPrefab.SetValue(fvrObj, original);

                            IM.OD.Add(fvrObj.ItemID, fvrObj);

                            ManagerSingleton <IM> .Instance.odicTagCategory.AddOrCreate(fvrObj.Category).Add(fvrObj);
                            ManagerSingleton <IM> .Instance.odicTagFirearmEra.AddOrCreate(fvrObj.TagEra).Add(fvrObj);
                            ManagerSingleton <IM> .Instance.odicTagFirearmSize.AddOrCreate(fvrObj.TagFirearmSize).Add(fvrObj);
                            ManagerSingleton <IM> .Instance.odicTagFirearmAction.AddOrCreate(fvrObj.TagFirearmAction).Add(fvrObj);
                            ManagerSingleton <IM> .Instance.odicTagFirearmFiringMode.AddOrCreate(fvrObj.TagFirearmFiringModes.FirstOrDefault()).Add(fvrObj);
                            ManagerSingleton <IM> .Instance.odicTagFirearmFeedOption.AddOrCreate(fvrObj.TagFirearmFeedOption.FirstOrDefault()).Add(fvrObj);
                            ManagerSingleton <IM> .Instance.odicTagFirearmMount.AddOrCreate(fvrObj.TagFirearmMounts.FirstOrDefault()).Add(fvrObj);
                            ManagerSingleton <IM> .Instance.odicTagAttachmentMount.AddOrCreate(fvrObj.TagAttachmentMount).Add(fvrObj);
                            ManagerSingleton <IM> .Instance.odicTagAttachmentFeature.AddOrCreate(fvrObj.TagAttachmentFeature).Add(fvrObj);
                        }
                        foreach (ItemSpawnerID id in bundle.Result.LoadAllAssets <ItemSpawnerID>())
                        {
                            IM.CD[id.Category].Add(id);
                            IM.SCD[id.SubCategory].Add(id);
                        }
                    }
                    else
                    {
                        Logger.LogError("AssetBundle is somehow null, what did you do?");
                    }
                });
            }
        }
Ejemplo n.º 4
0
        void OnDestroy()
        {
            if (dontDrop)
            {
                return;
            }

            TNHTweakerLogger.Log("TNHTweaker -- Lootable link was destroyed!", TNHTweakerLogger.LogType.TNH);

            List <EquipmentGroup> selectedGroups = group.GetSpawnedEquipmentGroups();
            string selectedItem;
            int    spawnedItems = 0;

            foreach (EquipmentGroup selectedGroup in selectedGroups)
            {
                for (int itemIndex = 0; itemIndex < selectedGroup.ItemsToSpawn; itemIndex++)
                {
                    if (selectedGroup.IsCompatibleMagazine)
                    {
                        FVRObject mag = FirearmUtils.GetAmmoContainerForEquipped(selectedGroup.MinAmmoCapacity, selectedGroup.MaxAmmoCapacity);
                        if (mag != null)
                        {
                            selectedItem = mag.ItemID;
                        }
                        else
                        {
                            TNHTweakerLogger.Log(
                                "TNHTweaker -- Spawning nothing, since group was compatible magazines, and could not find a compatible magazine for player",
                                TNHTweakerLogger.LogType.TNH);
                            return;
                        }
                    }

                    else
                    {
                        selectedItem = selectedGroup.GetObjects().GetRandom();
                    }

                    if (LoadedTemplateManager.LoadedVaultFiles.ContainsKey(selectedItem))
                    {
                        AnvilManager.Run(TNHTweakerUtils.SpawnFirearm(LoadedTemplateManager.LoadedVaultFiles[selectedItem],
                                                                      transform.position + (Vector3.up * 0.1f * spawnedItems), transform.rotation));
                    }
                    else
                    {
                        Instantiate(IM.OD[selectedItem].GetGameObject(), transform.position + (Vector3.up * 0.1f * spawnedItems), transform.rotation);
                    }

                    spawnedItems += 1;
                }
            }
        }
Ejemplo n.º 5
0
        private static bool SpawnItemRelated(ItemSpawnerV2 __instance, int i)
        {
            //If the selected item has a spawner entry, use that
            if (OtherLoader.SpawnerEntriesByID.ContainsKey(__instance.m_selectedID))
            {
                __instance.Boop(1);

                ItemSpawnerData data = __instance.GetComponent <ItemSpawnerData>();
                AnvilManager.Run(SpawnItems(__instance, data.VisibleSecondaryEntries[i]));
            }

            //Otherwise try to use legacy spawner ID
            else if (IM.HasSpawnedID(__instance.m_selectedID))
            {
                return(true);
            }

            else
            {
                __instance.Boop(2);
            }

            return(false);
        }
Ejemplo n.º 6
0
        public void GetObjectWithKeyboard()
        {
#if !UNITY_EDITOR && !UNITY_STANDALONE
            SteamVR_Events.System(EVREventType.VREvent_KeyboardDone).RemoveAllListeners();
            SteamVR_Events.System(EVREventType.VREvent_KeyboardDone).Listen(delegate {
                StringBuilder stringBuilder = new StringBuilder(256);
                SteamVR.instance.overlay.GetKeyboardText(stringBuilder, 256);
                string assetName = stringBuilder.ToString();

                List <AssetBundle> assetBundles = new List <AssetBundle>();
                foreach (string assBundle in System.IO.Directory.GetFiles(Application.streamingAssetsPath))
                {
                    if (!assBundle.Contains("."))
                    {
                        assetBundles.Add(AnvilManager.GetBundleAsync(System.IO.Path.GetFileName(assBundle)).Result);
                    }
                }

                foreach (AssetBundle assetBundle in assetBundles)
                {
                    if (assetBundle != null)
                    {
                        string firstMatch = assetBundle.GetAllAssetNames().FirstOrDefault(s => s.ToLower().Contains(assetName.ToLower()));

                        if (firstMatch != null && !string.IsNullOrEmpty(firstMatch))
                        {
                            UpdateCurrentGameObj(assetBundle.LoadAsset <GameObject>(firstMatch));
                            SpawnerRefreshElements(firstMatch);
                            break;
                        }
                    }
                }
            });
            SteamVR.instance.overlay.ShowKeyboard((int)EGamepadTextInputMode.k_EGamepadTextInputModeNormal, (int)EGamepadTextInputLineMode.k_EGamepadTextInputLineModeSingleLine, "Enter the name of an asset.", 256, "", false, 0);
#endif
        }
Ejemplo n.º 7
0
        public void Update()
        {
            if (Helpers.BepInExGetKeyDown(_shortcutPrintLayerAndTagsInfo.Value))
            {
                string LayerNames = "Layers:";
                for (int i = 0; i < 32; i++)
                {
                    LayerNames += $"\n{i} - {LayerMask.LayerToName(i)}";
                }
                Debug.Log(LayerNames);

                string LayerCollisions = "Layer Collisions: (+ for ignoring)\n";
                LayerCollisions += "   |  0|  1|  2|  3|  4|  5|  6|  7|  8|  9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| 31|";
                for (int i = 0; i < 32; i++)
                {
                    LayerCollisions += $"\n{i,3}|";
                    for (int j = 0; j < 32; j++)
                    {
                        LayerCollisions += !Physics.GetIgnoreLayerCollision(2 ^ i, 2 ^ j) ? " + |" : "   |";
                    }
                }
                Debug.Log(LayerCollisions);
            }
            else if (Helpers.BepInExGetKeyDown(_shortcutPrintAllStreamingAssetsBundles.Value))
            {
                string ootpoot = "";

                foreach (string assBundle in System.IO.Directory.GetFiles(Application.streamingAssetsPath))
                {
                    if (!assBundle.Contains("."))
                    {
                        AssetBundle asset = AnvilManager.GetBundleAsync(System.IO.Path.GetFileName(assBundle)).Result;
                        if (asset != null)
                        {
                            string[] names = System.IO.Path.GetFileName(assBundle).Split(new[] { "_" }, StringSplitOptions.None);
                            string   name  = names[names.Length - 1];
                            ootpoot += $"{name}: {string.Join($"\n{name}: ", asset.GetAllAssetNames())}\n\n\n";
                        }
                    }
                }

                foreach (System.Collections.Generic.KeyValuePair <string, ItemSpawnerID> kvp in (System.Collections.Generic.Dictionary <string, ItemSpawnerID>)AccessTools.Field(typeof(IM), "SpawnerIDDic").GetValue(ManagerSingleton <IM> .Instance))
                {
                    ootpoot += $"{kvp.Key} - {kvp.Value}\n";
                }

                Debug.Log(ootpoot);
            }

            else if (Helpers.BepInExGetKeyDown(_shortcutTelePlayerToReset.Value))
            {
                GM.CurrentMovementManager.TeleportToPoint(GM.CurrentSceneSettings.DeathResetPoint.position, true);
            }
            else if (Helpers.BepInExGetKeyDown(_shortcutTelePlayer2mForward.Value))
            {
                GM.CurrentMovementManager.TeleportToPoint(GM.CurrentPlayerRoot.position + (GM.CurrentPlayerBody.Head.forward * 2.0f), true);
            }
            else if (Helpers.BepInExGetKeyDown(_shortcutTelePlayerToOrigin.Value))
            {
                GM.CurrentMovementManager.TeleportToPoint(Vector3.zero, true);
            }

            else if (Helpers.BepInExGetKeyDown(_shortcutSpawnModPanelV2.Value))
            {
                ItemSpawnerID id = IM.GetSpawnerID("MiscUtModPanelV2");
                if (id != null)
                {
                    GameObject panel = Instantiate(id.MainObject.GetGameObject(), new Vector3(0f, .25f, 0f) + GM.CurrentPlayerRoot.position, Quaternion.identity);
                    if (GM.CurrentPlayerBody.QuickbeltSlots.Count > 0)
                    {
                        foreach (FVRQuickBeltSlot qbSlot in GM.CurrentPlayerBody.QuickbeltSlots)
                        {
                            if (qbSlot.HeldObject == null && qbSlot.CurObject == null)
                            {
                                panel.GetComponent <FVRPhysicalObject>().SetQuickBeltSlot(qbSlot);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    Logger.LogError("ModPanelV2 was null?");
                }
            }
            else if (Helpers.BepInExGetKeyDown(_shortcutScrambleMaterials.Value))
            {
                foreach (Renderer mr in UnityEngine.Object.FindObjectsOfType(typeof(UnityEngine.Renderer)))
                {
                    mr.material = (Resources.FindObjectsOfTypeAll(typeof(Material))[UnityEngine.Random.Range(0, Resources.FindObjectsOfTypeAll(typeof(Material)).Length)] as Material);
                }
            }
            else if (Helpers.BepInExGetKeyDown(_shortcutScrambleMeshes.Value))
            {
                foreach (MeshFilter mf in UnityEngine.Object.FindObjectsOfType(typeof(UnityEngine.MeshFilter)))
                {
                    mf.mesh = (Resources.FindObjectsOfTypeAll(typeof(Mesh))[UnityEngine.Random.Range(0, Resources.FindObjectsOfTypeAll(typeof(Mesh)).Length)] as Mesh);
                }
            }
        }
Ejemplo n.º 8
0
 public static void RunCoroutine(IEnumerator routine, Action <Exception> onError = null)
 {
     AnvilManager.Run(RunAndCatch(routine, onError));
 }