Skip to content

Commit f50302f

Browse files
committed
Multiplayer config sync + Flashkirby's Configurator
1 parent cc2b05b commit f50302f

File tree

4 files changed

+231
-46
lines changed

4 files changed

+231
-46
lines changed

Config.cs

Lines changed: 206 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,65 @@
33
using System.IO;
44
using Terraria;
55
using Terraria.IO;
6+
using Terraria.ModLoader;
67

78
namespace VanillaTweaks
89
{
910
public static class Config
1011
{
1112
public static bool GladiatorArmorTweak = true;
13+
const string GladiatorArmorTweakKey = "GladiatorArmorTweak";
14+
1215
public static bool ObsidianArmorTweak = true;
16+
const string ObsidianArmorTweakKey = "ObsidianArmorTweak";
17+
1318
public static bool MeteorArmorTweak = true;
19+
const string MeteorArmorTweakKey = "MeteorArmorTweak";
20+
21+
public static bool EskimoArmorTweak = true;
22+
const string EskimoArmorTweakKey = "EskimoArmorTweak";
23+
1424
public static bool RainArmorTweak = true;
25+
const string RainArmorTweakKey = "RainArmorTweak";
26+
1527
public static bool HammerTweaks = true;
28+
const string HammerTweaksKey = "HammerTweaks";
29+
1630
public static bool NightsEdgeAutoswing = true;
31+
const string NightsEdgeAutoswingKey = "NightsEdgeAutoswing";
32+
1733
public static bool TrueSwordsAutoswing = true;
34+
const string TrueSwordsAutoswingKey = "TrueSwordsAutoswing";
35+
1836
public static bool SwatHelmetTweak = true;
37+
const string SwatHelmetTweakKey = "SwatHelmetTweak";
38+
1939
public static bool SkullTweak = true;
40+
const string SkullTweakKey = "SkullTweak";
41+
2042
public static bool FishBowlTweak = true;
43+
const string FishBowlTweakKey = "FishBowlTweak";
44+
2145
public static bool SandstoneRename = true;
46+
const string SandstoneRenameKey = "SandstoneRename";
47+
2248
public static bool CobaltShieldRename = true;
49+
const string CobaltShieldRenameKey = "CobaltShieldRename";
50+
2351
public static bool BoneBlockFix = true;
52+
const string BoneBlockFixKey = "BoneBlockFix";
53+
2454
public static bool GoldCritterDropTweak = true;
25-
public static float ExtractSpeedMultipltier = 5f;
55+
const string GoldCritterDropTweakKey = "GoldCritterDropTweak";
56+
57+
public static float ExtractSpeedMultiplier = 5f;
58+
const string ExtractSpeedMultiplierKey = "ExtractSpeedMultiplier";
59+
60+
public static int JestersArrowCraft = 50;
61+
const string JestersArrowCraftKey = "JestersArrowCraft";
62+
63+
public static bool FavoriteTooltipRemove = true;
64+
const string FavoriteTooltipRemoveKey = "FavoriteTooltipRemove";
2665

2766
static string ConfigPath = Path.Combine(Main.SavePath, "Mod Configs", "Vanilla Tweaks.json");
2867

@@ -42,68 +81,194 @@ public static void Load()
4281
File.Move(OldConfigPath, ConfigPath);
4382
}
4483
if(File.Exists(OldConfigVersionPath))
45-
{
4684
File.Delete(OldConfigVersionPath);
47-
}
4885
if(Directory.GetFiles(OldConfigFolderPath).Length == 0 && Directory.GetDirectories(OldConfigFolderPath).Length == 0)
49-
{
5086
Directory.Delete(OldConfigFolderPath);
51-
}
5287
else
53-
{
5488
VanillaTweaks.Log("Old config folder still cotains some files/directories. They will not get deleted.");
55-
}
5689
}
5790
if(!ReadConfig())
58-
{
5991
VanillaTweaks.Log("Failed to read config file! Recreating config...");
60-
}
6192
SaveConfig();
6293
}
6394

