using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using EasyTextEffects.Editor.MyBoxCopy.Extensions;
using GameNetcodeStuff;
using HarmonyLib;
using LethalNetworkAPI;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LoveCompany")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LoveCompany")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("24200df4-b26b-4577-8900-6d6e22e77868")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 LoveCompany
{
public class CoupleSync : NetworkBehaviour
{
public struct CoupleData : INetworkSerializable
{
public FixedString64Bytes A;
public FixedString64Bytes B;
public unsafe void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
((BufferSerializer<FixedString64Bytes>*)(&serializer))->SerializeValue<FixedString64Bytes>(ref A, default(ForFixedStrings));
((BufferSerializer<FixedString64Bytes>*)(&serializer))->SerializeValue<FixedString64Bytes>(ref B, default(ForFixedStrings));
}
}
[CompilerGenerated]
private sealed class <DelayedApply>d__14 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public CoupleSync <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <DelayedApply>d__14(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
int num = <>1__state;
CoupleSync coupleSync = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 1;
return true;
case 1:
{
<>1__state = -1;
Debug.Log((object)$"CoupleA: {Couple.Value.A} CoupleB: {Couple.Value.B}");
CoupleData value = Couple.Value;
ref FixedString64Bytes a = ref value.A;
FixedString32Bytes val = FixedString32Bytes.op_Implicit("");
if (!((ref a) == (ref val)))
{
CoupleData value2 = Couple.Value;
ref FixedString64Bytes b = ref value2.B;
FixedString32Bytes val2 = FixedString32Bytes.op_Implicit("");
if (!((ref b) == (ref val2)))
{
Debug.Log((object)"[CoupleSync] Waiting to Applying Color and Showing Couple");
<>2__current = null;
<>1__state = 2;
return true;
}
}
return false;
}
case 2:
<>1__state = -1;
coupleSync.ApplyColor();
coupleSync.ShowCouple();
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <DelayedResetCouple>d__26 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <DelayedResetCouple>d__26(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(5f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
Plugin.mls.LogInfo((object)"ResetCouplePatch Called");
if ((Object)(object)NetworkManager.Singleton == (Object)null || (!NetworkManager.Singleton.IsServer && !NetworkManager.Singleton.IsHost))
{
return false;
}
if ((Object)(object)Instance == (Object)null)
{
return false;
}
ResetCoupleEvent.InvokeServer();
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <DelayedSetCouple>d__24 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public RoundManager __instance;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <DelayedSetCouple>d__24(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(7f);
<>1__state = 1;
return true;
case 1:
{
<>1__state = -1;
if ((Object)(object)Instance == (Object)null || !((NetworkBehaviour)Instance).IsSpawned)
{
Plugin.mls.LogError((object)"CoupleSync not spawned yet");
return false;
}
PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
if (((Object)__instance.currentLevel).name == "CompanyBuildingLevel")
{
Plugin.mls.LogInfo((object)"No Couple in Company Building!");
return false;
}
try
{
List<string> list = new List<string>();
for (int i = 0; i < allPlayerScripts.Count(); i++)
{
if (allPlayerScripts[i].playerSteamId != 0L && allPlayerScripts[i].isPlayerControlled && !allPlayerScripts[i].isPlayerDead)
{
list.Add(allPlayerScripts[i].playerUsername);
}
}
Plugin.mls.LogInfo((object)$"Players Count : {list.Count()}");
if (list.Count() < 2)
{
Plugin.mls.LogWarning((object)"Not enough players to be matched!");
return false;
}
int index = Random.Range(0, list.Count);
string text = list[index];
list.RemoveAt(index);
Plugin.mls.LogInfo((object)("coupleA : " + text));
index = Random.Range(0, list.Count);
string text2 = list[index];
Plugin.mls.LogInfo((object)("coupleB : " + text2));
Couple.Value = new CoupleData
{
A = FixedString64Bytes.op_Implicit(text),
B = FixedString64Bytes.op_Implicit(text2)
};
}
catch (Exception arg)
{
Plugin.mls.LogError((object)$"An Error Occured while setting Couple! {arg}");
}
return false;
}
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public static readonly LNetworkMessage<string> KillCoupleMessage = LNetworkMessage<string>.Connect("KillCoupleMessage", (Action<string, ulong>)null, (Action<string>)null, (Action<string, ulong>)null);
public static readonly LNetworkEvent ResetCoupleEvent = LNetworkEvent.Connect("ResetCoupleEvent", (Action<ulong>)null, (Action)null, (Action<ulong>)null);
public static readonly LNetworkVariable<CoupleData> Couple = LNetworkVariable<CoupleData>.Connect("Couple", default(CoupleData), (LNetworkVariableWritePerms)0, (Action<CoupleData, CoupleData>)null);
private Coroutine applyRoutine;
private bool tipShown;
public static CoupleSync Instance { get; private set; }
public override void OnNetworkSpawn()
{
Debug.Log((object)$"[CoupleSync] OnNetworkSpawn (IsServer={((NetworkBehaviour)this).IsServer}, IsClient={((NetworkBehaviour)this).IsClient}) Instance={this}");
((NetworkBehaviour)this).OnNetworkSpawn();
Instance = this;
KillCoupleMessage.OnServerReceived += ServerReceivedKillCoupleMessage;
KillCoupleMessage.OnClientReceived += ClientReceivedKillCoupleMessage;
ResetCoupleEvent.OnServerReceived += ServerReceivedResetCoupleEvent;
ResetCoupleEvent.OnClientReceived += ClientReceivedResetCoupleEvent;
Couple.OnValueChanged += OnCoupleChanged;
}
public override void OnNetworkDespawn()
{
Debug.Log((object)"[CoupleSync] OnNetworkDespawn");
((NetworkBehaviour)this).OnNetworkDespawn();
if ((Object)(object)Instance == (Object)(object)this)
{
Instance = null;
}
if (applyRoutine != null)
{
TryStopCoroutine(applyRoutine);
applyRoutine = null;
}
KillCoupleMessage.OnServerReceived -= ServerReceivedKillCoupleMessage;
KillCoupleMessage.OnClientReceived -= ClientReceivedKillCoupleMessage;
ResetCoupleEvent.OnServerReceived -= ServerReceivedResetCoupleEvent;
ResetCoupleEvent.OnClientReceived -= ClientReceivedResetCoupleEvent;
Couple.OnValueChanged -= OnCoupleChanged;
}
private void TryStopCoroutine(Coroutine c)
{
try
{
((MonoBehaviour)this).StopCoroutine(c);
}
catch
{
}
}
private void OnCoupleChanged(CoupleData oldval, CoupleData newval)
{
Debug.Log((object)$"[CoupleSync] OnCoupleChanged called IsClient={((NetworkBehaviour)this).IsClient} old={oldval} new={newval}");
if (applyRoutine != null)
{
((MonoBehaviour)this).StopCoroutine(applyRoutine);
}
applyRoutine = ((MonoBehaviour)this).StartCoroutine(DelayedApply());
}
[IteratorStateMachine(typeof(<DelayedApply>d__14))]
private IEnumerator DelayedApply()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <DelayedApply>d__14(0)
{
<>4__this = this
};
}
private void ServerReceivedKillCoupleMessage(string killedPlayerName, ulong senderClientId)
{
if (!((NetworkBehaviour)this).IsServer)
{
Debug.LogWarning((object)"[CoupleSync] ServerReceivedKillCoupleMessage called on non-server!");
return;
}
Debug.Log((object)$"[CoupleSync] ServerReceivedKillCoupleMessage: {killedPlayerName} from {senderClientId}");
KillCoupleMessage.SendClients(killedPlayerName);
Debug.Log((object)"[CoupleSync] Sent KillCoupleMessage to clients.");
ResetCoupleInternal();
}
private void ClientReceivedKillCoupleMessage(string killedPlayerName)
{
Debug.Log((object)$"[CoupleSync] ClientReceivedKillCoupleMessage: {killedPlayerName} (Instance={Instance})");
KillCouple(killedPlayerName);
}
private void ServerReceivedResetCoupleEvent(ulong senderClientId)
{
ResetCoupleInternal();
}
private void ResetCoupleInternal()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
if (((NetworkBehaviour)this).IsServer)
{
if (applyRoutine != null)
{
((MonoBehaviour)this).StopCoroutine(applyRoutine);
applyRoutine = null;
}
Couple.Value = new CoupleData
{
A = FixedString64Bytes.op_Implicit(""),
B = FixedString64Bytes.op_Implicit("")
};
ResetCoupleEvent.InvokeClients();
}
}
private void ClientReceivedResetCoupleEvent()
{
PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
for (int i = 0; i < allPlayerScripts.Count(); i++)
{
PlayerControllerB val = allPlayerScripts[i];
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.usernameBillboardText == (Object)null))
{
((TMP_Text)val.usernameBillboardText).text = val.playerUsername;
}
}
}
private void ShowCouple()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
if (!tipShown)
{
tipShown = true;
HUDManager.Instance.DisplayTip("Congratulations!", $"{Couple.Value.A} " + $"and {Couple.Value.B} fell in love.", false, false, "LC_Tip1");
}
}
private void ApplyColor()
{
CoupleData value = Couple.Value;
string text = ((object)(FixedString64Bytes)(ref value.A)).ToString();
value = Couple.Value;
string text2 = ((object)(FixedString64Bytes)(ref value.B)).ToString();
if (MyString.IsNullOrEmpty(text) || MyString.IsNullOrEmpty(text2))
{
return;
}
string playerUsername = GameNetworkManager.Instance.localPlayerController.playerUsername;
if (MyString.IsNullOrEmpty(playerUsername) || (!(playerUsername == text) && !(playerUsername == text2)))
{
return;
}
PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
if (allPlayerScripts == null || allPlayerScripts.Length == 0)
{
return;
}
for (int i = 0; i < allPlayerScripts.Count(); i++)
{
PlayerControllerB val = allPlayerScripts[i];
if (!((Object)(object)val == (Object)null) && !MyString.IsNullOrEmpty(val.playerUsername) && !((Object)(object)val.usernameBillboardText == (Object)null))
{
string playerUsername2 = val.playerUsername;
if ((playerUsername == text && playerUsername2 == text2) || (playerUsername == text2 && playerUsername2 == text))
{
((TMP_Text)val.usernameBillboardText).text = "<color=#ff46dc>" + val.playerUsername + "</color>";
}
else
{
((TMP_Text)val.usernameBillboardText).text = val.playerUsername;
}
}
}
}
private void KillCouple(string killed)
{
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
CoupleData value = Couple.Value;
string text = ((object)(FixedString64Bytes)(ref value.A)).ToString();
value = Couple.Value;
string text2 = ((object)(FixedString64Bytes)(ref value.B)).ToString();
if (!(killed != text) || !(killed != text2))
{
string text3 = ((killed == text) ? text2 : text);
PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
if (localPlayerController.playerUsername == text3)
{
localPlayerController.DamagePlayer(999, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
}
}
}
public void StartDelayedSetCouple(RoundManager __instance)
{
if (((NetworkBehaviour)this).IsServer && !((Object)(object)__instance == (Object)null))
{
((MonoBehaviour)this).StartCoroutine(DelayedSetCouple(__instance));
}
}
[IteratorStateMachine(typeof(<DelayedSetCouple>d__24))]
private IEnumerator DelayedSetCouple(RoundManager __instance)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <DelayedSetCouple>d__24(0)
{
__instance = __instance
};
}
public void StartDelayedResetCouple()
{
tipShown = false;
if (((NetworkBehaviour)this).IsServer)
{
((MonoBehaviour)this).StartCoroutine(DelayedResetCouple());
}
}
[IteratorStateMachine(typeof(<DelayedResetCouple>d__26))]
private IEnumerator DelayedResetCouple()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <DelayedResetCouple>d__26(0);
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("choguin.lovecompany", "LoveCompany", "0.0.2")]
public class Plugin : BaseUnityPlugin
{
public const string modGUID = "choguin.lovecompany";
public const string modName = "LoveCompany";
public const string modVersion = "0.0.2";
private Harmony _harmony = new Harmony("choguin.lovecompany");
internal static ManualLogSource mls = Logger.CreateLogSource(" LoveCompany");
public static AssetBundle LoveCompanyAssets;
private void Awake()
{
mls.LogInfo((object)"LoveCompany Awaked");
_harmony.PatchAll();
string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
string text = Path.Combine(directoryName, "lovecompany");
LoveCompanyAssets = AssetBundle.LoadFromFile(text);
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
Type[] array = types;
foreach (Type type in array)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo[] array2 = methods;
foreach (MethodInfo methodInfo in array2)
{
object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
if (customAttributes.Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "LoveCompany";
public const string PLUGIN_NAME = "LoveCompany";
public const string PLUGIN_VERSION = "0.0.1";
}
}
namespace LoveCompany.Patches
{
[HarmonyPatch]
public class NetworkObjectManager
{
private static GameObject coupleSyncObject;
private static bool prefabRegistered;
[HarmonyPatch(typeof(GameNetworkManager), "Start")]
[HarmonyPostfix]
public static void Init()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
if (!prefabRegistered && !((Object)(object)coupleSyncObject != (Object)null))
{
coupleSyncObject = (GameObject)Plugin.LoveCompanyAssets.LoadAsset("CoupleSyncObject");
coupleSyncObject.AddComponent<CoupleSync>();
NetworkManager.Singleton.AddNetworkPrefab(coupleSyncObject);
prefabRegistered = true;
}
}
[HarmonyPatch(typeof(StartOfRound), "Awake")]
[HarmonyPostfix]
private static void SpawnCoupleSync()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
{
GameObject val = Object.Instantiate<GameObject>(coupleSyncObject, Vector3.zero, Quaternion.identity);
val.GetComponent<NetworkObject>().Spawn(false);
}
}
}
[HarmonyPatch]
internal class Patch
{
private static string coupleA;
private static string coupleB;
[HarmonyPatch(typeof(RoundManager), "FinishGeneratingLevel")]
[HarmonyPostfix]
private static void SetCouplePatch(RoundManager __instance)
{
if ((Object)(object)CoupleSync.Instance == (Object)null || !((NetworkBehaviour)CoupleSync.Instance).IsSpawned)
{
Plugin.mls.LogError((object)"CoupleSync not ready, cannot start coroutine");
}
else
{
CoupleSync.Instance.StartDelayedSetCouple(__instance);
}
}
[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
[HarmonyPostfix]
private static void KillCouplePatch(PlayerControllerB __instance)
{
if (((NetworkBehaviour)__instance).IsOwner)
{
Plugin.mls.LogInfo((object)"KillCouplePatch Called");
CoupleSync.KillCoupleMessage.SendServer(__instance.playerUsername);
}
}
[HarmonyPatch(typeof(StartOfRound), "ShipLeave")]
[HarmonyPostfix]
private static void ResetCouplePatch(StartOfRound __instance)
{
if ((Object)(object)CoupleSync.Instance == (Object)null || !((NetworkBehaviour)CoupleSync.Instance).IsSpawned)
{
Plugin.mls.LogError((object)"CoupleSync not ready, cannot start coroutine");
}
else
{
CoupleSync.Instance.StartDelayedResetCouple();
}
}
}
}