Skip to content

Commit

Permalink
Merge pull request #10 from sc2ad/settings
Browse files Browse the repository at this point in the history
Added ModSettings in-game, with enabling and disabling
  • Loading branch information
sc2ad committed Feb 7, 2019
2 parents c8fe3f2 + aea4a04 commit eb50294
Show file tree
Hide file tree
Showing 87 changed files with 2,886 additions and 455 deletions.
21 changes: 11 additions & 10 deletions DotE_Patch_Mod/AllowDustChangingWithCrystalMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,35 @@
using System.Text;
using System.Threading.Tasks;

namespace DotE_Combo_Mod
namespace DustWithCrystal_Mod
{
class AllowDustChangingWithCrystalMod : PartialityMod
{
ScadMod mod = new ScadMod();
ScadMod mod = new ScadMod("DustAfterCrystal", typeof(AllowDustChangingWithCrystalMod));
public override void Init()
{
mod.path = @"DustAfterCrystal_log.txt";
mod.config = @"DustAfterCrystal_config.txt";
mod.default_config = "# Modify this file to change various settings of the DustAfterCrystal Mod for DotE.\n" + mod.default_config;
mod.PartialityModReference = this;
mod.Initialize();

// Setup default values for config


mod.ReadConfig();
mod.settings.ReadSettings();

mod.Log("Initialized!");
}
public override void OnLoad()
{
mod.Load();
if (Convert.ToBoolean(mod.Values["Enabled"]))
if (mod.settings.Enabled)
{
On.Room.CanBePowered_refString_bool_bool_bool_bool_bool += Room_CanBePowered;
On.Room.CanBeUnpowered += Room_CanBeUnpowered;
}
}
public void UnLoad()
{
mod.UnLoad();
On.Room.CanBePowered_refString_bool_bool_bool_bool_bool -= Room_CanBePowered;
On.Room.CanBeUnpowered -= Room_CanBeUnpowered;
}

private bool Room_CanBeUnpowered(On.Room.orig_CanBeUnpowered orig, Room self, bool checkCrystalState, bool checkPoweringPlayer, bool checkPowerChangeCooldown, bool ignoreShipConfig, bool displayError)
{
Expand Down
1 change: 1 addition & 0 deletions DotE_Patch_Mod/CustomHero-Mod/CustomHero-Mod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CustomHeroMod.cs" />
<Compile Include="CustomHeroTestSettings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
42 changes: 20 additions & 22 deletions DotE_Patch_Mod/CustomHero-Mod/CustomHeroMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,44 @@ namespace CustomHero_Mod
{
class CustomHeroMod : PartialityMod
{
ScadMod mod = new ScadMod();
ScadMod mod = new ScadMod("CustomHero", typeof(CustomHeroTestSettings), typeof(CustomHeroMod));

Dictionary<string, string> Ranks = new Dictionary<string, string>();

public override void Init()
{
mod.name = "CustomHero";
mod.default_config = "# Modify this file to change various settings of the CustomHero Mod for DotE.\n" + mod.default_config;
mod.PartialityModReference = this;
mod.Initialize();

// Setup default values for config
mod.Values.Add("HeroToReplace", "Skroig");
mod.Values.Add("HeroName", "Skrog");
mod.Values.Add("Hero HP", "1000");
mod.Values.Add("Speed", "80");
mod.Values.Add("LogHeroData", "True");
mod.Values.Add("Path to Ranks.txt", "Ranks.txt");

mod.ReadConfig();
mod.settings.ReadSettings();
ReadRanks();

mod.Log("Initialized!");
}
public override void OnLoad()
{
mod.Load();
if (Convert.ToBoolean(mod.Values["Enabled"]))
if (mod.settings.Enabled)
{
On.Hero.Init += Hero_Init;
On.Hero.ModifyLocalActiveHeroes += Hero_ModifyLocalActiveHeroes;
}
}
public void UnLoad()
{
On.Hero.Init -= Hero_Init;
On.Hero.ModifyLocalActiveHeroes -= Hero_ModifyLocalActiveHeroes;
}

private void Hero_ModifyLocalActiveHeroes(On.Hero.orig_ModifyLocalActiveHeroes orig, bool add, Hero hero)
{
// This should be called every time a hero is given/taken
orig(add, hero);
if (Convert.ToBoolean(mod.Values["Enabled"]))
if (mod.settings.Enabled)
{
if (mod.Values["HeroToReplace"] == hero.LocalizedName)
if ((mod.settings as CustomHeroTestSettings).ReplaceHero && (mod.settings as CustomHeroTestSettings).HeroToReplace == hero.LocalizedName)
{
// We are matching Heroes! Start to change data!
SetHeroStats(hero);
Expand All @@ -65,10 +63,10 @@ private void Hero_ModifyLocalActiveHeroes(On.Hero.orig_ModifyLocalActiveHeroes o

private void ReadRanks()
{
if (System.IO.File.Exists(mod.Values["Path to Ranks.txt"]))
if (System.IO.File.Exists((mod.settings as CustomHeroTestSettings).PathToRanks))
{
mod.Log("Reading Ranks.txt...");
string[] lines = System.IO.File.ReadAllLines(mod.Values["Path to Ranks.txt"]);
string[] lines = System.IO.File.ReadAllLines((mod.settings as CustomHeroTestSettings).PathToRanks);

foreach (string line in lines)
{
Expand All @@ -79,7 +77,7 @@ private void ReadRanks()
string[] spl = line.Split(new string[] { ": " }, StringSplitOptions.None);
string value = spl[1].Trim();
Ranks[spl[0]] = value;
mod.Log("Read hero: " + spl[0] + " with rank: " + value + " from " + mod.Values["Path to Ranks.txt"]);
mod.Log("Read hero: " + spl[0] + " with rank: " + value + " from " + (mod.settings as CustomHeroTestSettings).PathToRanks);
}
} else
{
Expand All @@ -90,11 +88,11 @@ private void ReadRanks()
private void Hero_Init(On.Hero.orig_Init orig, Hero self, ulong ownerPlayerID, Amplitude.StaticString heroDescName, Room spawnRoom, bool isRecruited, bool registerRecruitment, int initLevel, int unlockLevel, bool hasOperatingBonus, Dictionary<Amplitude.StaticString, List<ItemPersistentData>> initItemsByCategory, bool displayRecruitmentDialog, bool consumeLevelUpFood, bool updateDiscoverableHeroPool, int floorRecruited, Amplitude.StaticString[] permanentDescriptors, bool isStartingHero, int currentRespawnRoomCount, bool recruitable)
{
orig(self, ownerPlayerID, heroDescName, spawnRoom, isRecruited, registerRecruitment, initLevel, unlockLevel, hasOperatingBonus, initItemsByCategory, displayRecruitmentDialog, consumeLevelUpFood, updateDiscoverableHeroPool, floorRecruited, permanentDescriptors, isStartingHero, currentRespawnRoomCount, recruitable);
if (Convert.ToBoolean(mod.Values["LogHeroData"]))
if ((mod.settings as CustomHeroTestSettings).LogHeroData)
{
LogHeroData(self, heroDescName);
}
if (mod.Values["HeroToReplace"] == self.LocalizedName)
if ((mod.settings as CustomHeroTestSettings).ReplaceHero && (mod.settings as CustomHeroTestSettings).HeroToReplace == self.LocalizedName)
{
// We are matching Heroes! Start to change data!
SetHeroStats(self);
Expand All @@ -106,13 +104,13 @@ private void Hero_Init(On.Hero.orig_Init orig, Hero self, ulong ownerPlayerID, A
private void SetHeroStats(Hero self)
{
mod.Log("Found hero with name: " + self.LocalizedName + " Attempting to change data!");
new DynData<Hero>(self).Set<string>("LocalizedName", mod.Values["HeroName"]);
new DynData<Hero>(self).Set<string>("LocalizedName", (mod.settings as CustomHeroTestSettings).HeroName);
//self.HealthCpnt.PermanantHealthMalus = (float)Convert.ToDouble(mod.Values["Hero HP"]);
self.GetSimObj().SetPropertyBaseValue("MaxHealth", (float)Convert.ToDouble(mod.Values["Hero HP"]) - self.GetSimObj().GetPropertyValue("MaxHealth"));
self.GetSimObj().SetPropertyBaseValue("MoveSpeed", (float)Convert.ToDouble(mod.Values["Speed"]) - self.GetSimObj().GetPropertyValue("MoveSpeed"));
self.GetSimObj().SetPropertyBaseValue("MaxHealth", (mod.settings as CustomHeroTestSettings).HeroHP - self.GetSimObj().GetPropertyValue("MaxHealth"));
self.GetSimObj().SetPropertyBaseValue("MoveSpeed", (mod.settings as CustomHeroTestSettings).Speed - self.GetSimObj().GetPropertyValue("MoveSpeed"));
//self.RemoveSimDescriptor(SimMonoBehaviour.GetDBDescriptorByName(self.Config.Name), true);
// Okay so now that I removed the actual SMB, I need to create a new one where the max health is mine
self.HealthCpnt.SetHealth((float)Convert.ToDouble(mod.Values["Hero HP"]));
self.HealthCpnt.SetHealth((mod.settings as CustomHeroTestSettings).HeroHP);
mod.Log("New Name: " + self.LocalizedName + " and HP: " + self.HealthCpnt.GetHealth());
}

Expand Down
25 changes: 25 additions & 0 deletions DotE_Patch_Mod/CustomHero-Mod/CustomHeroTestSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using DustDevilFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomHero_Mod
{
public class CustomHeroTestSettings : CustomHeroSettings
{
public string HeroToReplace = "Skroig";
public string HeroName = "Skroggerz";
public bool ReplaceHero = false;
[SettingsRange(100, 100000)]
public float HeroHP = 1000;
[SettingsRange(10,1000)]
public float Speed = 80;
public bool LogHeroData = true;
public string PathToRanks = "Ranks.txt";
public CustomHeroTestSettings(string name) : base(name)
{
}
}
}
45 changes: 21 additions & 24 deletions DotE_Patch_Mod/CustomHeroMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,48 @@
using System.Text;
using System.Threading.Tasks;

namespace DotE_Combo_Mod
namespace CustomHero_Mod
{
class CustomHeroMod : PartialityMod
{
ScadMod mod = new ScadMod();
ScadMod mod = new ScadMod("CustomHero", typeof(CustomHeroTestSettings), typeof(CustomHeroMod));

Dictionary<string, string> Ranks = new Dictionary<string, string>();

public override void Init()
{
mod.path = @"CustomHero_log.txt";
mod.config = @"CustomHero_config.txt";
mod.default_config = "# Modify this file to change various settings of the CustomHero Mod for DotE.\n" + mod.default_config;
mod.PartialityModReference = this;
mod.Initialize();

// Setup default values for config
mod.Values.Add("HeroToReplace", "Skroig");
mod.Values.Add("HeroName", "Skrog");
mod.Values.Add("Hero HP", "1000");
mod.Values.Add("Speed", "80");
mod.Values.Add("LogHeroData", "True");
mod.Values.Add("Path to Ranks.txt", "Ranks.txt");

mod.ReadConfig();
mod.settings.ReadSettings();
ReadRanks();

mod.Log("Initialized!");
}
public override void OnLoad()
{
mod.Load();
if (Convert.ToBoolean(mod.Values["Enabled"]))
if (mod.settings.Enabled)
{
On.Hero.Init += Hero_Init;
On.Hero.ModifyLocalActiveHeroes += Hero_ModifyLocalActiveHeroes;
}
}
public void UnLoad()
{
On.Hero.Init -= Hero_Init;
On.Hero.ModifyLocalActiveHeroes -= Hero_ModifyLocalActiveHeroes;
}

private void Hero_ModifyLocalActiveHeroes(On.Hero.orig_ModifyLocalActiveHeroes orig, bool add, Hero hero)
{
// This should be called every time a hero is given/taken
orig(add, hero);
if (Convert.ToBoolean(mod.Values["Enabled"]))
if (mod.settings.Enabled)
{
if (mod.Values["HeroToReplace"] == hero.LocalizedName)
if ((mod.settings as CustomHeroTestSettings).ReplaceHero && (mod.settings as CustomHeroTestSettings).HeroToReplace == hero.LocalizedName)
{
// We are matching Heroes! Start to change data!
SetHeroStats(hero);
Expand All @@ -66,10 +63,10 @@ private void Hero_ModifyLocalActiveHeroes(On.Hero.orig_ModifyLocalActiveHeroes o

private void ReadRanks()
{
if (System.IO.File.Exists(mod.Values["Path to Ranks.txt"]))
if (System.IO.File.Exists((mod.settings as CustomHeroTestSettings).PathToRanks))
{
mod.Log("Reading Ranks.txt...");
string[] lines = System.IO.File.ReadAllLines(mod.Values["Path to Ranks.txt"]);
string[] lines = System.IO.File.ReadAllLines((mod.settings as CustomHeroTestSettings).PathToRanks);

foreach (string line in lines)
{
Expand All @@ -80,7 +77,7 @@ private void ReadRanks()
string[] spl = line.Split(new string[] { ": " }, StringSplitOptions.None);
string value = spl[1].Trim();
Ranks[spl[0]] = value;
mod.Log("Read hero: " + spl[0] + " with rank: " + value + " from " + mod.Values["Path to Ranks.txt"]);
mod.Log("Read hero: " + spl[0] + " with rank: " + value + " from " + (mod.settings as CustomHeroTestSettings).PathToRanks);
}
} else
{
Expand All @@ -91,11 +88,11 @@ private void ReadRanks()
private void Hero_Init(On.Hero.orig_Init orig, Hero self, ulong ownerPlayerID, Amplitude.StaticString heroDescName, Room spawnRoom, bool isRecruited, bool registerRecruitment, int initLevel, int unlockLevel, bool hasOperatingBonus, Dictionary<Amplitude.StaticString, List<ItemPersistentData>> initItemsByCategory, bool displayRecruitmentDialog, bool consumeLevelUpFood, bool updateDiscoverableHeroPool, int floorRecruited, Amplitude.StaticString[] permanentDescriptors, bool isStartingHero, int currentRespawnRoomCount, bool recruitable)
{
orig(self, ownerPlayerID, heroDescName, spawnRoom, isRecruited, registerRecruitment, initLevel, unlockLevel, hasOperatingBonus, initItemsByCategory, displayRecruitmentDialog, consumeLevelUpFood, updateDiscoverableHeroPool, floorRecruited, permanentDescriptors, isStartingHero, currentRespawnRoomCount, recruitable);
if (Convert.ToBoolean(mod.Values["LogHeroData"]))
if ((mod.settings as CustomHeroTestSettings).LogHeroData)
{
LogHeroData(self, heroDescName);
}
if (mod.Values["HeroToReplace"] == self.LocalizedName)
if ((mod.settings as CustomHeroTestSettings).ReplaceHero && (mod.settings as CustomHeroTestSettings).HeroToReplace == self.LocalizedName)
{
// We are matching Heroes! Start to change data!
SetHeroStats(self);
Expand All @@ -107,13 +104,13 @@ private void Hero_Init(On.Hero.orig_Init orig, Hero self, ulong ownerPlayerID, A
private void SetHeroStats(Hero self)
{
mod.Log("Found hero with name: " + self.LocalizedName + " Attempting to change data!");
new DynData<Hero>(self).Set<string>("LocalizedName", mod.Values["HeroName"]);
new DynData<Hero>(self).Set<string>("LocalizedName", (mod.settings as CustomHeroTestSettings).HeroName);
//self.HealthCpnt.PermanantHealthMalus = (float)Convert.ToDouble(mod.Values["Hero HP"]);
self.GetSimObj().SetPropertyBaseValue("MaxHealth", (float)Convert.ToDouble(mod.Values["Hero HP"]) - self.GetSimObj().GetPropertyValue("MaxHealth"));
self.GetSimObj().SetPropertyBaseValue("MoveSpeed", (float)Convert.ToDouble(mod.Values["Speed"]) - self.GetSimObj().GetPropertyValue("MoveSpeed"));
self.GetSimObj().SetPropertyBaseValue("MaxHealth", (mod.settings as CustomHeroTestSettings).HeroHP - self.GetSimObj().GetPropertyValue("MaxHealth"));
self.GetSimObj().SetPropertyBaseValue("MoveSpeed", (mod.settings as CustomHeroTestSettings).Speed - self.GetSimObj().GetPropertyValue("MoveSpeed"));
//self.RemoveSimDescriptor(SimMonoBehaviour.GetDBDescriptorByName(self.Config.Name), true);
// Okay so now that I removed the actual SMB, I need to create a new one where the max health is mine
self.HealthCpnt.SetHealth((float)Convert.ToDouble(mod.Values["Hero HP"]));
self.HealthCpnt.SetHealth((mod.settings as CustomHeroTestSettings).HeroHP);
mod.Log("New Name: " + self.LocalizedName + " and HP: " + self.HealthCpnt.GetHealth());
}

Expand Down
25 changes: 25 additions & 0 deletions DotE_Patch_Mod/CustomHeroTestSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using DustDevilFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomHero_Mod
{
public class CustomHeroTestSettings : CustomHeroSettings
{
public string HeroToReplace = "Skroig";
public string HeroName = "Skroggerz";
public bool ReplaceHero = false;
[SettingsRange(100, 100000)]
public float HeroHP = 1000;
[SettingsRange(10,1000)]
public float Speed = 80;
public bool LogHeroData = true;
public string PathToRanks = "Ranks.txt";
public CustomHeroTestSettings(string name) : base(name)
{
}
}
}
1 change: 1 addition & 0 deletions DotE_Patch_Mod/CustomItems-Mod/OPSashaItem-Mod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShinyItemConfig.cs" />
<Compile Include="ShinyItemMod.cs" />
<Compile Include="ShinyItemSettings.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
4 changes: 4 additions & 0 deletions DotE_Patch_Mod/CustomItems-Mod/ShinyItemConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace OPSashaItem_Mod
{
class ShinyItemConfig : CustomItem
{
public ShinyItemConfig(Type partialityType) : base(typeof(ShinyItemSettings), partialityType)
{
}

public override string GetAttackType()
{
return "FireGun";
Expand Down
5 changes: 3 additions & 2 deletions DotE_Patch_Mod/CustomItems-Mod/ShinyItemMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ namespace OPSashaItem_Mod
{
class ShinyItemMod : PartialityMod
{
ShinyItemConfig mod = new ShinyItemConfig();
ShinyItemConfig mod = new ShinyItemConfig(typeof(ShinyItemMod));

public override void Init()
{
mod.PartialityModReference = this;
mod.Initialize();
mod.ReadConfig();
mod.settings.ReadSettings();
}
public override void OnLoad()
{
Expand Down
16 changes: 16 additions & 0 deletions DotE_Patch_Mod/CustomItems-Mod/ShinyItemSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using DustDevilFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OPSashaItem_Mod
{
public class ShinyItemSettings : CustomItemSettings
{
public ShinyItemSettings(string name) : base(name)
{
}
}
}
Loading

0 comments on commit eb50294

Please sign in to comment.