64-
static bool ReadConfig()
95+
public static bool ReadConfig()
6596
{
6697
if(Configuration.Load())
6798
{
68-
Configuration.Get("GladiatorArmorTweak", ref GladiatorArmorTweak);
69-
Configuration.Get("ObsidianArmorTweak", ref ObsidianArmorTweak);
70-
Configuration.Get("MeteorArmorTweak", ref MeteorArmorTweak);
71-
Configuration.Get("HammerTweaks", ref HammerTweaks);
72-
Configuration.Get("NightsEdgeAutoswing", ref NightsEdgeAutoswing);
73-
Configuration.Get("TrueSwordsAutoswing", ref TrueSwordsAutoswing);
74-
Configuration.Get("SwatHelmetTweak", ref SwatHelmetTweak);
75-
Configuration.Get("SkullTweak", ref SkullTweak);
76-
Configuration.Get("FishBowlTweak", ref FishBowlTweak);
77-
Configuration.Get("SandstoneRename", ref SandstoneRename);
78-
Configuration.Get("CobaltShieldRename", ref CobaltShieldRename);
79-
Configuration.Get("BoneBlockFix", ref BoneBlockFix);
80-
Configuration.Get("SwatHelmetTweak", ref SwatHelmetTweak);
81-
Configuration.Get("GoldCritterDropTweak", ref GoldCritterDropTweak);
82-
Configuration.Get("ExtractSpeedMulitplier", ref ExtractSpeedMultipltier);
99+
Configuration.Get(GladiatorArmorTweakKey, ref GladiatorArmorTweak);
100+
Configuration.Get(ObsidianArmorTweakKey, ref ObsidianArmorTweak);
101+
Configuration.Get(MeteorArmorTweakKey, ref MeteorArmorTweak);
102+
Configuration.Get(EskimoArmorTweakKey, ref EskimoArmorTweak);
103+
Configuration.Get(RainArmorTweakKey, ref RainArmorTweak);
104+
Configuration.Get(HammerTweaksKey, ref HammerTweaks);
105+
Configuration.Get(NightsEdgeAutoswingKey, ref NightsEdgeAutoswing);
106+
Configuration.Get(TrueSwordsAutoswingKey, ref TrueSwordsAutoswing);
107+
Configuration.Get(SwatHelmetTweakKey, ref SwatHelmetTweak);
108+
Configuration.Get(SkullTweakKey, ref SkullTweak);
109+
Configuration.Get(FishBowlTweakKey, ref FishBowlTweak);
110+
Configuration.Get(SandstoneRenameKey, ref SandstoneRename);
111+
Configuration.Get(CobaltShieldRenameKey, ref CobaltShieldRename);
112+
Configuration.Get(BoneBlockFixKey, ref BoneBlockFix);
113+
Configuration.Get(GoldCritterDropTweakKey, ref GoldCritterDropTweak);
114+
Configuration.Get("ExtractSpeedMulitplier", ref ExtractSpeedMultiplier); //bit of a typo there :P
115+
Configuration.Get(ExtractSpeedMultiplierKey, ref ExtractSpeedMultiplier);
116+
Configuration.Get(JestersArrowCraftKey, ref JestersArrowCraft);
117+
Configuration.Get(FavoriteTooltipRemoveKey, ref FavoriteTooltipRemove);
83118
return true;
84119
}
85120
return false;
86121
}
87122

