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.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
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("RecentlyPlayedWith")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4+c8bbb869c167f339b4efc9110257eec700c5454a")]
[assembly: AssemblyProduct("RecentlyPlayedWith")]
[assembly: AssemblyTitle("RecentlyPlayedWith")]
[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 RecentlyPlayedWith
{
[BepInPlugin("Dev1A3.RecentlyPlayedWith", "RecentlyPlayedWith", "1.0.0")]
internal class PluginLoader : BaseUnityPlugin
{
internal const string modGUID = "Dev1A3.RecentlyPlayedWith";
internal const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("Dev1A3.RecentlyPlayedWith");
private static bool initialized;
public static PluginLoader Instance { get; private set; }
private void Awake()
{
if (!initialized)
{
initialized = true;
Instance = this;
Assembly executingAssembly = Assembly.GetExecutingAssembly();
harmony.PatchAll(executingAssembly);
PlayedWithConfig.InitConfig();
}
}
public void BindConfig<T>(ref ConfigEntry<T> config, string section, string key, T defaultValue, string description = "")
{
config = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, description);
}
}
internal class PlayedWithConfig
{
internal static ManualLogSource logSource;
internal static ConfigEntry<bool> IncludeOrbit;
internal static HashSet<ulong> PlayerList = new HashSet<ulong>();
internal static void InitConfig()
{
logSource = Logger.CreateLogSource("Dev1A3.RecentlyPlayedWith");
PluginLoader.Instance.BindConfig(ref IncludeOrbit, "Settings", "Enable In Orbit", defaultValue: true, "Should players be classed as recently played with whilst you are in orbit? Disabling this will only add people whilst the ship is landed.");
}
internal static void SetPlayedWith(ulong[] playerSteamIds, string debugType)
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
playerSteamIds = playerSteamIds.Where((ulong x) => (float)x != 0f && x != SteamId.op_Implicit(SteamClient.SteamId) && (debugType == "generateLevel" || !PlayerList.Contains(x))).ToArray();
if (playerSteamIds.Length == 0)
{
return;
}
ulong[] array = playerSteamIds;
foreach (ulong num in array)
{
if (!PlayerList.Contains(num))
{
PlayerList.Add(num);
}
SteamFriends.SetPlayedWith(SteamId.op_Implicit(num));
}
logSource.LogInfo((object)$"Set recently played with ({debugType}) for {playerSteamIds.Length} players.");
logSource.LogDebug((object)("Set recently played with (" + debugType + "): " + string.Join(", ", playerSteamIds)));
}
}
[HarmonyPatch]
internal static class SetPlayedWith_Patch
{
internal static bool initialJoin = true;
[HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")]
[HarmonyPostfix]
private static void GenerateNewLevelClientRpc(ref RoundManager __instance)
{
PlayedWithConfig.SetPlayedWith((from x in __instance.playersManager.allPlayerScripts
where x.isPlayerControlled || x.isPlayerDead
select x.playerSteamId).ToArray(), "generateLevel");
}
[HarmonyPatch(typeof(PlayerControllerB), "SendNewPlayerValuesClientRpc")]
[HarmonyPostfix]
private static void StartClient(ref ulong[] playerSteamIds)
{
if ((Object)(object)StartOfRound.Instance != (Object)null && (!StartOfRound.Instance.inShipPhase || PlayedWithConfig.IncludeOrbit.Value))
{
string debugType = "otherJoined";
if (initialJoin)
{
initialJoin = false;
debugType = "selfJoined";
}
PlayedWithConfig.SetPlayedWith(playerSteamIds.ToArray(), debugType);
}
}
[HarmonyPatch(typeof(StartOfRound), "OnPlayerDC")]
[HarmonyPostfix]
private static void OnPlayerDC(ref StartOfRound __instance, ref int playerObjectNumber, ulong clientId)
{
ulong playerSteamId = __instance.allPlayerScripts[playerObjectNumber].playerSteamId;
PlayedWithConfig.PlayerList.Remove(playerSteamId);
PlayedWithConfig.logSource.LogInfo((object)$"Removing {playerSteamId} from recently played with.");
}
[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
[HarmonyPostfix]
private static void SORDestroy(ref StartOfRound __instance)
{
initialJoin = true;
if (PlayedWithConfig.PlayerList.Count > 0)
{
PlayedWithConfig.PlayerList.Clear();
PlayedWithConfig.logSource.LogInfo((object)"Cleared recently played with (OnDestroy)");
}
}
}
internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "RecentlyPlayedWith";
public const string PLUGIN_NAME = "RecentlyPlayedWith";
public const string PLUGIN_VERSION = "1.0.4";
}
}