using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using ValuableBeerPotionMod;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
public class ValuableBeerPotion : MonoBehaviour
{
public enum State
{
Idle,
Active
}
private PhysGrabObject physGrabObject;
private List<string> transitiveVerbs = new List<string>();
private List<string> intransitiveVerbs = new List<string>();
private List<string> adjectives = new List<string>();
private List<string> intensifiers = new List<string>();
private List<string> nouns = new List<string>();
private List<string> adverbs = new List<string>();
private float coolDownUntilNextSentence = 3f;
private ParticleSystem particles;
private bool particlesPlaying;
public Renderer LovePotionRenderer;
private State currentState;
private string playerName = "[playerName]";
private void Start()
{
particles = ((Component)this).GetComponentInChildren<ParticleSystem>();
physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
InitializeWordLists();
}
private void Update()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
LovePotionRenderer.material.mainTextureOffset = new Vector2(0f, Time.time * 0.1f);
LovePotionRenderer.material.mainTextureScale = new Vector2(2f + Mathf.Sin(Time.time * 1f) * 0.25f, 2f + Mathf.Sin(Time.time * 1f) * 0.25f);
if (physGrabObject.grabbed)
{
if (!particlesPlaying)
{
particles.Play();
particlesPlaying = true;
}
}
else if (particlesPlaying)
{
particles.Stop();
particlesPlaying = false;
}
if (SemiFunc.IsMultiplayer())
{
switch (currentState)
{
case State.Idle:
StateIdle();
break;
case State.Active:
StateActive();
break;
}
}
}
private void StateIdle()
{
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
if (coolDownUntilNextSentence > 0f && physGrabObject.grabbed)
{
coolDownUntilNextSentence -= Time.deltaTime;
}
else
{
if (!Object.op_Implicit((Object)(object)PhysGrabber.instance) || !PhysGrabber.instance.grabbed || !Object.op_Implicit((Object)(object)PhysGrabber.instance.grabbedPhysGrabObject()) || !((Object)(object)PhysGrabber.instance.grabbedPhysGrabObject() == (Object)(object)physGrabObject))
{
return;
}
bool flag;
if (!SemiFunc.IsMultiplayer())
{
playerName = "this beer";
flag = true;
}
else
{
List<PlayerAvatar> list = SemiFunc.PlayerGetAllPlayerAvatarWithinRange(10f, ((Component)PhysGrabber.instance).transform.position, false, default(LayerMask));
PlayerAvatar val = null;
float num = float.MaxValue;
foreach (PlayerAvatar item in list)
{
if (!((Object)(object)item == (Object)(object)PlayerAvatar.instance))
{
float num2 = Vector3.Distance(((Component)PhysGrabber.instance).transform.position, ((Component)item).transform.position);
if (num2 < num)
{
num = num2;
val = item;
}
}
}
flag = true;
if ((Object)(object)val != (Object)null)
{
playerName = val.playerName();
}
else
{
playerName = "this beer";
}
}
if (flag)
{
string text = GenerateAffectionateSentence();
currentState = State.Active;
Color val2 = default(Color);
((Color)(ref val2))..ctor(1f, 0.9f, 0.5f, 1f);
ChatManager.instance.PossessChatScheduleStart(10);
ChatManager.instance.PossessChat((PossessChatID)1, text, 1f, val2, 0f, false, 0, (UnityEvent)null);
ChatManager.instance.PossessChatScheduleEnd();
}
}
}
private void StateActive()
{
if (PhysGrabber.instance.grabbed && Object.op_Implicit((Object)(object)PhysGrabber.instance.grabbedPhysGrabObject()) && (Object)(object)PhysGrabber.instance.grabbedPhysGrabObject() != (Object)(object)physGrabObject)
{
currentState = State.Idle;
coolDownUntilNextSentence = Random.Range(5f, 15f);
}
else if (!ChatManager.instance.StateIsPossessed())
{
currentState = State.Idle;
coolDownUntilNextSentence = Random.Range(5f, 15f);
}
}
private void InitializeWordLists()
{
transitiveVerbs.AddRange(new string[11]
{
"drink with", "toast with", "savor with", "clink glasses with", "share a pint with", "enjoy a brew with", "down a cold one with", "quaff with", "imbibe with", "raise a glass with",
"chug with"
});
intransitiveVerbs.AddRange(new string[12]
{
"bubble", "foam", "fizz", "ferment", "brew", "carbonate", "age", "mature", "condition", "sparkle",
"chill", "refresh"
});
adjectives.AddRange(new string[27]
{
"hops-olutely amazing", "brew-tiful", "beer-y special", "lager-ly unique", "ale-some", "pint-sized perfection", "malt-nificent", "stout-standing", "golden", "bubbly",
"frothylicious", "beer-y good", "refreshing", "crisp", "zesty", "hoppy", "malty", "smooth", "rich", "robust",
"full-bodied", "light", "dark", "amber", "craft", "draught", "cask-conditioned"
});
intensifiers.AddRange(new string[59]
{
"totally", "super", "uber", "mega", "super mega", "seriously", "majorly", "absolutely", "completely", "utterly",
"incredibly", "madly", "sooo", "really", "so", "sooooooooo", "unbelievably", "very", "extra", "extremely",
"really really", "fiercely", "greatly", "hugely", "immensely", "intensely", "massively", "so so soooo", "really really really", "simply",
"supremely", "surprisingly", "super mega ultra", "ultra", "unusually", "way way", "way", "insanely", "freakishly", "extra extra",
"overwhelmingly", "reeeaaally", "weirdly", "suuuuper", "way waaaay", "crazy", "like suuuuuper", "really sooo", "literally", "for reeeaal soo",
"honestly", "kinda", "sort of", "basically", "downright", "very very", "genuinely", "truly", "sincerely"
});
nouns.AddRange(new string[3] { "beer", "wheat beer", "craft beer" });
adverbs.AddRange(new string[59]
{
"totally", "super", "uber", "mega", "super mega", "seriously", "majorly", "absolutely", "completely", "utterly",
"incredibly", "madly", "sooo", "really", "so", "sooooooooo", "unbelievably", "very", "extra", "extremely",
"really really", "fiercely", "greatly", "hugely", "immensely", "intensely", "massively", "so so soooo", "really really really", "simply",
"supremely", "surprisingly", "super mega ultra", "ultra", "unusually", "way way", "way", "insanely", "freakishly", "extra extra",
"overwhelmingly", "reeeaaally", "weirdly", "suuuuper", "way waaaay", "crazy", "like suuuuuper", "really sooo", "literally", "for reeeaal soo",
"honestly", "kinda", "sort of", "basically", "downright", "very very", "genuinely", "truly", "sincerely"
});
}
private string GenerateAffectionateSentence()
{
List<string> list = new List<string>
{
"{playerName} go to drink this {noun}.", "Every time I see {playerName}, this {noun} {intransitiveVerb}.", "{playerName} and this {noun} are a {adjective} match.", "Got me {adverb} craving a {adjective} {noun} with {playerName}.", "Just want to {transitiveVerb} a {adjective} {noun}.", "Oh my, {playerName} and a {adjective} {noun}, {intensifier} perfect!", "{playerName} is as {adjective} as my favorite {noun}.", "{playerName}, you are the {noun} to my {adjective} day!", "This {noun} is so {adjective}, especially with {playerName}.", "Can't stop thinking about sharing a {adjective} {noun} with {playerName}.",
"{playerName}'s choice of {noun} is always so {adjective}.", "Dreaming of a {adjective} {noun} with {playerName} right now.", "With {playerName}, every {noun} tastes {intensifier} {adjective}.", "{playerName}, you make me want a {intensifier} {adjective} {noun}.", "Life is {intensifier} {adjective} with {playerName} and a good {noun}.", "{playerName} knows how to pick a {intensifier} {adjective} {noun}.", "A {adjective} {noun} with {playerName} is all I need.", "{playerName} turns every {noun} into a {adjective} experience.", "I want to beat my wife and go play gambling"
};
string text = list[Random.Range(0, list.Count)];
string text2 = text.Replace("{playerName}", playerName);
if (text.Contains("{transitiveVerb}"))
{
string newValue = transitiveVerbs[Random.Range(0, transitiveVerbs.Count)];
text2 = text2.Replace("{transitiveVerb}", newValue);
}
if (text.Contains("{intransitiveVerb}"))
{
string text3 = intransitiveVerbs[Random.Range(0, intransitiveVerbs.Count)];
if (text2.Contains("{intransitiveVerb}s"))
{
text3 = ((!text3.EndsWith("e")) ? (text3 + "es") : (text3 + "s"));
text2 = text2.Replace("{intransitiveVerb}s", text3);
}
else
{
text2 = text2.Replace("{intransitiveVerb}", text3);
}
}
if (text.Contains("{adjective}"))
{
string newValue2 = adjectives[Random.Range(0, adjectives.Count)];
text2 = text2.Replace("{adjective}", newValue2);
}
if (text.Contains("{intensifier}"))
{
string newValue3 = intensifiers[Random.Range(0, intensifiers.Count)];
text2 = text2.Replace("{intensifier}", newValue3);
}
if (text.Contains("{adverb}"))
{
string newValue4 = adverbs[Random.Range(0, adverbs.Count)];
text2 = text2.Replace("{adverb}", newValue4);
}
if (text.Contains("{noun}"))
{
string newValue5 = nouns[Random.Range(0, nouns.Count)];
text2 = text2.Replace("{noun}", newValue5);
}
return char.ToUpper(text2[0]) + text2.Substring(1);
}
}
namespace ValuableBeerPotionMod;
[BepInPlugin("com.modder.valuablebeerpotion", "Valuable Beer Potion Mod", "1.0.0")]
public class ValuableBeerPotionPlugin : BaseUnityPlugin
{
public static ManualLogSource Log;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"ValuableBeerPotion Mod: Starting initialization");
ValuableBeerPotionPatch.Initialize();
Log.LogInfo((object)"ValuableBeerPotion Mod: Initialization complete");
}
}
[HarmonyPatch]
public class ValuableBeerPotionPatch
{
public static class PlayerAvatarAccessor
{
private static FieldInfo playerNameField;
static PlayerAvatarAccessor()
{
Type typeFromHandle = typeof(PlayerAvatar);
playerNameField = typeFromHandle.GetField("_playerName", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle.GetField("playerName", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle.GetField("m_playerName", BindingFlags.Instance | BindingFlags.NonPublic);
if (playerNameField == null)
{
Debug.LogError((object)"ValuableBeerPotion Patch: Couldn't find playerName field in PlayerAvatar class");
}
else
{
Debug.Log((object)("ValuableBeerPotion Patch: Found playerName field: " + playerNameField.Name));
}
}
public static string GetPlayerName(PlayerAvatar playerAvatar)
{
if (playerNameField != null && (Object)(object)playerAvatar != (Object)null)
{
try
{
return (string)playerNameField.GetValue(playerAvatar);
}
catch (Exception ex)
{
Debug.LogError((object)("ValuableBeerPotion Patch: Error accessing playerName: " + ex.Message));
}
}
return "Unknown Player";
}
}
public static class PhysGrabberAccessor
{
private static FieldInfo grabbedPhysGrabObjectField;
static PhysGrabberAccessor()
{
Type typeFromHandle = typeof(PhysGrabber);
grabbedPhysGrabObjectField = typeFromHandle.GetField("_grabbedPhysGrabObject", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle.GetField("grabbedPhysGrabObject", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle.GetField("m_grabbedPhysGrabObject", BindingFlags.Instance | BindingFlags.NonPublic);
if (grabbedPhysGrabObjectField == null)
{
Debug.LogError((object)"ValuableBeerPotion Patch: Couldn't find grabbedPhysGrabObject field in PhysGrabber class");
}
else
{
Debug.Log((object)("ValuableBeerPotion Patch: Found grabbedPhysGrabObject field: " + grabbedPhysGrabObjectField.Name));
}
}
public static PhysGrabObject GetGrabbedPhysGrabObject(PhysGrabber physGrabber)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
if (grabbedPhysGrabObjectField != null && (Object)(object)physGrabber != (Object)null)
{
try
{
return (PhysGrabObject)grabbedPhysGrabObjectField.GetValue(physGrabber);
}
catch (Exception ex)
{
Debug.LogError((object)("ValuableBeerPotion Patch: Error accessing grabbedPhysGrabObject: " + ex.Message));
}
}
return null;
}
}
public static void Initialize()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
Debug.Log((object)"ValuableBeerPotion Patch: Initializing");
Harmony val = new Harmony("com.modder.valuablebeerpotion");
val.PatchAll(typeof(ValuableBeerPotionPatch));
Debug.Log((object)"ValuableBeerPotion Patch: Initialized successfully");
}
[HarmonyPatch(typeof(ValuableBeerPotion), "StateIdle")]
[HarmonyPrefix]
public static bool Prefix_StateIdle(ValuableBeerPotion __instance, ref float ___coolDownUntilNextSentence, PhysGrabObject ___physGrabObject, ref string ___playerName, ref ValuableBeerPotion.State ___currentState)
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: 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)
if (___coolDownUntilNextSentence > 0f && ___physGrabObject.grabbed)
{
___coolDownUntilNextSentence -= Time.deltaTime;
return false;
}
if (Object.op_Implicit((Object)(object)PhysGrabber.instance) && PhysGrabber.instance.grabbed)
{
PhysGrabObject grabbedPhysGrabObject = PhysGrabberAccessor.GetGrabbedPhysGrabObject(PhysGrabber.instance);
if (Object.op_Implicit((Object)(object)grabbedPhysGrabObject) && (Object)(object)grabbedPhysGrabObject == (Object)(object)___physGrabObject)
{
bool flag;
if (!SemiFunc.IsMultiplayer())
{
___playerName = "this beer";
flag = true;
}
else
{
List<PlayerAvatar> list = SemiFunc.PlayerGetAllPlayerAvatarWithinRange(10f, ((Component)PhysGrabber.instance).transform.position, false, default(LayerMask));
PlayerAvatar val = null;
float num = float.MaxValue;
foreach (PlayerAvatar item in list)
{
if (!((Object)(object)item == (Object)(object)PlayerAvatar.instance))
{
float num2 = Vector3.Distance(((Component)PhysGrabber.instance).transform.position, ((Component)item).transform.position);
if (num2 < num)
{
num = num2;
val = item;
}
}
}
flag = true;
if ((Object)(object)val != (Object)null)
{
___playerName = PlayerAvatarAccessor.GetPlayerName(val);
}
else
{
___playerName = "this beer";
}
}
if (flag)
{
MethodInfo method = typeof(ValuableBeerPotion).GetMethod("GenerateAffectionateSentence", BindingFlags.Instance | BindingFlags.NonPublic);
string text = (string)method.Invoke(__instance, null);
___currentState = ValuableBeerPotion.State.Active;
Color val2 = default(Color);
((Color)(ref val2))..ctor(1f, 0.9f, 0.5f, 1f);
ChatManager.instance.PossessChatScheduleStart(10);
ChatManager.instance.PossessChat((PossessChatID)1, text, 1f, val2, 0f, false, 0, (UnityEvent)null);
ChatManager.instance.PossessChatScheduleEnd();
}
}
}
return false;
}
[HarmonyPatch(typeof(ValuableBeerPotion), "StateActive")]
[HarmonyPrefix]
public static bool Prefix_StateActive(ValuableBeerPotion __instance, ref float ___coolDownUntilNextSentence, PhysGrabObject ___physGrabObject, ref ValuableBeerPotion.State ___currentState)
{
if (PhysGrabber.instance.grabbed)
{
PhysGrabObject grabbedPhysGrabObject = PhysGrabberAccessor.GetGrabbedPhysGrabObject(PhysGrabber.instance);
if (Object.op_Implicit((Object)(object)grabbedPhysGrabObject) && (Object)(object)grabbedPhysGrabObject != (Object)(object)___physGrabObject)
{
___currentState = ValuableBeerPotion.State.Idle;
___coolDownUntilNextSentence = Random.Range(5f, 15f);
return false;
}
}
if (!ChatManager.instance.StateIsPossessed())
{
___currentState = ValuableBeerPotion.State.Idle;
___coolDownUntilNextSentence = Random.Range(5f, 15f);
return false;
}
return false;
}
}
public static class RepoExtensions
{
private static FieldInfo _playerNameField;
private static FieldInfo _grabbedPhysGrabObjectField;
static RepoExtensions()
{
try
{
Type typeFromHandle = typeof(PlayerAvatar);
_playerNameField = typeFromHandle.GetField("_playerName", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle.GetField("playerName", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle.GetField("m_playerName", BindingFlags.Instance | BindingFlags.NonPublic);
if (_playerNameField == null)
{
Debug.LogError((object)"RepoExtensions: Couldn't find playerName field in PlayerAvatar class");
}
else
{
Debug.Log((object)("RepoExtensions: Found playerName field: " + _playerNameField.Name));
}
}
catch (Exception ex)
{
Debug.LogError((object)("RepoExtensions: Error initializing playerName field: " + ex.Message));
}
try
{
Type typeFromHandle2 = typeof(PhysGrabber);
_grabbedPhysGrabObjectField = typeFromHandle2.GetField("_grabbedPhysGrabObject", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle2.GetField("grabbedPhysGrabObject", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeFromHandle2.GetField("m_grabbedPhysGrabObject", BindingFlags.Instance | BindingFlags.NonPublic);
if (_grabbedPhysGrabObjectField == null)
{
Debug.LogError((object)"RepoExtensions: Couldn't find grabbedPhysGrabObject field in PhysGrabber class");
}
else
{
Debug.Log((object)("RepoExtensions: Found grabbedPhysGrabObject field: " + _grabbedPhysGrabObjectField.Name));
}
}
catch (Exception ex2)
{
Debug.LogError((object)("RepoExtensions: Error initializing grabbedPhysGrabObject field: " + ex2.Message));
}
}
public static string playerName(this PlayerAvatar playerAvatar)
{
if (_playerNameField != null && (Object)(object)playerAvatar != (Object)null)
{
try
{
return (string)_playerNameField.GetValue(playerAvatar);
}
catch (Exception ex)
{
Debug.LogError((object)("RepoExtensions: Error accessing playerName: " + ex.Message));
}
}
return "Unknown Player";
}
public static PhysGrabObject grabbedPhysGrabObject(this PhysGrabber physGrabber)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
if (_grabbedPhysGrabObjectField != null && (Object)(object)physGrabber != (Object)null)
{
try
{
return (PhysGrabObject)_grabbedPhysGrabObjectField.GetValue(physGrabber);
}
catch (Exception ex)
{
Debug.LogError((object)("RepoExtensions: Error accessing grabbedPhysGrabObject: " + ex.Message));
}
}
return null;
}
}