using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RepoEssentials.src.patches;
using TMPro;
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("Essentials")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.5.0")]
[assembly: AssemblyInformationalVersion("0.3.5+37b8757c0951071c5946177d7fbd4d258f820401")]
[assembly: AssemblyProduct("R.E.P.O Essentials Plugin")]
[assembly: AssemblyTitle("Essentials")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.5.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 RepoEssentials.src
{
[BepInPlugin("org.ccarrmcmahon.plugins.repo.essentials", "Essentials", "0.3.5")]
[BepInProcess("REPO.exe")]
[BepInIncompatibility("nickklmao.nolimitchatbox")]
[BepInIncompatibility("zelofi.MorePlayers")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
private void Awake()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Loading plugin...");
Harmony harmony = new Harmony("org.ccarrmcmahon.plugins.repo.essentials");
Logger.LogDebug((object)"Loading Harmony patches...");
ChatCharacterLimit.Initialize(((BaseUnityPlugin)this).Config, harmony);
CurrencyCulture.Initialize(harmony);
ServerMaxPlayers.Initialize(((BaseUnityPlugin)this).Config, harmony);
SinglePlayerChat.Initialize(harmony);
Logger.LogDebug((object)"Harmony patches loaded!");
Logger.LogInfo((object)"Plugin loaded successfully!");
}
}
}
namespace RepoEssentials.src.patches
{
public static class ChatCharacterLimit
{
public static ConfigEntry<int> CharacterLimit { get; private set; }
public static ConfigEntry<float> ChatTextWidth { get; private set; }
public static ConfigEntry<float> CharacterSpacing { get; private set; }
public static ConfigEntry<float> LineSpacing { get; private set; }
private static void LoadConfig(ConfigFile config)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Expected O, but got Unknown
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Expected O, but got Unknown
CharacterLimit = config.Bind<int>("Chat", "CharacterLimit", 250, new ConfigDescription("The maximum number of characters allowed in a chat messages.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>()));
ChatTextWidth = config.Bind<float>("Chat", "ChatTextWidth", 525f, new ConfigDescription("The width of the chat area.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-100f, 545f), Array.Empty<object>()));
CharacterSpacing = config.Bind<float>("Chat", "CharacterSpacing", -0.5f, new ConfigDescription("The spacing between characters in chat.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-1f, 10f), Array.Empty<object>()));
LineSpacing = config.Bind<float>("Chat", "LineSpacing", -45f, new ConfigDescription("The spacing between lines in chat.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-50f, 10f), Array.Empty<object>()));
}
private static void ChatManagerAwakePatch(Harmony harmony)
{
harmony.CreateClassProcessor(typeof(ChatManager_Awake_Patch)).Patch();
Plugin.Logger.LogDebug((object)" - ChatManager_Awake_Patch: True");
}
private static bool ChatManagerStateActivePatch(Harmony harmony)
{
harmony.CreateClassProcessor(typeof(ChatManager_StateActive_Patch)).Patch();
bool patchSuccessful = ChatManager_StateActive_Patch.PatchSuccessful;
Plugin.Logger.LogDebug((object)$" - ChatManager_StateActive_Patch: {patchSuccessful}");
return patchSuccessful;
}
private static bool ApplyPatches(Harmony harmony)
{
ChatManagerAwakePatch(harmony);
return true & ChatManagerStateActivePatch(harmony);
}
public static void Initialize(ConfigFile config, Harmony harmony)
{
Plugin.Logger.LogDebug((object)"Loading ChatCharacterLimit config...");
LoadConfig(config);
Plugin.Logger.LogDebug((object)" > Success: True");
Plugin.Logger.LogDebug((object)"Applying ChatCharacterLimit patches...");
bool flag = ApplyPatches(harmony);
Plugin.Logger.LogDebug((object)$" > Success: {flag}");
}
}
[HarmonyPatch(typeof(ChatManager), "Awake")]
public class ChatManager_Awake_Patch
{
public static bool PatchSuccessful { get; private set; }
private static void Prefix(ChatManager __instance)
{
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
int value = ChatCharacterLimit.CharacterLimit.Value;
Traverse.Create((object)__instance).Field("characterLimit").SetValue((object)value);
TextMeshProUGUI value2 = Traverse.Create((object)__instance).Field("chatText").GetValue<TextMeshProUGUI>();
if ((Object)(object)value2 == (Object)null)
{
Plugin.Logger.LogError((object)"Failed to find chatText component");
return;
}
RectTransform component = ((Component)value2).GetComponent<RectTransform>();
if ((Object)(object)component == (Object)null)
{
Plugin.Logger.LogError((object)"Failed to get RectTransform from chatText");
return;
}
((TMP_Text)value2).enableWordWrapping = true;
component.sizeDelta = new Vector2(ChatCharacterLimit.ChatTextWidth.Value, component.sizeDelta.y);
((TMP_Text)value2).characterSpacing = ChatCharacterLimit.CharacterSpacing.Value;
((TMP_Text)value2).lineSpacing = ChatCharacterLimit.LineSpacing.Value;
PatchSuccessful = true;
}
}
[HarmonyPatch(typeof(ChatManager), "StateActive")]
public class ChatManager_StateActive_Patch
{
public static bool PatchSuccessful { get; private set; }
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Expected O, but got Unknown
bool flag = false;
int num = -1;
List<CodeInstruction> list = instructions.ToList();
for (int i = 0; i < list.Count; i++)
{
if (!flag)
{
if (list[i].opcode == OpCodes.Ldstr && list[i].operand.ToString().Equals("\n"))
{
flag = true;
}
}
else if (flag && num == -1)
{
if (list[i].opcode == OpCodes.Callvirt && list[i].operand.ToString().Equals("Int32 get_Length()"))
{
num = i;
}
}
else if (i == num + 1 && list[i].opcode == OpCodes.Ldc_I4_S)
{
list[i] = new CodeInstruction(OpCodes.Ldc_I4, (object)ChatCharacterLimit.CharacterLimit.Value)
{
labels = list[i].labels
};
PatchSuccessful = true;
break;
}
}
if (!PatchSuccessful)
{
Plugin.Logger.LogError((object)"Failed to find the expected instructions to patch.");
return instructions;
}
return list.AsEnumerable();
}
}
public static class CurrencyCulture
{
private static void SemiFuncDollarGetStringPatch(Harmony harmony)
{
harmony.CreateClassProcessor(typeof(SemiFunc_DollarGetString_Patch)).Patch();
Plugin.Logger.LogDebug((object)" - SemiFunc_DollarGetString_Patch: True");
}
private static void ApplyPatches(Harmony harmony)
{
SemiFuncDollarGetStringPatch(harmony);
}
public static void Initialize(Harmony harmony)
{
Plugin.Logger.LogDebug((object)"Applying CurrencyCulture patches...");
ApplyPatches(harmony);
Plugin.Logger.LogDebug((object)" > Success: True");
}
}
[HarmonyPatch(typeof(SemiFunc), "DollarGetString")]
public class SemiFunc_DollarGetString_Patch
{
private static bool Prefix(int value, ref string __result)
{
__result = string.Format(CultureInfo.CurrentCulture, "{0:#,0}", value);
return false;
}
}
public static class ServerMaxPlayers
{
public static ConfigEntry<int> MaxPlayers { get; private set; }
private static void LoadConfig(ConfigFile config)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
MaxPlayers = config.Bind<int>("Server", "MaxPlayers", 6, new ConfigDescription("The maximum number of players allowed to join a server.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
}
private static bool NetworkConnectTryJoiningRoomPatch(Harmony harmony)
{
harmony.CreateClassProcessor(typeof(NetworkConnect_TryJoiningRoom_Patch)).Patch();
bool patchSuccessful = NetworkConnect_TryJoiningRoom_Patch.PatchSuccessful;
Plugin.Logger.LogDebug((object)$" - NetworkConnect_TryJoiningRoom_Patch: {patchSuccessful}");
return patchSuccessful;
}
private static bool SteamManagerHostLobbyPatch(Harmony harmony)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
MethodInfo method = typeof(SteamManager).GetMethod("HostLobby", BindingFlags.Instance | BindingFlags.Public).GetCustomAttribute<AsyncStateMachineAttribute>().StateMachineType.GetMethod("MoveNext", BindingFlags.Instance | BindingFlags.NonPublic);
HarmonyMethod val = new HarmonyMethod(typeof(SteamManager_HostLobby_Patch), "Transpiler", (Type[])null);
harmony.Patch((MethodBase)method, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
bool patchSuccessful = SteamManager_HostLobby_Patch.PatchSuccessful;
Plugin.Logger.LogDebug((object)$" - SteamManager_HostLobby_Patch: {patchSuccessful}");
return patchSuccessful;
}
private static bool ApplyPatches(Harmony harmony)
{
return true & NetworkConnectTryJoiningRoomPatch(harmony) & SteamManagerHostLobbyPatch(harmony);
}
public static void Initialize(ConfigFile config, Harmony harmony)
{
Plugin.Logger.LogDebug((object)"Loading ServerMaxPlayers config...");
LoadConfig(config);
Plugin.Logger.LogDebug((object)" > Success: True");
Plugin.Logger.LogDebug((object)"Applying ServerMaxPlayers patches...");
bool flag = ApplyPatches(harmony);
Plugin.Logger.LogDebug((object)$" > Success: {flag}");
}
}
[HarmonyPatch(typeof(NetworkConnect), "TryJoiningRoom")]
public class NetworkConnect_TryJoiningRoom_Patch
{
public static bool PatchSuccessful { get; private set; }
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
int num = 0;
List<CodeInstruction> list = instructions.ToList();
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldc_I4_6)
{
CodeInstruction value = new CodeInstruction(OpCodes.Ldc_I4_S, (object)(sbyte)ServerMaxPlayers.MaxPlayers.Value)
{
labels = list[i].labels
};
list[i] = value;
num++;
}
}
PatchSuccessful = num == 1;
if (!PatchSuccessful)
{
Plugin.Logger.LogError((object)($"Found {num} occurrences of ldc.i4.6 in NetworkConnect::TryJoiningRoom() instead of" + $" {1}."));
return instructions;
}
return list.AsEnumerable();
}
}
public class SteamManager_HostLobby_Patch
{
public static bool PatchSuccessful { get; private set; }
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
int num = 0;
List<CodeInstruction> list = instructions.ToList();
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldc_I4_6)
{
CodeInstruction value = new CodeInstruction(OpCodes.Ldc_I4_S, (object)(sbyte)ServerMaxPlayers.MaxPlayers.Value)
{
labels = list[i].labels
};
list[i] = value;
num++;
}
}
PatchSuccessful = num == 1;
if (!PatchSuccessful)
{
Plugin.Logger.LogError((object)$"Found {num} occurrences of ldc.i4.6 in SteamManager::HostLobby() instead of {1}.");
return instructions;
}
return list.AsEnumerable();
}
}
public static class SinglePlayerChat
{
private static bool ChatManagerUpdatePatch(Harmony harmony)
{
harmony.CreateClassProcessor(typeof(ChatManager_Update_Patch)).Patch();
bool patchSuccessful = ChatManager_Update_Patch.PatchSuccessful;
Plugin.Logger.LogDebug((object)$" - ChatManager_Update_Patch: {patchSuccessful}");
return patchSuccessful;
}
private static bool ApplyPatches(Harmony harmony)
{
return true & ChatManagerUpdatePatch(harmony);
}
public static void Initialize(Harmony harmony)
{
Plugin.Logger.LogDebug((object)"Applying SinglePlayerChat patches...");
bool flag = ApplyPatches(harmony);
Plugin.Logger.LogDebug((object)$" > Success: {flag}");
}
}
[HarmonyPatch(typeof(ChatManager), "Update")]
public class ChatManager_Update_Patch
{
public static bool PatchSuccessful { get; private set; }
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Expected O, but got Unknown
int num = 0;
List<CodeInstruction> list = instructions.ToList();
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Call && list[i].operand.ToString().Equals("Boolean IsMultiplayer()"))
{
CodeInstruction value = new CodeInstruction(OpCodes.Ldc_I4_1, (object)null)
{
labels = list[i].labels
};
list[i] = value;
num++;
}
}
PatchSuccessful = num == 2;
if (!PatchSuccessful)
{
Plugin.Logger.LogError((object)$"Found {num} occurrences of SemiFunc::IsMultiplayer() in ChatManager::Update() instead of {2}.");
return instructions;
}
return list.AsEnumerable();
}
}
}
namespace RepoEssentials.src.configs
{
public static class GameInfo
{
public const string NAME = "R.E.P.O.";
public const string VERSION = "0.1.2";
public const string APP_ID = "3241660";
public const string BUILD_ID = "17560228";
public const string EXECUTABLE_NAME = "REPO.exe";
}
public static class PluginInfo
{
public const string GUID = "org.ccarrmcmahon.plugins.repo.essentials";
public const string NAME = "Essentials";
public const string VERSION = "0.3.5";
public const string AUTHOR = "CCarrMcMahon";
public const string ENTRY = "RepoEssentials.Plugin.Awake";
public const string MANIFEST = "manifest.json";
public const string ASSEMBLY = "Essentials.dll";
}
}