using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using DiceKingdoms.Game;
using DiceKingdoms.Interface;
using DiceKingdoms.Network;
using DiceModders.ModCore;
using DiceModders.ModCore.Tools;
using DiceModders.UiKit;
using DiceModders.UiKit.Custom;
using DiceModders.UiKit.Native;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Runtime.CompilerServices;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DiceModders")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A Casino for Dice Kingdoms: a new building where you can spin a wheel of fortune once in a while, with good and bad outcomes. A lobby rule.")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("DiceModders.Casino")]
[assembly: AssemblyTitle("DiceModders.Casino")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[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 DiceModders.Casino
{
internal static class Casino
{
private static LobbyRule<bool> _on;
private static LobbyRule<int> _jackpot;
private static LobbyRule<int> _win;
private static LobbyRule<int> _bad;
private static LobbyRule<int> _catastrophe;
private static LobbyRule<int> _stake;
private static LobbyRule<int> _cooldown;
private static LobbyRule<int> _winGold;
private static LobbyRule<int> _winEach;
internal static (LobbyRule<int> rule, string unit)[] Numbers => new(LobbyRule<int>, string)[8]
{
(_jackpot, "%"),
(_win, "%"),
(_bad, "%"),
(_catastrophe, "%"),
(_stake, ""),
(_cooldown, ""),
(_winGold, ""),
(_winEach, "")
};
internal static LobbyRule<bool> Rule => _on;
internal static int ChanceSum => (_jackpot?.Live ?? 0) + (_win?.Live ?? 0) + (_bad?.Live ?? 0) + (_catastrophe?.Live ?? 0);
internal static bool On
{
get
{
if (Plugin.On && _on != null)
{
return _on.Value;
}
return false;
}
}
internal static int JackpotPercent => _jackpot?.Value ?? 5;
internal static int WinPercent => _win?.Value ?? 15;
internal static int BadPercent => _bad?.Value ?? 30;
internal static int CatastrophePercent => _catastrophe?.Value ?? 5;
internal static int Stake => _stake?.Value ?? 3;
internal static int Cooldown => _cooldown?.Value ?? 3;
internal static int WinGold => _winGold?.Value ?? 6;
internal static int WinEach => _winEach?.Value ?? 1;
internal static bool IsChance(LobbyRule<int> rule)
{
if (rule != _jackpot && rule != _win && rule != _bad)
{
return rule == _catastrophe;
}
return true;
}
internal static void Install(Patcher patcher)
{
_on = Rules.Toggle("casino.on", "Casino", false, "Adds the Casino, a building (needs a University) where you can spin a wheel of fortune once in a while: good and bad outcomes.", (Func<bool>)(() => false), true);
_jackpot = Rules.Number("casino.jackpot", "Jackpot chance (%)", 5, 0, 30, 5, "Chance of a tsunami on every other player.", (Func<bool>)(() => false), true);
_win = Rules.Number("casino.win", "Win chance (%)", 15, 0, 60, 5, "Chance of winning gold or some of each resource.", (Func<bool>)(() => false), true);
_bad = Rules.Number("casino.bad", "Bad luck chance (%)", 30, 0, 60, 5, "Chance of robbers from another island or a fire on your island.", (Func<bool>)(() => false), true);
_catastrophe = Rules.Number("casino.catastrophe", "Catastrophe chance (%)", 5, 0, 30, 5, "Chance of a tsunami and a meteorite on your own island.", (Func<bool>)(() => false), true);
_stake = Rules.Number("casino.stake", "Stake (gold)", 3, 1, 10, 1, "Gold a spin costs.", (Func<bool>)(() => false), true);
_cooldown = Rules.Number("casino.cooldown", "Turns between spins", 3, 1, 10, 1, "How many turns a player waits between two spins.", (Func<bool>)(() => false), true);
_winGold = Rules.Number("casino.winGold", "Gold win", 6, 1, 30, 1, "Gold a gold win gives.", (Func<bool>)(() => false), true);
_winEach = Rules.Number("casino.winEach", "Win of each resource", 1, 1, 5, 1, "How much of each resource the other win gives.", (Func<bool>)(() => false), true);
LobbyGroup heading = Groups.Get("casino", "Casino", 500);
ILobbyRule[] array = (ILobbyRule[])(object)new ILobbyRule[9]
{
(ILobbyRule)_on,
(ILobbyRule)_jackpot,
(ILobbyRule)_win,
(ILobbyRule)_bad,
(ILobbyRule)_catastrophe,
(ILobbyRule)_stake,
(ILobbyRule)_cooldown,
(ILobbyRule)_winGold,
(ILobbyRule)_winEach
};
for (int num = 0; num < array.Length; num++)
{
Group(array[num], heading);
}
}
private static void Group(ILobbyRule rule, LobbyGroup heading)
{
if (rule is LobbyRule<bool> val)
{
val.InGroup(heading);
}
else if (rule is LobbyRule<int> val2)
{
val2.InGroup(heading);
}
}
}
internal static class CasinoLook
{
internal static readonly string[] Styles = new string[7] { "europe", "middle-east", "viking", "ancient", "maya", "japan", "reskin" };
private static readonly string[] Tokens = new string[5] { "europe", "middle-east", "viking", "ancient", "maya" };
private static readonly Dictionary<IntPtr, BuildingVisual> Copies = new Dictionary<IntPtr, BuildingVisual>();
private static readonly Dictionary<string, Mesh> Meshes = new Dictionary<string, Mesh>();
private static readonly Dictionary<string, Mesh> SlotMeshes = new Dictionary<string, Mesh>();
private static Mesh _empty;
private static int _loadedFrame = -1;
private static bool _inside;
private static readonly HashSet<string> TextPicturesDone = new HashSet<string>();
private static Mesh Empty
{
get
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
if ((Object)(object)_empty == (Object)null)
{
_empty = new Mesh
{
name = "custom-empty"
};
((Object)_empty).hideFlags = (HideFlags)32;
}
return _empty;
}
}
internal static void Install(Patcher patcher)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
try
{
MethodInfo methodInfo = AccessTools.Method(typeof(PlayerSkins), "GetBuildingVisualPrefab", (Type[])null, (Type[])null);
patcher.Harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(CasinoLook), "LookPostfix", (Type[])null)
{
priority = 0
}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
catch (Exception ex)
{
Plugin.L.LogError((object)("casino look hook: " + ex));
}
Civilizations.WhenGameDataLoaded((Action)delegate
{
_loadedFrame = Time.frameCount;
Later.Run(Prepare);
});
}
private static void Prepare()
{
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Expected O, but got Unknown
try
{
Il2CppArrayBase<SkinRegistry> val = Resources.FindObjectsOfTypeAll<SkinRegistry>();
if (val.Length == 0 || CasinoType.Type == null)
{
return;
}
List<(int, int)> list = new List<(int, int)>
{
(0, 0),
(1, 1),
(2, 2),
(3, 3),
(4, 4)
};
foreach (ModCivilization item in Civilizations.All)
{
list.Add((item.Id, item.SkinsLike));
}
foreach (var (num, num2) in list)
{
try
{
PlayerSkins val2 = new PlayerSkins((Civilization)num2, val[0]);
if (num != num2)
{
val2.civilization = (Civilization)num;
}
val2.GetBuildingVisualPrefab(CasinoType.Type);
}
catch (Exception ex)
{
Plugin.Once("prepare" + num, "casino look for civilization " + num + ": " + ex.Message);
}
}
Plugin.L.LogInfo((object)("casino looks ready: " + Copies.Count));
}
catch (Exception ex2)
{
Plugin.Once("prepare", "casino looks: " + ex2);
}
}
public static void LookPostfix(PlayerSkins __instance, BuildingType __0, ref BuildingVisual __result)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Invalid comparison between Unknown and I4
if (_inside || __0 == null || (int)__0.name != 24 || __instance == null || CasinoType.Market == null || _loadedFrame < 0 || Time.frameCount <= _loadedFrame)
{
return;
}
_inside = true;
try
{
BuildingVisual buildingVisualPrefab = __instance.GetBuildingVisualPrefab(CasinoType.Market);
if ((Object)(object)buildingVisualPrefab == (Object)null)
{
return;
}
if (Copies.TryGetValue(((Il2CppObjectBase)buildingVisualPrefab).Pointer, out var value) && (Object)(object)value != (Object)null)
{
__result = value;
return;
}
value = Make(buildingVisualPrefab);
if ((Object)(object)value != (Object)null)
{
Copies[((Il2CppObjectBase)buildingVisualPrefab).Pointer] = value;
__result = value;
}
}
catch (Exception ex)
{
Plugin.Once("look", "casino look: " + ex);
}
finally
{
_inside = false;
}
}
private static BuildingVisual Make(BuildingVisual market)
{
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Expected O, but got Unknown
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0220: Unknown result type (might be due to invalid IL or missing references)
//IL_0225: Unknown result type (might be due to invalid IL or missing references)
string text = StyleOf(market);
Mesh val = MeshOf(text);
if ((Object)(object)val == (Object)null)
{
return null;
}
BuildingVisual val2 = Prefabs.Copy<BuildingVisual>(market, (string)null);
int num = 0;
int num2 = 0;
foreach (MeshFilter componentsInChild in ((Component)val2).GetComponentsInChildren<MeshFilter>(true))
{
if (GroupOf(((Object)((Component)componentsInChild).gameObject).name) != null)
{
Transform parent = ((Component)componentsInChild).transform.parent;
if ((Object)(object)parent != (Object)null && ((Component)parent).gameObject.activeSelf && (!((Object)(object)componentsInChild.sharedMesh != (Object)null) || !(((Object)componentsInChild.sharedMesh).name == "custom-empty")))
{
componentsInChild.sharedMesh = ForSlots(val, text, ((Component)componentsInChild).GetComponent<MeshRenderer>());
num++;
}
else
{
componentsInChild.sharedMesh = Empty;
num2++;
}
}
}
foreach (LODGroup componentsInChild2 in ((Component)val2).GetComponentsInChildren<LODGroup>(true))
{
try
{
componentsInChild2.RecalculateBounds();
}
catch
{
}
}
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(47, 4, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("casino look '");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' made from '");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((Object)((Component)market).gameObject).name);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' (");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(num);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" meshes, ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(num2);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" blanked)");
}
l.LogInfo(val3);
Sprite val4 = ((val2.icons != null && ((Il2CppArrayBase<Sprite>)(object)val2.icons).Length > 0) ? ((Il2CppArrayBase<Sprite>)(object)val2.icons)[0] : null);
int num3;
Rect rect;
if (!((Object)(object)val4 != (Object)null))
{
num3 = 256;
}
else
{
rect = val4.rect;
num3 = Mathf.RoundToInt(((Rect)(ref rect)).width);
}
int num4 = num3;
int num5;
if (!((Object)(object)val4 != (Object)null))
{
num5 = 256;
}
else
{
rect = val4.rect;
num5 = Mathf.RoundToInt(((Rect)(ref rect)).height);
}
int num6 = num5;
BuildingVisual target = val2;
string iconName = "org.dicemodders.dicekingdoms.casino casino-" + text;
IconRenderer.PlayerColours(iconName, ((Component)val2).gameObject, IconView.Building, num4, num6, (Action<Sprite[]>)delegate(Sprite[] sprites)
{
if (!((Object)(object)target == (Object)null) && sprites != null)
{
Il2CppReferenceArray<Sprite> icons = target.icons;
int num7 = ((Il2CppArrayBase<Sprite>)(object)icons)?.Length ?? sprites.Length;
Il2CppReferenceArray<Sprite> val5 = new Il2CppReferenceArray<Sprite>((long)num7);
for (int i = 0; i < num7; i++)
{
((Il2CppArrayBase<Sprite>)(object)val5)[i] = ((i < sprites.Length) ? sprites[i] : ((Il2CppArrayBase<Sprite>)(object)icons)?[i]);
}
target.icons = val5;
TextPictures(iconName, sprites, icons);
}
});
return val2;
}
private static void TextPictures(string iconName, Sprite[] sprites, Il2CppReferenceArray<Sprite> like)
{
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Expected O, but got Unknown
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
try
{
if (!TextPicturesDone.Add(iconName))
{
return;
}
List<Entry> list = new List<Entry>();
for (int i = 0; i < sprites.Length; i++)
{
Sprite s = sprites[i];
Sprite val = ((like != null && ((Il2CppArrayBase<Sprite>)(object)like).Length > 0) ? ((Il2CppArrayBase<Sprite>)(object)like)[Math.Min(i, ((Il2CppArrayBase<Sprite>)(object)like).Length - 1)] : null);
if (!((Object)(object)s == (Object)null) && !((Object)(object)val == (Object)null))
{
list.Add(new Entry(((Object)s).name, ((Object)val).name, (Func<Texture2D>)(() => Sprites.ReadableCopy(s))));
}
}
int num = TextSprites.AddLike(iconName + " Text", (IEnumerable<Entry>)list, IconRenderer.CacheKey(iconName));
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(34, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("casino look: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(num);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" text pictures for '");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(iconName);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'");
}
l.LogInfo(val2);
}
catch (Exception ex)
{
Plugin.L.LogError((object)("casino look: text pictures failed: " + ex.Message));
}
}
private static string StyleOf(BuildingVisual market)
{
string text = null;
bool flag = false;
bool flag2 = false;
foreach (MeshFilter componentsInChild in ((Component)market).GetComponentsInChildren<MeshFilter>(true))
{
string text2 = GroupOf(((Object)((Component)componentsInChild).gameObject).name);
if (text2 == null)
{
continue;
}
Transform parent = ((Component)componentsInChild).transform.parent;
if ((Object)(object)parent == (Object)null || !((Component)parent).gameObject.activeSelf)
{
continue;
}
string text3 = (((Object)(object)componentsInChild.sharedMesh != (Object)null) ? ((Object)componentsInChild.sharedMesh).name : "");
if (text3 == "custom-empty")
{
continue;
}
if (text3.StartsWith("custom-jp-", StringComparison.Ordinal))
{
flag2 = true;
}
else if (text3.StartsWith("custom-", StringComparison.Ordinal))
{
flag = true;
}
if (text != null)
{
continue;
}
string[] tokens = Tokens;
foreach (string text4 in tokens)
{
if (text2.EndsWith("-" + text4, StringComparison.Ordinal))
{
text = text4;
break;
}
}
}
if (flag2)
{
return "japan";
}
if (text == null)
{
text = "europe";
}
if (flag && text == "europe")
{
return "reskin";
}
return text;
}
private static Mesh MeshOf(string style)
{
if (Meshes.TryGetValue(style, out var value) && (Object)(object)value != (Object)null)
{
return value;
}
Assembly assembly = typeof(CasinoLook).Assembly;
string text = "models/casino-" + style + ".dkmesh.gz";
if (assembly.GetManifestResourceInfo(text) == null)
{
Plugin.Once("model:" + style, "casino model missing: " + text);
return null;
}
byte[] gz;
using (Stream stream = assembly.GetManifestResourceStream(text))
{
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
gz = memoryStream.ToArray();
}
string text2 = "1.0.2+" + Convert.ToHexString(SHA1.HashData(gz)).Substring(0, 12);
Vector3? val = default(Vector3?);
float num = default(float);
value = Meshes.LoadDkmesh("casino-" + style, (Func<Stream>)(() => new GZipStream(new MemoryStream(gz), CompressionMode.Decompress)), text2, ref val, ref num);
((Object)value).name = "casino-" + style;
((Object)value).hideFlags = (HideFlags)32;
Meshes[style] = value;
return value;
}
private static Mesh ForSlots(Mesh mesh, string style, MeshRenderer r)
{
Il2CppReferenceArray<Material> val = (((Object)(object)r != (Object)null) ? ((Renderer)r).sharedMaterials : null);
if (val == null || ((Il2CppArrayBase<Material>)(object)val).Length <= 1)
{
return mesh;
}
int num = 0;
for (int i = 0; i < ((Il2CppArrayBase<Material>)(object)val).Length; i++)
{
if ((Object)(object)((Il2CppArrayBase<Material>)(object)val)[i] != (Object)null && ((Object)((Il2CppArrayBase<Material>)(object)val)[i]).name.StartsWith("Colored-Paper", StringComparison.Ordinal))
{
num = i;
break;
}
}
string text = style + "/" + num + "/" + ((Il2CppArrayBase<Material>)(object)val).Length;
if (SlotMeshes.TryGetValue(text, out var value) && (Object)(object)value != (Object)null)
{
return value;
}
value = Object.Instantiate<Mesh>(mesh);
((Object)value).name = ((Object)mesh).name + "#" + text;
((Object)value).hideFlags = (HideFlags)32;
Il2CppStructArray<int> triangles = mesh.triangles;
value.subMeshCount = ((Il2CppArrayBase<Material>)(object)val).Length;
for (int j = 0; j < ((Il2CppArrayBase<Material>)(object)val).Length; j++)
{
value.SetTriangles((j == num) ? triangles : Il2CppStructArray<int>.op_Implicit(new int[0]), j);
}
SlotMeshes[text] = value;
return value;
}
private static string GroupOf(string name)
{
int num = name.IndexOf("-mesh_LOD", StringComparison.Ordinal);
if (num <= 0)
{
return null;
}
return name.Substring(0, num);
}
}
internal static class CasinoPanel
{
private static SpecializedPanel _sensor;
private static BuildInterface _build;
private static ButtonIcon _swapped;
private static Sprite _savedIcon;
private static Action _savedClick;
private static StructuredText _savedTip;
private static Sprite _icon;
private static Wheel.Outcome[] _iconFaces;
private static Action _click;
private static Action _nativeClick;
internal static void Install(Patcher patcher)
{
patcher.Patch(typeof(BuildInterface), "InitBuildingButtons", typeof(CasinoPanel), (string)null, "ButtonsPostfix");
patcher.Patch(typeof(BuildInterface), "RefreshButtons", typeof(CasinoPanel), (string)null, "RefreshPostfix");
Texts.LanguageChanged += delegate
{
if ((Object)(object)_swapped != (Object)null)
{
SetTip(_swapped);
}
};
}
public static void ButtonsPostfix(BuildInterface __instance)
{
try
{
Add(__instance);
}
catch (Exception ex)
{
Plugin.Once("panel", "casino panel: " + ex);
}
}
public static void RefreshPostfix(BuildInterface __instance)
{
try
{
if ((Object)(object)_swapped != (Object)null && (Object)(object)_build != (Object)null && ((Il2CppObjectBase)__instance).Pointer == ((Il2CppObjectBase)_build).Pointer)
{
SetTip(_swapped);
}
}
catch (Exception ex)
{
Plugin.Once("panel-refresh", "casino button tooltip: " + ex.Message);
}
}
private static void Add(BuildInterface build)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected O, but got Unknown
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
BuildingInformation val = ((build != null) ? build.buildingInformation : null);
if ((Object)(object)val == (Object)null || CasinoType.Type == null)
{
return;
}
_build = build;
if ((Object)(object)_sensor == (Object)null)
{
if (!ClassInjector.IsTypeRegisteredInIl2Cpp<CasinoSelected>())
{
ClassInjector.RegisterTypeInIl2Cpp<CasinoSelected>();
}
GameObject val2 = new GameObject("DM Casino holder");
val2.SetActive(false);
try
{
GameObject val3 = new GameObject("Casino");
val3.transform.SetParent(val2.transform, false);
RectTransform rectTransform = val3.AddComponent<RectTransform>();
_sensor = val3.AddComponent<SpecializedPanel>();
_sensor.rectTransform = rectTransform;
val3.AddComponent<CasinoSelected>();
val.AddSpecializedPanel(CasinoType.Type, _sensor);
return;
}
finally
{
Object.Destroy((Object)(object)val2);
}
}
val.AddSpecializedPanel(CasinoType.Type, _sensor);
}
internal static void Selected(bool on)
{
try
{
if (on)
{
SwapIn();
}
else
{
SwapOut();
}
}
catch (Exception ex)
{
Plugin.Once("panel-swap", "casino button: " + ex);
}
}
private static void SwapIn()
{
if ((Object)(object)_swapped != (Object)null || (Object)(object)_build == (Object)null)
{
return;
}
ButtonIcon val = (((Object)(object)_build.researchButton != (Object)null) ? ((Il2CppObjectBase)_build.researchButton).TryCast<ButtonIcon>() : null);
if (!((Object)(object)val == (Object)null))
{
_savedIcon = val.Icon;
_savedClick = ((BaseButton)val).onClick;
HasToolTip component = ((Component)val).GetComponent<HasToolTip>();
_savedTip = (((Object)(object)component != (Object)null) ? component.text : null);
if (_click == null)
{
_click = Click;
}
if (_nativeClick == null)
{
_nativeClick = DelegateSupport.ConvertDelegate<Action>((Delegate)_click);
}
((BaseButton)val).onClick = _nativeClick;
val.Icon = Icon();
SetTip(val);
_swapped = val;
}
}
private static void SwapOut()
{
ButtonIcon swapped = _swapped;
_swapped = null;
if (!((Object)(object)swapped == (Object)null))
{
((BaseButton)swapped).onClick = _savedClick;
swapped.Icon = _savedIcon;
HasToolTip component = ((Component)swapped).GetComponent<HasToolTip>();
if ((Object)(object)component != (Object)null && _savedTip != null)
{
component.text = _savedTip;
}
_savedClick = null;
_savedIcon = null;
_savedTip = null;
}
}
private static void Click()
{
try
{
WheelWindow.Open();
}
catch (Exception ex)
{
Plugin.L.LogWarning((object)("casino button: " + ex.Message));
}
try
{
EventSystem current = EventSystem.current;
if (current != null)
{
current.SetSelectedGameObject((GameObject)null);
}
}
catch
{
}
}
private static void SetTip(ButtonIcon button)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
HasToolTip component = ((Component)button).GetComponent<HasToolTip>();
if (!((Object)(object)component == (Object)null))
{
Il2CppReferenceArray<Object> val = new Il2CppReferenceArray<Object>(1L);
((Il2CppArrayBase<Object>)(object)val)[0] = (Object)(object)String.op_Implicit(Tx.T("window.title"));
component.text = new StructuredText(FormattableStringFactory.Create("{0}", val));
}
}
private static Sprite Icon()
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
Wheel.Outcome[] faces = Wheel.Faces;
if ((Object)(object)_icon == (Object)null || _iconFaces != faces)
{
_icon = Sprite.Create(WheelArt.Disc(96, faces), new Rect(0f, 0f, 96f, 96f), new Vector2(0.5f, 0.5f), 100f);
((Object)_icon).hideFlags = (HideFlags)32;
_iconFaces = faces;
}
return _icon;
}
}
internal sealed class CasinoSelected : MonoBehaviour
{
public CasinoSelected(IntPtr ptr)
: base(ptr)
{
}
public void OnEnable()
{
CasinoPanel.Selected(on: true);
}
public void OnDisable()
{
CasinoPanel.Selected(on: false);
}
}
internal static class CasinoType
{
internal const BuildingTypeName Name = (BuildingTypeName)24;
internal static BuildingType Type;
internal static BuildingType Market;
internal static void Install(Patcher patcher)
{
patcher.Patch(typeof(BuildingTypes), "Init", typeof(CasinoType), (string)null, "InitPostfix");
patcher.Patch(typeof(BuildingSerialization), "Awake", typeof(CasinoType), (string)null, "SerializationPostfix");
patcher.Patch(typeof(BuildInterface), "InitBuildingButtons", typeof(CasinoType), "ButtonsPrefix", (string)null);
patcher.Patch(typeof(BuildData), "CanBuildType", typeof(CasinoType), (string)null, "CanBuildPostfix");
patcher.Patch(typeof(BuildData), "Unlocked", typeof(CasinoType), (string)null, "UnlockedPostfix");
patcher.Patch(typeof(__c__DisplayClass4_0), "_Awake_b__0", typeof(CasinoType), "PoolingPrefix", (string)null);
Buildings.SuggestLimit((BuildingTypeName)24, 1, Casino.Rule);
Civilizations.GameDataLoaded += AddToExisting;
AddToExisting();
}
private static void AddToExisting()
{
try
{
foreach (BuildingTypes item in Resources.FindObjectsOfTypeAll<BuildingTypes>())
{
Append(item);
}
foreach (BuildingSerialization item2 in Resources.FindObjectsOfTypeAll<BuildingSerialization>())
{
AddIndex(item2);
}
}
catch (Exception ex)
{
Plugin.L.LogWarning((object)("casino type (existing data): " + ex.Message));
}
}
public static void InitPostfix(BuildingTypes __instance)
{
try
{
Append(__instance);
}
catch (Exception ex)
{
Plugin.Once("init", "casino type: " + ex);
}
}
private static void Append(BuildingTypes types)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Invalid comparison between Unknown and I4
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Expected O, but got Unknown
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Expected O, but got Unknown
Il2CppReferenceArray<BuildingType> val = ((types != null) ? types.Types : null);
if (val == null || ((Il2CppArrayBase<BuildingType>)(object)val).Length == 0)
{
return;
}
foreach (BuildingType item in (Il2CppArrayBase<BuildingType>)(object)val)
{
if (item != null && (int)item.name == 24)
{
return;
}
}
BuildingType market = types.market;
if (market != null)
{
Market = market;
if (Type == null)
{
Type = new BuildingType
{
name = (BuildingTypeName)24,
localPositions = market.localPositions,
localPositionsInWater = market.localPositionsInWater,
heightOverrides = market.heightOverrides,
visualPrefab = market.visualPrefab,
storageCapacity = default(ResourceAmount),
cost = new ResourceAmount
{
wood = 3,
stone = 2,
gold = 2,
hammer = 1
},
tier = 2,
bulkSize = market.bulkSize,
health = 20,
fortification = false,
garrison = false,
pillageReward = new ResourceAmount
{
gold = 3
},
remainsReward = new ResourceAmount
{
wood = 1,
stone = 1
},
hasEffectDescription = true
};
}
Il2CppReferenceArray<BuildingType> val2 = new Il2CppReferenceArray<BuildingType>((long)(((Il2CppArrayBase<BuildingType>)(object)val).Length + 1));
for (int i = 0; i < ((Il2CppArrayBase<BuildingType>)(object)val).Length; i++)
{
((Il2CppArrayBase<BuildingType>)(object)val2)[i] = ((Il2CppArrayBase<BuildingType>)(object)val)[i];
}
((Il2CppArrayBase<BuildingType>)(object)val2)[((Il2CppArrayBase<BuildingType>)(object)val).Length] = Type;
types.Types = val2;
Dictionary<BuildingTypeName, BuildingType> typesByName = types.typesByName;
if (typesByName != null && !typesByName.ContainsKey((BuildingTypeName)24))
{
typesByName.Add((BuildingTypeName)24, Type);
}
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(35, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("casino: added as building type ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(((Il2CppArrayBase<BuildingType>)(object)val).Length);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" of ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(((Il2CppArrayBase<BuildingType>)(object)val2).Length);
}
l.LogInfo(val3);
}
}
public static void PoolingPrefix(__c__DisplayClass4_0 __instance)
{
try
{
Dictionary<BuildingType, int> buildingTypeFactors = __instance.buildingTypeFactors;
if (Type != null && buildingTypeFactors != null && !buildingTypeFactors.ContainsKey(Type))
{
buildingTypeFactors.Add(Type, 1);
}
}
catch (Exception ex)
{
Plugin.Once("pooling", "casino (model pool): " + ex);
}
}
public static void SerializationPostfix(BuildingSerialization __instance)
{
try
{
AddIndex(__instance);
}
catch (Exception ex)
{
Plugin.Once("serialization", "casino type (network): " + ex);
}
}
private static void AddIndex(BuildingSerialization s)
{
if (Type == null || ((s != null) ? s.indexes : null) == null)
{
return;
}
BuildingTypes buildingTypes = s.buildingTypes;
if (((buildingTypes != null) ? buildingTypes.Types : null) == null)
{
return;
}
Il2CppReferenceArray<BuildingType> types = s.buildingTypes.Types;
for (int i = 0; i < ((Il2CppArrayBase<BuildingType>)(object)types).Length; i++)
{
if (((Il2CppArrayBase<BuildingType>)(object)types)[i] != null && ((Il2CppObjectBase)((Il2CppArrayBase<BuildingType>)(object)types)[i]).Pointer == ((Il2CppObjectBase)Type).Pointer)
{
if (!s.indexes.ContainsKey(Type))
{
s.indexes.Add(Type, i);
}
break;
}
}
}
public static void ButtonsPrefix(BuildInterface __instance)
{
try
{
Il2CppReferenceArray<BuildingType> buildableBuildingTypes = __instance.buildableBuildingTypes;
if (buildableBuildingTypes == null || Type == null)
{
return;
}
int num = -1;
for (int i = 0; i < ((Il2CppArrayBase<BuildingType>)(object)buildableBuildingTypes).Length; i++)
{
if (((Il2CppArrayBase<BuildingType>)(object)buildableBuildingTypes)[i] != null && ((Il2CppObjectBase)((Il2CppArrayBase<BuildingType>)(object)buildableBuildingTypes)[i]).Pointer == ((Il2CppObjectBase)Type).Pointer)
{
num = i;
break;
}
}
bool flag = Casino.On;
if (flag == num >= 0)
{
return;
}
Il2CppReferenceArray<BuildingType> val = new Il2CppReferenceArray<BuildingType>((long)(flag ? (((Il2CppArrayBase<BuildingType>)(object)buildableBuildingTypes).Length + 1) : (((Il2CppArrayBase<BuildingType>)(object)buildableBuildingTypes).Length - 1)));
int num2 = 0;
for (int j = 0; j < ((Il2CppArrayBase<BuildingType>)(object)buildableBuildingTypes).Length; j++)
{
if (j != num)
{
((Il2CppArrayBase<BuildingType>)(object)val)[num2++] = ((Il2CppArrayBase<BuildingType>)(object)buildableBuildingTypes)[j];
}
}
if (flag)
{
((Il2CppArrayBase<BuildingType>)(object)val)[num2] = Type;
}
__instance.buildableBuildingTypes = val;
}
catch (Exception ex)
{
Plugin.Once("buttons", "casino button: " + ex);
}
}
public static void CanBuildPostfix(BuildData __instance, BuildingType __0, ref bool __result)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Invalid comparison between Unknown and I4
try
{
if (!__result || __0 == null || (int)__0.name != 24)
{
return;
}
if (!Casino.On)
{
__result = false;
return;
}
Island island = ((PhaseData<BuildData, BuildIslandState>)(object)__instance).Island;
if ((Object)(object)((island != null) ? island.Owner : null) == (Object)null || island.Owner.IsAI)
{
__result = false;
return;
}
IslandGrid grid = island.grid;
if ((Object)(object)grid == (Object)null || !HasUniversity(grid))
{
__result = false;
}
}
catch (Exception ex)
{
Plugin.Once("canbuild", "casino limit: " + ex);
}
}
public static void UnlockedPostfix(BuildData __instance, BuildingType __0, ref bool __result)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Invalid comparison between Unknown and I4
try
{
if (__0 != null && (int)__0.name == 24)
{
Island island = ((PhaseData<BuildData, BuildIslandState>)(object)__instance).Island;
IslandGrid val = ((island != null) ? island.grid : null);
__result = (Object)(object)val != (Object)null && HasUniversity(val);
}
}
catch (Exception ex)
{
Plugin.Once("unlocked", "casino lock: " + ex);
}
}
internal static int Find(IslandGrid grid)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Invalid comparison between Unknown and I4
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)grid == (Object)null)
{
return -1;
}
Enumerator<Id, Building> enumerator = grid.Buildings.GetEnumerator();
while (enumerator.MoveNext())
{
Building current = enumerator.Current;
if (current.type != null && (int)current.type.name == 24)
{
return Id.OfPosition(current.transform.position).value;
}
}
return -1;
}
internal static bool IsCasino(IslandGrid grid, int id)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Invalid comparison between Unknown and I4
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)grid == (Object)null || id < 0)
{
return false;
}
Enumerator<Id, Building> enumerator = grid.Buildings.GetEnumerator();
while (enumerator.MoveNext())
{
Building current = enumerator.Current;
if (current.type != null && (int)current.type.name == 24 && Id.OfPosition(current.transform.position).value == id)
{
return true;
}
}
return false;
}
private static bool HasUniversity(IslandGrid grid)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Invalid comparison between Unknown and I4
Enumerator<Id, Building> enumerator = grid.Buildings.GetEnumerator();
while (enumerator.MoveNext())
{
Building current = enumerator.Current;
if (current.type != null && (int)current.type.name == 17)
{
return true;
}
}
return false;
}
internal static int Count(IslandGrid grid)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Invalid comparison between Unknown and I4
int num = 0;
Enumerator<Id, Building> enumerator = grid.Buildings.GetEnumerator();
while (enumerator.MoveNext())
{
Building current = enumerator.Current;
if (current.type != null && (int)current.type.name == 24)
{
num++;
}
}
return num;
}
}
internal static class Later
{
private static readonly List<(int frame, Action work)> Pending = new List<(int, Action)>();
private static GameObject _go;
internal static void Run(Action work)
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
Pending.Add((Time.frameCount, work));
if ((Object)(object)_go == (Object)null)
{
if (!ClassInjector.IsTypeRegisteredInIl2Cpp<CasinoLater>())
{
ClassInjector.RegisterTypeInIl2Cpp<CasinoLater>();
}
_go = new GameObject("DiceModders Casino Later")
{
hideFlags = (HideFlags)61
};
Object.DontDestroyOnLoad((Object)(object)_go);
_go.AddComponent<CasinoLater>();
}
_go.SetActive(true);
}
internal static void Tick()
{
int now = Time.frameCount;
List<(int frame, Action work)> list = Pending.FindAll(((int frame, Action work) p) => p.frame < now);
Pending.RemoveAll(((int frame, Action work) p) => p.frame < now);
foreach (var item2 in list)
{
Action item = item2.work;
try
{
item();
}
catch (Exception ex)
{
Plugin.Once("later", "casino (later): " + ex);
}
}
if (Pending.Count == 0 && (Object)(object)_go != (Object)null)
{
_go.SetActive(false);
}
}
}
internal sealed class CasinoLater : MonoBehaviour
{
public CasinoLater(IntPtr ptr)
: base(ptr)
{
}
private void Update()
{
Later.Tick();
}
}
[BepInPlugin("org.dicemodders.dicekingdoms.casino", "DiceKingdoms Casino", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInProcess("Dice-Kingdoms.exe")]
public sealed class Plugin : BasePlugin
{
public const string Guid = "org.dicemodders.dicekingdoms.casino";
public const string Name = "DiceKingdoms Casino";
public const string Version = "1.0.2";
internal static ManualLogSource L;
internal static bool On;
private static readonly HashSet<string> Logged = new HashSet<string>();
public override void Load()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
Tx.Load();
L = ((BasePlugin)this).Log;
Patcher val = new Patcher("org.dicemodders.dicekingdoms.casino", ((BasePlugin)this).Log);
Casino.Install(val);
CasinoType.Install(val);
CasinoLook.Install(val);
CasinoPanel.Install(val);
Wheel.Install(val);
UiScope ui = UiKit.CreateScope("org.dicemodders.dicekingdoms.casino");
WheelWindow.Install(ui, val);
SettingsWindow.Install(ui);
val.Summary();
Mods.Switch(((BasePlugin)this).Config, true, false, "Turns the Casino rule of this mod on or off.").WhenOn((Action)delegate
{
On = true;
WheelWindow.Refresh();
}, (Action)delegate
{
On = false;
WheelWindow.Refresh();
});
}
internal static void Once(string key, string message)
{
if (Logged.Add(key))
{
ManualLogSource l = L;
if (l != null)
{
l.LogError((object)message);
}
}
}
}
internal static class SettingsWindow
{
private static readonly Color Changed = new Color(1f, 0.82f, 0.45f, 1f);
private static readonly Color Normal = new Color(0.97f, 0.94f, 0.89f, 1f);
private static UiScope _ui;
private static UiWindow _win;
private static UiImage _wheel;
private static UiToggle _on;
private static UiText _status;
private static UiText _sum;
private static Texture2D _texture;
private static Wheel.Outcome[] _drawn;
private static readonly List<Action> Refreshers = new List<Action>();
private static readonly List<UiButton> EditButtons = new List<UiButton>();
internal static void Install(UiScope ui)
{
_ui = ui;
(LobbyRule<int>, string)[] numbers = Casino.Numbers;
for (int i = 0; i < numbers.Length; i++)
{
numbers[i].Item1.Changed += delegate
{
Refresh();
};
}
Casino.Rule.Changed += delegate
{
Refresh();
};
Lobby.Changed += Refresh;
Match.Started += Refresh;
Match.Ended += Refresh;
Tx.Block(ui, delegate
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
SettingsBlockSpec val = new SettingsBlockSpec();
val.set_Id("org.dicemodders.dicekingdoms.casino.lobby");
val.set_Page((SettingsPage)4);
val.set_Title(Tx.T("settings.block"));
val.set_Order(40);
val.set_Build((Action<SettingsBlockHandle>)delegate(SettingsBlockHandle block)
{
block.AddButton(Tx.T("settings.title"), Tx.T("settings.open"), (Action)Toggle);
});
return val;
});
}
internal static void Toggle()
{
if (_win != null)
{
_win.Close();
}
else
{
Open();
}
}
private static void Open()
{
_drawn = null;
UiScope ui = _ui;
_win = ((ui != null) ? ui.Custom.Window((Action<UiWindow>)delegate(UiWindow w)
{
w.Title(Tx.T("settings.title")).Size(560f, 780f).Position(100f, 40f)
.Draggable(true)
.Closable(true);
w.OnClose((Action)delegate
{
_win = null;
_wheel = null;
_on = null;
_status = (_sum = null);
Refreshers.Clear();
EditButtons.Clear();
});
w.Body.Spacing(4f);
_on = w.Body.Toggle(Casino.Rule.Title, Casino.Rule.Live, (Action<bool>)delegate(bool v)
{
if (!Casino.Rule.TrySet(v) && _status != null)
{
_status.Value = Tx.T("settings.hostOnly");
}
Refresh();
});
string description = Casino.Rule.Description;
if (!string.IsNullOrEmpty(description))
{
w.Body.Paragraph(description);
}
w.Body.Separator(1f);
_status = w.Body.Paragraph("");
_wheel = w.Body.Image((Texture)null);
UiImage wheel = _wheel;
object obj;
if (wheel == null)
{
obj = null;
}
else
{
RectTransform root = ((UiElement)wheel).Root;
obj = ((root != null) ? ((Component)root).GetComponent<LayoutElement>() : null);
}
LayoutElement val = (LayoutElement)obj;
if ((Object)(object)val != (Object)null)
{
val.preferredHeight = 200f;
}
_sum = w.Body.Paragraph("");
w.Body.Separator(1f);
(LobbyRule<int>, string)[] numbers = Casino.Numbers;
for (int num = 0; num < numbers.Length; num++)
{
var (rule, unit) = numbers[num];
Stepper(w.Body, rule, unit);
}
w.Body.Separator(1f);
UiButton val2 = w.Body.Button(Tx.T("settings.allDefault"), (Action)delegate
{
(LobbyRule<int>, string)[] numbers2 = Casino.Numbers;
for (int i = 0; i < numbers2.Length; i++)
{
LobbyRule<int> item = numbers2[i].Item1;
item.TrySet(item.Default);
}
});
if (val2 != null)
{
EditButtons.Add(val2);
}
}) : null);
Refresh();
}
private static void Stepper(UiContainer c, LobbyRule<int> rule, string unit)
{
UiText value = null;
UiButton plus = null;
UiContainer obj = c.Row((Action<UiContainer>)delegate(UiContainer r)
{
r.Spacing(4f);
UiText obj2 = r.Text(rule.Title);
if (obj2 != null)
{
UiLayout.FillWidth<UiText>(obj2);
}
UiButton obj3 = r.Button("-", (Action)delegate
{
Step(rule, -rule.Step);
});
UiButton val = ((obj3 != null) ? UiLayout.FixedW<UiButton>(obj3, 36f) : null);
UiText obj4 = r.Text("");
value = ((obj4 != null) ? UiLayout.FixedW<UiText>(obj4, 70f) : null);
UiButton obj5 = r.Button("+", (Action)delegate
{
Step(rule, rule.Step);
});
plus = ((obj5 != null) ? UiLayout.FixedW<UiButton>(obj5, 36f) : null);
UiButton obj6 = r.Button(Tx.T("settings.default"), (Action)delegate
{
rule.TrySet(rule.Default);
});
UiButton val2 = ((obj6 != null) ? UiLayout.FixedW<UiButton>(obj6, 90f) : null);
UiButton[] array = (UiButton[])(object)new UiButton[3] { val, plus, val2 };
foreach (UiButton val3 in array)
{
if (val3 != null)
{
EditButtons.Add(val3);
}
}
});
if (obj != null)
{
UiLayout.Height<UiContainer>(obj, 32f);
}
Refreshers.Add(delegate
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
if (value != null)
{
value.Value = rule.Live.ToString(CultureInfo.InvariantCulture) + unit;
value.Color((rule.Live == rule.Default) ? Normal : Changed);
if (plus != null && Casino.IsChance(rule) && Casino.ChanceSum + rule.Step > 100)
{
plus.Interactable(false);
}
}
});
}
private static void Step(LobbyRule<int> rule, int delta)
{
int num = Math.Clamp(rule.Live + delta, rule.Min, rule.Max);
if (delta > 0 && Casino.IsChance(rule))
{
int num2 = 100 - (Casino.ChanceSum - rule.Live);
if (num > num2)
{
num = Math.Max(rule.Live, num2 - num2 % Math.Max(1, rule.Step));
}
if (num == rule.Live)
{
if (_status != null)
{
_status.Value = Tx.T("settings.full");
}
return;
}
}
if (!rule.TrySet(num) && _status != null)
{
_status.Value = Tx.T("settings.hostOnly");
}
}
private static void Refresh()
{
if (_win == null)
{
return;
}
bool editable = Casino.Rule.Editable;
UiToggle obj = _on;
if (obj != null)
{
obj.Set(Casino.Rule.Live).Interactable(editable);
}
foreach (UiButton editButton in EditButtons)
{
if (editButton != null)
{
editButton.Interactable(editable);
}
}
foreach (Action refresher in Refreshers)
{
refresher();
}
if (_status != null)
{
_status.Value = (Casino.Rule.Live ? "" : (Tx.T("settings.ruleOff") + " ")) + (editable ? Tx.T("settings.host") : Tx.T("settings.readonly")) + ((Casino.ChanceSum > 100) ? (" " + Tx.T("settings.over", Casino.ChanceSum)) : "");
}
Wheel.Outcome[] faces = Wheel.Faces;
if ((Object)(object)_texture == (Object)null || _drawn != faces)
{
Texture2D texture = _texture;
_texture = WheelArt.Disc(256, faces);
_drawn = faces;
UiImage wheel = _wheel;
if (wheel != null)
{
wheel.SetTexture((Texture)(object)_texture);
}
if ((Object)(object)texture != (Object)null)
{
Object.Destroy((Object)(object)texture);
}
UiImage wheel2 = _wheel;
WheelArt.AddIcons(((Object)(object)((wheel2 != null) ? ((UiElement)wheel2).Root : null) != (Object)null && ((Transform)((UiElement)_wheel).Root).childCount > 0) ? ((Component)((Transform)((UiElement)_wheel).Root).GetChild(0)).gameObject : null, faces, delegate(string name)
{
UiScope ui = _ui;
return (ui == null) ? null : ui.Custom.Theme.Icon(name);
}, 13f);
}
else if (_wheel != null && (Object)(object)_wheel.Texture != (Object)(object)_texture)
{
_wheel.SetTexture((Texture)(object)_texture);
}
if (_sum != null)
{
_sum.Value = Tx.T("settings.sum", Wheel.Percent(Wheel.Outcome.Jackpot), Wheel.Percent(Wheel.Outcome.Gold, Wheel.Outcome.Each), Wheel.Percent(default(Wheel.Outcome)), Wheel.Percent(Wheel.Outcome.Robbers, Wheel.Outcome.Fire), Wheel.Percent(Wheel.Outcome.Catastrophe));
}
}
}
internal static class Tx
{
internal static TextSet Set;
internal static void Load()
{
Set = Texts.Load("texts.json", (string)null);
}
internal static string T(string key)
{
TextSet set = Set;
return ((set != null) ? set.Get(key) : null) ?? key;
}
internal static string T(string key, params object[] values)
{
TextSet set = Set;
return ((set != null) ? set.Get(key, values) : null) ?? key;
}
internal static SettingsBlockHandle Block(UiScope ui, Func<SettingsBlockSpec> spec)
{
if (ui == null)
{
return null;
}
SettingsBlockHandle handle = ui.Native.Settings.AddBlock(spec());
Texts.LanguageChanged += delegate
{
SettingsBlockHandle obj = handle;
if (obj != null)
{
((NativeHandle)obj).Dispose();
}
handle = ui.Native.Settings.AddBlock(spec());
};
return handle;
}
}
internal static class Wheel
{
internal enum Outcome
{
Nothing,
Gold,
Each,
Robbers,
Fire,
Jackpot,
Catastrophe
}
private sealed class IslandState
{
public int LastSpin = -100;
public int Pending = -1;
public int Face = -1;
public int FaceTurn = -1;
}
[CompilerGenerated]
private static class <>O
{
public static Handler <0>__Spin;
}
internal const int SpinAction = 1;
private static Outcome[] _faces;
private static string _facesFor;
private static readonly Dictionary<IntPtr, IslandState> States = new Dictionary<IntPtr, IslandState>();
private static DisastersPhase _heldPhase;
private static Il2CppReferenceArray<DisasterOccurrence> _heldList;
private static Action _heldEnd;
private static bool _replaying;
internal static int Stake => Casino.Stake;
internal static int Cooldown => Casino.Cooldown;
internal static Outcome[] Faces
{
get
{
string text = $"{Casino.JackpotPercent}|{Casino.WinPercent}|{Casino.BadPercent}|{Casino.CatastrophePercent}";
if (_faces != null && text == _facesFor)
{
return _faces;
}
_facesFor = text;
return _faces = Build(Casino.JackpotPercent / 5, Casino.WinPercent / 5, Casino.BadPercent / 5, Casino.CatastrophePercent / 5);
}
}
internal static bool Holding => (Object)(object)_heldPhase != (Object)null;
internal static event Action<int, Outcome> LocalResult;
private static Outcome[] Build(int jackpot, int win, int bad, int catastrophe)
{
int[] array = new int[4]
{
Math.Max(0, jackpot),
Math.Max(0, win),
Math.Max(0, bad),
Math.Max(0, catastrophe)
};
while (array[0] + array[1] + array[2] + array[3] > 20)
{
int num = 2;
int[] array2 = new int[3] { 1, 3, 0 };
foreach (int num2 in array2)
{
if (array[num2] > array[num])
{
num = num2;
}
}
array[num]--;
}
int count = 20 - array[0] - array[1] - array[2] - array[3];
List<(double pos, int order, Outcome what)> items = new List<(double, int, Outcome)>();
Spread(array[3], 10.0, 0, (int _) => Outcome.Catastrophe);
Spread(array[0], 0.0, 1, (int _) => Outcome.Jackpot);
Spread(array[1], 2.5, 2, (int k) => (k % 3 != 1) ? Outcome.Gold : Outcome.Each);
Spread(array[2], 1.2, 3, (int k) => (k % 2 != 0) ? Outcome.Fire : Outcome.Robbers);
Spread(count, 0.5, 4, (int _) => Outcome.Nothing);
items.Sort(((double pos, int order, Outcome what) a, (double pos, int order, Outcome what) b) => (a.pos == b.pos) ? a.order.CompareTo(b.order) : a.pos.CompareTo(b.pos));
Outcome[] array3 = new Outcome[20];
for (int num3 = 0; num3 < 20; num3++)
{
array3[num3] = items[num3].what;
}
return array3;
void Spread(int num4, double offset, int order, Func<int, Outcome> what)
{
for (int j = 0; j < num4; j++)
{
items.Add(((((double)j + 0.5) * 20.0 / (double)num4 + offset) % 20.0, order, what(j)));
}
}
}
internal static int Percent(params Outcome[] kinds)
{
int num = 0;
Outcome[] faces = Faces;
foreach (Outcome value in faces)
{
if (Array.IndexOf(kinds, value) >= 0)
{
num++;
}
}
return num * 100 / Faces.Length;
}
internal static void Install(Patcher patcher)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
object obj = <>O.<0>__Spin;
if (obj == null)
{
Handler val = Spin;
<>O.<0>__Spin = val;
obj = (object)val;
}
BuildActions.Register(1, "Casino (spin)", (Handler)obj);
patcher.Patch(typeof(DisastersPhase), "RandomOccurrences", typeof(Wheel), (string)null, "RandomPostfix");
patcher.Patch(typeof(DisastersPhase), "ExecuteOccurrences", typeof(Wheel), "ExecutePrefix", (string)null);
Match.Started += States.Clear;
Match.Ended += States.Clear;
}
private static IslandState StateOf(IslandGrid grid)
{
if (!States.TryGetValue(((Il2CppObjectBase)grid).Pointer, out var value))
{
value = (States[((Il2CppObjectBase)grid).Pointer] = new IslandState());
}
return value;
}
private static bool Due(IslandState state, int turn)
{
if (state.Pending >= 0)
{
return state.Pending < turn;
}
return false;
}
internal static int FaceOf(uint seed)
{
int num = (int)seed * -1640531535;
int num2 = (num ^ (num >>> 15)) * -2048144777;
return (int)((uint)(num2 ^ (num2 >>> 13)) % (uint)Faces.Length);
}
private static bool Spin(BuildData data, int casinoId)
{
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Expected O, but got Unknown
if (!Casino.On)
{
return false;
}
Island island = ((PhaseData<BuildData, BuildIslandState>)(object)data).Island;
IslandGrid val = ((island != null) ? island.grid : null);
Statistics val2 = ((island != null) ? island.statistics : null);
GameState gameState = ((PhaseData<BuildData, BuildIslandState>)(object)data).GameState;
if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)gameState == (Object)null || (Object)(object)island.Owner == (Object)null || island.Owner.IsAI)
{
return false;
}
if (!CasinoType.IsCasino(val, casinoId))
{
return false;
}
int turnCounter = gameState.TurnCounter;
IslandState islandState = StateOf(val);
if (islandState.Pending >= 0 || turnCounter - islandState.LastSpin < Cooldown)
{
return false;
}
if (val2.Storage.stored.gold < Stake)
{
return false;
}
val2.RemoveResource(new ResourceAmount
{
gold = Stake
});
islandState.LastSpin = turnCounter;
islandState.Pending = turnCounter;
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(68, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("turn ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(turnCounter);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(island.Owner.UserName);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" spun the wheel (");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(Stake);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" gold); it turns in the next disasters phase");
}
l.LogInfo(val3);
return true;
}
public static void RandomPostfix(DisastersPhase __instance, ref Il2CppReferenceArray<DisasterOccurrence> __result)
{
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Expected O, but got Unknown
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Expected O, but got Unknown
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Expected O, but got Unknown
//IL_0206: Unknown result type (might be due to invalid IL or missing references)
//IL_0210: Expected O, but got Unknown
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Expected O, but got Unknown
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Expected O, but got Unknown
try
{
if (!Casino.On || __result == null || States.Count == 0)
{
return;
}
GameState gameState = ((TurnPhase<DisastersData, DisastersIslandState>)(object)__instance).GameState;
Disasters disasters = __instance.disasters;
if ((Object)(object)gameState == (Object)null || (Object)(object)disasters == (Object)null)
{
return;
}
int turnCounter = gameState.TurnCounter;
List<DisasterOccurrence> list = new List<DisasterOccurrence>();
foreach (MatchPlayer item in Players.All)
{
Player game = item.Game;
Island island = item.Island;
IslandGrid val = ((island != null) ? island.grid : null);
if ((Object)(object)game == (Object)null || (Object)(object)val == (Object)null || !States.TryGetValue(((Il2CppObjectBase)val).Pointer, out var value) || !Due(value, turnCounter) || !SeedOf(__result, disasters, game, out var seed))
{
continue;
}
uint num = 1u;
switch (Faces[FaceOf(seed)])
{
case Outcome.Jackpot:
foreach (Player item2 in Others(game))
{
list.Add(new DisasterOccurrence((Disaster)(object)disasters.tsunami, game, item2, Next(seed, num++)));
}
break;
case Outcome.Robbers:
{
List<Player> list2 = Others(game);
if (list2.Count > 0)
{
list.Add(new DisasterOccurrence((Disaster)(object)disasters.robbers, list2[(int)((seed >> 7) % (uint)list2.Count)], game, Next(seed, num++)));
}
break;
}
case Outcome.Fire:
list.Add(new DisasterOccurrence((Disaster)(object)disasters.fire, game, game, Next(seed, num++)));
break;
case Outcome.Catastrophe:
list.Add(new DisasterOccurrence((Disaster)(object)disasters.tsunami, game, game, Next(seed, num++)));
list.Add(new DisasterOccurrence((Disaster)(object)disasters.meteorite, game, game, Next(seed, num++)));
break;
}
}
if (list.Count != 0)
{
Il2CppReferenceArray<DisasterOccurrence> val2 = new Il2CppReferenceArray<DisasterOccurrence>((long)(((Il2CppArrayBase<DisasterOccurrence>)(object)__result).Length + list.Count));
for (int i = 0; i < ((Il2CppArrayBase<DisasterOccurrence>)(object)__result).Length; i++)
{
((Il2CppArrayBase<DisasterOccurrence>)(object)val2)[i] = ((Il2CppArrayBase<DisasterOccurrence>)(object)__result)[i];
}
for (int j = 0; j < list.Count; j++)
{
((Il2CppArrayBase<DisasterOccurrence>)(object)val2)[((Il2CppArrayBase<DisasterOccurrence>)(object)__result).Length + j] = list[j];
}
__result = val2;
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(35, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("turn ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(turnCounter);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(": the wheel added ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(list.Count);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" disaster(s)");
}
l.LogInfo(val3);
}
}
catch (Exception ex)
{
Plugin.Once("random", "casino (disasters): " + ex);
}
}
private static uint Next(uint seed, uint k)
{
return seed * 747796405 + (uint)((int)k * -1403630843);
}
private static List<Player> Others(Player owner)
{
List<Player> list = new List<Player>();
foreach (MatchPlayer item in Players.All)
{
Player game = item.Game;
if (!((Object)(object)game == (Object)null) && !(((Il2CppObjectBase)game).Pointer == ((Il2CppObjectBase)owner).Pointer) && !game.IsDefeated && Team.Different(game, owner))
{
list.Add(game);
}
}
return list;
}
private static bool SeedOf(Il2CppReferenceArray<DisasterOccurrence> list, Disasters disasters, Player owner, out uint seed)
{
seed = 0u;
Starvation starvation = disasters.starvation;
IntPtr intPtr = ((starvation != null) ? ((Il2CppObjectBase)starvation).Pointer : IntPtr.Zero);
foreach (DisasterOccurrence item in (Il2CppArrayBase<DisasterOccurrence>)(object)list)
{
if (item != null && item.Disaster != null && !(((Il2CppObjectBase)item.Disaster).Pointer != intPtr))
{
Player target = item.Target;
if ((Object)(object)target != (Object)null && ((Il2CppObjectBase)target).Pointer == ((Il2CppObjectBase)owner).Pointer)
{
seed = item.Seed;
return true;
}
}
}
return false;
}
public static bool ExecutePrefix(DisastersPhase __instance, Il2CppReferenceArray<DisasterOccurrence> __0, Action __1)
{
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Expected O, but got Unknown
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
if (_replaying)
{
return true;
}
int num = -1;
Outcome arg = Outcome.Nothing;
try
{
if (!Casino.On || __0 == null || States.Count == 0)
{
return true;
}
GameState gameState = ((TurnPhase<DisastersData, DisastersIslandState>)(object)__instance).GameState;
Disasters disasters = __instance.disasters;
if ((Object)(object)gameState == (Object)null || (Object)(object)disasters == (Object)null)
{
return true;
}
int turnCounter = gameState.TurnCounter;
bool flag = default(bool);
foreach (MatchPlayer item in Players.All)
{
Player game = item.Game;
Island island = item.Island;
IslandGrid val = ((island != null) ? island.grid : null);
if ((Object)(object)game == (Object)null || (Object)(object)val == (Object)null || !States.TryGetValue(((Il2CppObjectBase)val).Pointer, out var value) || !Due(value, turnCounter))
{
continue;
}
value.Pending = -1;
if (!SeedOf(__0, disasters, game, out var seed))
{
continue;
}
int num2 = FaceOf(seed);
Outcome outcome = Faces[num2];
value.Face = num2;
value.FaceTurn = turnCounter;
Statistics statistics = island.statistics;
switch (outcome)
{
case Outcome.Gold:
if (statistics != null)
{
statistics.AddResource(new ResourceAmount
{
gold = Casino.WinGold
});
}
break;
case Outcome.Each:
{
int winEach = Casino.WinEach;
if (statistics != null)
{
statistics.AddResource(new ResourceAmount
{
food = winEach,
wood = winEach,
stone = winEach,
gold = winEach,
hammer = winEach,
military = winEach
});
}
break;
}
}
ManualLogSource l = Plugin.L;
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(34, 4, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("turn ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(turnCounter);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item.Name);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'s wheel stopped on face ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(num2);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Outcome>(outcome);
}
l.LogInfo(val2);
if (item.IsLocal)
{
num = num2;
arg = outcome;
}
}
}
catch (Exception ex)
{
Plugin.Once("execute", "casino (wheel): " + ex);
}
if (num < 0 || Wheel.LocalResult == null)
{
return true;
}
_heldPhase = __instance;
_heldList = __0;
_heldEnd = __1;
try
{
Wheel.LocalResult(num, arg);
}
catch (Exception ex2)
{
Plugin.Once("show", "casino (wheel window): " + ex2);
Release();
}
return false;
}
internal static void Release()
{
DisastersPhase heldPhase = _heldPhase;
if ((Object)(object)heldPhase == (Object)null)
{
return;
}
Il2CppReferenceArray<DisasterOccurrence> heldList = _heldList;
Action heldEnd = _heldEnd;
_heldPhase = null;
_heldList = null;
_heldEnd = null;
if (!Match.Running)
{
return;
}
_replaying = true;
try
{
heldPhase.ExecuteOccurrences(heldList, heldEnd);
}
catch (Exception ex)
{
Plugin.L.LogError((object)("casino: the held disasters could not run: " + ex));
}
finally
{
_replaying = false;
}
}
internal static (bool pending, int nextTurn, int face, int faceTurn) StateFor(Island island)
{
if ((Object)(object)((island != null) ? island.grid : null) == (Object)null || !States.TryGetValue(((Il2CppObjectBase)island.grid).Pointer, out var value))
{
return (pending: false, nextTurn: 0, face: -1, faceTurn: -1);
}
return (pending: value.Pending >= 0, nextTurn: value.LastSpin + Cooldown, face: value.Face, faceTurn: value.FaceTurn);
}
}
internal static class WheelArt
{
internal static readonly Color Jackpot = new Color(0.93f, 0.74f, 0.28f);
internal static readonly Color Win = new Color(0.47f, 0.7f, 0.38f);
internal static readonly Color Nothing = new Color(0.93f, 0.88f, 0.77f);
private static readonly Color Nothing2 = new Color(0.86f, 0.8f, 0.67f);
internal static readonly Color Bad = new Color(0.89f, 0.49f, 0.31f);
internal static readonly Color Catastrophe = new Color(0.62f, 0.21f, 0.22f);
private static readonly Color Wood = new Color(0.36f, 0.24f, 0.15f);
private static readonly Color WoodDark = new Color(0.25f, 0.16f, 0.1f);
private static readonly Color Gold = new Color(0.96f, 0.8f, 0.38f);
private static readonly Color GoldDark = new Color(0.72f, 0.53f, 0.2f);
private static readonly Color Clear = new Color(0f, 0f, 0f, 0f);
private static Disasters _disasters;
internal static Color Of(Wheel.Outcome o, int face)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//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_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
switch (o)
{
case Wheel.Outcome.Jackpot:
return Jackpot;
case Wheel.Outcome.Gold:
case Wheel.Outcome.Each:
return Win;
case Wheel.Outcome.Robbers:
case Wheel.Outcome.Fire:
return Bad;
case Wheel.Outcome.Catastrophe:
return Catastrophe;
default:
return (face % 2 == 0) ? Nothing : Nothing2;
}
}
internal static Texture2D Disc(int size, Wheel.Outcome[] faces)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_02db: Unknown result type (might be due to invalid IL or missing references)
//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Unknown result type (might be due to invalid IL or missing references)
//IL_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = Keep(new Texture2D(size, size, (TextureFormat)4, false)
{
filterMode = (FilterMode)1,
wrapMode = (TextureWrapMode)1
});
Color[] array = (Color[])(object)new Color[size * size];
float num = (float)(size - 1) / 2f;
float num2 = (float)size / 2f - 1.5f;
float num3 = num2 * 0.86f;
float num4 = num2 * 0.16f;
int num5 = faces.Length;
float num6 = 360f / (float)num5;
int num7 = num5;
Color val2 = default(Color);
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
float num8 = (float)j - num;
float num9 = (float)i - num;
float num10 = Mathf.Sqrt(num8 * num8 + num9 * num9);
float num11 = Mathf.Atan2(num8, num9) * 57.29578f;
if (num11 < 0f)
{
num11 += 360f;
}
if (num10 > num2)
{
val2 = Clear;
}
else if (num10 > num3)
{
float num12 = (num10 - num3) / (num2 - num3);
val2 = Color.Lerp(WoodDark, Wood, 1f - Mathf.Abs(num12 - 0.5f) * 2f);
float num13 = ((num11 / (360f / (float)num7) + 0.5f) % 1f - 0.5f) * (360f / (float)num7) * ((float)Math.PI / 180f) * ((num3 + num2) / 2f);
float num14 = num10 - (num3 + num2) / 2f;
float num15 = Mathf.Sqrt(num13 * num13 + num14 * num14);
float num16 = (num2 - num3) * 0.28f;
if (num15 < num16)
{
val2 = Color.Lerp(Gold, GoldDark, num15 / num16 * 0.8f);
}
if (num10 > num2 - 1.2f)
{
val2.a = Mathf.Clamp01(num2 - num10 + 0.2f);
}
}
else if (num10 > num3 - 2.2f)
{
val2 = GoldDark;
}
else if (num10 < num4)
{
float num17 = num10 / num4;
val2 = ((num10 < num4 * 0.45f) ? Color.Lerp(Gold, GoldDark, num17) : Color.Lerp(GoldDark, WoodDark, (num17 - 0.45f) * 1.4f));
}
else
{
int num18 = Mathf.Min(num5 - 1, (int)(num11 / num6));
float num19 = Mathf.Min(num11 - (float)num18 * num6, (float)(num18 + 1) * num6 - num11) * ((float)Math.PI / 180f) * num10;
Color val3 = Of(faces[num18], num18);
float num20 = Mathf.Lerp(0.82f, 1.06f, (num10 - num4) / (num3 - num4));
((Color)(ref val2))..ctor(Mathf.Clamp01(val3.r * num20), Mathf.Clamp01(val3.g * num20), Mathf.Clamp01(val3.b * num20), 1f);
if (num19 < 1.3f)
{
val2 = Color.Lerp(GoldDark, Gold, num19 / 1.3f);
}
}
array[i * size + j] = val2;
}
}
val.SetPixels(Il2CppStructArray<Color>.op_Implicit(array));
val.Apply();
return val;
}
private static Texture2D Keep(Texture2D tex)
{
((Object)tex).hideFlags = (HideFlags)32;
return tex;
}
internal static Texture2D Pointer(int width, int height)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = Keep(new Texture2D(width, height, (TextureFormat)4, false)
{
filterMode = (FilterMode)1,
wrapMode = (TextureWrapMode)1
});
Color[] array = (Color[])(object)new Color[width * height];
float num = (float)(width - 1) / 2f;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
float num2 = (float)i / (float)(height - 1) * ((float)width * 0.24f) - Mathf.Abs((float)j - num);
array[i * width + j] = ((num2 < 0f) ? Clear : ((num2 < 2f || i > height - 3) ? WoodDark : Color.Lerp(GoldDark, Gold, (float)i / (float)height)));
}
}
val.SetPixels(Il2CppStructArray<Color>.op_Implicit(array));
val.Apply();
return val;
}
internal static Sprite IconOf(Wheel.Outcome o, Func<string, Sprite> theme)
{
Disasters val = Disasters();
try
{
Sprite result;
switch (o)
{
case Wheel.Outcome.Jackpot:
{
object obj4;
if (val == null)
{
obj4 = null;
}
else
{
Tsunami tsunami = val.tsunami;
obj4 = ((tsunami != null) ? ((Disaster)tsunami).icon : null);
}
result = (Sprite)obj4;
break;
}
case Wheel.Outcome.Catastrophe:
{
object obj2;
if (val == null)
{
obj2 = null;
}
else
{
Meteorite meteorite = val.meteorite;
obj2 = ((meteorite != null) ? ((Disaster)meteorite).icon : null);
}
result = (Sprite)obj2;
break;
}
case Wheel.Outcome.Robbers:
{
object obj3;
if (val == null)
{
obj3 = null;
}
else
{
Robbers robbers = val.robbers;
obj3 = ((robbers != null) ? ((Disaster)robbers).icon : null);
}
result = (Sprite)obj3;
break;
}
case Wheel.Outcome.Fire:
{
object obj;
if (val == null)
{
obj = null;
}
else
{
Fire fire = val.fire;
obj = ((fire != null) ? ((Disaster)fire).icon : null);
}
result = (Sprite)obj;
break;
}
case Wheel.Outcome.Gold:
result = theme("gold");
break;
case Wheel.Outcome.Each:
result = theme("food");
break;
default:
result = null;
break;
}
return result;
}
catch
{
return null;
}
}
private static Disasters Disasters()
{
if ((Object)(object)_disasters != (Object)null)
{
return _disasters;
}
using (IEnumerator<Disasters> enumerator = Resources.FindObjectsOfTypeAll<Disasters>().GetEnumerator())
{
if (enumerator.MoveNext())
{
return _disasters = enumerator.Current;
}
}
return null;
}
internal static void AddIcons(GameObject picture, Wheel.Outcome[] faces, Func<string, Sprite> theme, float iconSize)
{
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)picture == (Object)null)
{
return;
}
for (int num = picture.transform.childCount - 1; num >= 0; num--)
{
Object.Destroy((Object)(object)((Component)picture.transform.GetChild(num)).gameObject);
}
int num2 = faces.Length;
Vector2 val3 = default(Vector2);
for (int i = 0; i < num2; i++)
{
Sprite val = IconOf(faces[i], theme);
if (!((Object)(object)val == (Object)null))
{
float num3 = ((float)i + 0.5f) * 360f / (float)num2;
float num4 = num3 * ((float)Math.PI / 180f);
GameObject val2 = new GameObject("Casino face " + i);
val2.transform.SetParent(picture.transform, false);
RectTransform obj = val2.AddComponent<RectTransform>();
((Vector2)(ref val3))..ctor(0.5f + 0.31f * Mathf.Sin(num4), 0.5f + 0.31f * Mathf.Cos(num4));
obj.anchorMin = val3;
obj.anchorMax = val3;
obj.sizeDelta = new Vector2(iconSize, iconSize);
obj.anchoredPosition = Vector2.zero;
((Transform)obj).localRotation = Quaternion.Euler(0f, 0f, 0f - num3);
Image obj2 = val2.AddComponent<Image>();
obj2.sprite = val;
obj2.preserveAspect = true;
((Graphic)obj2).raycastTarget = false;
}
}
}
}
internal static class WheelWindow
{
private static UiScope _ui;
private static TopBarButtonHandle _button;
private static UiWindow _window;
private static UiImage _wheel;
private static UiImage _pointer;
private static UiButton _spin;
private static UiText _status;
private static UiText _result;
private static Texture2D _wheelTexture;
private static Texture2D _pointerTexture;
private static Wheel.Outcome[] _texturedFaces;
private static float _angle;
private static int _shownFace = -1;
private static BuildInterface _build;
internal static void Install(UiScope ui, Patcher patcher)
{
_ui = ui;
UiScope ui2 = _ui;
if (ui2 != null)
{
ui2.WhenReady((Action<UiScope>)delegate(UiScope s)
{
_button = s.Native.TopBar.AddIconButton("gold", Tx.T("window.tooltip"), (Action)Toggle, 22);
Refresh();
});
}
Texts.LanguageChanged += delegate
{
TopBarButtonHandle button = _button;
if (button != null)
{
button.SetTooltip(Tx.T("window.tooltip"));
}
if (_window != null)
{
_window.Close();
Toggle();
}
};
Match.Started += delegate
{
_shownFace = -1;
_angle = 0f;
Refresh();
};
Match.Ended += Refresh;
Match.PhaseEntered += delegate
{
Refresh();
Redraw();
};
Wheel.LocalResult += Show;
patcher.Patch(typeof(BuildInterface), "OnEnable", typeof(WheelWindow), (string)null, "BuildShown");
patcher.Patch(typeof(BuildInterface), "OnDisable", typeof(WheelWindow), (string)null, "BuildHidden");
}
public static void BuildShown(BuildInterface __instance)
{
_build = __instance;
Redraw();
}
public static void BuildHidden(BuildInterface __instance)
{
if ((Object)(object)_build != (Object)null && (Object)(object)__instance != (Object)null && ((Il2CppObjectBase)_build).Pointer == ((Il2CppObjectBase)__instance).Pointer)
{
_build = null;
}
Redraw();
}
internal static void Refresh()
{
bool flag = Casino.On && Match.Running;
TopBarButtonHandle button = _button;
if (button != null)
{
button.SetVisible(flag);
}
if (!flag)
{
UiWindow window = _window;
if (window != null)
{
window.Close();
}
}
}
private static void Toggle()
{
if (_window != null)
{
_window.Close();
}
else
{
Open();
}
}
internal static void Open()
{
if (_window != null || !Casino.On)
{
return;
}
Wheel.Outcome[] faces = Wheel.Faces;
if ((Object)(object)_wheelTexture == (Object)null || _texturedFaces != faces)
{
if ((Object)(object)_wheelTexture != (Object)null)
{
Object.Destroy((Object)(object)_wheelTexture);
}
_wheelTexture = WheelArt.Disc(384, faces);
_texturedFaces = faces;
}
if ((Object)(object)_pointerTexture == (Object)null)
{
_pointerTexture = WheelArt.Pointer(48, 28);
}
UiScope ui = _ui;
_window = ((ui != null) ? ui.Custom.Window((Action<UiWindow>)delegate(UiWindow w)
{
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
w.Title(Tx.T("window.title")).Size(460f, 700f).Position(60f, 80f)
.Draggable(true)
.Closable(true);
w.OnClose((Action)delegate
{
_window = null;
_wheel = (_pointer = null);
_spin = null;
_status = (_result = null);
Wheel.Release();
});
_pointer = Height(w.Body.Image((Texture)(object)_pointerTexture), 26f);
GameObject val = PictureOf(_pointer);
if ((Object)(object)val != (Object)null)
{
val.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 1f);
}
_wheel = Height(w.Body.Image((Texture)(object)_wheelTexture), 270f);
WheelArt.AddIcons(Picture(), faces, delegate(string name)
{
UiScope ui2 = _ui;
return (ui2 == null) ? null : ui2.Custom.Theme.Icon(name);
}, 19f);
Turn(_angle);
_result = w.Body.Paragraph("");
w.Body.Separator(1f);
w.Body.Paragraph(Tx.T("window.odds", Hex(WheelArt.Jackpot), Hex(WheelArt.Win), Hex(WheelArt.Nothing), Hex(WheelArt.Bad), Hex(WheelArt.Catastrophe), Wheel.Percent(Wheel.Outcome.Jackpot), Wheel.Percent(Wheel.Outcome.Gold, Wheel.Outcome.Each), Casino.WinGold, Casino.WinEach, Wheel.Percent(default(Wheel.Outcome)), Wheel.Percent(Wheel.Outcome.Robbers, Wheel.Outcome.Fire), Wheel.Percent(Wheel.Outcome.Catastrophe)));
w.Body.Separator(1f);
_spin = w.Body.Button(Tx.T("window.spin", Wheel.Stake), (Action)Spin);
_status = w.Body.Paragraph("");
}) : null);
Redraw();
}
private static UiImage Height(UiImage image, float height)
{
object obj;
if (image == null)
{
obj = null;
}
else
{
RectTransform root = ((UiElement)image).Root;
obj = ((root != null) ? ((Component)root).GetComponent<LayoutElement>() : null);
}
LayoutElement val = (LayoutElement)obj;
if ((Object)(object)val != (Object)null)
{
val.preferredHeight = height;
}
return image;
}
private static string Hex(Color c)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
return ColorUtility.ToHtmlStringRGB(c);
}
private static void Spin()
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Invalid comparison between Unknown and I4
try
{
BuildData val = ((PhaseInterface<BuildData, BuildIslandState>)(object)_build)?.Data;
object obj;
if (val == null)
{
obj = null;
}
else
{
Island island = ((PhaseData<BuildData, BuildIslandState>)(object)val).Island;
obj = ((island != null) ? island.grid : null);
}
IslandGrid val2 = (IslandGrid)obj;
if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (int)Match.Phase != 4)
{
return;
}
int num = CasinoType.Find(val2);
if (num < 0)
{
return;
}
bool flag = BuildActions.Plan(val, 1, num);
BuildInterface build = _build;
if (build != null)
{
build.RefreshButtons();
}
Plugin.L.LogInfo((object)("spin: " + (flag ? "made" : "refused")));
}
catch (Exception ex)
{
Plugin.L.LogWarning((object)("spin: " + ex.Message));
}
Redraw();
}
private static void Show(int face, Wheel.Outcome outcome)
{
Open();
_shownFace = -1;
if (_result != null)
{
_result.Value = Tx.T("window.turning");
}
GameObject val = Picture();
if ((Object)(object)val == (Object)null)
{
_shownFace = face;
Redraw();
Wheel.Release();
return;
}
float num = 360f / (float)Wheel.Faces.Length;
float num2 = _angle % 360f;
int num3 = (int)(3 + (uint)Environment.TickCount % 3u);
float to = num2 - ((float)num3 * 360f + Mod(num2 - ((float)face * num + num / 2f), 360f));
WheelSpin.Start(val, PictureOf(_pointer), num, num2, to, 7f, delegate(float a)
{
_angle = a;
}, delegate
{
_shownFace = face;
Redraw();
Wheel.Release();
});
}
private static float Mod(float a, float m)
{
a %= m;
if (!(a < 0f))
{
return a;
}
return a + m;
}
private static GameObject Picture()
{
return PictureOf(_wheel);
}
private static GameObject PictureOf(UiImage image)
{
if (!((Object)(object)((image != null) ? ((UiElement)image).Root : null) != (Object)null) || ((Transform)((UiElement)image).Root).childCount <= 0)
{
return null;
}
return ((Component)((Transform)((UiElement)image).Root).GetChild(0)).gameObject;
}
private static void Turn(float angle)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
GameObject val = Picture();
if ((Object)(object)val != (Object)null)
{
val.transform.localRotation = Quaternion.Euler(0f, 0f, angle);
}
}
private static void Redraw()
{
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Invalid comparison between Unknown and I4
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Invalid comparison between Unknown and I4
if (_window != null)
{
MatchPlayer local = Players.Local;
Island obj = ((local != null) ? local.Island : null);
bool flag = CasinoType.Find((obj != null) ? obj.grid : null) >= 0;
(bool pending, int nextTurn, int face, int faceTurn) tuple = Wheel.StateFor(obj);
bool item = tuple.pending;
int item2 = tuple.nextTurn;
int turn = Match.Turn;
int? obj2;
if (obj == null)
{
obj2 = null;
}
else
{
Statistics statistics = obj.statistics;
obj2 = ((statistics != null) ? new int?(statistics.Storage.stored.gold) : ((int?)null));
}
int? num = obj2;
int valueOrDefault = num.GetValueOrDefault();
bool flag2 = flag && !item && turn >= item2 && valueOrDefault >= Wheel.Stake && (Object)(object)_build != (Object)null && (int)Match.Phase == 4;
UiButton spin = _spin;
if (spin != null)
{
spin.Interactable(flag2);
}
if (_status != null)
{
_status.Value = ((!flag) ? Tx.T("window.noCasino") : (item ? Tx.T("window.pending") : ((turn < item2) ? Tx.T("window.cooldown", item2 - turn) : (((int)Match.Phase != 4) ? Tx.T("window.buildOnly") : ((valueOrDefault < Wheel.Stake) ? Tx.T("window.noGold", Wheel.Stake) : Tx.T("window.ready", Wheel.Cooldown))))));
}
if (_result != null && _shownFace >= 0)
{
_result.Value = Tx.T("result." + Wheel.Faces[_shownFace].ToString().ToLowerInvariant());
}
else if (_result != null && !WheelSpin.Running)
{
_result.Value = "";
}
}
}
}
internal sealed class WheelSpin : MonoBehaviour
{
private float _from;
private float _to;
private float _time;
private float _duration;
private float _step;
private float _kick;
private int _line;
private Transform _pointer;
private Action<float> _onAngle;
private Action _onDone;
internal static bool Running;
public WheelSpin(IntPtr ptr)
: base(ptr)
{
}
internal static void Start(GameObject target, GameObject pointer, float step, float from, float to, float seconds, Action<float> onAngle, Action onDone)
{
if (!ClassInjector.IsTypeRegisteredInIl2Cpp<WheelSpin>())
{
ClassInjector.RegisterTypeInIl2Cpp<WheelSpin>();
}
WheelSpin wheelSpin = target.GetComponent<WheelSpin>() ?? target.AddComponent<WheelSpin>();
wheelSpin._from = from;
wheelSpin._to = to;
wheelSpin._time = 0f;
wheelSpin._duration = Mathf.Max(0.1f, seconds);
wheelSpin._step = Mathf.Max(1f, step);
wheelSpin._line = Line(from, wheelSpin._step);
wheelSpin._kick = 0f;
wheelSpin._pointer = (((Object)(object)pointer != (Object)null) ? pointer.transform : null);
wheelSpin._onAngle = onAngle;
wheelSpin._onDone = onDone;
((Behaviour)wheelSpin).enabled = true;
Running = true;
}
private static int Line(float angle, float step)
{
return Mathf.FloorToInt(angle / step);
}
public void Update()
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
float unscaledDeltaTime = Time.unscaledDeltaTime;
_time += unscaledDeltaTime;
float num = Mathf.Clamp01(_time / _duration);
float num2 = 1f - Mathf.Pow(1f - num, 4f);
float num3 = Mathf.Lerp(_from, _to, num2);
((Component)this).transform.localRotation = Quaternion.Euler(0f, 0f, num3);
_onAngle?.Invoke(num3);
int num4 = Line(num3, _step);
if (num4 != _line)
{
_line = num4;
_kick = 1f;
}
else
{
_kick = Mathf.Max(0f, _kick - unscaledDeltaTime * 7f);
}
if ((Object)(object)_pointer != (Object)null)
{
_pointer.localRotation = Quaternion.Euler(0f, 0f, 26f * Mathf.SmoothStep(0f, 1f, _kick));
}
if (!(num < 1f))
{
Finish();
}
}
public void OnDestroy()
{
Finish();
}
private void Finish()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
if (!Running && _onDone == null)
{
return;
}
if ((Object)(object)_pointer != (Object)null)
{
_pointer.localRotation = Quaternion.identity;
}
((Behaviour)this).enabled = false;
Running = false;
Action onDone = _onDone;
_onDone = null;
try
{
onDone?.Invoke();
}
catch (Exception ex)
{
Plugin.L.LogWarning((object)("wheel: " + ex.Message));
}
}
}
}