Decompiled source of LetsGoGambling v1.0.0

doomahreal.ultrakill.LetsGoGambling/LetsGoGambling.dll

Decompiled 5 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;

[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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LetsGoGambling")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LetsGoGambling")]
[assembly: AssemblyTitle("LetsGoGambling")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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;
		}
	}
}
public class MultiplyBetButton : MonoBehaviour
{
	[SerializeField]
	private int multiplier = 2;

	private Button button;

	private void Awake()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		button = ((Component)this).GetComponent<Button>();
		if ((Object)(object)button != (Object)null)
		{
			((UnityEvent)button.onClick).AddListener(new UnityAction(MultiplyBet));
		}
		else
		{
			Debug.LogError((object)"Button component not found on this GameObject.");
		}
	}

	public void MultiplyBet()
	{
		BetTextUpdater.MultiplyBet(multiplier);
	}
}
public class BetTextUpdater : MonoBehaviour
{
	private static int currentBet = 1000;

	private TextMeshProUGUI betText;

	private static BetTextUpdater instance;

	private void Awake()
	{
		betText = ((Component)this).GetComponent<TextMeshProUGUI>();
		if ((Object)(object)betText == (Object)null)
		{
			Debug.LogError((object)"TextMeshProUGUI component not found on the GameObject.");
		}
		else
		{
			UpdateBetText();
		}
	}

	private void OnEnable()
	{
		instance = this;
		UpdateBetText();
	}

	private void OnDisable()
	{
		if ((Object)(object)instance == (Object)(object)this)
		{
			instance = null;
		}
	}

	private static void UpdateBetText()
	{
		if ((Object)(object)instance != (Object)null && (Object)(object)instance.betText != (Object)null)
		{
			((TMP_Text)instance.betText).text = "Current <color=orange>Bet</color>:\n" + GetCurrentBet().ToString("N0") + " <color=orange>P</color>";
		}
	}

	public static int GetCurrentBet()
	{
		return currentBet;
	}

	public static void SetDefaultBet(int defaultBet)
	{
		currentBet = defaultBet;
		UpdateBetText();
	}

	public static void MultiplyBet(int multiplier)
	{
		int num = currentBet + multiplier;
		if (num >= 0)
		{
			currentBet = num;
			UpdateBetText();
		}
	}
}
[HarmonyPatch(typeof(MoneyText))]
[HarmonyPatch("DivideMoney")]
public static class MoneyTextPatch
{
	private static bool Prefix(ref string __result, int dosh)
	{
		if (dosh > 1000000000)
		{
			__result = FormatLargeNumber(dosh);
			return false;
		}
		return true;
	}

	private static string FormatLargeNumber(int dosh)
	{
		return dosh.ToString("N0");
	}
}
public class Reel : MonoBehaviour
{
	public Sprite[] symbolSprites;

	public Image reelImage;

	public float spinSpeed = 1000f;

	private bool isSpinning = false;

	private float targetTime = 1f;

	private int landedIndex;

	private void Start()
	{
		reelImage = ((Component)this).GetComponent<Image>();
	}

	private float GetRandomDelay(float minDelay, float maxDelay)
	{
		Random random = new Random();
		return (float)((double)minDelay + random.NextDouble() * (double)(maxDelay - minDelay));
	}

	public void StartSpinProcess()
	{
		float minDelay = 0.1f;
		float maxDelay = 0.5f;
		float randomDelay = GetRandomDelay(minDelay, maxDelay);
		((MonoBehaviour)this).Invoke("StartSpin", randomDelay);
	}

	public void StartSpin()
	{
		isSpinning = true;
		Random random = new Random();
		float num = 0.5f;
		float num2 = 3.5f;
		targetTime = (float)((double)num + random.NextDouble() * (double)(num2 - num));
		((MonoBehaviour)this).StartCoroutine(SpinReel());
	}

