You are viewing a potentially older version of this package. View all versions.
Zehs-REPOLib-2.0.0 icon

REPOLib

Library for adding content to R.E.P.O.

Date uploaded 2 weeks ago
Version 2.0.0
Download link Zehs-REPOLib-2.0.0.zip
Downloads 575311
Dependency string Zehs-REPOLib-2.0.0

This mod requires the following mods to function

BepInEx-BepInExPack-5.4.2100 icon
BepInEx-BepInExPack

BepInEx pack for Mono Unity games. Preconfigured and ready to use.

Preferred version: 5.4.2100

README

REPOLib

GitHub Thunderstore Version Thunderstore Downloads NuGet Version

Library for adding content to R.E.P.O.

Features

  • Registering network prefabs.
  • Registering valuables.
  • Registering items.
  • Registering enemies.
  • Registering levels.
  • ResourcesHelper to help get network prefab IDs.
  • Method to spawn network prefabs. (Which works in both multiplayer and singleplayer)
  • Methods to get valuables and spawn valuables.
  • Methods to get items and spawn items.
  • Methods to get enemies and spawn enemies.
  • Registering custom chat /commands
    • Built-in dev mode commands: Spawn Valuable, Spawn Item, Spawn Enemy
  • Fixing audio mixer groups.
  • Making networked events.
  • Registering features without code using the REPOLib-Sdk.

Usage

Click to expand

Reference REPOLib in your project's .csproj file.

<ItemGroup>
  <PackageReference Include="Zehs.REPOLib" Version="1.*" />
</ItemGroup>

Add REPOLib as a dependency to your plugin class.

[BepInDependency(REPOLib.MyPluginInfo.PLUGIN_GUID, BepInDependency.DependencyFlags.HardDependency)]
[BepInPlugin("You.YourMod", "YourMod", "1.0.0")]
[BepInDependency(REPOLib.MyPluginInfo.PLUGIN_GUID, BepInDependency.DependencyFlags.HardDependency)]
public class YourMod : BaseUnityPlugin
{
    // ...
}
Network prefabs

Registering a network prefab.

[BepInPlugin("You.YourMod", "YourMod", "1.0.0")]
[BepInDependency(REPOLib.MyPluginInfo.PLUGIN_GUID, BepInDependency.DependencyFlags.HardDependency)]
public class YourMod : BaseUnityPlugin
{
    // ...

    private void Awake()
    {
        // ...

        AssetBundle assetBundle = AssetBundle.LoadFromFile("your_assetbundle_file_path");
        GameObject prefab = assetBundle.LoadAsset<GameObject>("your_network_prefab");

        // Register a network prefab.
        REPOLib.Modules.NetworkPrefabs.RegisterNetworkPrefab(prefab);
    }
}
Valuables

Registering a valuable.

[BepInPlugin("You.YourMod", "YourMod", "1.0.0")]
[BepInDependency(REPOLib.MyPluginInfo.PLUGIN_GUID, BepInDependency.DependencyFlags.HardDependency)]
public class YourMod : BaseUnityPlugin
{
    // ...

    private void Awake()
    {
        // ...

        AssetBundle assetBundle = AssetBundle.LoadFromFile("your_assetbundle_file_path");
        GameObject prefab = assetBundle.LoadAsset<GameObject>("your_valuable_prefab");

        // Register a valuable.
        REPOLib.Modules.Valuables.RegisterValuable(prefab);
    }
}

Registering a valuable to a specific level.

[BepInPlugin("You.YourMod", "YourMod", "1.0.0")]
[BepInDependency(REPOLib.MyPluginInfo.PLUGIN_GUID, BepInDependency.DependencyFlags.HardDependency)]
public class YourMod : BaseUnityPlugin
{
    // ...

    private void Awake()
    {
        // ...

        AssetBundle assetBundle = AssetBundle.LoadFromFile("your_assetbundle_file_path");
        GameObject prefab = assetBundle.LoadAsset<GameObject>("your_valuable_prefab");

        // Valuables Presets:
        // "Valuables - Generic"
        // "Valuables - Wizard"
        // "Valuables - Manor"
        // "Valuables - Arctic"

        List<string> presets = new List<string> { "Valuables - Wizard" };

        // Register a valuable.
        REPOLib.Modules.Valuables.RegisterValuable(prefab, presets);
    }
}
Items

