Decompiled source of serek items v2.0.4

serek.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[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("serek")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("serek")]
[assembly: AssemblyTitle("serek")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 serekRafek
{
	[BepInPlugin("serekRafek.plugin", "serekRafek", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private struct ItemDefinition
		{
			public string ItemScriptName;

			public string PrefabName;

			public string DisplayName;

			public int Rarity;
		}

		private const string PLUGIN_GUID = "serekRafek.plugin";

		private const string PLUGIN_NAME = "serekRafek";

		private const string PLUGIN_VERSION = "1.0.0";

		private const string ASSET_BUNDLE_FILENAME = "serekScrap";

		public static Plugin instance;

		internal static ManualLogSource mls = Logger.CreateLogSource("serekRafek.plugin");

		private readonly ItemDefinition[] itemDefinitions = new ItemDefinition[17]
		{
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/SerekItem.asset",
				PrefabName = "assets/serek/serekscrap.prefab",
				DisplayName = "Sereček Ráfeček",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/MalboroItem.asset",
				PrefabName = "assets/serek/Malboro.prefab",
				DisplayName = "Cíčka",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/ZangetsuItem.asset",
				PrefabName = "assets/serek/Zangetsu.prefab",
				DisplayName = "Zangetsu",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/BongItem.asset",
				PrefabName = "assets/serek/Bong.prefab",
				DisplayName = "BONG",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/MoneyItem.asset",
				PrefabName = "assets/serek/Money.prefab",
				DisplayName = "Židovské peníz",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/MerakItem.asset",
				PrefabName = "assets/serek/Merak.prefab",
				DisplayName = "Měřák",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/TwingoItem.asset",
				PrefabName = "assets/serek/Twingo.prefab",
				DisplayName = "Twingo",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/SpagetyItem.asset",
				PrefabName = "assets/serek/Spagety.prefab",
				DisplayName = "Adam Špageťák",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/PhaetonItem.asset",
				PrefabName = "assets/serek/phaeton.prefab",
				DisplayName = "Phaeton",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/MeowlItem.asset",
				PrefabName = "assets/serek/meowl.prefab",
				DisplayName = "Meowl",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/PeugeotItem.asset",
				PrefabName = "assets/serek/Peugeot.prefab",
				DisplayName = "Pžot",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/T3.asset",
				PrefabName = "assets/serek/T3.prefab",
				DisplayName = "T3",
				Rarity = 90
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/SkodaItem.asset",
				PrefabName = "assets/serek/Skoda.prefab",
				DisplayName = "Škoda WRC",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/KafickoItem.asset",
				PrefabName = "assets/serek/kaficko.prefab",
				DisplayName = "Kafíčko",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/MrdnaItem.asset",
				PrefabName = "assets/serek/mrdna.prefab",
				DisplayName = "Mrdna S.R.O.",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/YarisItem.asset",
				PrefabName = "assets/serek/yaris.prefab",
				DisplayName = "Yaris",
				Rarity = 80
			},
			new ItemDefinition
			{
				ItemScriptName = "assets/serek/JobItem.asset",
				PrefabName = "assets/serek/Job.prefab",
				DisplayName = "Žádost o práci",
				Rarity = 80
			}
		};

		private void Awake()
		{
			instance = this;
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "serekScrap");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			if ((Object)(object)val == (Object)null)
			{
				mls.LogError((object)("[ERROR] Failed to load AssetBundle from path: " + text + ". Check that the file exists next to your DLL."));
				return;
			}
			mls.LogInfo((object)"AssetBundle loaded successfully.");
			ItemDefinition[] array = itemDefinitions;
			foreach (ItemDefinition definition in array)
			{
				RegisterCustomScrap(val, definition);
			}
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "serekRafek.plugin");
			mls.LogInfo((object)"!!!!!!ALL CUSTOM SCRAP LOADED AND REGISTERED!!!!!!!");
		}

		private void RegisterCustomScrap(AssetBundle bundle, ItemDefinition definition)
		{
			Item val = bundle.LoadAsset<Item>(definition.ItemScriptName);
			if ((Object)(object)val == (Object)null)
			{
				mls.LogError((object)("[ERROR] Failed to load Item ScriptableObject: " + definition.ItemScriptName + ". Skipping registration for this item."));
				return;
			}
			GameObject val2 = bundle.LoadAsset<GameObject>(definition.PrefabName);
			if ((Object)(object)val2 == (Object)null)
			{
				mls.LogError((object)("[ERROR] Failed to load GameObject Prefab: " + definition.PrefabName + ". Skipping registration for this item."));
				return;
			}
			val.spawnPrefab = val2;
			val.itemName = definition.DisplayName;
			val.isScrap = true;
			if ((Object)(object)val.spawnPrefab.GetComponent<GrabbableObject>() == (Object)null)
			{
				mls.LogError((object)("[ERROR] Prefab for '" + definition.DisplayName + "' is missing a GrabbableObject component. REQUIRED for scrap."));
				return;
			}
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, definition.Rarity, (LevelTypes)(-1));
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			mls.LogInfo((object)$"[SUCCESS] Registered item: {val.itemName} (Worth: {val.minValue} - {val.maxValue}, Rarity: {definition.Rarity})");
		}
	}
	public class SmokeableJoint : GrabbableObject
	{
		[Header("Joint Settings")]
		public int puffsRemaining = 1000;

		public float cooldownTime = 2.5f;

		[Header("Effects")]
		public GameObject smokeParticlePrefab;

		public AudioClip inhaleSFX;

		public AudioClip exhaleSFX;

		private float currentCooldown = 0f;

		private AudioSource audioSource;

		private Coroutine smokeCoroutine;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			audioSource = ((Component)this).GetComponent<AudioSource>();
			if ((Object)(object)audioSource == (Object)null)
			{
				Debug.LogError((object)"SmokeableJoint: No AudioSource found on this object!");
			}
			puffsRemaining = Random.Range(3, 6);
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if (currentCooldown > 0f)
			{
				currentCooldown -= Time.deltaTime;
			}
			if (base.isPocketed && (Object)(object)base.playerHeldBy != (Object)null)
			{
				if (base.playerHeldBy.activatingItem)
				{
					base.playerHeldBy.activatingItem = false;
				}
				base.playerHeldBy.playerBodyAnimator.SetBool("HoldMask", false);
			}
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && !(currentCooldown > 0f) && puffsRemaining > 0 && !((Object)(object)base.playerHeldBy == (Object)null) && !base.isPocketed)
			{
				if (smokeCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(smokeCoroutine);
				}
				smokeCoroutine = ((MonoBehaviour)this).StartCoroutine(SmokeRoutine());
				SmokeServerRpc();
			}
		}

		public override void PocketItem()
		{
			StopSmoking();
			((GrabbableObject)this).PocketItem();
		}

		public override void DiscardItem()
		{
			StopSmoking();
			((GrabbableObject)this).DiscardItem();
		}

		private void StopSmoking()
		{
			if (smokeCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(smokeCoroutine);
				smokeCoroutine = null;
			}
			if ((Object)(object)base.playerHeldBy != (Object)null)
			{
				base.playerHeldBy.playerBodyAnimator.SetBool("HoldMask", false);
				base.playerHeldBy.activatingItem = false;
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void SmokeServerRpc()
		{
			SmokeClientRpc();
		}

		[ClientRpc]
		public void SmokeClientRpc()
		{
			if ((Object)(object)base.playerHeldBy != (Object)null && !((NetworkBehaviour)base.playerHeldBy).IsOwner)
			{
				if (smokeCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(smokeCoroutine);
				}
				smokeCoroutine = ((MonoBehaviour)this).StartCoroutine(SmokeRoutine());
			}
		}

		private IEnumerator SmokeRoutine()
		{
			currentCooldown = cooldownTime;
			if ((Object)(object)base.playerHeldBy != (Object)null)
			{
				base.playerHeldBy.activatingItem = true;
				base.playerHeldBy.playerBodyAnimator.SetBool("HoldMask", true);
			}
			if ((Object)(object)inhaleSFX != (Object)null && (Object)(object)audioSource != (Object)null)
			{
				audioSource.PlayOneShot(inhaleSFX);
			}
			float timer = 0f;
			while (timer < 1.2f)
			{
				timer += Time.deltaTime;
				if (base.isPocketed || !base.isHeld || (Object)(object)base.playerHeldBy == (Object)null)
				{
					StopSmoking();
					yield break;
				}
				yield return null;
			}
			if ((Object)(object)base.playerHeldBy != (Object)null)
			{
				base.playerHeldBy.playerBodyAnimator.SetBool("HoldMask", false);
				base.playerHeldBy.activatingItem = false;
			}
			if ((Object)(object)exhaleSFX != (Object)null && (Object)(object)audioSource != (Object)null)
			{
				audioSource.PlayOneShot(exhaleSFX);
			}
			if ((Object)(object)smokeParticlePrefab != (Object)null)
			{
				Vector3 spawnPosition = ((!((Object)(object)base.playerHeldBy != (Object)null) || !((NetworkBehaviour)base.playerHeldBy).IsOwner || !((Object)(object)base.playerHeldBy.gameplayCamera != (Object)null)) ? (((Component)this).transform.position + ((Component)this).transform.up * 0.15f) : (((Component)base.playerHeldBy.gameplayCamera).transform.position + ((Component)base.playerHeldBy.gameplayCamera).transform.forward * 0.5f + ((Component)base.playerHeldBy.gameplayCamera).transform.up * -0.2f));
				GameObject smoke = Object.Instantiate<GameObject>(smokeParticlePrefab, spawnPosition, Quaternion.identity);
				Object.Destroy((Object)(object)smoke, 5f);
			}
			if ((Object)(object)base.playerHeldBy != (Object)null && ((NetworkBehaviour)base.playerHeldBy).IsOwner)
			{
				float currentDrunk = base.playerHeldBy.drunkness;
				base.playerHeldBy.drunkness = Mathf.Clamp(currentDrunk + 0.2f, 0f, 5f);
				if (base.playerHeldBy.insanityLevel > 0f)
				{
					base.playerHeldBy.insanityLevel = Mathf.Max(base.playerHeldBy.insanityLevel - 15f, 0f);
				}
				puffsRemaining--;
			}
		}
	}
}