Skip to content

0: Creating a mod

Miron Alexandru edited this page Dec 24, 2021 · 1 revision

The Mod class

The Mod class is where most of the juicy mod logic can be defined.

To create a mod, you need to create a public subclass of Mod somewhere within your assembly. GrindScript will automatically find it during load.

using System;
using System.Collections.Generic;
using System.IO;
using Quests;
using SoG.Modding;
using SoG.Modding.Content;
using SoG.Modding.Utils;
using SoG.Modding.Extensions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MyCoolNamespace
{
    public class HelloWorld: Mod
    {
        public override string NameID => "AUniqueNameIDHere";

        public override Version ModVersion => Version("1.2.3.4");

        public override void Load()
        {
            // Create some mod entries
            // Retrieve other mods
            // Load assets

            // AssetPath is the folder in which you should put your assets.
            // It points to $"Content/ModContent/{NameID}/" (check SoG's Steam folder!)

            ItemEntry item = CreateItem("HelloWorldShield");
            item.Name = "Hello World!";
            item.Description = "This is a dope modded shield!";
            item.EquipType = EquipmentType.Shield;
            item.IconPath = this.AssetPath + "Items/ModShield/Icon";
            item.EquipResourcePath = this.AssetPath + "Items/ModShield";
            item.ShldHP = 350;

            Logger.Info("Hello from mod HelloWorld!");
        }

        public override void PostLoad()
        {
            // In here goes anything that can't be done during Load
            // For instance, Audio IDs are only available once Load() exits

            Logger.Info("Hello from PostLoad!");
        }

        public override void Unload()
        {
            Logger.Info("Unloadin'!");
        }

        public override void OnPlayerDamaged(PlayerView view, ref int damage, ref byte type)
        {
            Logger.Info($"Player got hurt for {damage} damage!");
        }

        public override void OnPlayerKilled(PlayerView player)
        {
            Logger.Info("get rekt, LOL");
        }

        public override void SaveArcadeData(BinaryWriter stream)
        {
            stream.Write("<Arcade Data here or sumthin'>");
        }

        public override void LoadArcadeData(BinaryReader stream, Version saveVersion)
        {
            Logger.Info("Arcade mod version: " + saveVersion.ToString());
            try
            {
                Logger.Info("Arcade data: " + stream.ReadString());
            }
            catch
            {
                Logger.Info("No arcade data");
            }
        }
    }
}

Mod class members

Mod has some special members you can access:

  • ModVersion - the version of your mod. This is used for saving, multiplayer, and dependency checking
  • AssetPath - the default asset path for your mod
  • DisableObjectCreation - returns false by default. You can override it to return true if you want
    • Mods that have this set to true can't create entries, but they also won't appear in mod saves
    • They also act as local-only mods when in multiplayer. Think of this as Optifine from Minecraft
  • Logger - a default logger object. You can use its methods to send text to the console window
  • Content - an XNA ContentManager initialized using the game's "Content/" folder

Clone this wiki locally