Decompiled source of LateClipSimple v0.1.0

plugins/LateClipSimple.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using Zorro.PhotonUtility;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 LateClipSimple
{
	[BepInPlugin("cn_xc.LateClipSimple", "Late Clip Simple", "0.1.0")]
	public class LateClipPlugin : BaseUnityPlugin
	{
		internal const string Guid = "cn_xc.LateClipSimple";

		internal static ManualLogSource Log;

		private ConfigEntry<bool> _enabled;

		private ConfigEntry<int> _maxClips;

		private ConfigEntry<bool> _verbose;

		private readonly HashSet<Guid> _published = new HashSet<Guid>();

		private bool _subscribed;

		private void Awake()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("常规", "启用录像补发", true, "有新玩家加入时,把本机录制过的录像重新公布给他。关闭则完全不做任何事。");
			_maxClips = ((BaseUnityPlugin)this).Config.Bind<int>("常规", "单次最多补发", 10, new ConfigDescription("每次最多补发多少段,避免一次性占满带宽(每块 30KB、每 0.2 秒一包)。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			_verbose = ((BaseUnityPlugin)this).Config.Bind<bool>("调试", "详细日志", false, "输出每一段的分块与跳过原因。");
			Log.LogInfo((object)"[录像补发] 已加载 v0.1.0");
		}

		private void Update()
		{
			if (!_subscribed)
			{
				PlayerHandler instance = PlayerHandler.instance;
				if (!((Object)(object)instance == (Object)null))
				{
					instance.OnPlayerJoined = (Action<Player>)Delegate.Combine(instance.OnPlayerJoined, new Action<Player>(OnJoined));
					_subscribed = true;
					Log.LogInfo((object)"[录像补发] 已订阅加入事件");
				}
			}
		}

		private void OnJoined(Player p)
		{
			if (!_enabled.Value)
			{
				return;
			}
			try
			{
				Republish();
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[录像补发] 补发失败:" + ex.Message));
			}
		}

		private void Republish()
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			Dictionary<VideoHandle, CameraRecording> recordings = RecordingsHandler.GetRecordings();
			if (recordings == null)
			{
				Verbose("暂无录像数据");
				return;
			}
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			foreach (KeyValuePair<VideoHandle, CameraRecording> item in recordings)
			{
				CameraRecording value = item.Value;
				if ((Object)(object)value == (Object)null)
				{
					continue;
				}
				int num4 = 0;
				try
				{
					num4 = value.ClipCount;
				}
				catch
				{
					continue;
				}
				for (int i = 0; i < num4 && num < _maxClips.Value; i++)
				{
					Clip val = null;
					try
					{
						val = value.GetClip(i);
					}
					catch
					{
						continue;
					}
					if (val == null)
					{
						continue;
					}
					if (!val.local)
					{
						num2++;
						continue;
					}
					Guid id = val.clipID.id;
					if (_published.Contains(id))
					{
						num3++;
						continue;
					}
					CustomCommands<CustomCommandType>.SendPackage((CustomCommandPackage<CustomCommandType>)new AddClipToShareQueuePackage
					{
						ClipID = val.clipID,
						VideoHandle = value.videoHandle,
						ClipOwner = PhotonNetwork.LocalPlayer.ActorNumber,
						isReRequest = true
					}, (ReceiverGroup)1);
					_published.Add(id);
					num++;
					Verbose("已重新公布 " + id.ToString().Substring(0, 8));
				}
				if (num >= _maxClips.Value)
				{
					break;
				}
			}
			Log.LogInfo((object)("[录像补发] 已补发 " + num + " 段;跳过:非本机录制 " + num2 + " 段、此前已公布 " + num3 + " 段"));
		}

		private static void Verbose(string msg)
		{
			LateClipPlugin lateClipPlugin = null;
			try
			{
				lateClipPlugin = Chainloader.PluginInfos["cn_xc.LateClipSimple"].Instance as LateClipPlugin;
			}
			catch
			{
			}
			if ((Object)(object)lateClipPlugin != (Object)null && lateClipPlugin._verbose.Value)
			{
				Log.LogInfo((object)("[录像补发] " + msg));
			}
		}
	}
}