Decompiled source of gamba mod v1.0.8

gamba.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.InputSystem;
using gamba.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("gamba")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("gamba")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7601084b-2d90-4d4c-9c56-4fe8ac3e7a8d")]
[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 gamba
{
	[BepInPlugin("Alexsio.GambaMod", "GambaMod", "1.0.8")]
	public class GambaBase : BaseUnityPlugin
	{
		private const string modGUID = "Alexsio.GambaMod";

		private const string modName = "GambaMod";

		private const string modVersion = "1.0.8";

		private readonly Harmony harmony = new Harmony("Alexsio.GambaMod");

		private static GambaBase Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Alexsio.GambaMod");
			mls.LogInfo((object)"Gamba mod up and awake");
			harmony.PatchAll(typeof(GambaBase));
			harmony.PatchAll(typeof(TerminalPatch));
		}
	}
}
namespace gamba.Patches
{
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		private static char[,] symbols = new char[2, 3]
		{
			{ 'O', 'X', '#' },
			{ '*', '?', '@' }
		};

		private static Random random = new Random();

		private static string[,] slots = GetSlots();

		private static TerminalNode spinNode = new TerminalNode();

		private static TerminalNode savedNode = new TerminalNode();

		private static int betAmount = 0;

		private static bool homeModified = false;

		private static bool leaving = false;

		private static string[,] GetSlots()
		{
			string[,] array = new string[5, 5];
			for (int i = 0; i < 5; i++)
			{
				for (int j = 0; j < 5; j++)
				{
					array[i, j] = $"{GetRandomSymbol(i, j)}";
				}
			}
			return array;
		}

		private static string[,] SpinSlots(string[,] slots)
		{
			for (int i = 0; i < 5; i++)
			{
				for (int j = 0; j < 5; j++)
				{
					slots[i, j] = $"{GetRandomSymbol(i, j)}";
				}
			}
			return slots;
		}

		private static char GetRandomSymbol(int row, int col)
		{
			int num = random.Next(1, 101);
			int num2 = 40;
			int num3 = 25;
			int num4 = 20;
			int num5 = 5;
			int num6 = 3;
			if (num <= num2)
			{
				return symbols[0, 0];
			}
			if (num <= num2 + num3)
			{
				return symbols[0, 1];
			}
			if (num <= num2 + num3 + num4)
			{
				return symbols[0, 2];
			}
			if (num <= num2 + num3 + num4 + num5)
			{
				return symbols[1, 0];
			}
			if (num <= num2 + num3 + num4 + num5 + num6)
			{
				return symbols[1, 1];
			}
			return symbols[1, 2];
		}

		private static int CalculateWinnings(string[,] slots, int gambleAmount)
		{
			int num = 0;
			Dictionary<string, int> symbolMultipliers = new Dictionary<string, int>
			{
				{ "O", 2 },
				{ "X", 3 },
				{ "#", 4 },
				{ "*", 8 },
				{ "?", 10 },
				{ "@", 20 }
			};
			for (int i = 0; i < 5; i++)
			{
				if (CheckLine(slots[i, 0], slots[i, 1], slots[i, 2], slots[i, 3], slots[i, 4]))
				{
					num += CalculateLineWinnings(slots[i, 0], symbolMultipliers, gambleAmount);
				}
			}
			for (int j = 0; j < 5; j++)
			{
				if (CheckLine(slots[0, j], slots[1, j], slots[2, j], slots[3, j], slots[4, j]))
				{
					num += CalculateLineWinnings(slots[0, j], symbolMultipliers, gambleAmount);
				}
			}
			if (CheckLine(slots[0, 0], slots[1, 1], slots[2, 2], slots[3, 3], slots[4, 4]))
			{
				num += CalculateLineWinnings(slots[0, 0], symbolMultipliers, gambleAmount);
			}
			if (CheckLine(slots[0, 4], slots[1, 3], slots[2, 2], slots[3, 1], slots[4, 0]))
			{
				num += CalculateLineWinnings(slots[0, 4], symbolMultipliers, gambleAmount);
			}
			if (CheckLine(slots[0, 4], slots[1, 3], slots[2, 2], slots[3, 1], slots[4, 0]) && CheckLine(slots[0, 0], slots[1, 1], slots[2, 2], slots[3, 3], slots[4, 4]))
			{
				num += CalculateLineWinnings(slots[0, 4], symbolMultipliers, gambleAmount);
			}
			if (CheckLine(slots[0, 0], slots[1, 1], slots[2, 2], slots[1, 3], slots[0, 4]))
			{
				num += CalculateLineWinnings(slots[0, 0], symbolMultipliers, gambleAmount);
			}
			if (CheckLine(slots[0, 0], slots[1, 1], slots[1, 2], slots[1, 3], slots[0, 4]))
			{
				num += CalculateLineWinnings(slots[0, 0], symbolMultipliers, gambleAmount);
			}
			if (CheckLine(slots[4, 0], slots[3, 1], slots[2, 2], slots[3, 3], slots[4, 4]))
			{
				num += CalculateLineWinnings(slots[4, 0], symbolMultipliers, gambleAmount);
			}
			if (CheckLine(slots[4, 0], slots[3, 1], slots[3, 2], slots[3, 3], slots[4, 4]))
			{
				num += CalculateLineWinnings(slots[4, 0], symbolMultipliers, gambleAmount);
			}
			if (CheckLine(slots[2, 0], slots[1, 1], slots[0, 2], slots[1, 3], slots[2, 4]))
			{
				num += CalculateLineWinnings(slots[2, 0], symbolMultipliers, gambleAmount);
			}
			if (CheckLine(slots[2, 0], slots[3, 1], slots[4, 2], slots[3, 3], slots[2, 4]))
			{
				num += CalculateLineWinnings(slots[2, 0], symbolMultipliers, gambleAmount);
			}
			return num;
		}