88-
static void SaveConfig()
123+
public static void SaveConfig()
89124
{
90125
Configuration.Clear();
91-
Configuration.Put("GladiatorArmorTweak", GladiatorArmorTweak);
92-
Configuration.Put("ObsidianArmorTweak", ObsidianArmorTweak);
93-
Configuration.Put("MeteorArmorTweak", MeteorArmorTweak);
94-
Configuration.Put("HammerTweaks", HammerTweaks);
95-
Configuration.Put("NightsEdgeAutoswing", NightsEdgeAutoswing);
96-
Configuration.Put("TrueSwordsAutoswing", TrueSwordsAutoswing);
97-
Configuration.Put("SwatHelmetTweak", SwatHelmetTweak);
98-
Configuration.Put("SkullTweak", SkullTweak);
99-
Configuration.Put("FishBowlTweak", FishBowlTweak);
100-
Configuration.Put("SandstoneRename", SandstoneRename);
101-
Configuration.Put("CobaltShieldRename", CobaltShieldRename);
102-
Configuration.Put("BoneBlockFix", BoneBlockFix);
103-
Configuration.Put("SwatHelmetTweak", SwatHelmetTweak);
104-
Configuration.Put("GoldCritterDropTweak", GoldCritterDropTweak);
105-
Configuration.Put("ExtractSpeedMulitplier", ExtractSpeedMultipltier);
126+
Configuration.Put(GladiatorArmorTweakKey, GladiatorArmorTweak);
127+
Configuration.Put(ObsidianArmorTweakKey, ObsidianArmorTweak);
128+
Configuration.Put(MeteorArmorTweakKey, MeteorArmorTweak);
129+
Configuration.Put(EskimoArmorTweakKey, EskimoArmorTweak);
130+
Configuration.Put(RainArmorTweakKey, RainArmorTweak);
131+
Configuration.Put(HammerTweaksKey, HammerTweaks);
132+
Configuration.Put(NightsEdgeAutoswingKey, NightsEdgeAutoswing);
133+
Configuration.Put(TrueSwordsAutoswingKey, TrueSwordsAutoswing);
134+
Configuration.Put(SwatHelmetTweakKey, SwatHelmetTweak);
135+
Configuration.Put(SkullTweakKey, SkullTweak);
136+
Configuration.Put(FishBowlTweakKey, FishBowlTweak);
137+
Configuration.Put(SandstoneRenameKey, SandstoneRename);
138+
Configuration.Put(CobaltShieldRenameKey, CobaltShieldRename);
139+
Configuration.Put(BoneBlockFixKey, BoneBlockFix);
140+
Configuration.Put(GoldCritterDropTweakKey, GoldCritterDropTweak);
141+
Configuration.Put(ExtractSpeedMultiplierKey, ExtractSpeedMultiplier);
142+
Configuration.Put(JestersArrowCraftKey, JestersArrowCraft);
143+
Configuration.Put(FavoriteTooltipRemoveKey, FavoriteTooltipRemove);
106144
Configuration.Save();
107145
}
146+
147+
//TODO: Transmations
148+
public static void LoadFKConfig(Mod mod)
149+
{
150+
var setting = FKTModSettings.ModSettingsAPI.CreateModSettingConfig(mod);
151+
152+
setting.AddComment("Features marked with an asterisk (*) require an item reset to update properly.\n" +
153+
"An item can be reset by either re-entering the world or by placing it into an Item Frame, Weapon Rack or Mannequin.");
154+
setting.AddComment("Features marked with two asterisks (**) require a mod reload to update properly.");
155+
setting.AddComment("Most values are only modifiable in singleplayer.");
156+
157+
const float commentScale = 0.8f;
158+
159+
setting.AddComment("Defense increased*, set bonus: +15% crit chance", commentScale);
160+
setting.AddBool(GladiatorArmorTweakKey, "Gladiator Armor Tweaks", false);
161+
setting.AddComment("+3% ranged crit chance for each piece, set bonus: +10% move speed and shadow trail", commentScale);
162+
setting.AddBool(ObsidianArmorTweakKey, "Obsidian Armor Tweaks", false);
163+
setting.AddComment("Defense decreased*, no magic bonuses", commentScale);
164+
setting.AddBool(MeteorArmorTweakKey, "Meteor Armor Tweaks", false);
165+
setting.AddComment("Defense increased*, immunity to cold water, set bonus: Warmth buff, immunity to Frostburn, Chilled and Frozen", commentScale);
166+
setting.AddBool(EskimoArmorTweakKey, "Eskimo Armor Tweaks", false);
167+
setting.AddComment("Set bonus: +1 defense, immunity to being wet", commentScale);
168+
setting.AddBool(RainArmorTweakKey, "Rain Armor Tweaks", false);
169+
setting.AddComment("Rebalances a few hammers/hamaxes", commentScale);
170+
setting.AddBool(HammerTweaksKey, "Hammer Tweaks*", false);
171+
setting.AddBool(NightsEdgeAutoswingKey, "Night's Edge Autoswing*", true);
172+
setting.AddBool(TrueSwordsAutoswingKey, "True Swords Autoswing*", true);
173+
setting.AddComment("+14 defense, +15% ranged damage (all types), +5% ranged crit chance\n" +
174+
"If Miscellania is installed, equipping a SWAT Helmet and a Reinforced Vest grants a set bonus", commentScale);
175+
setting.AddBool(SwatHelmetTweakKey, "SWAT Helmet Tweaks*", false);
176+
setting.AddComment("Flips the Skull sprite so that it faces to the right like other armor/vanity", commentScale);
177+
setting.AddBool(SkullTweakKey, "Skull Flip", true);
178+
setting.AddComment("+1 defense", commentScale);
179+
setting.AddBool(FishBowlTweakKey, "Fish Bowl Tweaks*", false);
180+
setting.AddComment("Renames items such as Sandstone Brick to Sand Brick", commentScale);
181+
setting.AddBool(SandstoneRenameKey, "Rename Sandstone Items**", true);
182+
setting.AddComment("Renames the Cobalt Shield to Guardian's Shield", commentScale);
183+
setting.AddBool(CobaltShieldRenameKey, "Rename Cobalt Shield**", true);
184+
setting.AddComment("Bone Block Walls craft back into Bones**, Bone Blocks drop raw Bones when mined", commentScale);
185+
setting.AddBool(BoneBlockFixKey, "Bone Block Fix", false);
186+
setting.AddComment("Gold critters drop 1 Gold when killed (as opposed to 5 Gold when sold)", commentScale);
187+
setting.AddBool(GoldCritterDropTweakKey, "Gold Critters Drop Coins", false);
188+
setting.AddFloat(ExtractSpeedMultiplierKey, "Extractinator Speed Multiplier", 0f, 5f, false);
189+
setting.AddBool(FavoriteTooltipRemoveKey, "Remove \"Favorite Item\" Tooltips", true);
190+
setting.AddComment("Setting this value to 0 will remove the recipe entirely", commentScale);
191+
setting.AddInt(JestersArrowCraftKey, "Jester's Arrows Crafted per Star**", 0, 100, false);
192+
}
193+
194+
public static void UpdateFKConfig(Mod mod)
195+
{
196+
FKTModSettings.ModSetting setting;
197+
if(FKTModSettings.ModSettingsAPI.TryGetModSetting(mod, out setting))
198+
{
199+
setting.Get(GladiatorArmorTweakKey, ref GladiatorArmorTweak);
200+
setting.Get(ObsidianArmorTweakKey, ref ObsidianArmorTweak);
201+
setting.Get(MeteorArmorTweakKey, ref MeteorArmorTweak);
202+
setting.Get(EskimoArmorTweakKey, ref EskimoArmorTweak);
203+
setting.Get(RainArmorTweakKey, ref RainArmorTweak);
204+
setting.Get(HammerTweaksKey, ref HammerTweaks);
205+
setting.Get(NightsEdgeAutoswingKey, ref NightsEdgeAutoswing);
206+
setting.Get(TrueSwordsAutoswingKey, ref TrueSwordsAutoswing);
207+
setting.Get(SwatHelmetTweakKey, ref SwatHelmetTweak);
208+
setting.Get(SkullTweakKey, ref SkullTweak);
209+
setting.Get(FishBowlTweakKey, ref FishBowlTweak);
210+
setting.Get(SandstoneRenameKey, ref SandstoneRename);
211+
setting.Get(CobaltShieldRenameKey, ref CobaltShieldRename);
212+
setting.Get(BoneBlockFixKey, ref BoneBlockFix);
213+
setting.Get(GoldCritterDropTweakKey, ref GoldCritterDropTweak);
214+
setting.Get(ExtractSpeedMultiplierKey, ref ExtractSpeedMultiplier);
215+
setting.Get(FavoriteTooltipRemoveKey, ref FavoriteTooltipRemove);
216+
setting.Get(JestersArrowCraftKey, ref JestersArrowCraft);
217+
}
218+
}
219+
220+
class MultiplayerSyncWorld : ModWorld
221+
{
222+
public override void NetSend(BinaryWriter writer)
223+
{
224+
var data = new BitsByte();
225+
data[0] = GladiatorArmorTweak;
226+
data[1] = ObsidianArmorTweak;
227+
data[2] = MeteorArmorTweak;
228+
data[3] = RainArmorTweak;
229+
data[4] = HammerTweaks;
230+
data[5] = NightsEdgeAutoswing;
231+
data[6] = TrueSwordsAutoswing;
232+
data[7] = SwatHelmetTweak;
233+
writer.Write((byte)data);
234+
data.ClearAll();
235+
data[0] = FishBowlTweak;
236+
data[1] = BoneBlockFix;
237+
data[2] = GoldCritterDropTweak;
238+
data[3] = EskimoArmorTweak;
239+
writer.Write((byte)data);
240+
writer.Write(ExtractSpeedMultiplier);
241+
writer.Write((short)JestersArrowCraft);
242+
}
243+
244+
public override void NetReceive(BinaryReader reader)
245+
{
246+
SaveConfig();
247+
var data = (BitsByte)reader.ReadByte();
248+
GladiatorArmorTweak = data[0];
249+
ObsidianArmorTweak = data[1];
250+
MeteorArmorTweak = data[2];
251+
RainArmorTweak = data[3];
252+
HammerTweaks = data[4];
253+
NightsEdgeAutoswing = data[5];
254+
TrueSwordsAutoswing = data[6];
255+
SwatHelmetTweak = data[7];
256+
data = (BitsByte)reader.ReadByte();
257+
FishBowlTweak = data[0];
258+
BoneBlockFix = data[1];
259+
GoldCritterDropTweak = data[2];
260+
EskimoArmorTweak = data[3];
261+
ExtractSpeedMultiplier = reader.ReadSingle();
262+
JestersArrowCraft = reader.ReadInt16();
263+
}
264+
}
265+
266+
class MultiplayerSyncPlayer : ModPlayer
267+
{
268+
public override void PlayerDisconnect(Player player)
269+
{
270+
ReadConfig();
271+
}
272+
}
108273
}
109274
}

