Decompiled source of Balkan Company v1.0.0

Drunk Company.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Drunk_Company.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Drunk Company")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Drunk Company")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ebec061f-f0fb-4f23-a59b-a822b541d5c6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Drunk_Company
{
	[BepInPlugin("zakater.Drunk_Company", "Drunk Company", "1.0.0")]
	public class MainClass : BaseUnityPlugin
	{
		private const string modGUID = "zakater.Drunk_Company";

		private const string modName = "Drunk Company";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("zakater.Drunk_Company");

		private static MainClass Instance;

		internal ManualLogSource mls;

		public static List<Texture2D> painting_textures = new List<Texture2D>();

		internal static List<Texture2D> poster_textures = new List<Texture2D>();

		internal static List<Texture2D> nametag_textures = new List<Texture2D>();

		internal static List<AudioClip> SoundEffects = new List<AudioClip>();

		internal static List<AudioClip> Baboon_SoundEffects = new List<AudioClip>();

		internal static AssetBundle bundle;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("zakater.Drunk_Company");
			mls.LogInfo((object)"Drunk company be running!");
			harmony.PatchAll(typeof(MainClass));
			harmony.PatchAll(typeof(StartOfRound));
			harmony.PatchAll(typeof(BaboonBirdAI));
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "drunk_company");
			bundle = AssetBundle.LoadFromFile(text);
			Item val = bundle.LoadAsset<Item>("Assets/LaskoBeer.asset");
			Utilities.FixMixerGroups(val.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterScrap(val, 100, (LevelTypes)(-1));
			Item val2 = bundle.LoadAsset<Item>("Assets/UnionBeer.asset");
			Utilities.FixMixerGroups(val2.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
			Items.RegisterScrap(val2, 100, (LevelTypes)(-1));
			Item val3 = bundle.LoadAsset<Item>("Assets/PittingerBeer.asset");
			Utilities.FixMixerGroups(val3.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val3.spawnPrefab);
			Items.RegisterScrap(val3, 100, (LevelTypes)(-1));
			Texture2D[] collection = (Texture2D[])(object)new Texture2D[4]
			{
				bundle.LoadAsset<Texture2D>("Assets/PaintingTextures/PaintingTextureA.png"),
				bundle.LoadAsset<Texture2D>("Assets/PaintingTextures/PaintingTextureB.png"),
				bundle.LoadAsset<Texture2D>("Assets/PaintingTextures/PaintingTextureC.png"),
				bundle.LoadAsset<Texture2D>("Assets/PaintingTextures/PaintingTextureD.png")
			};
			painting_textures.AddRange(collection);
			TexturesPatch.Init(mls, painting_textures);
			Texture2D[] collection2 = (Texture2D[])(object)new Texture2D[2]
			{
				bundle.LoadAsset<Texture2D>("Assets/PosterTextures/TipsPoster2.png"),
				bundle.LoadAsset<Texture2D>("Assets/PosterTextures/posters.png")
			};
			poster_textures.AddRange(collection2);
			AudioClip[] collection3 = (AudioClip[])(object)new AudioClip[9]
			{
				bundle.LoadAsset<AudioClip>("Assets/Audio/KlincKlanc.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/DajPicke.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/smeskajmo se.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/smeskajmo se uzleba.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/smeskajmo se cough cough.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/jedi leba domaci mrane.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/jedi domaci mranauu.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/smej se hahaha.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Sateliti-Audi.mp3")
			};
			SoundEffects.AddRange(collection3);
			AudioClip[] collection4 = (AudioClip[])(object)new AudioClip[7]
			{
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/a mas 20eur.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/alo alo.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/kaj gledas.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/najdl te bomo.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/oojjj.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/sipsu matr.mp3"),
				bundle.LoadAsset<AudioClip>("Assets/Audio/Baboon/ti se sam mirki sam mirki se.mp3")
			};
			Baboon_SoundEffects.AddRange(collection4);
			Texture2D[] collection5 = (Texture2D[])(object)new Texture2D[1] { bundle.LoadAsset<Texture2D>("Assets/NametagTextures/") };
			nametag_textures.AddRange(collection5);
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "zakater.Drunk_Company");
		}
	}
}
namespace Drunk_Company.Patches
{
	[HarmonyPatch(typeof(BaboonBirdAI))]
	internal class BaboonBirdAIPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void OverrideAudio(BaboonBirdAI __instance)
		{
			for (int i = 0; i < __instance.cawLaughSFX.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)MainClass.Baboon_SoundEffects[i]))
				{
					__instance.cawLaughSFX[i] = MainClass.Baboon_SoundEffects[i];
				}
			}
			for (int j = 0; j < __instance.cawScreamSFX.Length; j++)
			{
				if (Object.op_Implicit((Object)(object)MainClass.Baboon_SoundEffects[j]))
				{
					__instance.cawScreamSFX[j] = MainClass.Baboon_SoundEffects[j];
				}
			}
		}

		private static void OverrideAudio2(BaboonHawkAudioEvents __instance)
		{
			for (int i = 0; i < __instance.randomClips.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)MainClass.Baboon_SoundEffects[i]))
				{
					__instance.randomClips[i] = MainClass.Baboon_SoundEffects[i];
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "ShowNameBillboard")]
	internal class BillboardPatch
	{
		private static void Postfix(PlayerControllerB __instance)
		{
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void OverrideAudio(StartOfRound __instance)
		{
			__instance.shipIntroSpeechSFX = MainClass.SoundEffects[0];
		}
	}
	[HarmonyPatch(typeof(TexturesPatch))]
	internal class TexturesPatch
	{
		private static ManualLogSource Logger { get; set; }

		public static List<Texture2D> PaintingTextures { get; set; }

		public static void Init(ManualLogSource logger, List<Texture2D> painting_textures)
		{
			Logger = logger;
			PaintingTextures = painting_textures;
		}

		[HarmonyPatch(typeof(GrabbableObject), "SetScrapValue")]
		[HarmonyPostfix]
		private static void OverrideTextures(GrabbableObject __instance)
		{
			if (__instance.itemProperties.itemName == "Painting")
			{
				if (PaintingTextures.Count > 0)
				{
					Random random = new Random();
					int index = random.Next(PaintingTextures.Count);
					Texture2D texture = PaintingTextures[index];
					UpdateTexture(texture, __instance.itemProperties.materialVariants[0]);
					UpdateTexture(texture, __instance.itemProperties.materialVariants[1]);
				}
				else
				{
					Debug.LogWarning((object)"No textures available in the painting_textures list.");
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void StartPatch()
		{
			Logger.LogInfo((object)"Patching Start in StartOfRound");
			UpdateMaterials(0);
		}

		[HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")]
		[HarmonyPostfix]
		private static void GenerateNewLevelClientRpcPatch(int randomSeed)
		{
			Logger.LogInfo((object)"Patching GenerateNewLevelClientRpc in RoundManager");
			UpdateMaterials(randomSeed);
		}

		private static void UpdateMaterials(int seed)
		{
			Logger.LogInfo((object)"Patching the textures");
			Material[] materials = ((Renderer)GameObject.Find("HangarShip/Plane.001").GetComponent<MeshRenderer>()).materials;
			UpdateTexture(MainClass.poster_textures[1], materials[0]);
			UpdateTexture(MainClass.poster_textures[0], materials[1]);
		}

		private static void UpdateTexture(Texture2D texture, Material material)
		{
			if ((Object)(object)texture != (Object)null)
			{
				Logger.LogInfo((object)("Applying specific texture to " + ((Object)material).name));
				material.mainTexture = (Texture)(object)texture;
			}
			else
			{
				Logger.LogError((object)"Texture is null, cannot apply to material.");
			}
		}
	}
}