Decompiled source of ForceRule v1.0.1

ForceRule.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AutoRuleVote")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoRuleVote")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4acd0f6f-75a7-4915-92a5-6b3b3019f974")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AutoRuleVote
{
	[BepInPlugin("com.Moffein.ForceRule", "ForceRule", "1.0.0")]
	public class ForceRulePlugin : BaseUnityPlugin
	{
		private static ConfigEntry<string> ruleListString;

		private static ConfigEntry<int> voteCountOverride;

		private static HashSet<int> ruleChoiceIndices = new HashSet<int>();

		public void Awake()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			ReadConfig();
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(ParseRuleList));
			PreGameRuleVoteController.UpdateGameVotes += new Manipulator(OverrideVotes);
		}

		private void OverrideVotes(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCall<NetworkServer>(x, "get_active")
			}))
			{
				val.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)delegate(bool networkServerActive)
				{
					if (networkServerActive)
					{
						int value = voteCountOverride.Value;
						foreach (int ruleChoiceIndex in ruleChoiceIndices)
						{
							Debug.Log((object)("ForceRule: Overriding votes for RuleChoiceIndex " + ruleChoiceIndex));
							PreGameRuleVoteController.votesForEachChoice[ruleChoiceIndex] = value;
						}
					}
					return networkServerActive;
				});
			}
			else
			{
				Debug.LogError((object)"ForceRule: IL Hook failed.");
			}
		}

		private void ReadConfig()
		{
			//IL_0011: 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)
			//IL_0030: Expected O, but got Unknown
			//IL_0030: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_0078: Expected O, but got Unknown
			ruleListString = ((BaseUnityPlugin)this).Config.Bind<string>(new ConfigDefinition("Settings", "Rule List"), "", new ConfigDescription("List of rules to force enable, separated by commas. Enter rules_list_choices in console for a full list of valid choices.", (AcceptableValueBase)null, Array.Empty<object>()));
			ruleListString.SettingChanged += RuleListString_SettingChanged;
			voteCountOverride = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition("Settings", "Vote Count Override"), 100, new ConfigDescription("Overrides vote count for specified rules with this value. If rule voting is disabled, just set this to 1.", (AcceptableValueBase)null, Array.Empty<object>()));
		}

		private void RuleListString_SettingChanged(object sender, EventArgs e)
		{
			ParseRuleList();
		}

		private void ParseRuleList()
		{
			ruleChoiceIndices.Clear();
			string[] array = ruleListString.Value.Split(new char[1] { ',' });
			string[] array2 = array;
			foreach (string text in array2)
			{
				string text2 = text.Trim();
				if (text2.Length > 0)
				{
					RuleChoiceDef val = RuleCatalog.FindChoiceDef(text2);
					if (val == null)
					{
						Debug.LogError((object)("ForceRule: Could not find RuleChoiceDef for " + ((object)val)?.ToString() + ", skipping."));
						continue;
					}
					ruleChoiceIndices.Add(val.globalIndex);
					Debug.Log((object)("ForceRule: Added " + (object)val));
				}
			}
		}
	}
}
namespace R2API.Utils
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class ManualNetworkRegistrationAttribute : Attribute
	{
	}
}