	private IEnumerator SpinReel()
	{
		float elapsedTime = 0f;
		while (elapsedTime < targetTime)
		{
			elapsedTime += Time.deltaTime;
			int randomIndex = Random.Range(0, symbolSprites.Length);
			reelImage.sprite = symbolSprites[randomIndex];
			landedIndex = randomIndex;
			yield return (object)new WaitForSeconds(1f / spinSpeed);
		}
		isSpinning = false;
	}

	public bool IsSpinning()
	{
		return isSpinning;
	}

	public int GetLandedIndex()
	{
		return landedIndex;
	}

	public void SetLandedIndex(int index)
	{
		landedIndex = index;
		reelImage.sprite = symbolSprites[index];
	}
}
public class DefaultBetButton : MonoBehaviour
{
	private Button button;

	private void Awake()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		button = ((Component)this).GetComponent<Button>();
		if ((Object)(object)button != (Object)null)
		{
			((UnityEvent)button.onClick).AddListener(new UnityAction(SetDefaultBet));
		}
		else
		{
			Debug.LogError((object)"Button component not found on this GameObject.");
		}
	}

	public void SetDefaultBet()
	{
		BetTextUpdater.SetDefaultBet(1000);
	}
}
public class ShaderLoader : MonoBehaviour
{
	[Tooltip("The addressable key for the shader to be loaded.")]
	public string shaderAddress;

	private void Start()
	{
		LoadAndApplyShader(shaderAddress);
	}

	private void LoadAndApplyShader(string address)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		AsyncOperationHandle<Shader> val = Addressables.LoadAssetAsync<Shader>((object)address);
		val.Completed += OnShaderLoaded;
	}

	private void OnShaderLoaded(AsyncOperationHandle<Shader> handle)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Invalid comparison between Unknown and I4
		if ((int)handle.Status == 1)
		{
			Shader result = handle.Result;
			ApplyShaderToAllMaterials(result);
		}
		else
		{
			Debug.LogError((object)("Failed to load shader: " + handle.OperationException));
		}
	}

	private void ApplyShaderToAllMaterials(Shader shader)
	{
		Renderer component = ((Component)this).GetComponent<Renderer>();
		if ((Object)(object)component != (Object)null)
		{
			Material[] sharedMaterials = component.sharedMaterials;
			foreach (Material val in sharedMaterials)
			{
				val.shader = shader;
			}
		}
		else
		{
			Debug.LogWarning((object)("No Renderer found on GameObject: " + ((Object)((Component)this).gameObject).name));
		}
	}
}
public class SlotMachineController : MonoBehaviour
{
	public Reel[] reels;

	public Button spinButton;

	private bool lastSpinWasWin = false;

	private int[] rewardMultipliers = new int[4] { 100, 50, 25, 10 };

	private bool isFirstSpin = true;

