Replanted.PluginTemplate
1.1.0
It is recommended to use MelonLoader for modding PvZ Replanted instead.
dotnet new install Replanted.PluginTemplate@1.1.0
PvZ: Replanted BepInEx Plugin Template
A simple BepInEx plugin template for modding Plants vs Zombies: Replanted. This template provides a blank starting project to help you create a custom plugin quickly and easily.
If you need help or want to be a part of the Plants vs Zombies: Replanted modding community, join our Discord server!
Features
- Preconfigured plugin structure with necessary IL2CPP assembly references
- Example Plugin class with basic logging
- Ready-to-build .NET solution and project
- Available on NuGet:
Replanted.PluginTemplate
Requirements
Getting Started
1. Install via NuGet
You can install this project teplate from NuGet:
dotnet new install Replanted.PluginTemplate
And then create a new project using Visual Studio or by running:
dotnet add package Replanted.PluginTemplate
2. Modify the Template
When you open the solution in your IDE (e.g. Visual Studio or Rider), the main sctructure should look something like this:
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
namespace ReplantedTemplate;
[BepInPlugin(Name, Name, Version)]
public class ReplantedTemplatePlugin : BasePlugin
{
public const string Name = "ReplantedTemplate";
public const string Version = "1.0.0";
public const string Id = "com.yourname.plugin";
public Harmony Harmony { get; } = new Harmony(Id);
public static ManualLogSource Logger;
public override void Load()
{
Logger = Log;
Logger.LogInfo($"\"{Name}\" Plugin has been loaded.");
Harmony.PatchAll();
}
}
From here you can:
- Create your own custom classes that reference the game code (from the
Reloadednamespace). - Use tools like HarmonyX to patch game methods.
- Log into the BepInEx console with the provided logger/
3. Build and Install
- Download and extract the
Unity.IL2CPPversion of BepInEx into your PvZ: Replanted directory. - Build the project to generate a
.dllfile inbin/Debug/net6.0/. - Place the output
.dllinto your BepInEx/plugins/ folder in the game directory. - Launch the game. You should see the BepInEx console and your plugin should load.
⚠️ If the game reopens and the BepInEx console window disappears after launch, create a file called
steam_appid.txtin your game directory and paste the following string inside: 3654560
Patching Methods
The plugin template comes with an example patch that demonstrates how to use HarmonyX to inject code:
// Example Harmony Patch that changes any planted seed to a Marigold
[HarmonyPatch(typeof(Board), nameof(Board.AddPlant))]
internal static class PlantPlacedPatch
{
internal static void Prefix(Board __instance, ref SeedType theSeedType)
{
ReplantedTemplatePlugin.Logger.LogInfo($"Changing planted seed from {theSeedType} to Marigold.");
theSeedType = SeedType.Marigold;
}
}
[HarmonyPatch(typeof(Board), nameof(Board.AddPlant))]- This attribute defines what class (eg. Board) and the name of a method (eg. AddPlant) to patch.internal static void Prefix- The method namePrefixmeans this patch will execute before the actual method. You can usePostfixto run code after.Board __instance, ref SeedType theSeedType- Defining an__instanceparameter provides access to the instance of the class. You can also include any parameters of the original method. In the case of the example,theSeedTypeis prefixed with therefkeyword to modify it before the plant is placed.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|