using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using Zorro.Core;
[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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FoodRandomiser")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.0+d458d06da08d630589239d87e26706682db39b9a")]
[assembly: AssemblyProduct("FoodRandomiser")]
[assembly: AssemblyTitle("FoodRandomiser")]
[assembly: AssemblyVersion("1.0.1.0")]
[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.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]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace FoodRandomiser
{
public class Hooks
{
[HarmonyPatch(typeof(AirportCheckInKiosk), "StartGame")]
public class AirportCheckInKiosk_StartGame
{
public static void Prefix()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_0038: Expected O, but got Unknown
if (PhotonNetwork.IsMasterClient)
{
Room currentRoom = PhotonNetwork.CurrentRoom;
Hashtable val = new Hashtable();
((Dictionary<object, object>)val).Add((object)"piepieonline_shuffle_seed", (object)Random.Range(0, int.MaxValue));
currentRoom.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
}
}
}
}
[BepInPlugin("FoodRandomiser", "FoodRandomiser", "1.0.0")]
public class Plugin : BaseUnityPlugin, IInRoomCallbacks
{
public const string PROPKEY_SHUFFLE_SEED = "piepieonline_shuffle_seed";
public static ConfigEntry<bool> Enabled = null;
public static ManualLogSource PluginLogger = null;
public static ConfigEntry<ShuffleModes> ShuffleMode = null;
private static Dictionary<string, List<(string typeName, string componentJson)>> _originalActions = new Dictionary<string, List<(string, string)>>();
private static readonly HashSet<string> ActionFilter = new HashSet<string> { "Action_RestoreHunger", "Action_GiveExtraStamina", "Action_InflictPoison", "Action_ModifyStatus" };
private static readonly Dictionary<string, string> RandomInTypePool = new Dictionary<string, string>
{
{ "Apple Berry Red", "Apple Berry" },
{ "Apple Berry Green", "Apple Berry" },
{ "Apple Berry Yellow", "Apple Berry" },
{ "Berrynana Blue", "Berrynana" },
{ "Berrynana Brown", "Berrynana" },
{ "Berrynana Pink", "Berrynana" },
{ "Berrynana Yellow", "Berrynana" },
{ "Clusterberry Black", "Clusterberry" },
{ "Clusterberry Red", "Clusterberry" },
{ "Clusterberry Yellow", "Clusterberry" },
{ "Kingberry Green", "Kingberry" },
{ "Kingberry Purple", "Kingberry" },
{ "Kingberry Yellow", "Kingberry" },
{ "Mushroom Chubby", "Mushroom" },
{ "Mushroom Cluster", "Mushroom" },
{ "Mushroom Cluster Poison", "Mushroom" },
{ "Mushroom Lace", "Mushroom" },
{ "Mushroom Lace Poison", "Mushroom" },
{ "Mushroom Normie", "Mushroom" },
{ "Mushroom Normie Poison", "Mushroom" },
{ "Winterberry Orange", "Winterberry" },
{ "Winterberry Yellow", "Winterberry" }
};
private static readonly Dictionary<string, string> RandomInNaturePool = new Dictionary<string, string>
{
{ "Apple Berry Red", "Random" },
{ "Apple Berry Green", "Random" },
{ "Apple Berry Yellow", "Random" },
{ "Berrynana Blue", "Random" },
{ "Berrynana Brown", "Random" },
{ "Berrynana Pink", "Random" },
{ "Berrynana Yellow", "Random" },
{ "Clusterberry Black", "Random" },
{ "Clusterberry Red", "Random" },
{ "Clusterberry Yellow", "Random" },
{ "Kingberry Green", "Random" },
{ "Kingberry Purple", "Random" },
{ "Kingberry Yellow", "Random" },
{ "Mushroom Chubby", "Random" },
{ "Mushroom Cluster", "Random" },
{ "Mushroom Cluster Poison", "Random" },
{ "Mushroom Lace", "Random" },
{ "Mushroom Lace Poison", "Random" },
{ "Mushroom Normie", "Random" },
{ "Mushroom Normie Poison", "Random" },
{ "Winterberry Orange", "Random" },
{ "Winterberry Yellow", "Random" }
};
private void Awake()
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Expected O, but got Unknown
PluginLogger = ((BaseUnityPlugin)this).Logger;
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Is the mod enabled at all? (Game restart required)");
ShuffleMode = ((BaseUnityPlugin)this).Config.Bind<ShuffleModes>("General", "Shuffle Mode", ShuffleModes.RandomInType, "Random in type will use only effects from variants (Red/Green/Yellow crispberry shuffle), random in nature uses any natural effect");
if (Enabled.Value)
{
PluginLogger.LogInfo((object)"Plugin FoodRandomiser is loaded!");
Harmony val = new Harmony("FoodRandomiser");
val.PatchAll();
PhotonNetwork.AddCallbackTarget((object)this);
PluginLogger.LogInfo((object)"Plugin FoodRandomiser is patched!");
}
}
private void OnDestroy()
{
PhotonNetwork.RemoveCallbackTarget((object)this);
ResetItemDatabase();
}
public void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
{
if (((Dictionary<object, object>)(object)propertiesThatChanged).ContainsKey((object)"piepieonline_shuffle_seed"))
{
PluginLogger.LogInfo((object)"FoodRandomiser: Watched properties updated");
ResetItemDatabase();
ShuffleItemDatabase((int)propertiesThatChanged[(object)"piepieonline_shuffle_seed"]);
}
}
private static void ShuffleItemDatabase(int seed)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_035e: Unknown result type (might be due to invalid IL or missing references)
PluginLogger.LogInfo((object)$"Got shuffle request, using seed: {seed}");
State state = Random.state;
Random.InitState(seed);
ItemDatabase instance = SingletonAsset<ItemDatabase>.Instance;
Dictionary<string, string> dictionary = ((ShuffleMode.Value == ShuffleModes.RandomInType) ? RandomInTypePool : RandomInNaturePool);
Dictionary<string, List<List<(string, string)>>> dictionary2 = new Dictionary<string, List<List<(string, string)>>>();
foreach (KeyValuePair<ushort, Item> item in instance.itemLookup)
{
Item value = item.Value;
PluginLogger.LogInfo((object)("Item: " + ((Object)value).name + ", previous actions: " + string.Join("", from action in ((Component)value).GetComponents<ItemAction>().ToList()
select "\r\n\t" + ((object)action).GetType().Name + ": ")));
if (!dictionary.ContainsKey(((Object)value).name))
{
continue;
}
if (!dictionary2.ContainsKey(dictionary[((Object)value).name]))
{
dictionary2.Add(dictionary[((Object)value).name], new List<List<(string, string)>>());
}
List<(string, string)> list = new List<(string, string)>();
ItemAction[] components = ((Component)value).GetComponents<ItemAction>();
foreach (ItemAction val in components)
{
if (ActionFilter.Contains(((object)val).GetType().Name))
{
list.Add((((object)val).GetType().AssemblyQualifiedName, JsonUtility.ToJson((object)val)));
}
}
dictionary2[dictionary[((Object)value).name]].Add(list);
}
foreach (KeyValuePair<ushort, Item> item2 in instance.itemLookup)
{
Item value2 = item2.Value;
if (!dictionary.ContainsKey(((Object)value2).name))
{
continue;
}
int index = Random.Range(0, dictionary2[dictionary[((Object)value2).name]].Count);
List<(string, string)> list2 = dictionary2[dictionary[((Object)value2).name]][index];
dictionary2[dictionary[((Object)value2).name]].RemoveAt(index);
ItemAction[] components2 = ((Component)value2).GetComponents<ItemAction>();
foreach (ItemAction val2 in components2)
{
if (ActionFilter.Contains(((object)val2).GetType().Name))
{
Object.Destroy((Object)(object)val2);
}
}
string text = "";
foreach (var item3 in list2)
{
JsonUtility.FromJsonOverwrite(item3.Item2, (object)((Component)value2).gameObject.AddComponent(Type.GetType(item3.Item1)));
text = text + "\r\n\t" + Type.GetType(item3.Item1).Name;
}
PluginLogger.LogInfo((object)("Item: " + ((Object)value2).name + ", new actions added: " + text));
}
Random.state = state;
}
private static void ResetItemDatabase()
{
}
public void OnPlayerEnteredRoom(Player newPlayer)
{
}
public void OnPlayerLeftRoom(Player otherPlayer)
{
}
public void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
{
}
public void OnMasterClientSwitched(Player newMasterClient)
{
}
}
public enum ShuffleModes
{
RandomInType,
RandomInNature
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "FoodRandomiser";
public const string PLUGIN_NAME = "FoodRandomiser";
public const string PLUGIN_VERSION = "1.0.0";
}
}