Skip to content

4. PolyScripts

Lubyanoy Ivan edited this page May 28, 2025 · 4 revisions

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!

Entry Point

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.
        }
    }
}

Building a PolyScript

Create a C# Class Library Project: Use Visual Studio or a compatible IDE to create a new .NET 6.0 Class Library project.

Project configuration

<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>

Compile Your 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.

Clone this wiki locally