	private void Start()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		((UnityEvent)spinButton.onClick).AddListener((UnityAction)delegate
		{
			int money = GameProgressSaver.GetMoney();
			int currentBet = BetTextUpdater.GetCurrentBet();
			if (money >= currentBet)
			{
				if (!lastSpinWasWin)
				{
					GameProgressSaver.AddMoney(currentBet * -1);
				}
				StartSpinning();
			}
		});
	}

	private void StartSpinning()
	{
		Reel[] array = reels;
		foreach (Reel reel in array)
		{
			reel.StartSpinProcess();
		}
		((MonoBehaviour)this).StartCoroutine(CheckResults());
	}

	public void ForceWin(int symbolIndex)
	{
		Reel[] array = reels;
		foreach (Reel reel in array)
		{
			reel.SetLandedIndex(symbolIndex);
		}
		CheckWin();
	}

	private IEnumerator CheckResults()
	{
		bool spinning = true;
		while (spinning)
		{
			spinning = false;
			Reel[] array = reels;
			foreach (Reel reel in array)
			{
				if (reel.IsSpinning())
				{
					spinning = true;
					break;
				}
			}
			yield return null;
		}
		CheckWin();
	}

	private void CheckWin()
	{
		int[] array = new int[reels.Length];
		bool flag = true;
		for (int i = 0; i < reels.Length; i++)
		{
			array[i] = reels[i].GetLandedIndex();
			if (i > 0 && array[i] != array[i - 1])
			{
				flag = false;
			}
		}
		if (flag && !isFirstSpin)
		{
			int num = rewardMultipliers[array[0]];
			int num2 = BetTextUpdater.GetCurrentBet() * num;
			GameProgressSaver.AddMoney(num2);
		}
		lastSpinWasWin = flag;
		isFirstSpin = false;
	}
}
namespace LetsGoGambling
{
	public static class Loader
	{
		public static AssetBundle LoadBankrupcy()
		{
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				string name = "LetsGoGambling.gamble.bundle";
				using Stream stream = executingAssembly.GetManifestResourceStream(name);
				if (stream == null)
				{
					Debug.LogError((object)"Resource 'gamble.bundle' not found in embedded resources.");
					return null;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				return AssetBundle.LoadFromMemory(array);
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Error loading objector: " + ex.Message));
				return null;
			}
		}
	}
	[BepInPlugin("doomahreal.ultrakill.LetsGoGambling", "LetsGoGambling", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private AssetBundle Bundle;

		public static SpawnableObject Machine;

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			Debug.Log((object)"h");
			Bundle = Loader.LoadBankrupcy();
			Machine = Bundle.LoadAsset<SpawnableObject>("money.asset");
			Harmony val = new Harmony("doomahreal.ultrakill.LetsGoGambling");
			val.PatchAll();
		}

		public static void UpdateAllMoneyTexts()
		{
			MoneyText[] array = Object.FindObjectsOfType<MoneyText>();
			MoneyText[] array2 = array;
			foreach (MoneyText val in array2)
			{
				val.UpdateMoney();
			}
		}
	}
	[HarmonyPatch(typeof(SpawnMenu))]
	[HarmonyPatch("Awake")]
	public static class SpawnMenu_Patch
	{
		private static void Prefix(ref SpawnableObjectsDatabase ___objects)
		{
			bool flag = true;
			SpawnableObject[] sandboxTools = ___objects.sandboxTools;
			SpawnableObject[] array = sandboxTools;
			foreach (SpawnableObject val in array)
			{
				if ((Object)(object)val == (Object)(object)Plugin.Machine)
				{
					flag = false;
				}
			}
			if (flag)
			{
				SpawnableObject[] array2 = (SpawnableObject[])(object)new SpawnableObject[sandboxTools.Length + 1];
				Array.Copy(sandboxTools, array2, sandboxTools.Length);
				array2[^1] = Plugin.Machine;
				___objects.sandboxTools = array2;
			}
		}
	}
	[HarmonyPatch(typeof(EnemyInfoPage))]
	[HarmonyPatch("Start")]
	public static class EnemyInfoPage_Patch
	{
		private static void Prefix(ref SpawnableObjectsDatabase ___objects)
		{
			bool flag = true;
			SpawnableObject[] enemies = ___objects.enemies;
			SpawnableObject[] array = enemies;
			foreach (SpawnableObject val in array)
			{
				if ((Object)(object)val == (Object)(object)Plugin.Machine)
				{
					flag = false;
				}
			}
			if (flag)
			{
				SpawnableObject[] array2 = (SpawnableObject[])(object)new SpawnableObject[enemies.Length + 1];
				array2[0] = Plugin.Machine;
				Array.Copy(enemies, 0, array2, 1, enemies.Length);
				___objects.enemies = array2;
			}
		}
	}
	[HarmonyPatch(typeof(GameProgressSaver))]
	[HarmonyPatch("AddMoney")]
	public static class GameProgressSaver_Patch
	{
		private static void Postfix()
		{
			Plugin.UpdateAllMoneyTexts();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LetsGoGambling";

		public const string PLUGIN_NAME = "LetsGoGambling";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}