VanillaTweaks.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ namespace VanillaTweaks
1010
{
1111
public class VanillaTweaks : Mod
1212
{
13-
internal static bool MiscellaniaLoaded;
13+
public static bool MiscellaniaLoaded;
14+
public static bool FKtModSettingsLoaded;
1415

1516
public override void Load()
1617
{
17-
Config.Load();
1818
MiscellaniaLoaded = ModLoader.GetMod("GoldensMisc") != null;
19+
FKtModSettingsLoaded = ModLoader.GetMod("FKTModSettings") != null;
20+
21+
Config.Load();
22+
if(FKtModSettingsLoaded)
23+
Config.LoadFKConfig(this);
24+
1925
LanguageManager.Instance.OnLanguageChanged += LangTweaks.EditNames;
2026
LanguageManager.Instance.OnLanguageChanged += LangTweaks.EditTooltips;
2127
LangTweaks.EditNames(LanguageManager.Instance);
@@ -33,6 +39,18 @@ public override void PostAddRecipes()
3339
RecipeTweaks.TweakCoins();
3440
}
3541

42+
public override void PostUpdateInput()
43+
{
44+
if(FKtModSettingsLoaded && !Main.gameMenu)
45+
Config.UpdateFKConfig(this);
46+
}
47+
48+
public override void PreSaveAndQuit()
49+
{
50+
if(FKtModSettingsLoaded)
51+
Config.SaveConfig();
52+
}
53+
3654
public static void Log(string message, params object[] formatData)
3755
{
3856
ErrorLogger.Log(String.Format("[Vanilla Tweaks][{0}] {1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), string.Format(message, formatData)));

build.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
displayName = Vanilla Tweaks
22
author = goldenapple
3-
version = 2.3
3+
version = 2.4
44
homepage = http://forums.terraria.org/index.php?threads/vanilla-tweaks-a-mod-with-no-content.37443/
55
hideCode = false
66
includeSource = true
7-
buildIgnore = obj\*, bin\*, *.csproj, .git\*, .gitattributes, .gitignore
7+
buildIgnore = obj\*, bin\*, *.csproj, .git\*, .gitattributes, .gitignore
8+
weakReferences = FKTModSettings

description.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ Changes include:
77
-Bone Blocks now drop Bones
88
And some others! Visit the mod's homepage for the full list.
99

10-
NOTE: Since the 2.0 update you can now disable/enable features as you wish! Visit the mod's homepage for more info.
10+
NOTE: Since the 2.0 update you can now disable/enable features as you wish! Visit the mod's homepage for more info.
11+
Install Flashkirby's Mod Settings Configurator to change them in-game.

0 commit comments

Comments
 (0)