You are viewing a potentially older version of this package. View all versions.
Vibecodeguy-PickupShareApi-1.0.0 icon

PickupShareApi

Library. Lets a loot-sharing mod publish which players have already collected which drop, so another mod can move that drop without the lobby losing track. Does nothing on its own.

Date uploaded 5 hours ago
Version 1.0.0
Download link Vibecodeguy-PickupShareApi-1.0.0.zip
Downloads 38
Dependency string Vibecodeguy-PickupShareApi-1.0.0

This mod requires the following mods to function

bbepis-BepInExPack-5.4.2121 icon
bbepis-BepInExPack

Unified BepInEx all-in-one modding pack - plugin framework, detour library

Preferred version: 5.4.2121

README

PickupShareApi

A library. Installing it on its own does nothing — something else has to use it.

It solves one specific problem: Risk of Rain 2 never synchronises the position of a spawned pickup. CharacterNetworkTransform only ever rides on characters, and a drop's position reaches other players exactly once, inside its spawn message. So a mod that wants to move a drop cannot move it — it has to destroy it and spawn a replacement.

That is fine, until a loot-sharing mod is also installed. Those track drops by instance id, and the replacement gets a new one. A drop that half the lobby had already collected comes back looking untouched, and everyone gets a second copy.

This library is the hand-off between the two.

For a mod that tracks drops

Implement IPickupStateProvider and register in Awake:

[BepInDependency("com.majai.pickupshareapi", BepInDependency.DependencyFlags.HardDependency)]
public class MyLootPlugin : BaseUnityPlugin
{
    private readonly MyStateProvider _provider = new MyStateProvider();

    public void Awake()    => PickupShareApi.RegisterProvider(_provider);
    public void OnDestroy() => PickupShareApi.UnregisterProvider(_provider);
}

One provider at a time. Registering a second replaces the first and logs loudly about it, because two mods tracking the same drops would contradict each other.

For a mod that moves drops

Call the static forwarders. Spawn the replacement before destroying the original — Unity is free to hand the freed instance id straight back out, and a replacement that inherited the old id would be matched against the very record you are moving off it.

var replacement = GenericPickupController.CreatePickup(in info);
PickupShareApi.TransferOrbState(original.GetInstanceID(), replacement.GetInstanceID());
NetworkServer.Destroy(original.gameObject);

Every call is safe with no provider registered — the transfers return false, the queries return false, the forgets do nothing. That is the correct answer for a vanilla run, where a drop is either untouched or already gone. So a consumer does not need to know whether a loot-sharing mod is installed, and does not need to depend on one.

PickupShareApi.HasProvider is there if you want to check anyway. Check it at the point of use rather than at load — load order is not guaranteed to favour you.

Also included

PickupClassifier.IsCommandCube(picker)PickupPickerController also drives the Scrapper, 3D printers, Meal Prep, the Hoard, the Solus vendor, Lemurian eggs, Delusion and Rebirth. Those take an item from a player rather than handing one out, and treating one as a Command cube breaks it badly. Fails to false when it cannot tell.

PickupClassifier.IsRuntimeSpawned(component) — whether an object was dropped during the run or shipped with the scene. Only a runtime object can be destroyed and respawned.

API version

PickupShareApi.ApiVersion is 1. It is bumped only when an existing member changes meaning or disappears; new members leave it alone.


ภาษาไทย

เป็น library ล้วน ลงเฉยๆ ไม่ทำอะไรเลย ต้องมี mod อื่นเรียกใช้

แก้ปัญหาเดียว: RoR2 ไม่ sync ตำแหน่งของ pickup ที่ spawn แล้ว ตำแหน่งถูกส่งครั้งเดียว ตอน spawn เท่านั้น mod ที่อยากย้าย orb เลยย้ายตรงๆ ไม่ได้ ต้องทำลายของเดิมแล้ว spawn ตัวใหม่

ปัญหาคือ mod แชร์ของจำ orb ด้วย instance id ซึ่งตัวใหม่ได้ id ใหม่ orb ที่ครึ่งห้องเก็บไปแล้ว จะกลับมาดูเหมือนยังไม่มีใครแตะ แล้วทุกคนเก็บซ้ำได้ library ตัวนี้คือสะพานส่งต่อสถานะระหว่างสองฝั่ง

  • ฝั่งที่เก็บสถานะ implement IPickupStateProvider แล้ว RegisterProvider ตอน Awake
  • ฝั่งที่ย้าย orb เรียก PickupShareApi.TransferOrbState(oldId, newId)spawn ตัวใหม่ก่อน ทำลายตัวเก่าทีหลังเสมอ เพราะ Unity คืน instance id มาใช้ซ้ำได้
  • ถ้าไม่มีใคร register ทุก call ปลอดภัยหมด (คืน false / ไม่ทำอะไร) ซึ่งถูกต้องสำหรับ run vanilla

CHANGELOG

Changelog

1.0.0

  • First release. Contract version 1.
  • IPickupStateProvider / PickupShareApi — a loot-sharing mod registers as the provider, and any other mod can hand a drop's collection record from a pickup being destroyed onto its replacement. Safe to call with no provider registered.
  • PickupClassifier — tells an Artifact of Command cube apart from the Scrapper, printers, Meal Prep, the Hoard, the Solus vendor, Lemurian eggs, Delusion and Rebirth, which all run on the same component but take items rather than give them.