using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MyMods.SmokingMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+908d413c7c9398bc8dbad7382e5d5268a3df5016")]
[assembly: AssemblyProduct("MyMods.SmokingMod")]
[assembly: AssemblyTitle("MyMods.SmokingMod")]
[assembly: AssemblyVersion("0.2.0.0")]
internal static class SmokingModRightHandCheck
{
internal static void Tick(ManualLogSource logger)
{
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: 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)
Keyboard current = Keyboard.current;
if (current != null && ((ButtonControl)current.f9Key).wasPressedThisFrame)
{
string source;
Transform val = Find(logger, "F9", out source);
if (!((Object)(object)val == (Object)null))
{
string[] obj = new string[12]
{
"F9: ",
((Object)val).name,
" via ",
source,
" | path=",
FullPath(val),
" | world position=",
null,
null,
null,
null,
null
};
Vector3 val2 = val.position;
obj[7] = ((Vector3)(ref val2)).ToString("F4");
obj[8] = " | world quaternion=";
Quaternion rotation = val.rotation;
obj[9] = ((Quaternion)(ref rotation)).ToString("F5");
obj[10] = " | world Euler degrees=";
val2 = val.eulerAngles;
obj[11] = ((Vector3)(ref val2)).ToString("F2");
logger.LogInfo((object)string.Concat(obj));
}
}
}
internal static Transform Find(ManualLogSource logger, string key, out string source)
{
source = "SkinnedMeshRenderer.bones";
Character localCharacter = Character.localCharacter;
if ((Object)(object)localCharacter == (Object)null)
{
if (logger != null)
{
logger.LogWarning((object)(key + ": Local character is unavailable. Enter a playable scene and press " + key + " again."));
}
return null;
}
return Find(((Component)localCharacter).transform, logger, key, out source);
}
internal static Transform Find(Transform root, ManualLogSource logger, string key, out string source)
{
source = "SkinnedMeshRenderer.bones";
SkinnedMeshRenderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<SkinnedMeshRenderer>(true);
Transform val = null;
SkinnedMeshRenderer[] array = componentsInChildren;
for (int i = 0; i < array.Length; i++)
{
Transform[] bones = array[i].bones;
foreach (Transform val2 in bones)
{
if (IsRightHand(val2) && val2.IsChildOf(root))
{
val = val2;
break;
}
}
if ((Object)(object)val != (Object)null)
{
break;
}
}
if ((Object)(object)val == (Object)null)
{
source = "Transform hierarchy";
Transform[] componentsInChildren2 = ((Component)root).GetComponentsInChildren<Transform>(true);
Transform[] bones = componentsInChildren2;
foreach (Transform val3 in bones)
{
if (IsRightHand(val3))
{
val = val3;
break;
}
}
if ((Object)(object)val == (Object)null)
{
if (logger != null)
{
logger.LogWarning((object)(key + ": Hand_R under Arm_R/Elbow_R not found on " + FullPath(root) + ". " + $"Checked {componentsInChildren.Length} skinned renderers and {componentsInChildren2.Length} transforms."));
}
return null;
}
}
return val;
}
private static bool IsRightHand(Transform bone)
{
if ((Object)(object)bone != (Object)null && ((Object)bone).name == "Hand_R" && (Object)(object)bone.parent != (Object)null && ((Object)bone.parent).name == "Elbow_R" && (Object)(object)bone.parent.parent != (Object)null)
{
return ((Object)bone.parent.parent).name == "Arm_R";
}
return false;
}
private static string FullPath(Transform node)
{
Stack<string> stack = new Stack<string>();
Transform val = node;
while ((Object)(object)val != (Object)null)
{
stack.Push(((Object)val).name);
val = val.parent;
}
return string.Join("/", stack.ToArray());
}
}
namespace SmokingMod;
[BepInPlugin("MyMods.SmokingMod", "SmokingMod", "0.2.0")]
public sealed class Plugin : BaseUnityPlugin
{
private readonly TestCigarette cigarette = new TestCigarette();
private SmokingMultiplayer multiplayer;
private ConfigEntry<float> mouthX;
private ConfigEntry<float> mouthY;
private ConfigEntry<float> mouthZ;
private ConfigEntry<float> travelSeconds;
private void Awake()
{
cigarette.BindSmoke(((BaseUnityPlugin)this).Config);
multiplayer = new SmokingMultiplayer(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
mouthX = ((BaseUnityPlugin)this).Config.Bind<float>("Smoking", "MouthOffsetX", 0f, "Offset along Head local X.");
mouthY = ((BaseUnityPlugin)this).Config.Bind<float>("Smoking", "MouthOffsetY", 0f, "Offset along Head local Y.");
mouthZ = ((BaseUnityPlugin)this).Config.Bind<float>("Smoking", "MouthOffsetZ", 0f, "Offset along Head local Z.");
travelSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Smoking", "TravelSeconds", 0.45f, "Seconds for one full trip.");
}
private void LateUpdate()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(mouthX.Value, mouthY.Value, mouthZ.Value);
cigarette.UpdateSmoking(val, travelSeconds.Value, ((BaseUnityPlugin)this).Logger);
cigarette.UpdateSmoke(((BaseUnityPlugin)this).Logger);
multiplayer.Tick(cigarette, val, travelSeconds.Value);
}
private void OnDestroy()
{
multiplayer?.Dispose();
cigarette.Dispose();
}
private void Update()
{
SmokingModRightHandCheck.Tick(((BaseUnityPlugin)this).Logger);
Keyboard current = Keyboard.current;
if (current != null && ((ButtonControl)current.f7Key).wasPressedThisFrame)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"F7: Key press detected.");
cigarette.Toggle(((BaseUnityPlugin)this).Logger);
}
Keyboard current2 = Keyboard.current;
if (current2 != null && ((ButtonControl)current2.f8Key).wasPressedThisFrame)
{
cigarette.ToggleSmoking(Character.localCharacter, ((BaseUnityPlugin)this).Logger);
}
}
}
internal sealed class SmokingMultiplayer : IDisposable
{
private sealed class RemoteProp
{
internal Character Character { get; }
internal TestCigarette Cigarette { get; }
internal RemoteProp(Character character, TestCigarette cigarette)
{
Character = character;
Cigarette = cigarette;
}
}
private const string StateKey = "MyMods.SmokingMod.state.v1";
private readonly Dictionary<int, RemoteProp> props = new Dictionary<int, RemoteProp>();
private readonly HashSet<int> visibleActors = new HashSet<int>();
private readonly List<int> expiredActors = new List<int>();
private readonly ConfigFile config;
private readonly ManualLogSource logger;
private Room room;
private int? sentState;
private float nextPoll;
internal SmokingMultiplayer(ConfigFile config, ManualLogSource logger)
{
this.config = config;
this.logger = logger;
}
internal void Tick(TestCigarette local, Vector3 mouthOffset, float travelSeconds)
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
Room val = (PhotonNetwork.InRoom ? PhotonNetwork.CurrentRoom : null);
if (room != val)
{
ClearProps();
room = val;
sentState = null;
nextPoll = 0f;
}
if (room == null)
{
return;
}
if (Time.unscaledTime >= nextPoll)
{
nextPoll = Time.unscaledTime + 0.1f;
Publish(local);
RefreshProps();
}
foreach (RemoteProp value in props.Values)
{
if (!((Object)(object)value.Character == (Object)null))
{
value.Cigarette.UpdateSmoking(mouthOffset, travelSeconds, logger);
value.Cigarette.UpdateSmoke(logger);
}
}
}
private void Publish(TestCigarette local)
{
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
Character localCharacter = Character.localCharacter;
PhotonView val = (((Object)(object)localCharacter == (Object)null) ? null : ((MonoBehaviourPun)localCharacter).photonView);
Player localPlayer = PhotonNetwork.LocalPlayer;
int num = 0;
if (local.IsVisible && (Object)(object)val != (Object)null && val.ViewID > 0 && val.Owner == localPlayer)
{
num = (val.ViewID << 1) | (local.IsTowardMouth ? 1 : 0);
}
if (num != sentState && localPlayer.SetCustomProperties(new Hashtable { [(object)"MyMods.SmokingMod.state.v1"] = num }, (Hashtable)null, (WebFlags)null))
{
sentState = num;
}
}
private void RefreshProps()
{
visibleActors.Clear();
Player[] playerListOthers = PhotonNetwork.PlayerListOthers;
Character val3 = default(Character);
foreach (Player val in playerListOthers)
{
if (val.IsInactive || !((Dictionary<object, object>)(object)val.CustomProperties).TryGetValue((object)"MyMods.SmokingMod.state.v1", out object value) || !(value is int num) || num < 2)
{
continue;
}
PhotonView val2 = PhotonView.Find(num >> 1);
if ((Object)(object)val2 == (Object)null || val2.OwnerActorNr != val.ActorNumber || !((Component)val2).TryGetComponent<Character>(ref val3) || !((Component)val3).gameObject.activeInHierarchy)
{
continue;
}
int actorNumber = val.ActorNumber;
if (!props.TryGetValue(actorNumber, out var value2) || (Object)(object)value2.Character != (Object)(object)val3 || !value2.Cigarette.IsVisible)
{
RemoveProp(actorNumber);
string source;
Transform val4 = SmokingModRightHandCheck.Find(((Component)val3).transform, null, "", out source);
if ((Object)(object)val4 == (Object)null)
{
continue;
}
TestCigarette testCigarette = new TestCigarette();
if (!testCigarette.ShowRemote(val4, logger))
{
testCigarette.Dispose();
continue;
}
testCigarette.BindSmoke(config);
value2 = new RemoteProp(val3, testCigarette);
props.Add(actorNumber, value2);
}
visibleActors.Add(actorNumber);
if (value2.Cigarette.IsTowardMouth != ((num & 1) != 0))
{
value2.Cigarette.ToggleSmoking(val3, logger);
}
}
expiredActors.Clear();
foreach (int key in props.Keys)
{
if (!visibleActors.Contains(key))
{
expiredActors.Add(key);
}
}
foreach (int expiredActor in expiredActors)
{
RemoveProp(expiredActor);
}
}
private void RemoveProp(int actor)
{
if (props.Remove(actor, out var value))
{
value.Cigarette.Dispose();
}
}
private void ClearProps()
{
foreach (RemoteProp value in props.Values)
{
value.Cigarette.Dispose();
}
props.Clear();
}
public void Dispose()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
if (PhotonNetwork.InRoom && sentState.GetValueOrDefault() != 0)
{
PhotonNetwork.LocalPlayer.SetCustomProperties(new Hashtable { [(object)"MyMods.SmokingMod.state.v1"] = 0 }, (Hashtable)null, (WebFlags)null);
}
ClearProps();
}
}
internal sealed class TestCigarette
{
private GameObject prop;
private Mesh cigaretteMesh;
private Material[] cigaretteMaterials;
private ConfigEntry<string> smokeColor;
private ConfigEntry<float> smokeSize;
private ConfigEntry<float> smokeLifetime;
private ConfigEntry<float> smokeRate;
private ConfigEntry<float> smokeRiseSpeed;
private GameObject smokeOwner;
private ParticleSystem smoke;
private Material smokeMaterial;
private Texture2D smokeTexture;
private bool emitting;
private Vector3 handPosition;
private Quaternion handRotation;
private Transform head;
private Transform mouth;
private Renderer headRenderer;
private float faceSign;
private bool towardMouth;
private float progress;
internal bool IsVisible
{
get
{
if ((Object)(object)prop != (Object)null)
{
return prop.activeInHierarchy;
}
return false;
}
}
internal bool IsTowardMouth => towardMouth;
internal void Toggle(ManualLogSource logger)
{
string source;
Transform val = SmokingModRightHandCheck.Find(logger, "F7", out source);
if ((Object)(object)val == (Object)null)
{
if ((Object)(object)prop != (Object)null && prop.activeSelf)
{
ResetSmoking(logger);
prop.SetActive(false);
logger.LogInfo((object)"F7: Test cigarette hidden because the right hand is unavailable.");
}
return;
}
if ((Object)(object)prop == (Object)null)
{
PrepareProp(val, Camera.main, logger);
return;
}
if ((Object)(object)prop.transform.parent != (Object)(object)val)
{
ResetSmoking(logger);
Attach(val, Camera.main);
}
if (prop.activeSelf)
{
ResetSmoking(logger);
}
prop.SetActive(!prop.activeSelf);
}
internal bool ShowRemote(Transform hand, ManualLogSource logger)
{
if ((Object)(object)prop == (Object)null && !PrepareProp(hand, null, logger))
{
return false;
}
prop.SetActive(true);
return true;
}
internal void Dispose()
{
DisposeSmoke();
Object.Destroy((Object)(object)prop);
Object.Destroy((Object)(object)cigaretteMesh);
if (cigaretteMaterials != null)
{
Material[] array = cigaretteMaterials;
for (int i = 0; i < array.Length; i++)
{
Object.Destroy((Object)(object)array[i]);
}
}
}
private bool PrepareProp(Transform hand, Camera camera, ManualLogSource logger)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
if (!LoadModel(logger))
{
return false;
}
prop = new GameObject("SmokingMod_Cigarette");
prop.SetActive(false);
prop.AddComponent<MeshFilter>().sharedMesh = cigaretteMesh;
((Renderer)prop.AddComponent<MeshRenderer>()).sharedMaterials = cigaretteMaterials;
Attach(hand, camera);
return true;
}
private bool LoadModel(ManualLogSource logger)
{
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Expected O, but got Unknown
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: Expected O, but got Unknown
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Invalid comparison between Unknown and I4
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
Shader val = Shader.Find("Universal Render Pipeline/Unlit");
if ((Object)(object)val == (Object)null || !val.isSupported)
{
val = Shader.Find("Universal Render Pipeline/Lit");
}
if ((Object)(object)val == (Object)null || !val.isSupported)
{
logger.LogWarning((object)"F7: URP material is unavailable.");
return false;
}
using (Stream stream = typeof(TestCigarette).Assembly.GetManifestResourceStream("SmokingMod.CigaretteMesh.bin"))
{
if (stream == null)
{
logger.LogWarning((object)"F7: Embedded cigarette model is missing.");
return false;
}
using BinaryReader binaryReader = new BinaryReader(stream);
Vector3[] array = (Vector3[])(object)new Vector3[binaryReader.ReadInt32()];
Material[] array2 = (Material[])(object)new Material[binaryReader.ReadInt32()];
for (int i = 0; i < array.Length; i++)
{
array[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
}
Mesh val2 = new Mesh
{
name = "SmokingMod_CigaretteMesh",
vertices = array
};
val2.subMeshCount = array2.Length;
Color val3 = default(Color);
for (int j = 0; j < array2.Length; j++)
{
((Color)(ref val3))..ctor(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
int[] array3 = new int[binaryReader.ReadInt32()];
for (int k = 0; k < array3.Length; k++)
{
array3[k] = binaryReader.ReadInt32();
}
val2.SetTriangles(array3, j, false);
Material val4 = new Material(val);
val4.SetColor("_BaseColor", ((int)QualitySettings.activeColorSpace == 1) ? val3 : ((Color)(ref val3)).gamma);
array2[j] = val4;
}
val2.RecalculateNormals();
val2.RecalculateBounds();
cigaretteMesh = val2;
cigaretteMaterials = array2;
}
logger.LogInfo((object)$"F7: Loaded cigarette model ({cigaretteMesh.vertexCount} vertices, {cigaretteMesh.subMeshCount} materials).");
return true;
}
private void Attach(Transform hand, Camera camera)
{
//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_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: 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_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: 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)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: 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)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: 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_00d9: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
Transform transform = prop.transform;
transform.SetParent(hand, false);
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(0.3f, 0f, 0.3f);
Vector3 val2 = new Vector3(0.25f, 1f, 0f);
Vector3 normalized = ((Vector3)(ref val2)).normalized;
if ((Object)(object)camera != (Object)null)
{
val2 = hand.InverseTransformDirection(((Component)camera).transform.up + 0.28f * ((Component)camera).transform.right);
normalized = ((Vector3)(ref val2)).normalized;
val += hand.InverseTransformVector(0.072f * ((Component)camera).transform.right);
}
if ((Object)(object)hand.parent != (Object)null)
{
val2 = hand.position - hand.parent.position;
Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
val += hand.InverseTransformVector(0.0725f * normalized2);
}
handPosition = val + normalized * 0.5076f;
transform.localPosition = handPosition;
handRotation = Quaternion.FromToRotation(Vector3.up, normalized);
transform.localRotation = handRotation;
transform.localScale = new Vector3(0.1575f, 0.705f, 0.1575f);
}
internal void BindSmoke(ConfigFile config)
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Expected O, but got Unknown
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Expected O, but got Unknown
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Expected O, but got Unknown
smokeColor = config.Bind<string>("Smoke", "Color", "#F5F5F580", "Smoke color as #RRGGBBAA.");
smokeSize = config.Bind<float>("Smoke", "StartSize", 0.035f, new ConfigDescription("Initial particle diameter in world units.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.005f, 0.3f), Array.Empty<object>()));
smokeLifetime = config.Bind<float>("Smoke", "Lifetime", 2.2f, new ConfigDescription("Particle lifetime in seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 8f), Array.Empty<object>()));
smokeRate = config.Bind<float>("Smoke", "Rate", 14f, new ConfigDescription("Particles per second (0 disables emission).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
smokeRiseSpeed = config.Bind<float>("Smoke", "RiseSpeed", 0.2f, new ConfigDescription("Upward speed in world units per second.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1.5f), Array.Empty<object>()));
}
internal void UpdateSmoke(ManualLogSource logger)
{
if ((Object)(object)prop == (Object)null || !prop.activeInHierarchy)
{
if (emitting)
{
if ((Object)(object)smoke != (Object)null)
{
smoke.Stop(true, (ParticleSystemStopBehavior)0);
}
emitting = false;
logger.LogInfo((object)"Smoke: stopped and cleared.");
}
return;
}
if ((Object)(object)smokeOwner != (Object)(object)prop)
{
smokeOwner = prop;
emitting = false;
smoke = CreateSmoke(logger);
}
if (!((Object)(object)smoke == (Object)null) && !emitting)
{
ApplySmokeSettings(logger);
smoke.Play();
emitting = true;
logger.LogInfo((object)$"Smoke: playing at the lit tip, rate={smokeRate.Value:F1}/s.");
}
}
private ParticleSystem CreateSmoke(ManualLogSource logger)
{
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Expected O, but got Unknown
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: 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_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_0254: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_0288: Unknown result type (might be due to invalid IL or missing references)
//IL_028f: Expected O, but got Unknown
//IL_0299: Unknown result type (might be due to invalid IL or missing references)
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
//IL_02be: Unknown result type (might be due to invalid IL or missing references)
//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
//IL_02da: Unknown result type (might be due to invalid IL or missing references)
//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
//IL_0301: Unknown result type (might be due to invalid IL or missing references)
//IL_0306: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: Unknown result type (might be due to invalid IL or missing references)
//IL_031c: Unknown result type (might be due to invalid IL or missing references)
//IL_0327: Unknown result type (might be due to invalid IL or missing references)
//IL_032c: Unknown result type (might be due to invalid IL or missing references)
//IL_033a: Unknown result type (might be due to invalid IL or missing references)
//IL_0379: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)smokeMaterial == (Object)null)
{
Shader val = Shader.Find("Universal Render Pipeline/Particles/Unlit");
if ((Object)(object)val == (Object)null || !val.isSupported)
{
logger.LogWarning((object)"Smoke: URP Particles/Unlit is unavailable; cigarette controls remain active.");
return null;
}
smokeTexture = CreateSmokeTexture();
smokeMaterial = new Material(val)
{
name = "SmokingMod_SmokeMaterial"
};
smokeMaterial.SetTexture("_BaseMap", (Texture)(object)smokeTexture);
smokeMaterial.SetColor("_BaseColor", Color.white);
smokeMaterial.SetFloat("_Surface", 1f);
smokeMaterial.SetFloat("_Blend", 0f);
smokeMaterial.SetFloat("_SrcBlend", 5f);
smokeMaterial.SetFloat("_DstBlend", 10f);
smokeMaterial.SetFloat("_SrcBlendAlpha", 1f);
smokeMaterial.SetFloat("_DstBlendAlpha", 10f);
smokeMaterial.SetFloat("_ZWrite", 0f);
smokeMaterial.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
smokeMaterial.DisableKeyword("_ALPHATEST_ON");
smokeMaterial.SetOverrideTag("RenderType", "Transparent");
smokeMaterial.renderQueue = 3000;
}
GameObject val2 = new GameObject("SmokingMod_LitTipSmoke");
val2.SetActive(false);
val2.layer = prop.layer;
val2.transform.SetParent(prop.transform, false);
Bounds bounds = cigaretteMesh.bounds;
val2.transform.localPosition = new Vector3(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).max.y, ((Bounds)(ref bounds)).center.z);
ParticleSystem val3 = val2.AddComponent<ParticleSystem>();
MainModule main = val3.main;
((MainModule)(ref main)).playOnAwake = false;
((MainModule)(ref main)).loop = true;
((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)1;
((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
((MainModule)(ref main)).startRotation = new MinMaxCurve(0f, MathF.PI * 2f);
((MainModule)(ref main)).maxParticles = 512;
ShapeModule shape = val3.shape;
((ShapeModule)(ref shape)).enabled = false;
SizeOverLifetimeModule sizeOverLifetime = val3.sizeOverLifetime;
((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, AnimationCurve.EaseInOut(0f, 1f, 1f, 3.2f));
Gradient val4 = new Gradient();
val4.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
{
new GradientColorKey(Color.white, 0f),
new GradientColorKey(Color.white, 1f)
}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
{
new GradientAlphaKey(0.4f, 0f),
new GradientAlphaKey(1f, 0.16f),
new GradientAlphaKey(0.5f, 0.52f),
new GradientAlphaKey(0f, 1f)
});
ColorOverLifetimeModule colorOverLifetime = val3.colorOverLifetime;
((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val4);
ParticleSystemRenderer component = val2.GetComponent<ParticleSystemRenderer>();
((Renderer)component).sharedMaterial = smokeMaterial;
component.renderMode = (ParticleSystemRenderMode)0;
((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)component).receiveShadows = false;
val2.SetActive(true);
logger.LogInfo((object)$"Smoke: emitter created at lit-tip local Y={((Bounds)(ref bounds)).max.y:F4}, shader={((Object)smokeMaterial.shader).name}.");
return val3;
}
private void ApplySmokeSettings(ManualLogSource logger)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: 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_011a: 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_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: 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)
Color val = default(Color);
if (!ColorUtility.TryParseHtmlString(smokeColor.Value, ref val))
{
val = Color32.op_Implicit(new Color32((byte)245, (byte)245, (byte)245, (byte)128));
logger.LogWarning((object)"Smoke: invalid color; using #F5F5F580.");
}
MainModule main = smoke.main;
((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(val);
((MainModule)(ref main)).startSize = new MinMaxCurve(smokeSize.Value * 0.75f, smokeSize.Value);
((MainModule)(ref main)).startLifetime = new MinMaxCurve(smokeLifetime.Value * 0.85f, smokeLifetime.Value);
EmissionModule emission = smoke.emission;
((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(smokeRate.Value);
VelocityOverLifetimeModule velocityOverLifetime = smoke.velocityOverLifetime;
((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)1;
((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(-0.025f, 0.025f);
((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(smokeRiseSpeed.Value * 0.8f, smokeRiseSpeed.Value);
((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = new MinMaxCurve(-0.025f, 0.025f);
}
private static Texture2D CreateSmokeTexture()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
{
name = "SmokingMod_SmokeSoftStamp",
wrapMode = (TextureWrapMode)1,
filterMode = (FilterMode)1
};
Color32[] array = (Color32[])(object)new Color32[4096];
for (int i = 0; i < 64; i++)
{
for (int j = 0; j < 64; j++)
{
float num = ((float)j + 0.5f) * 2f / 64f - 1f;
float num2 = ((float)i + 0.5f) * 2f / 64f - 1f;
float num3 = Mathf.Clamp01(1f - Mathf.Sqrt(num * num + num2 * num2));
array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(255f * Mathf.SmoothStep(0f, 1f, num3)));
}
}
val.SetPixels32(array);
val.Apply(false, true);
return val;
}
internal void DisposeSmoke()
{
if ((Object)(object)smoke != (Object)null)
{
Object.Destroy((Object)(object)((Component)smoke).gameObject);
}
if ((Object)(object)smokeMaterial != (Object)null)
{
Object.Destroy((Object)(object)smokeMaterial);
}
if ((Object)(object)smokeTexture != (Object)null)
{
Object.Destroy((Object)(object)smokeTexture);
}
}
internal void ToggleSmoking(Character player, ManualLogSource logger)
{
//IL_00ff: 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_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: 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)
if ((Object)(object)prop == (Object)null || !prop.activeInHierarchy)
{
logger.LogInfo((object)"F8: Cigarette is hidden; smoking unavailable.");
return;
}
if (!towardMouth && progress == 0f)
{
Transform parent = prop.transform.parent;
while ((Object)(object)parent != (Object)null)
{
if (!(((Object)parent).name != "Torso"))
{
head = parent.Find("Head");
break;
}
parent = parent.parent;
}
if ((Object)(object)head == (Object)null)
{
logger.LogWarning((object)"F8: Head not found near Hand_R.");
return;
}
mouth = head.Find("Face/Mouth Card");
Transform val = head.Find("HeadMesh");
headRenderer = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Renderer>() : null);
Vector3 val2 = (((Object)(object)player != (Object)null) ? ((Component)player).transform.forward : head.forward);
faceSign = ((Vector3.Dot(head.forward, val2) < 0f) ? (-1f) : 1f);
if ((Object)(object)mouth == (Object)null)
{
logger.LogWarning((object)"F8: Mouth Card not found; using Head with the configured offset.");
}
}
towardMouth = !towardMouth;
logger.LogInfo((object)(towardMouth ? "F8: Moving to the mouth." : "F8: Returning to the hand."));
}
internal void UpdateSmoking(Vector3 offset, float seconds, ManualLogSource logger)
{
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0215: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: 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_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: 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_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
//IL_01f0: 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_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_0232: Unknown result type (might be due to invalid IL or missing references)
//IL_0233: Unknown result type (might be due to invalid IL or missing references)
//IL_0238: Unknown result type (might be due to invalid IL or missing references)
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_0240: Unknown result type (might be due to invalid IL or missing references)
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_0252: Unknown result type (might be due to invalid IL or missing references)
//IL_0257: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_0260: Unknown result type (might be due to invalid IL or missing references)
//IL_0265: Unknown result type (might be due to invalid IL or missing references)
//IL_026a: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Unknown result type (might be due to invalid IL or missing references)
//IL_0272: Unknown result type (might be due to invalid IL or missing references)
//IL_0277: Unknown result type (might be due to invalid IL or missing references)
//IL_027c: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: 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_028e: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
//IL_02d9: 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_02e9: Unknown result type (might be due to invalid IL or missing references)
//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)prop == (Object)null || !prop.activeInHierarchy)
{
ResetSmoking(logger);
}
else
{
if (!towardMouth && progress == 0f)
{
return;
}
Transform transform = prop.transform;
Transform parent = transform.parent;
if ((Object)(object)head == (Object)null || (Object)(object)parent == (Object)null)
{
logger.LogWarning((object)"F8: Smoking target disappeared.");
ResetSmoking(logger);
return;
}
float num = progress;
float num2 = ((seconds >= 0.05f && !float.IsInfinity(seconds)) ? seconds : 0.45f);
progress = Mathf.MoveTowards(progress, towardMouth ? 1f : 0f, Time.deltaTime / num2);
Vector3 val = head.forward * faceSign;
Vector3 val2 = (((Object)(object)mouth != (Object)null) ? mouth.position : head.position) - head.TransformVector(new Vector3(0f, 0.4f, 0f));
if ((Object)(object)headRenderer != (Object)null)
{
Bounds localBounds = headRenderer.localBounds;
Transform transform2 = ((Component)headRenderer).transform;
float num3 = Vector3.Dot(transform2.TransformPoint(((Bounds)(ref localBounds)).center) - val2, val);
float num4 = Mathf.Abs(Vector3.Dot(transform2.TransformVector(Vector3.right * ((Bounds)(ref localBounds)).extents.x), val)) + Mathf.Abs(Vector3.Dot(transform2.TransformVector(Vector3.up * ((Bounds)(ref localBounds)).extents.y), val)) + Mathf.Abs(Vector3.Dot(transform2.TransformVector(Vector3.forward * ((Bounds)(ref localBounds)).extents.z), val));
val2 += val * Mathf.Max(0f, num3 + num4 + 0.012f);
}
else
{
val2 += val * 0.09f;
}
val2 += head.TransformVector(offset);
Vector3 val3 = val - head.up * 0.1f;
Vector3 val4 = parent.InverseTransformDirection(((Vector3)(ref val3)).normalized);
Quaternion val5 = Quaternion.FromToRotation(handRotation * Vector3.up, val4) * handRotation;
float num5 = Mathf.SmoothStep(0f, 1f, progress);
Vector3 val6 = parent.InverseTransformPoint(val2) + val5 * Vector3.up * transform.localScale.y;
transform.localPosition = Vector3.Lerp(handPosition, val6, num5);
transform.localRotation = Quaternion.Slerp(handRotation, val5, num5);
if (num < 1f && progress == 1f)
{
logger.LogInfo((object)"F8: Cigarette reached the mouth.");
}
else if (num > 0f && progress == 0f)
{
logger.LogInfo((object)"F8: Cigarette back in the hand.");
}
}
}
private void ResetSmoking(ManualLogSource logger)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
if (towardMouth || progress > 0f)
{
if ((Object)(object)prop != (Object)null)
{
prop.transform.localPosition = handPosition;
prop.transform.localRotation = handRotation;
}
logger.LogInfo((object)"Smoking canceled; cigarette reset to the hand.");
}
towardMouth = false;
progress = 0f;
head = (mouth = null);
headRenderer = null;
}
}