Skip to content

Commit

Permalink
Added compat for Hospitality: Casino and Hospitality: Vending machines (
Browse files Browse the repository at this point in the history
#411)

* Added compat for Hospitality: Casino

* Added compat for Hospitality: Vending machines
  • Loading branch information
SokyranTheDragon authored Jan 8, 2024
1 parent 754a0bb commit 821501e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Source/Mods/HospitalityCasino.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using HarmonyLib;
using Multiplayer.API;
using Verse;

namespace Multiplayer.Compat
{
/// <summary>
/// Hospitality: Casino by Adamas
/// </summary>
/// <see href="https://github.com/tomvd/HospitalityCasino"/>
/// <see href="https://steamcommunity.com/sharedfiles/filedetails/?id=2939292644"/>
[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<object>()));
}

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");
}
}
}
16 changes: 16 additions & 0 deletions Source/Mods/HospitalityVendingMachines.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Verse;

namespace Multiplayer.Compat
{
/// <summary>
/// Hospitality: Vending machines by Adamas
/// </summary>
/// <see href="https://github.com/tomvd/VendingMachines"/>
/// <see href="https://steamcommunity.com/sharedfiles/filedetails/?id=3014885065"/>
[MpCompatFor("Adamas.VendingMachines")]
public class HospitalityVendingMachines
{
public HospitalityVendingMachines(ModContentPack mod)
=> HospitalityCasino.InitializeGizmos("VendingMachines");
}
}

0 comments on commit 821501e

Please sign in to comment.