Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 5.0.x
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

bin/
obj/

CLAUDE.md
12 changes: 12 additions & 0 deletions Framework/Model/DebrisData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SaveAnywhere.Framework.Model
{
public sealed record DebrisData(
string Map,
int X,
int Y,
string QualifiedItemId,
int Stack,
int Quality,
bool IsResourcePile
);
}
1 change: 1 addition & 0 deletions Framework/Model/PlayerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class PlayerData
public PositionData[] Position { get; init; }

public bool IsCharacterSwimming { get; init; }
public DebrisData[] Debris { get; init; }
}
}
408 changes: 362 additions & 46 deletions Framework/SaveManager.cs

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,44 @@ game), if you have GMCM use it instead.

#### Created by Omegasis, Aredjay, and RealSweetPanda

### Changelog

#### 3.5.0

- **Fixed villagers freezing or walking through walls/water after loading a mid-day save.** The game precomputes each
NPC's daily route from their morning position and replays it without collision checks; after a mid-day reload NPCs
were not where those routes expected, which froze them or sent them cutting through walls, water, and map edges
(and could make them vanish into unreachable spots). Villagers now get a fresh path to their current schedule
destination computed from the tile they actually stand on, using the game's own schedule pathfinding, and
villagers who already reached their destination resume their idle behavior (reading, standing at the counter,
etc.) instead of standing blank.
- **Fixed monster health resetting on reload — this was letting players save-scum out of fights.** The mod was
stripping every monster from the world before each mid-day save; the game's own save code never touches monsters,
so this was purely the mod deleting them from the file. Reloading meant any monster you were fighting came back
at full health or vanished entirely. Vanilla monsters now save and reload with their current health. Monster
types added by other mods are still excluded from the save file (some aren't safe to serialize), so they behave
as before.
- **Fixed the player sometimes spawning inside solid rock in mines and the Volcano Dungeon.** Those floors are
randomly regenerated every time you enter them and were never part of the save file to begin with, so reloading
mid-mine puts you in a brand-new layout — your saved spot could now be a wall. The mod checks for this and moves
you to the nearest open tile using the same recovery the game uses for its own stale warp points.
- **Dropped items no longer disappear on reload.** Something you just chopped, looted, or knocked loose that's
still sitting on the ground used to vanish, because the game doesn't normally expect the ground to have anything
on it when a save happens. This covers both single-item drops (loot, quest items, tools/weapons, unpicked forage)
and loose resource piles (wood/stone/coal left over from chopping a tree or mining a rock), indoors or out.
- **Fixed saving changing tomorrow's weather** (e.g. deleting rain, or corrupting the forecast when saving on a
festival day).
- **Fixed multiplayer hang:** mid-day saving with farmhands connected froze the game on the saving screen forever;
the mod now blocks the save with a clear message instead.
- Skipped the few-second "has been saved" animation for a mid-day save — that screen is vanilla's end-of-night
transition, and doesn't make sense when the clock isn't actually advancing to the next day.
- Fixed a crash (`ArgumentException`) on the second mid-day save of a session in some cases.
- Fixed a possible crash on load if the mid-day save data was missing or corrupted.
- Farmhands connecting to a host no longer get warped to the host's saved position.
- Hidden off-map NPCs (e.g. Marlon) are no longer saved/restored.
- Removed a redundant double screen-fade when loading a mid-day save.
- Updated build tooling for current SMAPI (no deprecated APIs).

### Notes

The mod should now work with map extension mods, modded characters, modded items, etc in the newest update. If it
Expand Down
51 changes: 41 additions & 10 deletions SaveAnywhere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ private void BuildConfigMenu(object sender, GameLaunchedEventArgs e)

private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
{
// ShouldResetSchedules = true;
// Farmhands also get SaveLoaded when connecting; only the host restores
// world state (positions, clock, schedules).
if (!Context.IsMainPlayer) return;
if (SaveManager.saveDataExists())
SaveManager.LoadData();
}
Expand All @@ -78,9 +80,17 @@ private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
}


// Vanilla monsters are left in place so the real save serializes them
// with their current health (vanilla's own save code never touches
// monsters). Only monster types from OTHER mods' assemblies are
// stripped before the save and re-added immediately after — those
// aren't covered by the base game's XmlInclude list and would crash
// the save's XmlSerializer with an "unexpected type" error otherwise.
public void cleanMonsters()
{
_monsters = new Dictionary<GameLocation, List<Monster>>();
var baseAssembly = typeof(Monster).Assembly;

foreach (var location in Game1.locations)
{
if (location is Forest)
Expand All @@ -91,37 +101,58 @@ public void cleanMonsters()
}
_monsters.Add(location, new List<Monster>());
foreach (var character in location.characters)
if (character is Monster monster)
{
Monitor.Log(character.Name);
if (character is Monster monster && monster.GetType().Assembly != baseAssembly)
_monsters[location].Add(monster);
}

foreach (var monster in _monsters[location])
location.characters.Remove(monster);
}


}

public void RestoreMonsters()
{
if (_monsters == null) return;

foreach (var monster1 in _monsters)
foreach (var monster2 in monster1.Value)
monster1.Key.addCharacter(monster2);

var forest = Utility.fuzzyLocationSearch("Forest");
if (Game1.year <= 2 || Game1.isRaining || Utility.isFestivalDay(Game1.dayOfMonth, Game1.season) || forest.getCharacterFromName("TrashBear") != null || NetWorldState.checkAnywhereForWorldStateID("trashBearDone"))
return;
forest.characters.Add( new TrashBear());
if (forest != null
&& Game1.year > 2
&& !Game1.isRaining
&& !Utility.isFestivalDay(Game1.dayOfMonth, Game1.season)
&& forest.getCharacterFromName("TrashBear") == null
&& !NetWorldState.checkAnywhereForWorldStateID("trashBearDone"))
{
forest.characters.Add(new TrashBear());
}

// Always clear, regardless of the TrashBear branch above — this used to
// only run when TrashBear conditions were met, so on the next mid-day
// save cleanMonsters() would call _monsters.Add() on a location key that
// was never cleared, throwing an ArgumentException on the second save of
// a session.
_monsters.Clear();
}

private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
{
if (!Context.IsPlayerFree || e.Button != _config.SaveKey || Game1.eventUp || Game1.isFestival())
return;
if (SaveManager.IsSaving) return;

if (Game1.client == null)
{
// The vanilla save menu waits on a ready-check barrier that includes
// every online farmer; farmhands never join it for a mid-day save, so
// the game would hang on "saving" forever with remote players connected.
if (Context.HasRemotePlayers)
{
Game1.addHUDMessage(new HUDMessage("Can't save mid-day while other players are connected.", 3));
return;
}

if (Game1.player.currentLocation.characters.Any(x => x is Junimo))
Game1.addHUDMessage(new HUDMessage("The spirits don't want you to save here.", 3));
else
Expand Down
2 changes: 1 addition & 1 deletion SaveAnywhere.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.1.1" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.4.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Save Anywhere Redux",
"Author": "Open Source",
"Version": "3.3.0",
"Version": "3.5.0",
"Description": "This mod allows you to save your game at any time, anywhere.",
"UniqueID": "Omegasis.SaveAnywhere",
"EntryDll": "SaveAnywhere.dll",
Expand Down
Loading