		private static bool CheckLine(params string[] symbols)
		{
			return symbols.All((string symbol) => symbol == symbols[0]);
		}

		private static int CalculateLineWinnings(string symbol, Dictionary<string, int> symbolMultipliers, int betAmount)
		{
			betAmount *= ((!symbolMultipliers.TryGetValue(symbol, out var value)) ? 1 : value);
			return betAmount;
		}

		private static string updateScreen(string[,] slots, int betAmount)
		{
			return "Welcome to the Company slot machine\n---------------------------------------------------\n\n\n         " + slots[0, 0] + "   |   " + slots[0, 1] + "   |   " + slots[0, 2] + "   |   " + slots[0, 3] + "   |   " + slots[0, 4] + "         \n             |       |       |       |             \n         " + slots[1, 0] + "   |   " + slots[1, 1] + "   |   " + slots[1, 2] + "   |   " + slots[1, 3] + "   |   " + slots[1, 4] + "         \n             |       |       |       |             \n         " + slots[2, 0] + "   |   " + slots[2, 1] + "   |   " + slots[2, 2] + "   |   " + slots[2, 3] + "   |   " + slots[2, 4] + "         \n             |       |       |       |             \n         " + slots[3, 0] + "   |   " + slots[3, 1] + "   |   " + slots[3, 2] + "   |   " + slots[3, 3] + "   |   " + slots[3, 4] + "         \n             |       |       |       |             \n         " + slots[4, 0] + "   |   " + slots[4, 1] + "   |   " + slots[4, 2] + "   |   " + slots[4, 3] + "   |   " + slots[4, 4] + "         \n\n\n---------------------------------------------------\n" + $"Spinning with {betAmount} credits... no luck!\n";
		}

		private static string emptyScreen(string[,] slots)
		{
			return "Welcome to the Company slot machine\n---------------------------------------------------\n\n\n         " + slots[0, 0] + "   |   " + slots[0, 1] + "   |   " + slots[0, 2] + "   |   " + slots[0, 3] + "   |   " + slots[0, 4] + "         \n             |       |       |       |             \n         " + slots[1, 0] + "   |   " + slots[1, 1] + "   |   " + slots[1, 2] + "   |   " + slots[1, 3] + "   |   " + slots[1, 4] + "         \n             |       |       |       |             \n         " + slots[2, 0] + "   |   " + slots[2, 1] + "   |   " + slots[2, 2] + "   |   " + slots[2, 3] + "   |   " + slots[2, 4] + "         \n             |       |       |       |             \n         " + slots[3, 0] + "   |   " + slots[3, 1] + "   |   " + slots[3, 2] + "   |   " + slots[3, 3] + "   |   " + slots[3, 4] + "         \n             |       |       |       |             \n         " + slots[4, 0] + "   |   " + slots[4, 1] + "   |   " + slots[4, 2] + "   |   " + slots[4, 3] + "   |   " + slots[4, 4] + "         \n\n\n---------------------------------------------------\nOut of credits!\n";
		}

