Skip to content

Commit

Permalink
- Introduced concept of Tester Features, optionally, somewhat-secret …
Browse files Browse the repository at this point in the history
…things that can be enabled by helpers and testers

- Created the Mod validation Tester Feature, and the Multiplayer Tester Feature
  • Loading branch information
agilbert1412 committed Dec 9, 2024
1 parent 234adf7 commit 5b4b65f
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 20 deletions.
13 changes: 12 additions & 1 deletion StardewArchipelago/Archipelago/ModsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using KaitoKid.ArchipelagoUtilities.Net.Interfaces;
using StardewArchipelago.Constants.Modded;
using StardewArchipelago.GameModifications.Testing;
using StardewModdingAPI;

namespace StardewArchipelago.Archipelago
Expand All @@ -11,12 +12,14 @@ namespace StardewArchipelago.Archipelago
public class ModsManager
{
private readonly ILogger _logger;
private readonly TesterFeatures _testerFeatures;
private readonly List<string> _activeMods;
private readonly VersionValidator _versionValidator;

public ModsManager(ILogger logger, List<string> activeMods)
public ModsManager(ILogger logger, TesterFeatures testerFeatures, List<string> activeMods)
{
_logger = logger;
_testerFeatures = testerFeatures;
_activeMods = activeMods;
_versionValidator = new VersionValidator();
}
Expand Down Expand Up @@ -117,10 +120,18 @@ private bool IsModActiveAndCorrectVersion(List<IModInfo> loadedModData, string d
}

existingVersion = modInfo.Manifest.Version.ToString();
if (_testerFeatures.UnstableMods.Value != VerifyMods.MODS_AND_VERSIONS)
{
return true;
}
return _versionValidator.IsVersionCorrect(existingVersion, desiredVersion);
}

existingVersion = "[NOT FOUND]";
if (_testerFeatures.UnstableMods.Value == VerifyMods.NOTHING)
{
return true;
}
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions StardewArchipelago/Archipelago/SlotData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using KaitoKid.ArchipelagoUtilities.Net.Interfaces;
using Newtonsoft.Json;
using StardewArchipelago.GameModifications.Testing;
using StardewValley;
using StardewValley.GameData;

Expand Down Expand Up @@ -109,7 +110,7 @@ public class SlotData : ISlotData
public bool AppearanceRandomizationDaily { get; set; }
public ModsManager Mods { get; set; }

