R.E.P.O.

Details

Last Updated
6 days ago
First Uploaded
6 days ago
Downloads
4.4K
Likes
0
Size
123KB
Dependency string
Kai09TA-REPOUpgradeAPI-1.0.0
Dependants

🇺🇸 REPOUpgradeAPI – Player Upgrade Sync API (Dependency Mod)

This API was originally created for my personal mod projects, but separating it as a standalone module made development easier, so I decided to publish it in case others find it useful.

If you need to reach me, I'm available in the R.E.P.O Modding Server on Discord: https://discord.gg/vPJtKhYAFe


REPOUpgradeAPI is a lightweight framework that provides a clean and safe way to synchronize player upgrades across host and clients. It handles RPC dispatching, synchronization logic, and UI refresh internally, so mods can focus only on calling simple API methods.


🔧 Basic Usage

using REPOUpgradeAPI;

public class ExampleMod : BaseUnityPlugin
{
    void Start()
    {
        // Increase Jump upgrade by +1
        UpgradeAPI.Add(UpgradeType.Jump, 1);

        // Set Sprint upgrade to level 3
        UpgradeAPI.Set(UpgradeType.Sprint, 3);
    }
}

Only UpgradeAPI.Add() and UpgradeAPI.Set() are needed. All networking, syncing, and local UI updates are handled internally.


📂 API Summary

● Add

UpgradeAPI.Add(UpgradeType type, int delta);
UpgradeAPI.Add(string typeName, int delta);
  • UpgradeType … vanilla-like safe enum (Energy, Health, Jump, …)
  • string typeNameStat dictionary name or internal key

● Set

UpgradeAPI.Set(UpgradeType type, int level);
UpgradeAPI.Set(string typeName, int level);

🧩 Type Name / Dictionary Name Support

Besides the enum, REPOUpgradeAPI also supports direct dictionary names from StatsManager:

// Directly touch the underlying StatsManager dictionary:
UpgradeAPI.Add("playerUpgradeHealth", 1);
UpgradeAPI.Add("playerUpgradeStaminaRegen", 1);
UpgradeAPI.Add("playerUpgradeUnstableCore", 1);

Internally, the API:

  1. First tries to treat the string as a full dictionary name (StatsManager.dictionaryOfDictionaries[typeName])
  2. Then falls back to legacy short keys (e.g. "energy", "jump")
  3. Finally, it tries to dynamically map to playerUpgrade* dictionaries

This makes the API compatible with:

  • Vanilla upgrades
  • New upgrades added by game updates
  • Custom upgrades added by other mods (as long as they expose a dictionary)

🧪 Debug / Introspection Helpers

For debugging or exploring new keys, the API can dump upgrade dictionaries:

// Log all playerUpgrade* dictionaries in StatsManager
UpgradeAPI.LogAllUpgradeDictionaries();

// Enumerate dictionary names (e.g. "playerUpgradeHealth", "playerUpgradeUnstableCore", ...)
foreach (var key in UpgradeAPI.ListUpgradeKeys())
    Logger.LogInfo($"Key: {key}");

These names can then be passed directly into UpgradeAPI.Add/Set.


⚙ Internal Features

  • UpgradeNet handles RPC and dispatch
  • UpgradeManager applies local and networked changes
  • RPC registration is done automatically via Harmony (dependency mod)
  • Works in both singleplayer (local-only) and multiplayer (via RPC)
  • Internal architecture is hidden from mod developers – you only call UpgradeAPI


🇯🇵 説明欄(JP)アップデート版

日本語側も同じノリで「基本+拡張」を足した版。


🇯🇵 REPOUpgradeAPI – プレイヤーアップグレード同期 API(前提MOD)

このAPIはもともと私自身のMODプロジェクト向けに作ったものですが、 前提MODとして切り出して公開したほうが扱いやすく、 必要な方にも使いやすいと考え公開しています。

連絡が必要な場合は Discord の R.E.P.O. Modding Server へどうぞ: https://discord.gg/vPJtKhYAFe


REPOUpgradeAPI は、プレイヤーアップグレードを簡単かつ安全に同期できる軽量APIです。 ホスト・クライアント間の同期や RPC、Stats UI の更新などはすべて内部で自動処理されます。 MOD 側は「どのステータスをどれだけ増減させるか」だけ指定すれば OK です。


🔧 使い方(基本)

using REPOUpgradeAPI;

public class ExampleMod : BaseUnityPlugin
{
    void Start()
    {
        // ジャンプレベルを +1
        UpgradeAPI.Add(UpgradeType.Jump, 1);

        // スプリントレベルを 3 に設定
        UpgradeAPI.Set(UpgradeType.Sprint, 3);
    }
}

MOD 開発者側で必要なのは UpgradeAPI.Add / UpgradeAPI.Set の 2 つだけ です。 内部で RPC や同期処理はすべて完了します。


📂 API 一覧

● Add

UpgradeAPI.Add(UpgradeType type, int delta);
UpgradeAPI.Add(string typeName, int delta);
  • UpgradeType … バニラ準拠の安全な enum(Energy, Health, Jump など)
  • string typeNameStatsManager の辞書名 or 内部キー文字列

● Set

UpgradeAPI.Set(UpgradeType type, int level);
UpgradeAPI.Set(string typeName, int level);

🧩 辞書名(StatsManager)での直接操作

enum だけでなく、StatsManager.dictionaryOfDictionaries の辞書名をそのまま指定して操作できます。

// StatsManager 内部の辞書を直接いじる例
UpgradeAPI.Add("playerUpgradeHealth", 1);
UpgradeAPI.Add("playerUpgradeStaminaRegen", 1);
UpgradeAPI.Add("playerUpgradeUnstableCore", 1);

内部では、以下の優先順で解釈されます:

  1. 渡された文字列を 辞書名としてそのまま検索StatsManager.dictionaryOfDictionaries[typeName]
  2. それで見つからなければ、レガシーな短縮キー("energy", "jump" など)にマップ
  3. さらに見つからなければ、playerUpgrade* 系辞書を動的に探索

これにより:

  • バニラのアップグレード
  • ゲームアップデートで追加された新アップグレード
  • 他 MOD が追加した独自アップグレード(辞書を持っていればOK)

を、同じ API から扱える ようになっています。


🧪 デバッグ用ヘルパー

新しく追加されたキーや辞書名を確認したい場合は、ログに一覧を出すこともできます。

// StatsManager 内の playerUpgrade* 辞書を全部ログ出力
UpgradeAPI.LogAllUpgradeDictionaries();

// 辞書名の列挙(例: "playerUpgradeHealth", "playerUpgradeUnstableCore", ...)
foreach (var key in UpgradeAPI.ListUpgradeKeys())
    Logger.LogInfo($"Key: {key}");

ここで出力された 辞書名そのものを UpgradeAPI.Add/Set に渡せば、そのまま操作できます。


⚙ 内部処理(開発者向け)

  • UpgradeNet が RPC を受信・配信
  • UpgradeManager がローカル処理と同期ロジックを実行
  • HarmonyPatch により PunManager に自動でコンポーネントを付与&RPC登録
  • シングルプレイ時はローカルのみ変更、マルチプレイ時は RPC を経由して全員へ同期
  • internal 実装は external から直接触れないように隠蔽 → MOD 側は UpgradeAPI のみを参照すればよい設計

Thunderstore development is made possible with ads. Please consider making an exception to your adblock.
Thunderstore development is made possible with ads. Please consider making an exception to your adblock.
Thunderstore development is made possible with ads. Please consider making an exception to your adblock.