Changes

Jump to navigation Jump to search
m
Text replacement - "tt>" to "samp>"
Line 57: Line 57:  
# Create an empty ''Class Library (.NET Framework)'' project.
 
# Create an empty ''Class Library (.NET Framework)'' project.
 
# Target .NET Framework 4.5, 4.5.1, or 4.5.2 for best compatibility.
 
# Target .NET Framework 4.5, 4.5.1, or 4.5.2 for best compatibility.
# Reference the [https://smapi.io/package/readme <tt>Pathoschild.Stardew.ModBuildConfig</tt> NuGet package] to automatically add the right references depending on the platform the mod is being compiled on.
+
# Reference the [https://smapi.io/package/readme <samp>Pathoschild.Stardew.ModBuildConfig</samp> NuGet package] to automatically add the right references depending on the platform the mod is being compiled on.
# Create a <tt>ModEntry</tt> class which subclasses <tt>StardewModdingAPI.Mod</tt>.
+
# Create a <samp>ModEntry</samp> class which subclasses <samp>StardewModdingAPI.Mod</samp>.
# Override the <tt>Entry</tt> method, and write your code using the [[#Mod APIs|SMAPI events and APIs]].
+
# Override the <samp>Entry</samp> method, and write your code using the [[#Mod APIs|SMAPI events and APIs]].
# Create a [[#Add your manifest|<tt>manifest.json</tt> file]] which describes your mod for SMAPI.
+
# Create a [[#Add your manifest|<samp>manifest.json</samp> file]] which describes your mod for SMAPI.
 
# Create [[#Release your mod|a zip file containing the mod files]] for release.
 
# Create [[#Release your mod|a zip file containing the mod files]] for release.
   Line 66: Line 66:  
* create a ''Class Library'' (not ''Class Library (.NET Framework)'') project;
 
* create a ''Class Library'' (not ''Class Library (.NET Framework)'') project;
 
* target .NET 5;
 
* target .NET 5;
* install the 3.4.0 beta version of the <tt>Pathoschild.Stardew.ModBuildConfig</tt> package.
+
* install the 3.4.0 beta version of the <samp>Pathoschild.Stardew.ModBuildConfig</samp> package.
 
}}
 
}}
 
}}
 
}}
Line 76: Line 76:  
# Create a solution with a ''Class Library (.NET Framework)'' project (see [[Modding:IDE reference#create-project|how to create a project]]). '''Make sure you choose .NET Framework (''not'' .NET Core, .NET Standard, or .NET 5+).'''
 
# Create a solution with a ''Class Library (.NET Framework)'' project (see [[Modding:IDE reference#create-project|how to create a project]]). '''Make sure you choose .NET Framework (''not'' .NET Core, .NET Standard, or .NET 5+).'''
 
# Change the target framework to .NET Framework 4.5, 4.5.1, or 4.5.2 for best compatibility (see [[Modding:IDE reference#set-target-framework|how to change target framework]]).<br /><small>That's the version installed and used by the game. Newer versions may not be installed for players, and SMAPI may not be able to load them.</small>
 
# Change the target framework to .NET Framework 4.5, 4.5.1, or 4.5.2 for best compatibility (see [[Modding:IDE reference#set-target-framework|how to change target framework]]).<br /><small>That's the version installed and used by the game. Newer versions may not be installed for players, and SMAPI may not be able to load them.</small>
# Reference the [https://www.nuget.org/packages/Pathoschild.Stardew.ModBuildConfig <tt>Pathoschild.Stardew.ModBuildConfig</tt> NuGet package] (see [[Modding:IDE reference#add-nuget|how to add the package]]).
+
# Reference the [https://www.nuget.org/packages/Pathoschild.Stardew.ModBuildConfig <samp>Pathoschild.Stardew.ModBuildConfig</samp> NuGet package] (see [[Modding:IDE reference#add-nuget|how to add the package]]).
 
# Restart Visual Studio/MonoDevelop after installing the package.
 
# Restart Visual Studio/MonoDevelop after installing the package.
   Line 82: Line 82:  
* create a ''Class Library'' (not ''Class Library (.NET Framework)'') project;
 
* create a ''Class Library'' (not ''Class Library (.NET Framework)'') project;
 