public SlotData(string slotName, Dictionary<string, object> slotDataFields, ILogger logger)
public SlotData(string slotName, Dictionary<string, object> slotDataFields, ILogger logger, TesterFeatures testerFeatures)
{
SlotName = slotName;
_slotDataFields = slotDataFields;
Expand Down Expand Up @@ -164,7 +165,7 @@ public SlotData(string slotName, Dictionary<string, object> slotDataFields, ILog
AppearanceRandomizationDaily = false; // GetSlotSetting(RANDOMIZE_NPC_APPEARANCES_DAILY_KEY, false);
var modsString = GetSlotSetting(MOD_LIST_KEY, "");
var mods = JsonConvert.DeserializeObject<List<string>>(modsString);
Mods = new ModsManager(_logger, mods);
Mods = new ModsManager(_logger, testerFeatures, mods);
}

private Walnutsanity GetSlotWalnutsanitySetting()
Expand Down
12 changes: 7 additions & 5 deletions StardewArchipelago/Archipelago/StardewArchipelagoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using KaitoKid.ArchipelagoUtilities.Net.Interfaces;
using Microsoft.Xna.Framework;
using StardewArchipelago.Extensions;
using StardewArchipelago.GameModifications.Testing;
using StardewModdingAPI;
using StardewValley;

Expand All @@ -21,6 +22,7 @@ public class StardewArchipelagoClient : ArchipelagoClient
private readonly IModHelper _modHelper;
private readonly IManifest _manifest;
private readonly Harmony _harmony;
private readonly TesterFeatures _testerFeatures;
private IDataStorageWrapper<BigInteger> _bigIntegerDataStorage;
private DeathManager _deathManager;

Expand All @@ -30,17 +32,18 @@ public class StardewArchipelagoClient : ArchipelagoClient

public SlotData SlotData => (SlotData)_slotData;

public StardewArchipelagoClient(ILogger logger, IModHelper modHelper, IManifest manifest, Harmony harmony, Action itemReceivedFunction, IJsonLoader jsonLoader) :
public StardewArchipelagoClient(ILogger logger, IModHelper modHelper, IManifest manifest, Harmony harmony, Action itemReceivedFunction, IJsonLoader jsonLoader, TesterFeatures testerFeatures) :
base(logger, new DataPackageCache(new ArchipelagoItemLoader(jsonLoader), new StardewArchipelagoLocationLoader(jsonLoader), "stardew_valley", "IdTables"), itemReceivedFunction)
{
_modHelper = modHelper;
_manifest = manifest;
_harmony = harmony;
_testerFeatures = testerFeatures;
}

protected override void InitializeSlotData(string slotName, Dictionary<string, object> slotDataFields)
{
_slotData = new SlotData(slotName, slotDataFields, Logger);
_slotData = new SlotData(slotName, slotDataFields, Logger, _testerFeatures);
}

public override bool ConnectToMultiworld(ArchipelagoConnectionInfo connectionInfo, out string errorMessage)
Expand All @@ -49,8 +52,7 @@ public override bool ConnectToMultiworld(ArchipelagoConnectionInfo connectionInf
{
return false;
}

#if RELEASE

if (!SlotData.Mods.IsModStateCorrect(_modHelper, out errorMessage))
{
DisconnectPermanently();
Expand All @@ -62,7 +64,7 @@ public override bool ConnectToMultiworld(ArchipelagoConnectionInfo connectionInf
DisconnectPermanently();
return false;
}
#endif

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using KaitoKid.ArchipelagoUtilities.Net.Interfaces;
using Microsoft.Xna.Framework;
using StardewArchipelago.Archipelago;
using StardewArchipelago.GameModifications.Testing;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Menus;
Expand All @@ -16,14 +17,16 @@ public class AdvancedOptionsManager
private static IModHelper _modHelper;
private readonly Harmony _harmony;
private static StardewArchipelagoClient _archipelago;
private static TesterFeatures _testerFeatures;

public AdvancedOptionsManager(ModEntry modEntry, ILogger logger, IModHelper modHelper, Harmony harmony, StardewArchipelagoClient archipelago)
public AdvancedOptionsManager(ModEntry modEntry, ILogger logger, IModHelper modHelper, Harmony harmony, StardewArchipelagoClient archipelago, TesterFeatures testerFeatures)
{
_modEntry = modEntry;
_logger = logger;
_modHelper = modHelper;
_harmony = harmony;
_archipelago = archipelago;
_testerFeatures = testerFeatures;
}

public void InjectArchipelagoAdvancedOptions()
Expand Down Expand Up @@ -99,6 +102,8 @@ public static bool LoadForNewGame_ForceSettings_Prefix(bool loadedGame = false)
ForceFarmTypeToArchipelagoProvidedFarm();
Game1.bundleType = Game1.BundleType.Default;
Game1.game1.SetNewGameOption<bool>("YearOneCompletable", false);
Game1.startingCabins = _testerFeatures.Multiplayer.Value;
Game1.cabinsSeparate = false;

return true; // run original logic
}
Expand Down
9 changes: 9 additions & 0 deletions StardewArchipelago/GameModifications/Testing/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace StardewArchipelago.GameModifications.Testing
{
public static class VerifyMods
{
public const int MODS_AND_VERSIONS = 0;
public const int MODS_ONLY = 1;
public const int NOTHING = 2;
}
}
14 changes: 14 additions & 0 deletions StardewArchipelago/GameModifications/Testing/TesterFeature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace StardewArchipelago.GameModifications.Testing
{
public class TesterFeature
{
public string Name { get; set; }
public int Value { get; set; }

public TesterFeature(string name, int defaultValue)
{
Name = name;
Value = defaultValue;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace StardewArchipelago.GameModifications.Testing
{
public class TesterFeatureNames
{
public const string UNSTABLE_MODS = "VerifyMods";
public const string MULTIPLAYER = "Multiplayer";
}
}
49 changes: 49 additions & 0 deletions StardewArchipelago/GameModifications/Testing/TesterFeatures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using KaitoKid.ArchipelagoUtilities.Net.Interfaces;
using StardewModdingAPI;

namespace StardewArchipelago.GameModifications.Testing
{
public class TesterFeatures
{
private const string TESTER_FEATURES_FILE = "tester.json";
public readonly TesterFeature Multiplayer = new(TesterFeatureNames.MULTIPLAYER, 0);
public readonly TesterFeature UnstableMods = new(TesterFeatureNames.UNSTABLE_MODS, VerifyMods.MODS_AND_VERSIONS);
private readonly Dictionary<string, TesterFeature> _featuresByName = new();

public TesterFeatures(ILogger logger, IModHelper modHelper)
{
_featuresByName.Add(Multiplayer.Name, Multiplayer);
_featuresByName.Add(UnstableMods.Name, UnstableMods);

#if DEBUG
UnstableMods.Value = VerifyMods.NOTHING;
#endif

try
{
var entries = modHelper.Data.ReadJsonFile<Dictionary<string, int>>(TESTER_FEATURES_FILE);
if (entries == null || !entries.Any())
{
return;
}

foreach (var (name, value) in entries)
{
if (!_featuresByName.ContainsKey(name))
{
continue;
}

_featuresByName[name].Value = value;
}
}
catch (Exception ex)
{
logger.LogError($"Failed at reading the TesterFeatures file. The file is probably corrupted and should be deleted to start fresh, or fixed manually");
}
}
}
}
25 changes: 16 additions & 9 deletions StardewArchipelago/Locations/Patcher/ModLocationPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using System;
using HarmonyLib;
using KaitoKid.ArchipelagoUtilities.Net.Interfaces;
using StardewArchipelago.Archipelago;
using StardewArchipelago.Constants.Modded;
Expand Down Expand Up @@ -38,14 +39,20 @@ public ModLocationPatcher(Harmony harmony, ILogger logger, IModHelper modHelper,

public void ReplaceAllLocationsRewardsWithChecks()
{
AddModSkillInjections();
AddDeepWoodsModInjections();
AddMagicModInjections();
AddSkullCavernElevatorModInjections();
AddSVEModInjections();
AddBoardingHouseInjections();
PatchSVEShops();

try
{
AddModSkillInjections();
AddDeepWoodsModInjections();
AddMagicModInjections();
AddSkullCavernElevatorModInjections();
AddSVEModInjections();
AddBoardingHouseInjections();
PatchSVEShops();
}
catch (Exception ex)
{
_logger.LogError($"Failed at Initializing mod content. Message: {ex.Message}");
}
}

public void CleanEvents()
Expand Down
7 changes: 5 additions & 2 deletions StardewArchipelago/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using StardewArchipelago.GameModifications.EntranceRandomizer;
using StardewArchipelago.GameModifications.Modded;
using StardewArchipelago.GameModifications.Seasons;
using StardewArchipelago.GameModifications.Testing;
using StardewArchipelago.Goals;
using StardewArchipelago.Integrations.GenericModConfigMenu;
using StardewArchipelago.Items;
Expand Down Expand Up @@ -57,6 +58,7 @@ public class ModEntry : Mod
private LogHandler _logger;
private IModHelper _helper;
private Harmony _harmony;
private TesterFeatures _testerFeatures;
private StardewArchipelagoClient _archipelago;
private AdvancedOptionsManager _advancedOptionsManager;
private Mailman _mail;
Expand Down Expand Up @@ -108,8 +110,9 @@ public override void Entry(IModHelper helper)
_logger = new LogHandler(Monitor);
_helper = helper;
_harmony = new Harmony(ModManifest.UniqueID);
_testerFeatures = new TesterFeatures(_logger, _helper);

_archipelago = new StardewArchipelagoClient(_logger, _helper, ModManifest, _harmony, OnItemReceived, new SmapiJsonLoader(_helper));
_archipelago = new StardewArchipelagoClient(_logger, _helper, ModManifest, _harmony, OnItemReceived, new SmapiJsonLoader(_helper), _testerFeatures);

_helper.Events.GameLoop.GameLaunched += OnGameLaunched;
_helper.Events.GameLoop.SaveCreating += OnSaveCreating;
Expand Down Expand Up @@ -224,7 +227,7 @@ private void ResetArchipelago()
_bundlesManager = null;
SeasonsRandomizer.ResetMailKeys();
_multiSleep = new MultiSleep(_logger, _helper, _harmony);
_advancedOptionsManager = new AdvancedOptionsManager(this, _logger, _helper, _harmony, _archipelago);
_advancedOptionsManager = new AdvancedOptionsManager(this, _logger, _helper, _harmony, _archipelago, _testerFeatures);
_advancedOptionsManager.InjectArchipelagoAdvancedOptions();
_giftHandler = new CrossGiftHandler();
_villagerEvents = new ModifiedVillagerEventChecker();
Expand Down

0 comments on commit 5b4b65f

Please sign in to comment.