		private static string updateSlotScreen(string[,] slots)
		{
			return "Welcome to the Company slot machine\n---------------------------------------------------\n\n\n         " + slots[0, 0] + "   |   " + slots[0, 1] + "   |   " + slots[0, 2] + "   |   " + slots[0, 3] + "   |   " + slots[0, 4] + "         \n             |       |       |       |             \n         " + slots[1, 0] + "   |   " + slots[1, 1] + "   |   " + slots[1, 2] + "   |   " + slots[1, 3] + "   |   " + slots[1, 4] + "         \n             |       |       |       |             \n         " + slots[2, 0] + "   |   " + slots[2, 1] + "   |   " + slots[2, 2] + "   |   " + slots[2, 3] + "   |   " + slots[2, 4] + "         \n             |       |       |       |             \n         " + slots[3, 0] + "   |   " + slots[3, 1] + "   |   " + slots[3, 2] + "   |   " + slots[3, 3] + "   |   " + slots[3, 4] + "         \n             |       |       |       |             \n         " + slots[4, 0] + "   |   " + slots[4, 1] + "   |   " + slots[4, 2] + "   |   " + slots[4, 3] + "   |   " + slots[4, 4] + "         \n\n\n---------------------------------------------------\nPlease enter how much you would like to gamble\n(bet [amount]): ";
		}

		private static string winScreen(string[,] slots, int winnings)
		{
			return "Welcome to the Company slot machine\n---------------------------------------------------\n\n\n         " + slots[0, 0] + "   |   " + slots[0, 1] + "   |   " + slots[0, 2] + "   |   " + slots[0, 3] + "   |   " + slots[0, 4] + "         \n             |       |       |       |             \n         " + slots[1, 0] + "   |   " + slots[1, 1] + "   |   " + slots[1, 2] + "   |   " + slots[1, 3] + "   |   " + slots[1, 4] + "         \n             |       |       |       |             \n         " + slots[2, 0] + "   |   " + slots[2, 1] + "   |   " + slots[2, 2] + "   |   " + slots[2, 3] + "   |   " + slots[2, 4] + "         \n             |       |       |       |             \n         " + slots[3, 0] + "   |   " + slots[3, 1] + "   |   " + slots[3, 2] + "   |   " + slots[3, 3] + "   |   " + slots[3, 4] + "         \n             |       |       |       |             \n         " + slots[4, 0] + "   |   " + slots[4, 1] + "   |   " + slots[4, 2] + "   |   " + slots[4, 3] + "   |   " + slots[4, 4] + "         \n\n\n---------------------------------------------------\n" + $"Won {winnings} credits!\n";
		}

		private static bool TryParseBetAmount(string input, out int betAmount)
		{
			string[] array = input.Split(new char[1] { ' ' });
			if (array.Length == 2 && int.TryParse(array[1], out betAmount))
			{
				return true;
			}
			betAmount = 0;
			return false;
		}

		[HarmonyPatch("ParsePlayerSentence")]
		[HarmonyPrefix]
		private static void stringCheck(ref Terminal __instance)
		{
			string text = __instance.screenText.text.Substring(__instance.screenText.text.Length - __instance.textAdded);
			if (text.StartsWith("bet"))
			{
				if (TryParseBetAmount(text, out betAmount))
				{
					savedNode = __instance.terminalNodes.specialNodes[11];
					__instance.terminalNodes.specialNodes[11] = spinNode;
				}
				else
				{
					__instance.terminalNodes.specialNodes[11] = savedNode;
				}
			}
		}

		[HarmonyPatch("PressESC")]
		[HarmonyPrefix]
		private static void checkEsc(ref CallbackContext context)
		{
			if (((CallbackContext)(ref context)).action.name == "OpenMenu")
			{
				leaving = true;
			}
		}

		[HarmonyPatch("BeginUsingTerminal")]
		[HarmonyPrefix]
		private static void resetEsc()
		{
			leaving = false;
		}

		[HarmonyPatch("OnSubmit")]
		[HarmonyPrefix]
		private static void resubmitBet(ref Terminal __instance)
		{
			if (__instance.textAdded == 0 && __instance.currentNode.terminalEvent == "spinGamba" && !leaving)
			{
				__instance.LoadNewNode(__instance.currentNode);
			}
		}