Registering an item.

[BepInPlugin("You.YourMod", "YourMod", "1.0.0")]
[BepInDependency(REPOLib.MyPluginInfo.PLUGIN_GUID, BepInDependency.DependencyFlags.HardDependency)]
public class YourMod : BaseUnityPlugin
{
    // ...

    private void Awake()
    {
        // ...

        AssetBundle assetBundle = AssetBundle.LoadFromFile("your_assetbundle_file_path");
        Item item = assetBundle.LoadAsset<Item>("your_item");

        // Register an item.
        REPOLib.Modules.Items.RegisterItem(item);
    }
}
Enemies

Registering an enemy.

[BepInPlugin("You.YourMod", "YourMod", "1.0.0")]
[BepInDependency(REPOLib.MyPluginInfo.PLUGIN_GUID, BepInDependency.DependencyFlags.HardDependency)]
public class YourMod : BaseUnityPlugin
{
    // ...

    private void Awake()
    {
        // ...

        AssetBundle assetBundle = AssetBundle.LoadFromFile("your_assetbundle_file_path");
        EnemySetup enemy = assetBundle.LoadAsset<EnemySetup>("your_enemy_setup");

        // Register an enemy.
        REPOLib.Modules.Enemies.RegisterEnemy(enemy);
    }
}
Levels

Registering a level.

[BepInPlugin("You.YourMod", "YourMod", "1.0.0")]
[BepInDependency(REPOLib.MyPluginInfo.PLUGIN_GUID, BepInDependency.DependencyFlags.HardDependency)]
public class YourMod : BaseUnityPlugin
{
    // ...

    private void Awake()
    {
        // ...

        AssetBundle assetBundle = AssetBundle.LoadFromFile("your_assetbundle_file_path");
        Level level = assetBundle.LoadAsset<Level>("your_level");

        // Register a level.
        REPOLib.Modules.Levels.RegisterLevel(level);
    }
}
Chat commands

Registering a chat /command.

using REPOLib.Commands;

public static class YourCommand
{
    // ...

    [CommandInitializer]
    public static void Initialize()
    {
        // Perform any setup or caching
    }

    [CommandExecution(
        "Your Command Name",
        "Description of what the command does and how to use it.",
        enabledByDefault: true,
        requiresDeveloperMode: false
        )]
    [CommandAlias("yourcommand")]
    [CommandAlias("yourcmd")]
    public static void Execute(string args)
    {
        // ...
    }
}
Fixing audio mixer groups

Fixing audio mixer groups on a prefab and their children.

[BepInPlugin("You.YourMod", "YourMod", "1.0.0")]
[BepInDependency(REPOLib.MyPluginInfo.PLUGIN_GUID, BepInDependency.DependencyFlags.HardDependency)]
public class YourMod : BaseUnityPlugin
{
    // ...

    private void Awake()
    {
        // ...

        AssetBundle assetBundle = AssetBundle.LoadFromFile("your_assetbundle_file_path");
        GameObject prefab = assetBundle.LoadAsset<GameObject>("your_prefab");

        // Fix the audio mixer groups on a prefab and their children.
        REPOLib.Modules.Utilities.FixAudioMixerGroups(prefab);
    }
}

Registering any features will automatically fix their prefabs audio mixer groups.

Networked events

Creating a networked event.

using ExitGames.Client.Photon;
using REPOLib.Modules;

[BepInPlugin("You.YourMod", "YourMod", "1.0.0")]
[BepInDependency(REPOLib.MyPluginInfo.PLUGIN_GUID, BepInDependency.DependencyFlags.HardDependency)]
public class YourMod : BaseUnityPlugin
{
    // ...

    public static NetworkedEvent ExampleEvent;

    private void Awake()
    {
        // ...

        ExampleEvent = new NetworkedEvent("My Example Event", HandleExampleEvent);
    }

    // EventData is from ExitGames.Client.Photon
    private static void HandleExampleEvent(EventData eventData)
    {
        string message = (string)eventData.CustomData;
        Debug.Log($"Received message from example event: {message}");
    }
}

Calling a networked event.

// The data you are sending through your networked event.
string message = "Hello World!";

