Skip to content

Commit

Permalink
Updated ScadMod to contain a name, added DustDevil framework version
Browse files Browse the repository at this point in the history
  • Loading branch information
sc2ad committed Nov 20, 2018
1 parent e9c5964 commit f04acf8
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 88 deletions.
3 changes: 1 addition & 2 deletions DotE_Patch_Mod/CustomHero-Mod/CustomHeroMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
18 changes: 9 additions & 9 deletions DotE_Patch_Mod/CustomItems-Mod/ShinyItemConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,17 @@ 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()
{
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()
Expand All @@ -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");
}
}
}
81 changes: 18 additions & 63 deletions DotE_Patch_Mod/DustDevilFramework/CustomItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<SimulationDescriptor>(false).TryGetValue(GetBaseDescriptor().Name, out desc);
if (desc != null)
{
orig(self);
return;
}
ItemHeroConfig itemHeroConfig = GetItemHeroConfig();
Databases.GetDatabase<ItemConfig>(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!");
Expand All @@ -108,23 +117,6 @@ private void ItemHero_Init(On.ItemHero.orig_Init orig, ItemHero self, ulong owne
Databases.GetDatabase<SimulationDescriptor>(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<ItemConfig>(false).Add(itemHeroConfig);
Log("Added the item (ItemHeroConfig) to the database!");
}
catch (ArgumentException e)
{
Expand All @@ -135,28 +127,7 @@ private void Session_Update(On.Session.orig_Update orig, Session self)
}
orig(self);
}
public class SimDescriptorWrapper
{
List<SimulationModifierDescriptor> simulationModifierDescriptors = new List<SimulationModifierDescriptor>();
List<SimulationPropertyDescriptor> simulationPropertyDescriptors = new List<SimulationPropertyDescriptor>();
// 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();
Expand Down Expand Up @@ -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("</LocalizationPair>") != -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());
}
Expand Down
89 changes: 89 additions & 0 deletions DotE_Patch_Mod/DustDevilFramework/DustDevil.cs
Original file line number Diff line number Diff line change
@@ -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<string> ModList = new List<string>();

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<MainMenuPanel>(self).Get<AgePrimitiveLabel>("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<AgePrimitiveLabel>();
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);
}
}
}
3 changes: 3 additions & 0 deletions DotE_Patch_Mod/DustDevilFramework/DustDevilFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CustomHero.cs" />
<Compile Include="CustomItem.cs" />
<Compile Include="DustDevil.cs" />
<Compile Include="PodMod.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScadMod.cs" />
<Compile Include="SimDescriptorWrapper.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
5 changes: 5 additions & 0 deletions DotE_Patch_Mod/DustDevilFramework/PodMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
18 changes: 15 additions & 3 deletions DotE_Patch_Mod/DustDevilFramework/ScadMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> Values = new Dictionary<string, string>();

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");
Expand Down Expand Up @@ -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()
Expand Down
46 changes: 46 additions & 0 deletions DotE_Patch_Mod/DustDevilFramework/SimDescriptorWrapper.cs
Original file line number Diff line number Diff line change
@@ -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<SimulationModifierDescriptor> Modifiers { get { return simulationModifierDescriptors; } set { simulationModifierDescriptors = value; } }
public List<SimulationPropertyDescriptor> Properties { get { return simulationPropertyDescriptors; } set { simulationPropertyDescriptors = value; } }
List<SimulationModifierDescriptor> simulationModifierDescriptors = new List<SimulationModifierDescriptor>();
List<SimulationPropertyDescriptor> simulationPropertyDescriptors = new List<SimulationPropertyDescriptor>();
// 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<SimulationPropertyDescriptor>(desc).Set<float>("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;
}
}
}
3 changes: 1 addition & 2 deletions DotE_Patch_Mod/DustGenerator-Mod/DustGeneratorMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading

0 comments on commit f04acf8

Please sign in to comment.