public Item CloneItem(Item origItem, int newID) { // clone it, set inactive, and dont destroy on load origItem.gameObject.SetActive(false); GameObject newItem = Instantiate(origItem.gameObject); origItem.gameObject.SetActive(true); newItem.SetActive(false); DontDestroyOnLoad(newItem); // get the Item component and set our custom ID first Item item = newItem.GetComponent <Item>(); item.ItemID = newID; // fix ResourcesPrefabManager dictionary if (At.GetValue(typeof(ResourcesPrefabManager), null, "ITEM_PREFABS") is Dictionary <string, Item> Items) { if (Items.ContainsKey(item.ItemID.ToString())) { Items[item.ItemID.ToString()] = item; } else { Items.Add(item.ItemID.ToString(), item); } At.SetValue(Items, typeof(ResourcesPrefabManager), null, "ITEM_PREFABS"); //SideLoader.Log(string.Format("Added {0} to RPM dictionary.", item.Name)); } return(item); }
// create a skillschool template. public static SkillSchool CreateSkillSchool(string name) { if ((Resources.Load("_characters/CharacterProgression") as GameObject).transform.Find("Test") is Transform template) { // instantiate a copy of the dev template var customObj = Instantiate(template).gameObject; DontDestroyOnLoad(customObj); var CustomTree = customObj.GetComponent <SkillSchool>(); // set the name to the gameobject and the skill tree name/uid customObj.name = name; At.SetValue(name, typeof(SkillSchool), CustomTree, "m_defaultName"); At.SetValue("", typeof(SkillSchool), CustomTree, "m_nameLocKey"); At.SetValue(new UID(name), typeof(SkillSchool), CustomTree, "m_uid"); // add it to the game's skill tree holder. var list = (At.GetValue(typeof(SkillTreeHolder), SkillTreeHolder.Instance, "m_skillTrees") as SkillSchool[]).ToList(); list.Add(CustomTree); At.SetValue(list.ToArray(), typeof(SkillTreeHolder), SkillTreeHolder.Instance, "m_skillTrees"); return(CustomTree); } return(null); }
private AudioSource PlayMusicHook(On.GlobalAudioManager.orig_PlayMusic orig, GlobalAudioManager self, GlobalAudioManager.Sounds _sound, float _fade) { string songName = _sound.ToString(); if (SL.Instance.AudioClips.ContainsKey(songName) && At.GetValue(typeof(GlobalAudioManager), self, "s_musicSources") is DictionaryExt <GlobalAudioManager.Sounds, GlobalAudioManager.MusicSource> dict) { // set our custom clip to the actual GlobalAudioManager dictionary, so it works with the game systems as expected if (!dict.ContainsKey(_sound) && At.Call(self, "GetPrefabPath", new object[] { _sound }) is string prefabPath) { GameObject gameObject = Resources.Load("_Sounds/" + prefabPath) as GameObject; gameObject = Instantiate(gameObject); AudioSource component = gameObject.GetComponent <AudioSource>(); DontDestroyOnLoad(gameObject); dict.Add(_sound, new GlobalAudioManager.MusicSource(component)); } dict[_sound].Source.clip = SL.Instance.AudioClips[_sound.ToString()]; At.SetValue(dict, typeof(GlobalAudioManager), self, "s_musicSources"); At.Call(self, "CleanUpMusic", null); At.SetValue(_sound, typeof(GlobalAudioManager), self, "s_currentMusic"); StartCoroutine(FadeMusic(self, _sound, dict[_sound], _fade)); return(dict[_sound].Source); } else { return(orig(self, _sound, _fade)); } }
// custom recipes public static void DefineRecipe(int ItemID, int craftingType, List <int> IngredientIDs) { if (ResourcesPrefabManager.Instance.GetItemPrefab(ItemID) is Item item) { SideLoader.Log(" - Defining recipe for " + item.Name); Recipe recipe = Recipe.CreateInstance("Recipe") as Recipe; recipe.SetCraftingType((Recipe.CraftingType)craftingType); recipe.SetRecipeID(ItemID); recipe.SetRecipeName(item.Name); recipe.SetRecipeResults(item, 1); RecipeIngredient[] ingredients = new RecipeIngredient[IngredientIDs.Count()]; for (int i = 0; i < IngredientIDs.Count(); i++) { int id = IngredientIDs[i]; RecipeIngredient ingredient = new RecipeIngredient() { ActionType = RecipeIngredient.ActionTypes.AddSpecificIngredient, AddedIngredient = ResourcesPrefabManager.Instance.GetItemPrefab(id), }; ingredients[i] = ingredient; } recipe.SetRecipeIngredients(ingredients); recipe.Init(); // add to recipe dictionary if (At.GetValue(typeof(RecipeManager), RecipeManager.Instance, "m_recipes") is Dictionary <string, Recipe> dict && At.GetValue(typeof(RecipeManager), RecipeManager.Instance, "m_recipeUIDsPerUstensils") is Dictionary <Recipe.CraftingType, List <UID> > dict2) { // add to main recipe dictionary dict.Add(recipe.UID, recipe); At.SetValue(dict, typeof(RecipeManager), RecipeManager.Instance, "m_recipes"); // add to the "UID per Utensil" dictionary thing if (!dict2.ContainsKey(recipe.CraftingStationType)) { dict2.Add(recipe.CraftingStationType, new List <UID>()); } dict2[recipe.CraftingStationType].Add(recipe.UID); At.SetValue(dict2, typeof(RecipeManager), RecipeManager.Instance, "m_recipeUIDsPerUstensils"); SideLoader.Log("added " + item.Name + " to custom recipe to dict"); } } }
private IEnumerator FadeMusic(GlobalAudioManager _manager, GlobalAudioManager.Sounds _music, GlobalAudioManager.MusicSource musSource, float _time, bool _in = true) { float vol; float targetVol; if (!_in) { vol = musSource.Source.volume; targetVol = 0f; } else { vol = 0f; targetVol = musSource.OrigVolume; } if (!musSource.Source.gameObject.activeSelf) { musSource.Source.gameObject.SetActive(true); } if (_in) { musSource.Source.Play(); } float lerp = 0f; while (lerp < 1f) { if (!musSource.Source) { break; } lerp = Mathf.Clamp01(lerp + Time.deltaTime / _time); musSource.Source.volume = Mathf.Lerp(vol, targetVol, lerp); yield return(null); } if (!_in && musSource.Source) { if (At.GetValue(typeof(GlobalAudioManager), _manager, "m_eventMusic") is GlobalAudioManager.Sounds _eventMusic && _eventMusic != GlobalAudioManager.Sounds.NONE && _music == _eventMusic) { musSource.Source.Stop(); } else { musSource.Source.Pause(); } }
public void SetNameAndDesc(Item item, string name, string desc) { ItemLocalization loc = new ItemLocalization(name, desc); At.SetValue(name, typeof(Item), item, "m_name"); if (At.GetValue(typeof(LocalizationManager), LocalizationManager.Instance, "m_itemLocalization") is Dictionary <int, ItemLocalization> dict) { if (dict.ContainsKey(item.ItemID)) { dict[item.ItemID] = loc; } else { dict.Add(item.ItemID, loc); } At.SetValue(dict, typeof(LocalizationManager), LocalizationManager.Instance, "m_itemLocalization"); } }
public IEnumerator ReplaceActiveAssets() { SideLoader.Log("Replacing Materials.."); float start = Time.time; // ============ materials ============ var list = Resources.FindObjectsOfTypeAll <Material>() .Where(x => x.mainTexture != null && SL.Instance.TextureData.ContainsKey(x.mainTexture.name)) .ToList(); SideLoader.Log(string.Format("Found {0} materials to replace.", list.Count)); int i = 0; foreach (Material m in list) { string name = m.mainTexture.name; i++; SideLoader.Log(string.Format(" - Replacing material {0} of {1}: {2}", i, list.Count, name)); // set maintexture (diffuse map) m.mainTexture = SL.Instance.TextureData[name]; // ======= set other shader material layers ======= if (name.EndsWith("_d")) { name = name.Substring(0, name.Length - 2); } // try remove the _d suffix, if its there // check each shader material suffix name foreach (KeyValuePair <string, string> entry in TextureSuffixes) { if (entry.Key == "_d") { continue; } // already set MainTex if (SL.Instance.TextureData.ContainsKey(name + entry.Key)) { SideLoader.Log(" - Setting " + entry.Value + " for " + m.name); m.SetTexture(entry.Value, SL.Instance.TextureData[name + entry.Key]); } } yield return(null); } // ========= sprites ========= SideLoader.Log("Replacing PrefabManager icons..."); if (At.GetValue(typeof(ResourcesPrefabManager), null, "ITEM_PREFABS") is Dictionary <string, Item> dict) { foreach (Item item in dict.Values .Where(x => x.ItemID > 2000000 && x.ItemIcon != null && x.ItemIcon.texture != null && SL.Instance.TextureData.ContainsKey(x.ItemIcon.texture.name))) { string name = item.ItemIcon.texture.name; SideLoader.Log(string.Format(" - Replacing item icon: {0}", name)); var tex = SL.Instance.TextureData[name]; var sprite = CreateSprite(tex); At.SetValue(sprite, typeof(Item), item, "m_itemIcon"); } } // ============================================== SideLoader.Log("Active assets replaced. Time: " + (Time.time - start), 0); SL.Instance.Loading = false; }