Decompiled source of TrueScore v1.0.2

TrueScore.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("CW-TrueScore")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CW-TrueScore")]
[assembly: AssemblyTitle("CW-TrueScore")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace TrueScore
{
	[ContentWarningPlugin("Electric131.TrueScore", "1.0.2", true)]
	[BepInPlugin("Electric131.TrueScore", "TrueScore", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "Electric131.TrueScore";

		public const string ModName = "TrueScore";

		public const string ModVersion = "1.0.2";

		public static ManualLogSource? logger;

		public static float temp_t;

		public static float temp_time;

		public static float temp_views;

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			logger.LogInfo((object)"Plugin Electric131.TrueScore loaded!");
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
			logger.LogInfo((object)"Patches created successfully");
		}

		[HarmonyPatch(typeof(UI_Views), "Update")]
		[HarmonyPrefix]
		public static bool UpdatePatch(ref UI_Views __instance)
		{
			if (SurfaceNetworkHandler.RoomStats == null)
			{
				return false;
			}
			int scoreToViews = BigNumbers.GetScoreToViews((float)SurfaceNetworkHandler.RoomStats.CurrentQuota, GameAPI.CurrentDay);
			int scoreToViews2 = BigNumbers.GetScoreToViews((float)SurfaceNetworkHandler.RoomStats.QuotaToReach, GameAPI.CurrentDay);
			((TMP_Text)__instance.text).text = BigNumbers.ViewsToString(scoreToViews) + "/" + BigNumbers.ViewsToString(scoreToViews2) + " " + __instance.m_ViewsText + " (" + SurfaceNetworkHandler.RoomStats.CurrentQuota + "/" + SurfaceNetworkHandler.RoomStats.QuotaToReach + " Score)";
			return false;
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> DisplayVideoEvalPatch(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Expected O, but got Unknown
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Expected O, but got Unknown
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Expected O, but got Unknown
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Expected O, but got Unknown
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Expected O, but got Unknown
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Expected O, but got Unknown
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Expected O, but got Unknown
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Expected O, but got Unknown
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[2]
			{
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(UploadCompleteUI), "m_viewsCurve"), (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null)
			}).ThrowIfInvalid("Unable to find where views text is set while video is running").Advance(1)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldnull, (object)null)
				})
				.Advance(2)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[4]
				{
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(Plugin), "temp_t")),
					new CodeInstruction(OpCodes.Ldnull, (object)null),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(Plugin), "temp_t")),
					new CodeInstruction(OpCodes.Ldnull, (object)null)
				})
				.Advance(2)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(Plugin), "temp_time")),
					new CodeInstruction(OpCodes.Ldnull, (object)null),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(Plugin), "temp_time"))
				})
				.Advance(2)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1]
				{
					new CodeInstruction(OpCodes.Ldnull, (object)null)
				})
				.Advance(3)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(Plugin), "temp_views")),
					new CodeInstruction(OpCodes.Ldnull, (object)null),
					new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(Plugin), "temp_views"))
				})
				.Advance(6)
				.Insert((CodeInstruction[])(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Ldloc_1, (object)null),
					new CodeInstruction(OpCodes.Ldc_I4_0, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Plugin), "AppendScore", (Type[])null, (Type[])null))
				})
				.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(PhotonNetwork), "get_IsMasterClient", (Type[])null, (Type[])null), (string)null)
				})
				.ThrowIfInvalid("Unable to find where text is set when video is over")
				.Insert((CodeInstruction[])(object)new CodeInstruction[3]
				{
					new CodeInstruction(OpCodes.Ldloc_1, (object)null),
					new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
					new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Plugin), "AppendScore", (Type[])null, (Type[])null))
				})
				.InstructionEnumeration();
		}

		public static void AppendScore(UploadCompleteUI __instance, bool end)
		{
			if (end)
			{
				temp_t = temp_time;
			}
			int scoreToViews = BigNumbers.GetScoreToViews(1f, SurfaceNetworkHandler.RoomStats.CurrentDay);
			TextMeshProUGUI views = __instance.m_views;
			((TMP_Text)views).text = ((TMP_Text)views).text + " (" + BigNumbers.ViewsToString(Mathf.FloorToInt(__instance.m_viewsCurve.Evaluate(temp_t / temp_time) * (temp_views / (float)scoreToViews))).ToString() + " Score)";
		}
	}
}