// Call networked event on everyone. (This works in singleplayer)
ExampleEvent.RaiseEvent(message, REPOLib.Modules.NetworkingEvents.RaiseAll, SendOptions.SendReliable);

// Call networked event on everyone but yourself. (This works in singleplayer)
ExampleEvent.RaiseEvent(message, REPOLib.Modules.NetworkingEvents.RaiseOthers, SendOptions.SendReliable);

// Call networked event on the master client. (This works in singleplayer)
ExampleEvent.RaiseEvent(message, REPOLib.Modules.NetworkingEvents.RaiseMasterClient, SendOptions.SendReliable);

[!NOTE] Registering features (Valuables, Items, Enemies, etc...) automatically registers their prefabs as a network prefab.

[!NOTE] Registering features (Valuables, Items, Enemies, etc...) automatically fixes their prefabs audio mixer groups.

[!TIP] You can enable extended logging in the config settings to get more info about features being registered, custom network prefabs being spawned, and more.

Chat Commands

[!IMPORTANT] You must enable DeveloperMode in the config settings to use developer mode commands.

Chat commands currently only work in multiplayer since you need access to the in-game chat to use commands.

This mod comes with a few built-in chat commands:

1. Spawn Valuable /spawnvaluable <name>

This command will spawn a valuable in front of you.
Replace <name> with the name of the valuable prefab.
Names are not case-sensitive.
Example usage: /spawnvaluable diamond
This command has multiple aliases: /spawnval, /sv
This command requires developer mode to be enabled.
This command is host-only!

2. Spawn Item /spawnitem <name>

This command will spawn an item in front of you.
Replace <name> with the name of the item or item prefab.
Names are not case-sensitive.
Example usage: /spawnitem gun
This command has one alias: /si
This command requires developer mode to be enabled.
This command is host-only!

3. Spawn Enemy /spawnenemy <name>

This command will spawn an enemy on top of you after a few seconds.
Replace <name> with the name of the enemy or enemy prefab.
Names are not case-sensitive.
Example usage: /spawnenemy huntsman
This command has one alias: /se
This command requires developer mode to be enabled.
This command is host-only!

[!TIP] Commands can be enabled/disabled in the config settings.

If you are a mod developer and want to add your own custom chat commands to your mod, check the Usage > Chat commands section.

Contribute

Anyone is free to contribute.

https://github.com/ZehsTeam/REPOLib

To set up the project, copy the REPOLib.csproj.user.example file to REPOLib.csproj.user. If needed, change the settings found in that file.

Bundle Loading

REPOLib loads any bundles under the plugins folder with the .repobundle extension. These bundles are then scanned for Mod and Content assets, which allows codeless registration of features in tandem with REPOLib-Sdk.

Bundles are loaded asynchronously, which enables other mods to do their initialization while files are being read from disk, which in turn leads to shorter startup times. Hence, using this system is the preferred way to use this library, even if you're already writing your own plugin code.

[!WARNING] If you're writing a mod that interacts with modded content, remember that all REPOLib content may not be registered by game start because of async bundle loading.

To work around this, either do your initialization at a later stage (for example when joining a lobby) or subscribe to the REPOLib.BundleLoader.OnAllBundlesLoaded event (however this requires a dependency on REPOLib).

If you want more control over the loading of bundles, you can use the public APIs from REPOLib.BundleLoader.

using REPOLib;
using UnityEngine;
using System.Collections;

BundleLoader.LoadBundle(
    "/path/to/bundle",
    // Callback when the bundle has finished loading, which is guaranteed to happen before the player joins a lobby.
    // Note that this needs to return an IEnumerator.
    OnBundleLoaded,
    // If this is true, REPOLib will load and register all Content assets from the bundle, as if it was loaded automatically.
    // Defaults to false.
    loadContents: true
);

IEnumerator OnBundleLoaded(AssetBundle bundle) {
    Debug.Log("My bundle was loaded!");
    
    // Do some more (asynchronous) setup logic,
    // or, if loadContents is false, load and register your content
    
    yield break;
}

[!IMPORTANT] If you are loading bundles manually, do not give them the .repobundle extension, as that will make them load twice.

Developer Contact

Report bugs, suggest features, or provide feedback:

