From 821501ecbe4e2a8963aa0b26ccb5e15f59575c39 Mon Sep 17 00:00:00 2001 From: SokyranTheDragon <36712560+SokyranTheDragon@users.noreply.github.com> Date: Mon, 8 Jan 2024 19:03:16 +0100 Subject: [PATCH] Added compat for Hospitality: Casino and Hospitality: Vending machines (#411) * Added compat for Hospitality: Casino * Added compat for Hospitality: Vending machines --- Source/Mods/HospitalityCasino.cs | 44 +++++++++++++++++++++++ Source/Mods/HospitalityVendingMachines.cs | 16 +++++++++ 2 files changed, 60 insertions(+) create mode 100644 Source/Mods/HospitalityCasino.cs create mode 100644 Source/Mods/HospitalityVendingMachines.cs diff --git a/Source/Mods/HospitalityCasino.cs b/Source/Mods/HospitalityCasino.cs new file mode 100644 index 0000000..44257b4 --- /dev/null +++ b/Source/Mods/HospitalityCasino.cs @@ -0,0 +1,44 @@ +using System; +using HarmonyLib; +using Multiplayer.API; +using Verse; + +namespace Multiplayer.Compat +{ + /// + /// Hospitality: Casino by Adamas + /// + /// + /// + [MpCompatFor("Adamas.HospitalityCasino")] + public class HospitalityCasino + { + public HospitalityCasino(ModContentPack mod) + { + InitializeGizmos("HospitalityCasino"); + + // The method is called from SlotMachineComp.CompTick and calls ThingMaker.MakeThing. + // The method itself is only called once (sets initialized to true and skips execution + // if true). Due to the method making a thing during ticking, but max only once per + // game launch, it'll cause issues with MP when someone joins a game with already built + // slot machines. Making the thing will use up thing IDs in Thing.PostMake (and may + // potentially result in RNG calls, but doesn't seem like it's the case this time). + // Anyway, just ensure the textures are initialized on game launch instead of when + // playing the game to prevent issues (seems like making them during startup is safe). + LongEventHandler.ExecuteWhenFinished( + () => AccessTools.DeclaredMethod("HospitalityCasino.HospitalityCasinoMod:InitialiseTextures") + .Invoke(null, Array.Empty())); + } + + public static void InitializeGizmos(string targetNamespace) + { + var type = AccessTools.TypeByName($"{targetNamespace}.CompVendingMachine"); + + // Gizmos + MP.RegisterSyncMethod(type, "ToggleActive"); + MP.RegisterSyncMethod(type, "SetPricing"); + // The setter is never used, but may as well sync it in case it's ever used in the future. + MP.RegisterSyncMethod(type, "Pricing"); + } + } +} \ No newline at end of file diff --git a/Source/Mods/HospitalityVendingMachines.cs b/Source/Mods/HospitalityVendingMachines.cs new file mode 100644 index 0000000..729ae11 --- /dev/null +++ b/Source/Mods/HospitalityVendingMachines.cs @@ -0,0 +1,16 @@ +using Verse; + +namespace Multiplayer.Compat +{ + /// + /// Hospitality: Vending machines by Adamas + /// + /// + /// + [MpCompatFor("Adamas.VendingMachines")] + public class HospitalityVendingMachines + { + public HospitalityVendingMachines(ModContentPack mod) + => HospitalityCasino.InitializeGizmos("VendingMachines"); + } +} \ No newline at end of file