		[HarmonyPatch("LoadNewNode")]
		[HarmonyPrefix]
		private static void spinGamba(ref TerminalNode node, ref Terminal __instance)
		{
			if (node.terminalEvent == "spinGamba")
			{
				__instance.terminalNodes.specialNodes[11] = savedNode;
				if (__instance.groupCredits - betAmount >= 0 && betAmount != 0)
				{
					Terminal obj = __instance;
					obj.groupCredits -= betAmount;
					node.displayText = updateScreen(SpinSlots(slots), betAmount);
					int num = CalculateWinnings(slots, betAmount);
					if (num > 0)
					{
						node.displayText = winScreen(slots, num);
						__instance.PlayTerminalAudioServerRpc(0);
						__instance.PlayTerminalAudioServerRpc(3);
					}
					else
					{
						__instance.PlayTerminalAudioServerRpc(1);
					}
					Terminal obj2 = __instance;
					obj2.groupCredits += num;
					__instance.SyncGroupCreditsServerRpc(__instance.groupCredits, __instance.numberOfItemsInDropship);
				}
				else
				{
					node.displayText = emptyScreen(SpinSlots(slots));
				}
			}
			if (node.terminalEvent == "gamba")
			{
				node.displayText = updateSlotScreen(SpinSlots(slots));
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void addGamba(ref Terminal __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Expected O, but got Unknown
			//IL_056b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Expected O, but got Unknown
			TerminalNode val = new TerminalNode();
			val.displayText = "Welcome to the Company slot machine\n---------------------------------------------------\n\n\n         " + slots[0, 0] + "   |   " + slots[0, 1] + "   |   " + slots[0, 2] + "   |   " + slots[0, 3] + "   |   " + slots[0, 4] + "         \n             |       |       |       |             \n         " + slots[1, 0] + "   |   " + slots[1, 1] + "   |   " + slots[1, 2] + "   |   " + slots[1, 3] + "   |   " + slots[1, 4] + "         \n             |       |       |       |             \n         " + slots[2, 0] + "   |   " + slots[2, 1] + "   |   " + slots[2, 2] + "   |   " + slots[2, 3] + "   |   " + slots[2, 4] + "         \n             |       |       |       |             \n         " + slots[3, 0] + "   |   " + slots[3, 1] + "   |   " + slots[3, 2] + "   |   " + slots[3, 3] + "   |   " + slots[3, 4] + "         \n             |       |       |       |             \n         " + slots[4, 0] + "   |   " + slots[4, 1] + "   |   " + slots[4, 2] + "   |   " + slots[4, 3] + "   |   " + slots[4, 4] + "         \n\n\n---------------------------------------------------\nPlease enter how much you would like to gamble\n(bet [amount]): ";
			val.clearPreviousText = true;
			val.terminalEvent = "gamba";
			TerminalKeyword val2 = new TerminalKeyword();
			val2.word = "slots";
			val2.isVerb = false;
			val2.specialKeywordResult = val;
			slots = SpinSlots(slots);
			spinNode.displayText = "Welcome to the Company slot machine\n---------------------------------------------------\n\n\n         " + slots[0, 0] + "   |   " + slots[0, 1] + "   |   " + slots[0, 2] + "   |   " + slots[0, 3] + "   |   " + slots[0, 4] + "         \n             |       |       |       |             \n         " + slots[1, 0] + "   |   " + slots[1, 1] + "   |   " + slots[1, 2] + "   |   " + slots[1, 3] + "   |   " + slots[1, 4] + "         \n             |       |       |       |             \n         " + slots[2, 0] + "   |   " + slots[2, 1] + "   |   " + slots[2, 2] + "   |   " + slots[2, 3] + "   |   " + slots[2, 4] + "         \n             |       |       |       |             \n         " + slots[3, 0] + "   |   " + slots[3, 1] + "   |   " + slots[3, 2] + "   |   " + slots[3, 3] + "   |   " + slots[3, 4] + "         \n             |       |       |       |             \n         " + slots[4, 0] + "   |   " + slots[4, 1] + "   |   " + slots[4, 2] + "   |   " + slots[4, 3] + "   |   " + slots[4, 4] + "         \n\n\n---------------------------------------------------\nSpinning....\n";
			spinNode.clearPreviousText = true;
			spinNode.terminalEvent = "spinGamba";
			TerminalKeyword val3 = new TerminalKeyword();
			val3.word = "bet";
			val3.isVerb = false;
			val3.specialKeywordResult = spinNode;
			__instance.terminalNodes.allKeywords = CollectionExtensions.AddToArray<TerminalKeyword>(__instance.terminalNodes.allKeywords, val2);
			__instance.terminalNodes.allKeywords = CollectionExtensions.AddToArray<TerminalKeyword>(__instance.terminalNodes.allKeywords, val3);
			if (!homeModified)
			{
				string displayText = __instance.terminalNodes.specialNodes[1].displayText;
				__instance.terminalNodes.specialNodes[1].displayText = displayText.Substring(0, displayText.Length - 2) + "[Gamba Mod]\nType \"slots\" to begin your gambling career!\n";
				homeModified = true;
			}
			TerminalKeyword[] allKeywords = __instance.terminalNodes.allKeywords;
			foreach (TerminalKeyword val4 in allKeywords)
			{
				Console.WriteLine(val4.specialKeywordResult.displayText);
				if (val4.word.Equals("other"))
				{
					int num = val4.specialKeywordResult.displayText.IndexOf("t.");
					string displayText2 = val4.specialKeywordResult.displayText;
					val4.specialKeywordResult.displayText = displayText2.Substring(0, num + 2) + "\n\n>SLOTS\nGamble company credits in the slot machine.\n";
				}
			}
		}
	}
}