diff --git a/.vs/PortiaMods/v16/.suo b/.vs/PortiaMods/v16/.suo index 7d8b883..7685cd1 100644 Binary files a/.vs/PortiaMods/v16/.suo and b/.vs/PortiaMods/v16/.suo differ diff --git a/CookingMachine/Main.cs b/CookingMachine/Main.cs index 4e0699e..2a1a084 100644 --- a/CookingMachine/Main.cs +++ b/CookingMachine/Main.cs @@ -4,6 +4,7 @@ using Pathea.HomeNs; using Pathea.ItemSystem; using Pathea.ModuleNs; +using System; using System.Collections.Generic; using System.Reflection; using UnityEngine; @@ -75,34 +76,41 @@ static void Postfix(ref List ___sourceData, ref CompoundTable[ List datas = Singleton.Instance.DataList; foreach(CookMenuData data in datas) { - CompoundItemData cid = cidd; - cid.ID = start++; - cid.NameID = Module.Self.GetItemNameId(data.Food); - cid.ItemID = data.Food; - cid.BookId = start2++; - if (data.Mats.Count > 0 && ItemObject.CreateItem(data.Mats[0].ID) != null) + try { - cid.RequireItem1 = data.Mats[0].ID; - cid.RequireItemNum1 = data.Mats[0].Num; - if (data.Mats.Count > 1 && ItemObject.CreateItem(data.Mats[1].ID) != null) + CompoundItemData cid = cidd; + cid.ID = start++; + cid.NameID = Module.Self.GetItemNameId(data.Food); + cid.ItemID = data.Food; + cid.BookId = start2++; + if (data.Mats.Count > 0 && ItemObject.CreateItem(data.Mats[0].ID) != null) { - cid.RequireItem2 = data.Mats[1].ID; - cid.RequireItemNum2 = data.Mats[1].Num; - if (data.Mats.Count > 2 && ItemObject.CreateItem(data.Mats[2].ID) != null) + cid.RequireItem1 = data.Mats[0].ID; + cid.RequireItemNum1 = data.Mats[0].Num; + if (data.Mats.Count > 1 && ItemObject.CreateItem(data.Mats[1].ID) != null) { - cid.RequireItem3 = data.Mats[2].ID; - cid.RequireItemNum3 = data.Mats[2].Num; + cid.RequireItem2 = data.Mats[1].ID; + cid.RequireItemNum2 = data.Mats[1].Num; + if (data.Mats.Count > 2 && ItemObject.CreateItem(data.Mats[2].ID) != null) + { + cid.RequireItem3 = data.Mats[2].ID; + cid.RequireItemNum3 = data.Mats[2].Num; + } } } + else + { + continue; + } + Dbgl("adding to " + (int)cidd.CompoundType); + CompoundItem ci = new CompoundItem(cid); + ___m_compoundTable[(int)cidd.CompoundType].AddItem(ci); + //___sourceData.Add(cid); } - else + catch (Exception ex) { - continue; + Dbgl("exception: " + ex); } - Dbgl("adding to "+ (int)cidd.CompoundType); - CompoundItem ci = new CompoundItem(cid); - ___m_compoundTable[(int)cidd.CompoundType].AddItem(ci); - //___sourceData.Add(cid); } } diff --git a/FarmAnimals/FarmAnimals.csproj b/FarmAnimals/FarmAnimals.csproj new file mode 100644 index 0000000..e7a1779 --- /dev/null +++ b/FarmAnimals/FarmAnimals.csproj @@ -0,0 +1,107 @@ + + + + + Debug + AnyCPU + {0BD0B28D-9672-4ADD-9558-2317673C52DA} + Library + Properties + FarmAnimals + FarmAnimals + v3.5 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\external\0Harmony-1.2.dll + + + ..\external\UnityModManager\0Harmony12.dll + + + ..\external\Assembly-CSharp.dll + + + ..\external\Assembly-CSharp-firstpass.dll + + + + + + + + + ..\external\UnityEngine.dll + + + ..\external\UnityEngine.AnimationModule.dll + + + ..\external\UnityEngine.AudioModule.dll + + + ..\external\UnityEngine.CoreModule.dll + + + ..\external\UnityEngine.ImageConversionModule.dll + + + ..\external\UnityEngine.IMGUIModule.dll + + + ..\external\UnityEngine.ParticleSystemModule.dll + + + ..\external\UnityEngine.PhysicsModule.dll + + + ..\external\UnityEngine.TextRenderingModule.dll + + + ..\external\UnityEngine.UI.dll + + + ..\external\UnityEngine.UIModule.dll + + + ..\external\UnityEngine.UnityWebRequestAudioModule.dll + + + ..\external\UnityEngine.UnityWebRequestModule.dll + + + ..\external\UnityEngine.UnityWebRequestWWWModule.dll + + + ..\external\UnityModManager\UnityModManager.dll + + + + + + + + + + call $(SolutionDir)copyDll.bat FarmAnimals + + \ No newline at end of file diff --git a/FarmAnimals/Main.cs b/FarmAnimals/Main.cs new file mode 100644 index 0000000..f7d71fd --- /dev/null +++ b/FarmAnimals/Main.cs @@ -0,0 +1,200 @@ +using Harmony12; +using Pathea; +using Pathea.ACT; +using Pathea.ModuleNs; +using System; +using System.Collections.Generic; +using System.Reflection; +using Pathea.ActorNs; +using UnityEngine; +using UnityModManagerNet; +using static Pathea.ActorMotor; +using Pathea.AnimalFarmNs; +using Pathea.HomeNs; +using Hont.ExMethod.Collection; +using Pathea.TipsNs; + +namespace FarmAnimals +{ + public class Main + { + public static Settings settings { get; private set; } + + public static bool enabled; + + private static readonly bool isDebug = true; + + public static void Dbgl(string str = "", bool pref = true) + { + if (isDebug) + Debug.Log((pref ? "FarmAnimals " : "") + str); + } + + private static void Load(UnityModManager.ModEntry modEntry) + { + settings = Settings.Load(modEntry); + + modEntry.OnGUI = OnGUI; + modEntry.OnSaveGUI = OnSaveGUI; + modEntry.OnToggle = OnToggle; + + var harmony = HarmonyInstance.Create(modEntry.Info.Id); + harmony.PatchAll(Assembly.GetExecutingAssembly()); + } + + // Called when the mod is turned to on/off. + static bool OnToggle(UnityModManager.ModEntry modEntry, bool value /* active or inactive */) + { + enabled = value; + return true; // Permit or not. + } + private static void OnSaveGUI(UnityModManager.ModEntry modEntry) + { + settings.Save(modEntry); + } + + private static void OnGUI(UnityModManager.ModEntry modEntry) + { + GUILayout.Label(string.Format("Animal Growth Speed: {0:F1}", settings.AnimalGrowthSpeed), new GUILayoutOption[0]); + settings.AnimalGrowthSpeed = GUILayout.HorizontalSlider(settings.AnimalGrowthSpeed * 10f, 1f, 1000f, new GUILayoutOption[0]) / 10f; + GUILayout.Space(10f); + GUILayout.Label(string.Format("Max Animal Growth: {0:F1}%", settings.MaxAnimalGrowthPercent), new GUILayoutOption[0]); + settings.MaxAnimalGrowthPercent = GUILayout.HorizontalSlider(settings.MaxAnimalGrowthPercent, 1f, 300f, new GUILayoutOption[0]); + GUILayout.Space(10f); + GUILayout.Label(string.Format("Base Pregnancy Chance: {0:F1}%", settings.BasePregnancyChance), new GUILayoutOption[0]); + settings.BasePregnancyChance = GUILayout.HorizontalSlider(settings.BasePregnancyChance, 1f, 100f, new GUILayoutOption[0]); + GUILayout.Space(10f); + } + + [HarmonyPatch(typeof(AnimalData), nameof(AnimalData.GetDataByDataId))] + static class AnimalData_GedDataByDataId + { + static void Prefix(List ___datas) + { + if (!enabled) + return; + if (___datas == null) + { + SqliteDataReader sqliteDataReader = LocalDb.cur.ReadFullTable("AnimalFarm_Animal"); + if (sqliteDataReader == null) + { + return; + } + ___datas = DbReader.Read(sqliteDataReader, 20); + } + for(int i = 0; i < ___datas.Count; i++) + { + typeof(AnimalData).GetProperty("TotalPoint").SetValue(___datas[i],(int)Math.Round(___datas[i].StandardPoint * settings.MaxAnimalGrowthPercent / 100f), null); + string name = TextMgr.GetStr(___datas[i].NameId, -1); + Dbgl($"{name} max points set to {___datas[i].TotalPoint}"); + } + } + } + + [HarmonyPatch(typeof(AnimalinFarm), "AddAgeChange")] + static class AnimalinFarm_AddAgeChange + { + static void Prefix(ref float foodNum) + { + if (!enabled) + return; + foodNum *= settings.AnimalGrowthSpeed; + } + + [HarmonyPatch(typeof(AnimalFarmUnit), "Reproduction")] + static class AnimalFarmUnit_Reproduction + { + private static bool Prefix(ref AnimalFarmUnit __instance) + { + if (!enabled) + return false; + if (__instance.Animals.Count >= __instance.HouseData.AnimalMax) + { + Dbgl($"farm already full, cancelling"); + return false; + } + + int tipsId; + + Dictionary> aifs = new Dictionary>(); + foreach(AnimalinFarm aif in __instance.Animals) + { + if (aif.Age >= aif.Data.StandardPoint) + { + if (aifs.ContainsKey(aif.Data.Id)) + { + aifs[aif.Data.Id].Add(aif); + } + else + { + aifs.Add(aif.Data.Id, new List() { aif }); + } + } + } + + Dictionary newAnimals = new Dictionary(); + foreach(KeyValuePair> kvp in aifs) + { + newAnimals.Add(kvp.Key, 0); + } + + while(aifs.Keys.Count > 0) + { + if (__instance.Animals.Count >= __instance.HouseData.AnimalMax) + { + Dbgl($"farm filled up, breaking"); + break; + } + int idx = aifs.Keys.ToArray()[UnityEngine.Random.Range(0, aifs.Count - 1)]; + if(aifs[idx].Count < 2) + { + aifs.Remove(idx); + } + else + { + List aifl = aifs[idx]; + List matureAnimals = aifl.FindAll((AnimalinFarm a) => a.Age >= a.Data.StandardPoint); + if(matureAnimals.Count < 2) + { + aifs.Remove(idx); + } + else + { + int a = UnityEngine.Random.Range(0, matureAnimals.Count-1); + AnimalinFarm aa = matureAnimals[a]; + matureAnimals.RemoveAt(a); + int b = UnityEngine.Random.Range(0, matureAnimals.Count-1); + AnimalinFarm ab = matureAnimals[a]; + matureAnimals.RemoveAt(b); + float chancea = settings.BasePregnancyChance + (100 - settings.BasePregnancyChance) * ((aa.Age - aa.Data.StandardPoint) / aa.Data.StandardPoint); + float chanceb = settings.BasePregnancyChance + (100 - settings.BasePregnancyChance) * ((ab.Age - ab.Data.StandardPoint) / ab.Data.StandardPoint); + float chance = (chancea + chanceb) / 2f; + Dbgl($"type: {idx} age: {aa.Age} {ab.Age} preg chance: {chance}"); + if (UnityEngine.Random.Range(0, 100) <= chance) + { + Dbgl($"birthing"); + __instance.AddAnimal(idx, out tipsId); + typeof(AnimalinFarm).GetField("age", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(aa, aa.Data.StandardPoint); + typeof(AnimalinFarm).GetField("age", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(ab, ab.Data.StandardPoint); + newAnimals[idx]++; + } + aifs[idx].Remove(aa); + aifs[idx].Remove(ab); + } + } + } + foreach(KeyValuePair kvp in newAnimals) + { + if(kvp.Value > 0) + { + string name = TextMgr.GetStr(AnimalData.GetDataByDataId(kvp.Key).NameId, -1); + Dbgl($"sending tips ui"); + Singleton.Instance.SendSystemTip($"A {name} gave birth!"); + } + } + return false; + } + } + } + } +} diff --git a/FarmAnimals/Settings.cs b/FarmAnimals/Settings.cs new file mode 100644 index 0000000..620ea5a --- /dev/null +++ b/FarmAnimals/Settings.cs @@ -0,0 +1,16 @@ +using UnityModManagerNet; + +namespace FarmAnimals +{ + public class Settings : UnityModManager.ModSettings + { + public float AnimalGrowthSpeed { get; set; } = 1.0f; + public float MaxAnimalGrowthPercent { get; set; } = 200.0f; + public float BasePregnancyChance { get; set; } = 10.0f; + + public override void Save(UnityModManager.ModEntry modEntry) + { + Save(this, modEntry); + } + } +} \ No newline at end of file diff --git a/Livestock/Livestock.csproj b/Livestock/Livestock.csproj new file mode 100644 index 0000000..216fa5c --- /dev/null +++ b/Livestock/Livestock.csproj @@ -0,0 +1,50 @@ + + + + + Debug + AnyCPU + 41ef26ba-bd9e-421a-ac2c-0ca5518b3d76 + Library + Properties + Livestock + Livestock + v3.5 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + diff --git a/Livestock/Main.cs b/Livestock/Main.cs new file mode 100644 index 0000000..c7f5efc --- /dev/null +++ b/Livestock/Main.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Livestock +{ + public class Class1 + { + } +} diff --git a/PortiaMods.sln b/PortiaMods.sln index 70a237c..bf91289 100644 --- a/PortiaMods.sln +++ b/PortiaMods.sln @@ -97,6 +97,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UMMFreeze", "UMMFreeze\UMMF EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookingMachine", "CookingMachine\CookingMachine.csproj", "{B096B212-BD66-4D48-B27E-AAE36F2D5FFB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FarmAnimals", "FarmAnimals\FarmAnimals.csproj", "{0BD0B28D-9672-4ADD-9558-2317673C52DA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Television", "Television\Television.csproj", "{2A22EEE4-3941-4346-AE27-BBB1B2469F4D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -291,6 +295,14 @@ Global {B096B212-BD66-4D48-B27E-AAE36F2D5FFB}.Debug|Any CPU.Build.0 = Debug|Any CPU {B096B212-BD66-4D48-B27E-AAE36F2D5FFB}.Release|Any CPU.ActiveCfg = Release|Any CPU {B096B212-BD66-4D48-B27E-AAE36F2D5FFB}.Release|Any CPU.Build.0 = Release|Any CPU + {0BD0B28D-9672-4ADD-9558-2317673C52DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0BD0B28D-9672-4ADD-9558-2317673C52DA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0BD0B28D-9672-4ADD-9558-2317673C52DA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0BD0B28D-9672-4ADD-9558-2317673C52DA}.Release|Any CPU.Build.0 = Release|Any CPU + {2A22EEE4-3941-4346-AE27-BBB1B2469F4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A22EEE4-3941-4346-AE27-BBB1B2469F4D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A22EEE4-3941-4346-AE27-BBB1B2469F4D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A22EEE4-3941-4346-AE27-BBB1B2469F4D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Television/Main.cs b/Television/Main.cs new file mode 100644 index 0000000..2856ee7 --- /dev/null +++ b/Television/Main.cs @@ -0,0 +1,197 @@ +using Harmony12; +using Pathea; +using System; +using System.Collections.Generic; +using System.Reflection; +using UnityEngine; +using UnityModManagerNet; +using Pathea.AnimalFarmNs; +using Pathea.HomeNs; +using Hont.ExMethod.Collection; +using Pathea.TipsNs; +using System.IO; +using Pathea.ItemSystem; +using System.Linq; + +namespace Television +{ + public class Main + { + public static Settings settings { get; private set; } + + public static bool enabled; + + private static readonly bool isDebug = true; + + public static void Dbgl(string str = "", bool pref = true) + { + if (isDebug) + Debug.Log((pref ? "Television " : "") + str); + } + + private static void Load(UnityModManager.ModEntry modEntry) + { + settings = Settings.Load(modEntry); + + modEntry.OnGUI = OnGUI; + modEntry.OnSaveGUI = OnSaveGUI; + modEntry.OnToggle = OnToggle; + + LoadVideoFiles(); + + + var harmony = HarmonyInstance.Create(modEntry.Info.Id); + harmony.PatchAll(Assembly.GetExecutingAssembly()); + } + + // Called when the mod is turned to on/off. + static bool OnToggle(UnityModManager.ModEntry modEntry, bool value /* active or inactive */) + { + enabled = value; + return true; // Permit or not. + } + private static void OnSaveGUI(UnityModManager.ModEntry modEntry) + { + settings.Save(modEntry); + } + + private static void OnGUI(UnityModManager.ModEntry modEntry) + { + } + + private static void LoadVideoFiles() + { + int id = 40032000; + + string path = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\\assets"; + + videoPaths.Clear(); + + foreach (string file in Directory.GetFiles(path)) + { + string name = Path.GetFileName(file); + Dbgl("file: " + name); + name = name.Substring(0, name.Length - 4); + Dbgl("name: " + name); + + if (file.EndsWith(".mp4")) + { + videoPaths.Add(name, file); + videoNames.Add(id++, name); + } + else if (file.EndsWith(".txt")) + { + videoPaths.Add(name, File.ReadAllLines(file)[0]); + videoNames.Add(id++, name); + } + } + } + + private static Dictionary videoPaths = new Dictionary(); + private static Dictionary videoNames = new Dictionary(); + + [HarmonyPatch(typeof(VideoChoiceUICtr), "GetVideoes")] + static class VideoChoiceUICtr_GetVideoes + { + static void Postfix(ref List __result) + { + if (!enabled) + return; + if (__result == null) + { + __result = new List(); + } + foreach (KeyValuePair kvp in videoNames) + { + __result.Add(new VideoTypeData() + { + FileName = kvp.Value, + Id = kvp.Key + });; + } + + } + } + + + + [HarmonyPatch(typeof(ItemDataMgr), "OnLoad")] + static class ItemDataMgr_OnLoad_Patch + { + static void Postfix(ItemDataMgr __instance, ref List ___itemBaseList, ref List ___equipmentDataList) + { + if (!enabled) + return; + + foreach (KeyValuePair kvp in videoNames) + { + ItemBaseConfData itemConf = new ItemBaseConfData() + { + ID = kvp.Key, + NameID = kvp.Key, + }; + + ___itemBaseList.Add(itemConf); + + } + } + } + + [HarmonyPatch(typeof(TextMgr), "Get")] + private static class TextMgr_Get_Patch + { + private static bool Prefix(int id, ref string __result) + { + if (!enabled) + return true; + + if (videoNames.ContainsKey(id)) + { + __result = videoNames[id]; + return false; + } + return true; + } + } + + + + [HarmonyPatch(typeof(TVCtr), "Play")] + static class TVCtr_Play + { + static bool Prefix(TVCtr __instance, string fileName) + { + if (!enabled) + return true; + + if (__instance.CurPlay == fileName) + { + return false; + } + if (string.IsNullOrEmpty(fileName)) + { + __instance.Stop(); + return false; + } + + Dbgl("filename: " + fileName); + + if (videoPaths.ContainsKey(fileName)) + { + Dbgl("got file: " + videoPaths[fileName]); + try + { + typeof(TVCtr).GetMethod("PlayUrl", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { videoPaths[fileName] }); + } + catch (Exception ex) + { + Dbgl("error: " + ex); + } + return false; + } + + return true; + } + } + } +} diff --git a/Television/Settings.cs b/Television/Settings.cs new file mode 100644 index 0000000..42dea86 --- /dev/null +++ b/Television/Settings.cs @@ -0,0 +1,13 @@ +using UnityModManagerNet; + +namespace Television +{ + public class Settings : UnityModManager.ModSettings + { + + public override void Save(UnityModManager.ModEntry modEntry) + { + Save(this, modEntry); + } + } +} \ No newline at end of file diff --git a/Television/Television.csproj b/Television/Television.csproj new file mode 100644 index 0000000..ea4d31e --- /dev/null +++ b/Television/Television.csproj @@ -0,0 +1,107 @@ + + + + + Debug + AnyCPU + {2A22EEE4-3941-4346-AE27-BBB1B2469F4D} + Library + Properties + Television + Television + v3.5 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\external\0Harmony-1.2.dll + + + ..\external\UnityModManager\0Harmony12.dll + + + ..\external\Assembly-CSharp.dll + + + ..\external\Assembly-CSharp-firstpass.dll + + + + + + + + + ..\external\UnityEngine.dll + + + ..\external\UnityEngine.AnimationModule.dll + + + ..\external\UnityEngine.AudioModule.dll + + + ..\external\UnityEngine.CoreModule.dll + + + ..\external\UnityEngine.ImageConversionModule.dll + + + ..\external\UnityEngine.IMGUIModule.dll + + + ..\external\UnityEngine.ParticleSystemModule.dll + + + ..\external\UnityEngine.PhysicsModule.dll + + + ..\external\UnityEngine.TextRenderingModule.dll + + + ..\external\UnityEngine.UI.dll + + + ..\external\UnityEngine.UIModule.dll + + + ..\external\UnityEngine.UnityWebRequestAudioModule.dll + + + ..\external\UnityEngine.UnityWebRequestModule.dll + + + ..\external\UnityEngine.UnityWebRequestWWWModule.dll + + + ..\external\UnityModManager\UnityModManager.dll + + + + + + + + + + call $(SolutionDir)copyDll.bat Television + + \ No newline at end of file diff --git a/repository.json b/repository.json index 814cb3f..a8d7997 100644 --- a/repository.json +++ b/repository.json @@ -13,6 +13,7 @@ {"Id": "DeeDeeAnywhere", "Version": "0.1.7"}, {"Id": "DialogueEdit", "Version": "0.1.0"}, {"Id": "Environment", "Version": "0.3.3"}, + {"Id": "FarmAnimals", "Version": "0.1.0"}, {"Id": "FasterPiggy", "Version": "0.1.0"}, {"Id": "FishBowlMod", "Version": "0.3.2"}, {"Id": "InfiniteLevels", "Version": "0.1.0"}, @@ -36,6 +37,7 @@ {"Id": "StorageAnywhere", "Version": "0.6.0"}, {"Id": "Swim", "Version": "0.2.1"}, {"Id": "Teleport", "Version": "0.0.1"}, + {"Id": "Television", "Version": "0.1.0"}, {"Id": "TreasureRevealer", "Version": "0.2.2"}, {"Id": "UMMFreeze", "Version": "0.1.0"}, {"Id": "UnlimitedCivicCorpsMissions", "Version": "0.4.0"},