-
-
Notifications
You must be signed in to change notification settings - Fork 7
4. PolyScripts
PolyScripts provide a powerful way to extend The Battle of Polytopia through direct code modification at runtime. They are compiled .NET class libraries (DLLs) that PolyMod loads alongside your mod.
PolyScripts rely on HarmonyX for non-destructive method patching. This allows your mod to modify the game's behavior without directly altering the base game files.
Tip
We have official PolyScript Template which you can check out!
Each PolyScript must have a public static void Load(ManualLogSource logger) method. This serves as the entry point for your PolyScript. PolyMod will automatically discover and execute this method when your mod is loaded.
using BepInEx.Logging;
namespace MyCoolMod
{
public static class MyCoolScript
{
public static void Load(ManualLogSource logger)
{
logger.LogMessage("PolyScript loaded!");
// Your code here! Use HarmonyX to patch game methods, etc.
}
}
}
Create a C# Class Library Project: Use Visual Studio or a compatible IDE to create a new .NET 6.0 Class Library project.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RestoreAdditionalProjectSources>
https://api.nuget.org/v3/index.json;
https://nuget.bepinex.dev/v3/index.json;
https://nuget.samboy.dev/v3/index.json;
https://polymod.dev/nuget/v3/index.json;
</RestoreAdditionalProjectSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PolyMod" Version="*" />
</ItemGroup>
</Project>
Run
dotnet build
This will generate a .dll file.
Copy the compiled .dll file into your mod's root directory (the same directory as your manifest.json
file).
Utilize the ManualLogSource
logger to output debugging information to the BepInEx console. This is critical for identifying issues in your code.