Skip to content

Support using Mod Call

JavidPack edited this page Jun 7, 2023 · 7 revisions

Mod.Call Features

HEROsMod provides Mod.Call functionality to allow modders to integrate with utilize various of the mod. The main feature to integrate with is the permission management system. Modders can add permissions that will be managed automatically in multiplayer. Modders can add buttons to the hotbar menu that allow for easy access to actions dictated by the modder. Modders can also check existing permissions to create logic that will piggyback off of the permissions the user has.

Another integration is adding new categories to the Item Browser, most typically used for adding weapon classes.

In addition, modders can trigger the hotbar to hide itself. Finally, modders can piggy back off of God Mode being active.

Mod.Call allows for mods to communicate with each other and cooperate, more info on Mod.Call can be learned from the tModLoader wiki. This guide will go through each Mod.Call pattern and corresponding arguments in detail below.

Mod.Calls

Current

These Mod.Call patterns are the currently available patterns. These are all available in the latest HEROsMod on 1.3 and 1.4 unless otherwise specified.

AddPermission

"AddPermission", string permissionName, string permissionDisplayName, Action<bool> groupUpdated
Adds a permission to be managed by the permission management system. By default, admin has access to all permissions, server admins will have to give permissions to specific users or groups in the group management menu. The permissionName should be a language agnostic key without spaces. The permissionDisplayName should be the localized text displayed in-game. The groupUpdated callback if provided will be invoked when permissions change. The new permission state of the local user is the bool provided. This should be called during Mod loading, preferably PostSetupContent.

AddSimpleButton

"AddSimpleButton", string permissionName, Asset<Texture2D> texture, Action buttonClickedAction, Action<bool> groupUpdated, Func<string> tooltip
Adds a button to the mod extensions menu. The texture should be 38x38 and have a white outline for the contents to fit the herosmod button style. The buttonClickedAction will be invoked when the button is clicked. groupUpdated will be called when the permission controlling the button is changed, use this to clean up effects that have been toggled if the user loses permissions. tooltip should return the current tooltip to be shown to the user and is called while the button is hovered. This should be called during Mod loading, preferably PostSetupContent.

HasPermission

"HasPermission", int player, string permissionName
(TODO: I think this only works on the server) Checks if the player with the given whoAmI has the permission provided. Useful for checking ModConfig.AcceptClientChanges. The callback in AddPermission might be more suitable to use for client effects, as it will automatically update.

HideHotbar

"HideHotbar"
Collapses the hotbar, used in CheatSheet to hide the HEROsMod hotbar when the CheatSheet hotbar is expanded.

AddItemCategory

"AddItemCategory", string name, string parent, Predicate<Item> belongs
Adds an item category with the given name displayed in the Item Browser tool. If parent is null or empty, the category will be added to the main listing in the Item Browser. If Parent matches an existing category, this category will be a sub-category. Existing categories can be found on ItemBrowser.cs. belongs should return true if the provided Item belongs to the category. This is useful for adding weapon classes.

RegisterGodModeCallback

"RegisterGodModeCallback", Action<bool> GodModeCallback (This Call added in v0.3.9 for 1.3 and v0.4.5 for 1.4)
Registers a callback to be called each update. The callback will provide a bool representing the current state of the local players GodMode. You'll want to store the result, then use that result in your logic to max out other stats desirable when in GodMode. You'll also want to set the stored state back to false in Mod.Unload in the case that HEROsMod is unloaded but your mod isn't.

Weak Reference Approach

Yet to be implemented.

Examples

Adding a Permission and Button

The following examples can be used as guides:

  • Shorter Respawn Time - A rather straightforward example adding 2 permissions and a button to control ModConfig and instant respawn features.
  • Begone, Evil! (Disable Evil Biome Spread) - Adds a permission and button to control the spread of corruption toggle
  • Antisocial - Adds a permission that is used to control who can update a ServerSide scoped ModConfig, limiting who can change how many social slots will give stat boosts
  • Cheat Sheet - Adds a bunch of permissions and makes all the mod tools dependent on the permission system

AddItemCategory

  • Thorium uses this to add a "Bard" sub-category for the Bard weapon class nested in the "Weapons" category:
HEROsMod.Call("AddItemCategory", "Bard", "Weapons",
(Predicate<Item>)((Item item) =>
{
   // This code would need to be adapted to however you identify your weapon classes
   return item.damage > 0 && item.modItem is BardItem;
}));

RegisterGodModeCallback

  • Thorium uses this to max out some class specific resources
private static void DoHEROsModSupport()
{
    Mod HEROsMod = ModLoader.GetMod("HEROsMod"); // 1.4 code would use TryGetMod instead
    if (HEROsMod != null && HEROsMod.Version >= new Version(0, 3, 9)) // This Call added in v0.3.9 for 1.3 and v0.4.5 for 1.4
    {
        HEROsMod.Call("RegisterGodModeCallback", (Action<bool>)HEROsModGodMode);
    }
}

private static void HEROsModGodMode(bool enabled)
{
    ResourcePlayer.godMode = enabled;
}

public class ResourcePlayer : ModPlayer
{
    public static bool godMode; //Set to false in unload

    public const int defaultResourceMax = 10;

    public int resourceMax = defaultResourceMax;
    public int resource = defaultResourceMax;

    public override void PreUpdate()
    {
        if (godMode)
        {
            resource = resourceMax;
        }
    }
}