using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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 = "")]
[assembly: AssemblyCompany("EthicalCompany")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Making the Company more ethical.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EthicalCompany")]
[assembly: AssemblyTitle("EthicalCompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace EthicalCompany;
[BepInPlugin("TofuTofuMe.EthicalCompany", "EthicalCompany", "1.0.1")]
[BepInProcess("Lethal Company.exe")]
public class Plugin : BaseUnityPlugin
{
public const string ModGUID = "TofuTofuMe.EthicalCompany";
public const string ModName = "EthicalCompany";
public const string ModVersion = "1.0.1";
private readonly Harmony harmony = new Harmony("TofuTofuMe.EthicalCompany");
public static ManualLogSource mls;
public static ConfigEntry<bool> isCompanyEthical;
public static ConfigEntry<bool> supplyOnCompany;
public static ConfigEntry<int> freeWeaponChance;
public static ConfigEntry<int> freeCredits;
public static ConfigEntry<string> supplyEquipment;
public static ConfigEntry<string> supplyWeapons;
public static bool isPlayerHost;
public static bool freeSupplyClaimed;
private void Awake()
{
mls = Logger.CreateLogSource("TofuTofuMe.EthicalCompany");
mls.LogInfo((object)"Loading TofuTofuMe.EthicalCompany...");
SetConfig();
harmony.PatchAll(typeof(Plugin));
mls.LogInfo((object)"TofuTofuMe.EthicalCompany loaded.");
mls.LogInfo((object)"The company just became ethical!");
}
private void SetConfig()
{
isCompanyEthical = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "isCompanyEthical", true, "Is the company ethical? This toggles the mod.");
supplyOnCompany = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "supplyOnCompany", true, "Should free goods only be given on the Company moon.");
freeWeaponChance = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "freeWeaponChance", 10, "Percent chance for the Company to give out arms. Set to 0 to disable.");
freeCredits = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "freeCreditsAmount", 60, "Free credits given when arriving at the Company. Set to 0 to disable.");
supplyEquipment = ((BaseUnityPlugin)this).Config.Bind<string>("Supplies", "supplyEquipment", "0, 1", "IDs of equipment supplied by the Company.");
supplyWeapons = ((BaseUnityPlugin)this).Config.Bind<string>("Supplies", "supplyWeapons", "2", "IDs of weapons supplied by the Company.");
}
[HarmonyPatch(typeof(RoundManager), "Start")]
[HarmonyPostfix]
private static void CheckIfHost()
{
isPlayerHost = ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost;
mls.LogInfo((object)("Is the player host? " + (isPlayerHost ? "Yes" : "No")));
}
[HarmonyPatch(typeof(StartOfRound), "openingDoorsSequence")]
[HarmonyPostfix]
private static void SupplyGoods()
{
if (!isPlayerHost || !isCompanyEthical.Value)
{
return;
}
Terminal val = Object.FindObjectOfType<Terminal>();
ItemDropship val2 = Object.FindObjectOfType<ItemDropship>();
List<int> list = new List<int>();
List<string> list2 = new List<string>();
mls.LogInfo((object)"Ship is landing!");
if ((supplyOnCompany.Value && StartOfRound.Instance.currentLevelID == 3 && !freeSupplyClaimed) || !supplyOnCompany.Value)
{
list2.AddRange(supplyEquipment.Value.Split(','));
if (freeWeaponChance.Value > 0 && Random.Range(0, 100) < freeWeaponChance.Value)
{
list2.AddRange(supplyWeapons.Value.Split(','));
HUDManager.Instance.AddTextToChatOnServer("<color=white>The Company thanks your service with lights and firepower.</color>", -1);
}
else
{
HUDManager.Instance.AddTextToChatOnServer("<color=white>The Company thanks your service with equipment.</color>", -1);
}
for (int i = 0; i < StartOfRound.Instance.livingPlayers; i++)
{
list.Clear();
foreach (string item in list2)
{
list.Add(int.Parse(item.Trim()));
}
val.BuyItemsServerRpc(list.ToArray(), val.groupCredits, 0);
}
if (freeCredits.Value > 0)
{
val.groupCredits += freeCredits.Value;
val.SyncGroupCreditsServerRpc(val.groupCredits, val.numberOfItemsInDropship);
HUDManager.Instance.AddTextToChatOnServer($"<color=white>The Company deposited {freeCredits.Value} to your bank account.</color>", -1);
}
Traverse.Create((object)val2).Method("LandShipOnServer", Array.Empty<object>()).GetValue();
if (supplyOnCompany.Value)
{
freeSupplyClaimed = true;
}
}
else if (supplyOnCompany.Value && StartOfRound.Instance.currentLevelID != 3)
{
mls.LogInfo((object)"No free supplies on moons.");
freeSupplyClaimed = false;
}
}
}