using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BoomboxSyncFix.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BoomboxSyncFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A mod to fix the base game bug of the Boombox not being synced between users.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+71645702ebc3ea437c29afaa8432d4398a219be3")]
[assembly: AssemblyProduct("BoomboxSyncFix")]
[assembly: AssemblyTitle("BoomboxSyncFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BoomboxSyncFix
{
[BepInPlugin("BoomboxSyncFix", "BoomboxSyncFix", "1.1.0")]
public class BoomboxSyncFixPlugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("BoomboxSyncFix");
public static BoomboxSyncFixPlugin Instance;
internal ManualLogSource logger;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
logger = Logger.CreateLogSource("BoomboxSyncFix");
logger.LogInfo((object)"Plugin BoomboxSyncFix has loaded!");
harmony.PatchAll(typeof(BoomboxSyncFixPlugin));
harmony.PatchAll(typeof(BoomboxItemStartMusicPatch));
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "BoomboxSyncFix";
public const string PLUGIN_NAME = "BoomboxSyncFix";
public const string PLUGIN_VERSION = "1.1.0";
}
}
namespace BoomboxSyncFix.Patches
{
[HarmonyPatch]
internal class BoomboxItemStartMusicPatch
{
private static Dictionary<BoomboxItem, bool> seedSyncDictionary = new Dictionary<BoomboxItem, bool>();
private static FieldInfo playersManagerField = AccessTools.Field(typeof(BoomboxItem), "playersManager");
[HarmonyPatch(typeof(BoomboxItem), "StartMusic")]
[HarmonyPrefix]
public static void StartMusicPatch(BoomboxItem __instance)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
StartOfRound val = (StartOfRound)playersManagerField.GetValue(__instance);
if ((!seedSyncDictionary.TryGetValue(__instance, out var value) || !value) && (Object)(object)val != (Object)null && val.randomMapSeed > 0)
{
int num = val.randomMapSeed - 10;
__instance.musicRandomizer = new Random(num);
BoomboxSyncFixPlugin.Instance.logger.LogInfo((object)$"Musicrandomizer variable has been synced with seed: {num}");
seedSyncDictionary[__instance] = true;
}
}
[HarmonyPatch(typeof(StartOfRound), "OnPlayerConnectedClientRpc")]
[HarmonyPrefix]
public static void OnPlayerConnectedPatch(StartOfRound __instance)
{
BoomboxSyncFixPlugin.Instance.logger.LogInfo((object)"Another client joined -- forcing everyone to reintialize musicRandomizer.");
forceReinitialize(seedSyncDictionary);
}
[HarmonyPatch(typeof(StartOfRound), "openingDoorsSequence")]
[HarmonyPrefix]
public static void OpeningDoorsSequencePatch(StartOfRound __instance)
{
BoomboxSyncFixPlugin.Instance.logger.LogInfo((object)"Round has loaded for all -- forcing everyone to reinitialize musicRandomizer.");
forceReinitialize(seedSyncDictionary);
}
private static void forceReinitialize(Dictionary<BoomboxItem, bool> seedSyncDictionary)
{
foreach (BoomboxItem item in seedSyncDictionary.Keys.ToList())
{
seedSyncDictionary[item] = false;
}
}
}
}