Skip to content

Commit

Permalink
Add a bunch of new mods
Browse files Browse the repository at this point in the history
  • Loading branch information
SinZ163 committed Mar 20, 2024
1 parent 8a206fa commit da4e95f
Show file tree
Hide file tree
Showing 25 changed files with 1,392 additions and 18 deletions.
32 changes: 32 additions & 0 deletions SinZational Scene Setup/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using StardewValley.Menus;
using System;
using System.Collections.Generic;
using xTile.Dimensions;

namespace SinZational_Scene_Setup
{
Expand All @@ -15,6 +16,7 @@ public class ModEntry : Mod
public override void Entry(IModHelper helper)
{
helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked;
helper.Events.GameLoop.DayStarted += GameLoop_DayStarted;

helper.ConsoleCommands.Add("sinz.playevents", "Auto plays events in the current location. If arguments are given is treated as a specific, or all if location is 'ALL'", (command, args) =>
{
Expand Down Expand Up @@ -49,6 +51,36 @@ public override void Entry(IModHelper helper)
});
}

private void GameLoop_DayStarted(object sender, StardewModdingAPI.Events.DayStartedEventArgs e)
{
foreach (var location in Game1.locations)
{
Dictionary<string, string> events;
try
{
events = Helper.GameContent.Load<Dictionary<string, string>>($"Data/Events/{location.Name}");
}
catch (ContentLoadException)
{
Monitor.Log($"Location {location.Name} does not have events?", LogLevel.Info);
continue;
}
Monitor.Log($"Location {location.Name} has {events.Count} events", LogLevel.Info);
foreach (var key in events.Keys)
{
var split = key.Split('/');
if (split.Length < 2) continue;
var eventId = split[0];
var args = split[1..];
Monitor.Log("Testing event " + key);
foreach (var arg in args)
{
Event.CheckPrecondition(location, eventId, arg);
}
}
}
}

private void GameLoop_UpdateTicked(object sender, StardewModdingAPI.Events.UpdateTickedEventArgs e)
{
if (!Context.IsWorldReady) return;
Expand Down
2 changes: 1 addition & 1 deletion SinZational Scene Setup/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"UniqueID": "SinZ.SceneSetup",
"Name": "SinZational Scene Setup",
"Author": "SinZ",
"Version": "0.0.1",
"Version": "0.0.1-Debug",
"Description": "A mod that exposes commands to autoplay events for a given or all locations",
"MinimumApiVersion": "3.18",
"EntryDll": "SinZational Scene Setup.dll"
Expand Down
120 changes: 120 additions & 0 deletions SinZational Science Showcase/ModEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using HarmonyLib;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewValley;
using StardewValley.ItemTypeDefinitions;
using StardewValley.Objects;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Emit;

namespace SinZational_Science_Showcase
{
public class ModEntry : Mod
{
public override void Entry(IModHelper helper)
{
//helper.Events.Input.ButtonReleased += Input_ButtonReleased;
var harmony = new Harmony(ModManifest.UniqueID);
harmony.Patch(AccessTools.Method(typeof(Hat), nameof(Hat.draw)), transpiler: new HarmonyMethod(typeof(HarmonyPatches).GetMethod(nameof(HarmonyPatches.Hat__Draw__Transpiler))));
}

/*
private void Input_ButtonReleased(object sender, StardewModdingAPI.Events.ButtonReleasedEventArgs e)
{
if (!Context.IsWorldReady) return;
if (Game1.activeClickableMenu != null) return;
if (e.Button != SButton.F5) return;
var coop = Game1.getFarm().buildings.Where(b => b.buildingType.Value == "Deluxe Coop").First();
var coopInterior = coop.indoors.Value as AnimalHouse;
var autoGrabber = coopInterior.objects.Values.Where(o => o.QualifiedItemId == "(BC)165").First();
var autoGrabberStorage = autoGrabber.heldObject.Value as Chest;
var dayCounter = 0;
var season = Game1.season;
do
{
Monitor.Log($"Day: {Game1.stats.DaysPlayed} ({season} {Game1.dayOfMonth}), Duck Feather count: {autoGrabberStorage.Items.CountId("(O)444")}, Rabbits Feet count: {autoGrabberStorage.Items.CountId("(O)446")}", LogLevel.Info);
Game1.stats.DaysPlayed++;
Game1.dayOfMonth++;
if (Game1.dayOfMonth > 28)
{
Game1.dayOfMonth = 1;
season++;
if (season > Season.Winter)
{
season = Season.Spring;
}
}
Game1.getFarm().tryToAddHay(20);
foreach (var animal in coopInterior.animals.Values)
{
animal.wasPet.Value = true;
// Eating outside
if (season != Season.Winter)
{
animal.friendshipTowardFarmer.Value += 8;
}
}
coopInterior.DayUpdate((int)((Game1.stats.DaysPlayed % 28) + 1));
if (dayCounter++ > 1000)
{
Monitor.Log("After 1000 simulations, did not show??", LogLevel.Warn);
autoGrabber.checkForAction(Game1.player);
break;
}
}
while (autoGrabberStorage.Items.CountId("(O)444") == 0);
}
*/

}

public static class HarmonyPatches
{
public static IEnumerable<CodeInstruction> Hat__Draw__Transpiler(ILGenerator generator, IEnumerable<CodeInstruction> instructions)
{
var output = new List<CodeInstruction>();
var skipCount = 0;
foreach (var instruction in instructions)
{
if (skipCount-- > 0) continue;
/*
* Replace the following
* IL_001f: ldsfld class StardewValley.LocalizedContentManager StardewValley.Game1::content
* IL_0024: ldstr "Characters\\Farmer\\hats_animals"
* IL_0029: callvirt instance !!0 StardewValley.LocalizedContentManager::Load<class [MonoGame.Framework]Microsoft.Xna.Framework.Graphics.Texture2D>(string)
* with
* ldloc_0
* call HarmonyPatches::Hat__Draw__GetAnimalHat
*/
if (instruction.opcode == OpCodes.Ldsfld)
{
var load = new CodeInstruction(OpCodes.Ldloc_0)
{
labels = instruction.labels
};
output.Add(load);
output.Add(new CodeInstruction(OpCodes.Call, typeof(HarmonyPatches).GetMethod(nameof(Hat__Draw__GetAnimalHat))));
skipCount = 2;
continue;
}
output.Add(instruction);
}
return output;
}

public static Texture2D Hat__Draw__GetAnimalHat(ParsedItemData itemData)
{
var rawData = itemData.RawData as string[];
ArgUtility.TryGetOptional(rawData, 8, out var textureName, out _, itemData.TextureName);
if (textureName == "Characters\\Farmer\\hats")
{
textureName = "Characters\\Farmer\\hats_animals";
}
return Game1.content.Load<Texture2D>(textureName);
}
}
}
18 changes: 18 additions & 0 deletions SinZational Science Showcase/SinZational Science Showcase.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>SinZational_Science_Showcase</RootNamespace>
<EnableHarmony>true</EnableHarmony>
<GamePath>C:\Users\acerP\Downloads\depotdownloader-2.4.7\stardew1.6-beta</GamePath>
</PropertyGroup>

<ItemGroup>
<Content Include="cp\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.1.1" />
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions SinZational Science Showcase/cp/content.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Format": "1.28.0",
"Changes": [
{
"Action": "EditData",
"Target": "Data/Achievements",
"Fields": {
"1": {
"0": "Achievement name"
}
}
}
]
}
16 changes: 16 additions & 0 deletions SinZational Science Showcase/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Name": "SinZational Science Showcase",
"Author": "SinZ",
"Version": "0.1.0-alpha",
"Description": "Visualizes Schedule information on the map to assist NPC creators",
"UniqueID": "SinZ.Science",
"EntryDll": "SinZational Science Showcase.dll",
"MinimumApiVersion": "3.0.0",
"UpdateKeys": [ "Nexus:-1" ],
"Dependencies": [
{
"UniqueID": "Pathoschild.ContentPatcher",
"IsRequired": false
}
]
}
Loading

0 comments on commit da4e95f

Please sign in to comment.