* target .NET 5;
 
* target .NET 5;
* install the 4.0.0 beta version of the <tt>Pathoschild.Stardew.ModBuildConfig</tt> package.
+
* install the 4.0.0 beta version of the <samp>Pathoschild.Stardew.ModBuildConfig</samp> package.
 
}}
 
}}
   Line 89: Line 89:     
<ol>
 
<ol>
<li>Delete the <tt>Class1.cs</tt> or <tt>MyClass.cs</tt> file (see [[Modding:IDE reference#delete-file|how to delete a file]]).</li>
+
<li>Delete the <samp>Class1.cs</samp> or <samp>MyClass.cs</samp> file (see [[Modding:IDE reference#delete-file|how to delete a file]]).</li>
<li>Add a C# class file called <tt>ModEntry.cs</tt> to your project (see [[Modding:IDE reference#Add a file|how to add a file]]).</li>
+
<li>Add a C# class file called <samp>ModEntry.cs</samp> to your project (see [[Modding:IDE reference#Add a file|how to add a file]]).</li>
<li>Put this code in the file (replace <tt>YourProjectName</tt> with the name of your project):
+
<li>Put this code in the file (replace <samp>YourProjectName</samp> with the name of your project):
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
 
using System;
 
using System;
Line 140: Line 140:  
# <code>using X;</code> (see [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive using directive]) makes classes in that namespace available in your code.
 
# <code>using X;</code> (see [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive using directive]) makes classes in that namespace available in your code.
 
# <code>namespace YourProjectName</code> (see [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/namespace namespace keyword]) defines the scope for your mod code. Don't worry about this when you're starting out, Visual Studio or MonoDevelop will add it automatically when you add a file.
 
# <code>namespace YourProjectName</code> (see [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/namespace namespace keyword]) defines the scope for your mod code. Don't worry about this when you're starting out, Visual Studio or MonoDevelop will add it automatically when you add a file.
# <code>public class ModEntry : Mod</code> (see [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/class class keyword]) creates your mod's main class, and subclasses SMAPI's <tt>Mod</tt> class. SMAPI will detect your <tt>Mod</tt> subclass automatically, and <tt>Mod</tt> gives you access to SMAPI's APIs.
+
# <code>public class ModEntry : Mod</code> (see [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/class class keyword]) creates your mod's main class, and subclasses SMAPI's <samp>Mod</samp> class. SMAPI will detect your <samp>Mod</samp> subclass automatically, and <samp>Mod</samp> gives you access to SMAPI's APIs.
 
# <code>public override void Entry(IModHelper helper)</code> is the method SMAPI will call when your mod is loaded into the game. The <code>helper</code> provides convenient access to many of SMAPI's APIs.
 
# <code>public override void Entry(IModHelper helper)</code> is the method SMAPI will call when your mod is loaded into the game. The <code>helper</code> provides convenient access to many of SMAPI's APIs.
# <code>helper.Events.Input.ButtonPressed += this.OnButtonPressed;</code> adds an 'event handler' (i.e. a method to call) when the button-pressed event happens. In other words, when a button is pressed (the <tt>helper.Events.Input.ButtonPressed</tt> event), SMAPI will call your <tt>this.OnButtonPressed</tt> method. See [[Modding:Modder Guide/APIs/Events|events in the SMAPI reference]] for more info.
+
# <code>helper.Events.Input.ButtonPressed += this.OnButtonPressed;</code> adds an 'event handler' (i.e. a method to call) when the button-pressed event happens. In other words, when a button is pressed (the <samp>helper.Events.Input.ButtonPressed</samp> event), SMAPI will call your <samp>this.OnButtonPressed</samp> method. See [[Modding:Modder Guide/APIs/Events|events in the SMAPI reference]] for more info.
    
===Add your manifest===
 
===Add your manifest===
Line 148: Line 148:     
<ol>
 
<ol>
<li>Add a file named <tt>manifest.json</tt> to your project.</li>
+
<li>Add a file named <samp>manifest.json</samp> to your project.</li>
 
<li>Paste this code into the file:
 
<li>Paste this code into the file:
 
<syntaxhighlight lang="json">
 
<syntaxhighlight lang="json">
Line 162: Line 162:  
}
 
}
 
</syntaxhighlight></li>
 
</syntaxhighlight></li>
<li>Replace the <tt>&lt;...&gt;</tt> placeholders with the correct info. Don't leave any <tt>&lt;&gt;</tt> symbols!</li>
+
<li>Replace the <samp>&lt;...&gt;</samp> placeholders with the correct info. Don't leave any <samp>&lt;&gt;</samp> symbols!</li>
 
</ol>
 
</ol>
   Line 168: Line 168:     
===Try your mod===
 
===Try your mod===
# Build the project.<br /><small>If you did the ''[[#Create the project|create the project]]'' steps correctly, this will automatically add your mod to the game's <tt>Mods</tt> folder.</small>
+
# Build the project.<br /><small>If you did the ''[[#Create the project|create the project]]'' steps correctly, this will automatically add your mod to the game's <samp>Mods</samp> folder.</small>
 
# Run the game through SMAPI.
 
# Run the game through SMAPI.
   Line 194: Line 194:  
<li>Use the [https://smapi.io/package/readme crossplatform build config] package to automatically set up your project references. This makes crossplatform compatibility easier and lets your code compile on any platform. (If you followed the above guide, you already have this.)</li>
 
<li>Use the [https://smapi.io/package/readme crossplatform build config] package to automatically set up your project references. This makes crossplatform compatibility easier and lets your code compile on any platform. (If you followed the above guide, you already have this.)</li>
   −
<li>Use <tt>System.IO.Path.Combine</tt> to build file paths, don't hardcode path separators since they won't work on all platforms.
+
<li>Use <samp>System.IO.Path.Combine</samp> to build file paths, don't hardcode path separators since they won't work on all platforms.
    
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
Line 204: Line 204:  
</syntaxhighlight></li>
 
</syntaxhighlight></li>
   −
<li>Use <tt>this.Helper.DirectoryPath</tt>, don't try to determine the mod path yourself.
+
<li>Use <samp>this.Helper.DirectoryPath</samp>, don't try to determine the mod path yourself.
    
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
Line 234: Line 234:     
===How do I decompile the game code?===
 
===How do I decompile the game code?===
It's often useful to see how the game code works. The game code is compiled into <tt>StardewValley.exe</tt> (i.e. converted to a machine-readable format), but you can decompile it get a mostly-readable approximation of the original code. (This might not be fully functional due to decompiler limitations, but you'll be able to see what it's doing.)
+
It's often useful to see how the game code works. The game code is compiled into <samp>StardewValley.exe</samp> (i.e. converted to a machine-readable format), but you can decompile it get a mostly-readable approximation of the original code. (This might not be fully functional due to decompiler limitations, but you'll be able to see what it's doing.)
    
To decompile the game code...
 
To decompile the game code...
Line 242: Line 242:  
:## Open ILSpy.
 
:## Open ILSpy.
 
:## Click ''View > Options'', scroll to the "Other" section at the bottom, and enable "Always qualify member references".
 
:## Click ''View > Options'', scroll to the "Other" section at the bottom, and enable "Always qualify member references".
:# Open <tt>StardewValley.exe</tt> in ILSpy.
+
:# Open <samp>StardewValley.exe</samp> in ILSpy.
 
:# Right-click on ''Stardew Valley'' and choose ''Save Code'' to create a decompiled project you can open in Visual Studio.
 
:# Right-click on ''Stardew Valley'' and choose ''Save Code'' to create a decompiled project you can open in Visual Studio.
    
To unpack the XNB data/image/map files, see [[Modding:Editing XNB files]].
 
To unpack the XNB data/image/map files, see [[Modding:Editing XNB files]].
   −
{{SMAPI upcoming|3.13.0|For Stardew Valley 1.5.5, open <tt>Stardew Valley.dll</tt> in ILSpy instead.}}
+
{{SMAPI upcoming|3.13.0|For Stardew Valley 1.5.5, open <samp>Stardew Valley.dll</samp> in ILSpy instead.}}
    
[[es:Modding:Guía del Modder/Introducción]]
 
[[es:Modding:Guía del Modder/Introducción]]
105,900

edits

Navigation menu