Decompiled source of RepeatPayments v1.0.0

plugins/RepeatPayments.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Repeat Payments")]
[assembly: AssemblyDescription("Repeat credit-card and gift-card payment rounds in Scam With Your Friends")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RepeatPayments;

[BepInPlugin("local.swyf.repeatpayments", "Repeat Payments", "1.0.0")]
[BepInProcess("Scam With Your Friends.exe")]
public sealed class Plugin : BaseUnityPlugin
{
	public const string Id = "local.swyf.repeatpayments";

	private Harmony harmony;

	private void Awake()
	{
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Expected O, but got Unknown
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Expected O, but got Unknown
		try
		{
			Type type = AccessTools.TypeByName("VictimCall");
			Type type2 = AccessTools.TypeByName("KolkataOsPlayer");
			if (type == null || type2 == null)
			{
				throw new MissingMemberException("Game payment types were not found.");
			}
			MethodInfo methodInfo = AccessTools.DeclaredMethod(type, "ServerConfigureCardScamRounds", new Type[1] { type2 }, (Type[])null);
			if (methodInfo == null || methodInfo.IsStatic || methodInfo.ReturnType != typeof(void))
			{
				throw new MissingMethodException("Expected payment configuration method was not found.");
			}
			PaymentLimitRewrite.Applied = false;
			harmony = new Harmony("local.swyf.repeatpayments");
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(PaymentLimitRewrite), "Transpiler", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
			if (!PaymentLimitRewrite.Applied)
			{
				throw new InvalidOperationException("The two expected payment-limit patterns were not found. This game build or another mod changed the method.");
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Repeat Payments active: credit-card and gift-card rounds set to 2147483647 per customer. Host-side effect; original game files are unchanged.");
		}
		catch (Exception ex)
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			((BaseUnityPlugin)this).Logger.LogError((object)("Repeat Payments could not activate. " + ex));
		}
	}

	private void OnDestroy()
	{
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}
}
internal static class PaymentLimitRewrite
{
	internal static bool Applied;

	public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>();
		foreach (CodeInstruction instruction in instructions)
		{
			list.Add(new CodeInstruction(instruction));
		}
		List<int> list2 = new List<int>();
		HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
		for (int i = 0; i + 4 < list.Count; i++)
		{
			if (list[i].opcode != OpCodes.Ldstr)
			{
				continue;
			}
			string text = list[i].operand as string;
			if ((text != "gift-card" && text != "credit-card") || !IsSupportedLimit(list[i + 1]) || list[i + 2].opcode != OpCodes.Ldarg_0 || list[i + 3].opcode != OpCodes.Ldfld)
			{
				continue;
			}
			FieldInfo fieldInfo = list[i + 3].operand as FieldInfo;
			MethodInfo methodInfo = list[i + 4].operand as MethodInfo;
			if (!(fieldInfo == null) && !(fieldInfo.Name != "sentinelCallState") && !(fieldInfo.DeclaringType == null) && !(fieldInfo.DeclaringType.Name != "VictimCall") && !(list[i + 4].opcode != OpCodes.Callvirt) && !(methodInfo == null) && !(methodInfo.Name != "SetMaxCompletions") && !(methodInfo.DeclaringType == null) && !(methodInfo.DeclaringType.Name != "ConversationScamSession"))
			{
				ParameterInfo[] parameters = methodInfo.GetParameters();
				if (!(methodInfo.ReturnType != typeof(void)) && parameters.Length == 3 && !(parameters[0].ParameterType != typeof(string)) && !(parameters[1].ParameterType != typeof(int)) && !(parameters[2].ParameterType.Name != "SentinelCallState"))
				{
					list2.Add(i + 1);
					hashSet.Add(text);
				}
			}
		}
		if (list2.Count != 2 || hashSet.Count != 2)
		{
			throw new InvalidOperationException("Repeat Payments: unsupported payment-limit IL; expected exactly one gift-card and one credit-card configuration call.");
		}
		foreach (int item in list2)
		{
			list[item].opcode = OpCodes.Ldc_I4;
			list[item].operand = int.MaxValue;
		}
		Applied = true;
		return list;
	}

	private static bool IsSupportedLimit(CodeInstruction instruction)
	{
		if (instruction.opcode == OpCodes.Ldc_I4_1)
		{
			return true;
		}
		if (instruction.opcode == OpCodes.Ldc_I4_S)
		{
			return Convert.ToInt32(instruction.operand) == 1;
		}
		if (instruction.opcode == OpCodes.Ldc_I4)
		{
			int num = Convert.ToInt32(instruction.operand);
			if (num != 1)
			{
				return num == int.MaxValue;
			}
			return true;
		}
		return false;
	}
}