Discord Server Forum Post
R.E.P.O. Modding Server #released-mods REPOLib

kofi

CHANGELOG

v2.0.1

  • Fixed BundleLoader causing an infinite loading screen when loading invalid content.
  • Moved documentation to the R.E.P.O. Modding Wiki.
  • Added XML documentation for most public API classes, methods, and properties. (#40)

v2.0.0

  • Added support for registering levels. (#32)
  • Added new async bundle loading system. (#15)
  • Added more safety checks when instantiating a network prefab.
  • Changed most of the extended logs to use the Debug log level, instead of Info. (#33)
  • Split the DeveloperMode config option into two ones:
    • DeveloperMode enables developer-only chat commands.
    • VanillaDeveloperMode enables the vanilla developer keyboard shortcuts.
  • Fixed the SpawnEnemy method ignoring the spawnDespawned parameter always spawning enemies not despawned.
  • Breaking changes:
    • Changed the signature of BundleLoader.LoadBundle (due to async loading).
    • Moved GenericValuablePresetName and ValuablePresets from Modules.Valuables to Modules.ValuablePresets.

v1.5.0

  • Added partial name matching to all spawn commands. (#17)
  • Added a new developer mode command Spawn Enemy.
    • Usage: /spawnenemy <name> (/se for short)
    • You must enable DeveloperMode mode in the config settings to use developer mode commands.
    • Note: developer mode commands are host-only!
  • Added methods/properties to the Valuables module.
    • SpawnValuable - Spawn a valuable.
    • AllValuables and GetValuables - Returns a list of all the valuables registered in the game. (Vanilla and Modded)
    • GetValuableByName and TryGetValuableByName - Returns a valuable prefab that equals the name.
    • GetValuableThatContainsName and TryGetValuableThatContainsName - Returns a valuable prefab that contains the name.
  • Added methods/properties to the Items module.
    • SpawnItem - Spawn an item.
    • AllItems and GetItems - Returns a list of all the items registered in the game. (Vanilla and Modded)
    • GetItemByName and TryGetItemByName - Returns an item that equals the name.
    • GetItemThatContainsName and TryGetItemThatContainsName - Returns an item that contains the name.
  • Added methods/properties to the Enemies module.
    • SpawnEnemy - Spawn an enemy.
    • AllEnemies and GetEnemies - Returns a list of all the enemies registered in the game. (Vanilla and Modded)
    • GetEnemyByName and TryGetEnemyByName - Returns an EnemySetup that equals the name.
    • GetEnemyThatContainsName and TryGetEnemyThatContainsName - Returns an EnemySetup that contains the name.
  • Added a method to the NetworkPrefabs module.
    • SpawnNetworkPrefab - Spawn a network prefab by providing a prefab ID.
      • This method works in both multiplayer and singleplayer.
      • Note: this will only spawn registered network prefabs.
  • You can now toggle developer mode using the REPOConfig mod.
  • You can now register enemy groups if you have already registered that enemy previously.

v1.4.2

  • Removed changelog field from the Mod asset. (#14)

REPOLib-Sdk v1.2.0

  • Added an Extra Files field to the Mod asset. (REPOLib-Sdk#7)
    • You can put your changelog file here.

v1.4.1

v1.4.0

v1.3.1

  • Added changelog field to the Mod asset. (#9)

v1.3.0

  • Added more validation when registering features to prevent conflicts and errors.
  • Added support for registering custom chat /commands. (#5)
    • Added some built-in developer mode commands: /spawnvaluable <name>, /spawnitem <name> (/sv and /si for short)
      • You must enable DeveloperMode mode in the config settings to use developer mode commands.
      • Note: developer mode commands are host-only!

v1.2.0

  • Added support for registering items.
  • Added support for registering enemies. (#2)
  • Added support for registering features without code using the REPOLib-Sdk. (#3)
  • Features now register network prefabs to have their prefabId match the Resources folder structure.
  • You can no longer manually pass in a prefabId when registering a valuable.

v1.1.0

  • You can now register valuables to specific levels. (#1)
    • Valuables Presets: Valuables - Generic, Valuables - Wizard, Valuables - Manor, Valuables - Arctic

v1.0.2

v1.0.1

  • Updated mod icon.

v1.0.0

  • Initial release.