From f04acf8234938b6bbe11c04cb30167b6965d4084 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 19 Nov 2018 21:25:52 -0800 Subject: [PATCH] Updated ScadMod to contain a name, added DustDevil framework version --- .../CustomHero-Mod/CustomHeroMod.cs | 3 +- .../CustomItems-Mod/ShinyItemConfig.cs | 18 ++-- .../DustDevilFramework/CustomItem.cs | 81 ++++------------- .../DustDevilFramework/DustDevil.cs | 89 +++++++++++++++++++ .../DustDevilFramework.csproj | 3 + DotE_Patch_Mod/DustDevilFramework/PodMod.cs | 5 ++ DotE_Patch_Mod/DustDevilFramework/ScadMod.cs | 18 +++- .../SimDescriptorWrapper.cs | 46 ++++++++++ .../DustGenerator-Mod/DustGeneratorMod.cs | 3 +- .../AllowDustChangingWithCrystalMod.cs | 4 +- .../ExitFinder-Mod/ExitFinderMod.cs | 3 +- DotE_Patch_Mod/Ping-Mod/PingMod.cs | 3 +- DotE_Patch_Mod/TrueIGT-Mod/TrueIGTMod.cs | 3 +- 13 files changed, 191 insertions(+), 88 deletions(-) create mode 100644 DotE_Patch_Mod/DustDevilFramework/DustDevil.cs create mode 100644 DotE_Patch_Mod/DustDevilFramework/SimDescriptorWrapper.cs diff --git a/DotE_Patch_Mod/CustomHero-Mod/CustomHeroMod.cs b/DotE_Patch_Mod/CustomHero-Mod/CustomHeroMod.cs index b03e684..d0196f8 100644 --- a/DotE_Patch_Mod/CustomHero-Mod/CustomHeroMod.cs +++ b/DotE_Patch_Mod/CustomHero-Mod/CustomHeroMod.cs @@ -20,8 +20,7 @@ class CustomHeroMod : PartialityMod public override void Init() { - mod.path = @"CustomHero_log.txt"; - mod.config = @"CustomHero_config.txt"; + mod.name = "CustomHero"; mod.default_config = "# Modify this file to change various settings of the CustomHero Mod for DotE.\n" + mod.default_config; mod.Initialize(); diff --git a/DotE_Patch_Mod/CustomItems-Mod/ShinyItemConfig.cs b/DotE_Patch_Mod/CustomItems-Mod/ShinyItemConfig.cs index 89a9039..918bfce 100644 --- a/DotE_Patch_Mod/CustomItems-Mod/ShinyItemConfig.cs +++ b/DotE_Patch_Mod/CustomItems-Mod/ShinyItemConfig.cs @@ -142,9 +142,9 @@ public override float GetStartingProbabilityWeight() public override SimulationDescriptor GetBaseDescriptor() { SimDescriptorWrapper wrapper = new SimDescriptorWrapper(); - wrapper.Add(SimulationProperties.AttackCooldown, -0.5f); - wrapper.Add(SimulationProperties.MoveSpeed, 3f); - return wrapper.GetDescriptor(GetName()); + wrapper.Add(SimulationProperties.AttackCooldown, -0.1f); + wrapper.Add(SimulationProperties.MoveSpeed, 1f); + return wrapper.GetDescriptor("ItemHero_" + GetName()); } public override SimulationDescriptor GetCommonDescriptor() @@ -152,7 +152,7 @@ public override SimulationDescriptor GetCommonDescriptor() SimDescriptorWrapper wrapper = new SimDescriptorWrapper(); wrapper.Add(SimulationProperties.AttackCooldown, -0.5f); wrapper.Add(SimulationProperties.MoveSpeed, 3f); - return wrapper.GetDescriptor(GetName() + "_Common"); + return wrapper.GetDescriptor("ItemHero_" + GetName() + "_Common"); } public override SimulationDescriptor GetRarity0Descriptor() @@ -163,29 +163,29 @@ public override SimulationDescriptor GetRarity0Descriptor() wrapper.Add(SimulationProperties.MaxHealth, 10000f); wrapper.Add(SimulationProperties.AttackPower, 100); wrapper.Add(SimulationProperties.HealthRegen, 800); - return wrapper.GetDescriptor(GetName() + "_Rarity0"); + return wrapper.GetDescriptor("ItemHero_" + GetName() + "_Rarity0"); } public override SimulationDescriptor GetRarity1Descriptor() { SimDescriptorWrapper wrapper = new SimDescriptorWrapper(); - wrapper.Add(SimulationProperties.AttackCooldown, -1.1f); + wrapper.Add(SimulationProperties.AttackCooldown, -1.09f); wrapper.Add(SimulationProperties.MoveSpeed, 18f); wrapper.Add(SimulationProperties.MaxHealth, 10000f); wrapper.Add(SimulationProperties.AttackPower, 100); wrapper.Add(SimulationProperties.HealthRegen, 800); - return wrapper.GetDescriptor(GetName() + "_Rarity1"); + return wrapper.GetDescriptor("ItemHero_" + GetName() + "_Rarity1"); } public override SimulationDescriptor GetRarity2Descriptor() { SimDescriptorWrapper wrapper = new SimDescriptorWrapper(); - wrapper.Add(SimulationProperties.AttackCooldown, -1.19999f); + wrapper.Add(SimulationProperties.AttackCooldown, -1.09999f); wrapper.Add(SimulationProperties.MoveSpeed, 90f); wrapper.Add(SimulationProperties.MaxHealth, 10000f); wrapper.Add(SimulationProperties.AttackPower, 100); wrapper.Add(SimulationProperties.HealthRegen, 800); - return wrapper.GetDescriptor(GetName() + "_Rarity2"); + return wrapper.GetDescriptor("ItemHero_" + GetName() + "_Rarity2"); } } } diff --git a/DotE_Patch_Mod/DustDevilFramework/CustomItem.cs b/DotE_Patch_Mod/DustDevilFramework/CustomItem.cs index e842e1e..7f2fc1d 100644 --- a/DotE_Patch_Mod/DustDevilFramework/CustomItem.cs +++ b/DotE_Patch_Mod/DustDevilFramework/CustomItem.cs @@ -40,6 +40,11 @@ public abstract class CustomItem : ScadMod public abstract string GetRealName(); public abstract string GetRealDescription(); + public CustomItem() + { + name = GetRealName(); + } + public void Initialize() { path = GetRealName() + "_log.txt"; @@ -69,20 +74,24 @@ public void Load() if (Convert.ToBoolean(Values["Enabled"])) { On.Session.Update += Session_Update; - On.ItemHero.Init += ItemHero_Init; - } - else - { - Log("Attempting to remove Localization changes!"); - RemoveLocalizationChanges(); } } - private void ItemHero_Init(On.ItemHero.orig_Init orig, ItemHero self, ulong ownerPlayerID, Amplitude.StaticString itemConfigName, Amplitude.StaticString rarityConfigName, Room spawnRoom, ItemType type) + private void Session_Update(On.Session.orig_Update orig, Session self) { - Log("Entered an ItemHero Init with name: " + itemConfigName + " and rarityName: " + rarityConfigName); + // Continue attempting to add the ItemHero until it has been added! try { + SimulationDescriptor desc; + Databases.GetDatabase(false).TryGetValue(GetBaseDescriptor().Name, out desc); + if (desc != null) + { + orig(self); + return; + } + ItemHeroConfig itemHeroConfig = GetItemHeroConfig(); + Databases.GetDatabase(false).Add(itemHeroConfig); + Log("Added the item (ItemHeroConfig) to the database!"); Log("Attempting to make sim descriptors"); SimulationDescriptor descriptor = GetBaseDescriptor(); Log("Successfully retrieved the overall descriptor!"); @@ -108,23 +117,6 @@ private void ItemHero_Init(On.ItemHero.orig_Init orig, ItemHero self, ulong owne Databases.GetDatabase(false).Add(rarity2); Log("Added Rarity2!"); Log("Added all SimDescriptors to the database!"); - } catch (ArgumentException e) - { - // Already exists in the database - } catch (NullReferenceException e) - { - // Database does not exist yet - } - orig(self, ownerPlayerID, itemConfigName, rarityConfigName, spawnRoom, type); - } - private void Session_Update(On.Session.orig_Update orig, Session self) - { - // Continue attempting to add the ItemHero until it has been added! - try - { - ItemHeroConfig itemHeroConfig = GetItemHeroConfig(); - Databases.GetDatabase(false).Add(itemHeroConfig); - Log("Added the item (ItemHeroConfig) to the database!"); } catch (ArgumentException e) { @@ -135,28 +127,7 @@ private void Session_Update(On.Session.orig_Update orig, Session self) } orig(self); } - public class SimDescriptorWrapper - { - List simulationModifierDescriptors = new List(); - List simulationPropertyDescriptors = new List(); - // Should only input SimulationProperties as a parameter - public void Add(Amplitude.StaticString name, float value) - { - SingleSimulationModifierDescriptor modif = new SingleSimulationModifierDescriptor(name, SimulationModifierDescriptor.ModifierOperation.Addition, value); - simulationPropertyDescriptors.Add(new SimulationPropertyDescriptor(name)); - simulationModifierDescriptors.Add(modif); - } - public SimulationDescriptor GetDescriptor(string name) - { - SimulationDescriptor descriptor = new SimulationDescriptor(); - descriptor.SetName("ItemHero_" + name); - - descriptor.SetProperties(simulationPropertyDescriptors.ToArray()); - descriptor.SetModifiers(simulationModifierDescriptors.ToArray()); - - return descriptor; - } - } + public abstract SimulationDescriptor GetBaseDescriptor(); public abstract SimulationDescriptor GetCommonDescriptor(); public abstract SimulationDescriptor GetRarity0Descriptor(); @@ -282,22 +253,6 @@ public void RemoveLocalizationChanges() { linesLst.RemoveAt(i); } - if (s.IndexOf("%Item_" + GetName() + "_Description") != -1) - { - int q = i; - for (int j = i; j < linesLst.Count; j++) - { - if (linesLst[j].IndexOf("") != -1) - { - // This is the stopping point for deleting. - q = j; - } - } - for (int l = i; l <= q; l++) - { - linesLst.RemoveAt(i); - } - } } System.IO.File.WriteAllLines(@"Public\Localization\english\ED_Localization_Locales.xml", linesLst.ToArray()); } diff --git a/DotE_Patch_Mod/DustDevilFramework/DustDevil.cs b/DotE_Patch_Mod/DustDevilFramework/DustDevil.cs new file mode 100644 index 0000000..c093763 --- /dev/null +++ b/DotE_Patch_Mod/DustDevilFramework/DustDevil.cs @@ -0,0 +1,89 @@ +using MonoMod.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace DustDevilFramework +{ + public class DustDevil + { + private static DustDevil Instance; + + public static int MajorVersion { get; } = 1; + public static int MinorVersion { get; } = 0; + public static int Revision { get; } = 0; + + private static List ModList = new List(); + + public static void CreateInstance(ScadMod mod) + { + if (Instance == null) + { + Instance = new DustDevil(); + } + ModList.Add(mod.name); + } + private DustDevil() + { + On.MainMenuPanel.OnLoad += MainMenuPanel_OnLoad; + } + + private System.Collections.IEnumerator MainMenuPanel_OnLoad(On.MainMenuPanel.orig_OnLoad orig, MainMenuPanel self) + { + System.Collections.IEnumerator temp = orig(self); + yield return temp; + AgePrimitiveLabel label = new DynData(self).Get("versionLabel"); + Debug.Log("Attempting to overwrite old version with DustDevil version!"); + Debug.Log("Current message is: " + label.Text); + label.Text = "#4D4D4D#Dungeon of the Endless, VERSION "; + label.Text += string.Concat(new object[] + { + "#REVERT##4D4D4D#", + Amplitude.Unity.Framework.Application.Version.Major, + ".", + Amplitude.Unity.Framework.Application.Version.Minor, + ".", + Amplitude.Unity.Framework.Application.Version.Revision, + "\nDustDevil VERSION: ", + DustDevil.MajorVersion, + ".", + DustDevil.MinorVersion, + ".", + DustDevil.Revision, + "#REVERT#" + }); + Debug.Log("Final message is: " + label.Text); + CreateModList(label); + yield break; + } + + private void CreateModList(AgePrimitiveLabel label) + { + Debug.Log("Attempting to create modlist!"); + Debug.Log("Label has position: " + label.transform.position); + GameObject o = (GameObject)GameObject.Instantiate(label.gameObject, new Vector3(0, 0, 0), Quaternion.identity); + o.transform.parent = label.gameObject.transform.parent; + + AgePrimitiveLabel l2 = o.GetComponent(); + l2.Alignement = AgeTextAnchor.UpperLeft; + string text = "ModList:\n"; + foreach (string name in ModList) + { + text += "- " + name + "\n"; + } + + Debug.Log("Label has alignment: " + label.Alignement + " new label has alignment: " + l2.Alignement); + Debug.Log("Label has 2d pos: " + label.Get2DPosition() + " new label has 2d pos: " + l2.Get2DPosition()); + Debug.Log("Label has agetransform: (" + label.AgeTransform.X + ", " + label.AgeTransform.Y + ", " + label.AgeTransform.Z + ")"); + Debug.Log("new label has agetransform: (" + l2.AgeTransform.X + ", " + l2.AgeTransform.Y + ", " + l2.AgeTransform.Z + ")"); + Debug.Log("Label pos vs new label pos: " + label.AgeTransform.Position.position + ", " + l2.AgeTransform.Position.position); + + l2.Text = text; + Debug.Log("ModList Text: " + l2.Text); + o.SetActive(true); + } + } +} diff --git a/DotE_Patch_Mod/DustDevilFramework/DustDevilFramework.csproj b/DotE_Patch_Mod/DustDevilFramework/DustDevilFramework.csproj index a0b6d28..ba8183f 100644 --- a/DotE_Patch_Mod/DustDevilFramework/DustDevilFramework.csproj +++ b/DotE_Patch_Mod/DustDevilFramework/DustDevilFramework.csproj @@ -62,10 +62,13 @@ + + + \ No newline at end of file diff --git a/DotE_Patch_Mod/DustDevilFramework/PodMod.cs b/DotE_Patch_Mod/DustDevilFramework/PodMod.cs index a99cb5b..61193d0 100644 --- a/DotE_Patch_Mod/DustDevilFramework/PodMod.cs +++ b/DotE_Patch_Mod/DustDevilFramework/PodMod.cs @@ -23,6 +23,11 @@ public abstract class PodMod : ScadMod public abstract string[] GetUnavailableBlueprints(); public abstract string[] GetUnavailableItems(); + public PodMod() + { + name = GetName(); + } + public void Initialize() { path = GetName() + "_log.txt"; diff --git a/DotE_Patch_Mod/DustDevilFramework/ScadMod.cs b/DotE_Patch_Mod/DustDevilFramework/ScadMod.cs index 8068f20..fbb9012 100644 --- a/DotE_Patch_Mod/DustDevilFramework/ScadMod.cs +++ b/DotE_Patch_Mod/DustDevilFramework/ScadMod.cs @@ -8,13 +8,24 @@ namespace DustDevilFramework { public class ScadMod { - public string path = @"placeholder_log.txt"; + public string name = "placeholder"; + public string path; - public string config = @"placeholder_config.txt"; + public string config; public string default_config = "# If these values are removed, the game will crash on initialization!\n"; public Dictionary Values = new Dictionary(); - + public ScadMod(string name) + { + this.name = name; + path = name + "_log.txt"; + config = name + "_config.txt"; + } + public ScadMod() + { + path = name + "_log.txt"; + config = name + "_config.txt"; + } public void Log(string s) { System.IO.File.AppendAllText(path, s + "\n"); @@ -58,6 +69,7 @@ public void Initialize() Log("==================================================================="); Values.Add("Enabled", "True"); + DustDevil.CreateInstance(this); // Add values here to the Values dictionary! } public void Load() diff --git a/DotE_Patch_Mod/DustDevilFramework/SimDescriptorWrapper.cs b/DotE_Patch_Mod/DustDevilFramework/SimDescriptorWrapper.cs new file mode 100644 index 0000000..a480c88 --- /dev/null +++ b/DotE_Patch_Mod/DustDevilFramework/SimDescriptorWrapper.cs @@ -0,0 +1,46 @@ +using Amplitude.Unity.Simulation; +using Amplitude.Unity.Simulation.SimulationModifierDescriptors; +using MonoMod.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DustDevilFramework +{ + public class SimDescriptorWrapper + { + public List Modifiers { get { return simulationModifierDescriptors; } set { simulationModifierDescriptors = value; } } + public List Properties { get { return simulationPropertyDescriptors; } set { simulationPropertyDescriptors = value; } } + List simulationModifierDescriptors = new List(); + List simulationPropertyDescriptors = new List(); + // Should only input SimulationProperties as a parameter + public void Add(Amplitude.StaticString name, float value) + { + SingleSimulationModifierDescriptor modif = new SingleSimulationModifierDescriptor(name, SimulationModifierDescriptor.ModifierOperation.Addition, value); + simulationPropertyDescriptors.Add(new SimulationPropertyDescriptor(name)); + simulationModifierDescriptors.Add(modif); + } + public void Add(Amplitude.StaticString name, float startingValue, SimulationModifierDescriptor modif = null) + { + SimulationPropertyDescriptor desc = new SimulationPropertyDescriptor(name); + new DynData(desc).Set("BaseValue", startingValue); + simulationPropertyDescriptors.Add(desc); + if (modif != null) + { + simulationModifierDescriptors.Add(modif); + } + } + public SimulationDescriptor GetDescriptor(string name) + { + SimulationDescriptor descriptor = new SimulationDescriptor(); + descriptor.SetName(name); + + descriptor.SetProperties(simulationPropertyDescriptors.ToArray()); + descriptor.SetModifiers(simulationModifierDescriptors.ToArray()); + + return descriptor; + } + } +} diff --git a/DotE_Patch_Mod/DustGenerator-Mod/DustGeneratorMod.cs b/DotE_Patch_Mod/DustGenerator-Mod/DustGeneratorMod.cs index ab95961..9cffa39 100644 --- a/DotE_Patch_Mod/DustGenerator-Mod/DustGeneratorMod.cs +++ b/DotE_Patch_Mod/DustGenerator-Mod/DustGeneratorMod.cs @@ -14,8 +14,7 @@ class DustGeneratorMod : PartialityMod ScadMod mod = new ScadMod(); public override void Init() { - mod.path = @"DustGenerator_log.txt"; - mod.config = @"DustGenerator_config.txt"; + mod.name = "DustGenerator"; mod.default_config = "# Modify this file to change various settings of the DustGenerator Mod for DotE.\n" + mod.default_config; mod.Initialize(); diff --git a/DotE_Patch_Mod/DustWithCrystal-Mod/AllowDustChangingWithCrystalMod.cs b/DotE_Patch_Mod/DustWithCrystal-Mod/AllowDustChangingWithCrystalMod.cs index d76dfbc..f3c036b 100644 --- a/DotE_Patch_Mod/DustWithCrystal-Mod/AllowDustChangingWithCrystalMod.cs +++ b/DotE_Patch_Mod/DustWithCrystal-Mod/AllowDustChangingWithCrystalMod.cs @@ -13,13 +13,11 @@ class AllowDustChangingWithCrystalMod : PartialityMod ScadMod mod = new ScadMod(); public override void Init() { - mod.path = @"DustAfterCrystal_log.txt"; - mod.config = @"DustAfterCrystal_config.txt"; + mod.name = "DustAfterCrystal"; mod.default_config = "# Modify this file to change various settings of the DustAfterCrystal Mod for DotE.\n" + mod.default_config; mod.Initialize(); // Setup default values for config - mod.ReadConfig(); diff --git a/DotE_Patch_Mod/ExitFinder-Mod/ExitFinderMod.cs b/DotE_Patch_Mod/ExitFinder-Mod/ExitFinderMod.cs index fb4929d..cf614c1 100644 --- a/DotE_Patch_Mod/ExitFinder-Mod/ExitFinderMod.cs +++ b/DotE_Patch_Mod/ExitFinder-Mod/ExitFinderMod.cs @@ -19,8 +19,7 @@ public class ExitFinderMod : PartialityMod public override void Init() { - mod.path = @"ExitFinder_log.txt"; - mod.config = @"ExitFinder_config.txt"; + mod.name = "ExitFinder"; mod.default_config = "# Modify this file to change various settings of the ExitFinder Mod for DotE.\n" + mod.default_config; mod.Initialize(); diff --git a/DotE_Patch_Mod/Ping-Mod/PingMod.cs b/DotE_Patch_Mod/Ping-Mod/PingMod.cs index ec76cbb..9e09e69 100644 --- a/DotE_Patch_Mod/Ping-Mod/PingMod.cs +++ b/DotE_Patch_Mod/Ping-Mod/PingMod.cs @@ -22,8 +22,7 @@ class PingMod : PartialityMod public override void Init() { - mod.path = @"Ping_log.txt"; - mod.config = @"Ping_config.txt"; + mod.name = "Ping"; mod.default_config = "# Modify this file to change various settings of the Ping Mod for DotE.\n" + mod.default_config; mod.Initialize(); diff --git a/DotE_Patch_Mod/TrueIGT-Mod/TrueIGTMod.cs b/DotE_Patch_Mod/TrueIGT-Mod/TrueIGTMod.cs index da93fba..315068a 100644 --- a/DotE_Patch_Mod/TrueIGT-Mod/TrueIGTMod.cs +++ b/DotE_Patch_Mod/TrueIGT-Mod/TrueIGTMod.cs @@ -19,8 +19,7 @@ class TrueIGTMod : PartialityMod ScadMod mod = new ScadMod(); public override void Init() { - mod.path = @"TrueIGT_log.txt"; - mod.config = @"TrueIGT_config.txt"; + mod.name = "TrueIGT"; mod.default_config = "# Modify this file to change various settings of the TrueIGT Mod for DotE.\n" + mod.default_config; mod.Initialize();