public static void CreateDefaultSosigTemplateFiles(List <SosigEnemyTemplate> sosigs, string path) { try { TNHTweakerLogger.Log("TNHTweaker -- Creating default sosig template files", TNHTweakerLogger.LogType.File); path = path + "/DefaultSosigTemplates"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (SosigEnemyTemplate template in sosigs) { if (File.Exists(path + "/" + template.SosigEnemyID + ".json")) { File.Delete(path + "/" + template.SosigEnemyID + ".json"); } // Create a new file using (StreamWriter sw = File.CreateText(path + "/" + template.SosigEnemyID + ".json")) { SosigTemplate sosig = new SosigTemplate(template); string characterString = JsonConvert.SerializeObject(sosig, Formatting.Indented, new StringEnumConverter()); sw.WriteLine(characterString); sw.Close(); } } } catch (Exception ex) { TNHTweakerLogger.LogError(ex.ToString()); } }
public static IEnumerator SpawnFirearm(SavedGunSerializable savedGun, Vector3 position, Quaternion rotation) { List <GameObject> toDealWith = new List <GameObject>(); List <GameObject> toMoveToTrays = new List <GameObject>(); FVRFireArm myGun = null; FVRFireArmMagazine myMagazine = null; List <int> validIndexes = new List <int>(); Dictionary <GameObject, SavedGunComponent> dicGO = new Dictionary <GameObject, SavedGunComponent>(); Dictionary <int, GameObject> dicByIndex = new Dictionary <int, GameObject>(); List <GameObject> gameObjects = new List <GameObject>(); SavedGun gun = savedGun.GetSavedGun(); for (int i = 0; i < gun.Components.Count; i++) { AnvilCallback <GameObject> gameObjectCallback = IM.OD[gun.Components[i].ObjectID].GetGameObjectAsync(); TNHTweakerLogger.Log($"Loading vault component: {gun.Components[i].ObjectID}", TNHTweakerLogger.LogType.General); yield return(gameObjectCallback); gameObjects.Add(gameObjectCallback.Result); } for (int j = 0; j < gun.Components.Count; j++) { GameObject gameObject = UnityEngine.Object.Instantiate(gameObjects[j]); dicGO.Add(gameObject, gun.Components[j]); dicByIndex.Add(gun.Components[j].Index, gameObject); if (gun.Components[j].isFirearm) { myGun = gameObject.GetComponent <FVRFireArm>(); savedGun.ApplyFirearmProperties(myGun); validIndexes.Add(j); gameObject.transform.position = position; gameObject.transform.rotation = Quaternion.identity; } else if (gun.Components[j].isMagazine) { myMagazine = gameObject.GetComponent <FVRFireArmMagazine>(); validIndexes.Add(j); if (myMagazine != null) { gameObject.transform.position = myGun.GetMagMountPos(myMagazine.IsBeltBox).position; gameObject.transform.rotation = myGun.GetMagMountPos(myMagazine.IsBeltBox).rotation; myMagazine.Load(myGun); myMagazine.IsInfinite = false; } } else if (gun.Components[j].isAttachment) { toDealWith.Add(gameObject); } else { toMoveToTrays.Add(gameObject); if (gameObject.GetComponent <Speedloader>() != null && gun.LoadedRoundsInMag.Count > 0) { Speedloader component = gameObject.GetComponent <Speedloader>(); component.ReloadSpeedLoaderWithList(gun.LoadedRoundsInMag); } else if (gameObject.GetComponent <FVRFireArmClip>() != null && gun.LoadedRoundsInMag.Count > 0) { FVRFireArmClip component2 = gameObject.GetComponent <FVRFireArmClip>(); component2.ReloadClipWithList(gun.LoadedRoundsInMag); } } gameObject.GetComponent <FVRPhysicalObject>().ConfigureFromFlagDic(gun.Components[j].Flags); } if (myGun.Magazine != null && gun.LoadedRoundsInMag.Count > 0) { myGun.Magazine.ReloadMagWithList(gun.LoadedRoundsInMag); myGun.Magazine.IsInfinite = false; } int BreakIterator = 200; while (toDealWith.Count > 0 && BreakIterator > 0) { BreakIterator--; for (int k = toDealWith.Count - 1; k >= 0; k--) { SavedGunComponent savedGunComponent = dicGO[toDealWith[k]]; if (validIndexes.Contains(savedGunComponent.ObjectAttachedTo)) { GameObject gameObject2 = toDealWith[k]; FVRFireArmAttachment component3 = gameObject2.GetComponent <FVRFireArmAttachment>(); FVRFireArmAttachmentMount mount = GetMount(dicByIndex[savedGunComponent.ObjectAttachedTo], savedGunComponent.MountAttachedTo); gameObject2.transform.rotation = Quaternion.LookRotation(savedGunComponent.OrientationForward, savedGunComponent.OrientationUp); gameObject2.transform.position = GetPositionRelativeToGun(savedGunComponent, myGun.transform); if (component3.CanScaleToMount && mount.CanThisRescale()) { component3.ScaleToMount(mount); } component3.AttachToMount(mount, false); if (component3 is Suppressor) { (component3 as Suppressor).AutoMountWell(); } validIndexes.Add(savedGunComponent.Index); toDealWith.RemoveAt(k); } } } int trayIndex = 0; int itemIndex = 0; for (int l = 0; l < toMoveToTrays.Count; l++) { toMoveToTrays[l].transform.position = position + (float)itemIndex * 0.1f * Vector3.up; toMoveToTrays[l].transform.rotation = rotation; itemIndex++; trayIndex++; if (trayIndex > 2) { trayIndex = 0; } } myGun.SetLoadedChambers(gun.LoadedRoundsInChambers); myGun.SetFromFlagList(gun.SavedFlags); myGun.transform.rotation = rotation; yield break; }