using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
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: AssemblyTitle("CodeJoel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CodeJoel")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7aa97a4d-4e08-4463-a9a2-41165b354691")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CodeJoel;
[BepInPlugin("Kyxino.LethalJoel", "CodeJoel", "0.2.0")]
public class Joel : BaseUnityPlugin
{
public const bool DEBUGGINGMODE = false;
private const string ModGUID = "Kyxino.LethalJoel";
private const string ModName = "CodeJoel";
private const string ModVersion = "0.2.0";
private const string ModWebsite = "https://discord.gg/rzQcgRDQw3";
private const string ModDescription = "Man, I'm dead. Use Code Joel. Enjoy ragdolled seizuring Joels. (Can't scan rn.)";
private string[] Dependencies = new string[1] { "BepInEx-BepInExPack-5.4.2100" };
public static ConfigFile JoelConfig = new ConfigFile(Paths.ConfigPath + "\\JoelSettings.cfg", true);
private readonly Harmony harmony = new Harmony("Kyxino.LethalJoel");
public static ManualLogSource MLS;
public static Item JoelItem;
private void Awake()
{
//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
//IL_0424: Unknown result type (might be due to invalid IL or missing references)
//IL_042e: Expected O, but got Unknown
MLS = Logger.CreateLogSource("Kyxino.LethalJoel");
bool flag = false;
if (Directory.Exists(Paths.PluginPath + "\\kyxino-CodeJoel\\config"))
{
Directory.Delete(Paths.PluginPath + "\\kyxino-CodeJoel\\config", recursive: true);
}
if (!JoelConfig.Bind<bool>("Active Settings", "ConfigEnabled", true, "Whether or not the mod runs.").Value)
{
return;
}
MLS.LogInfo((object)"Loading Joel.");
Stopwatch stopwatch = new Stopwatch();
AssetBundle val = null;
try
{
stopwatch.Start();
val = AssetBundle.LoadFromMemory(Resource1.CodeJoel);
stopwatch.Stop();
}
catch (Exception ex)
{
MLS.LogError((object)ex);
}
if ((Object)(object)val == (Object)null)
{
MLS.LogWarning((object)"Joel could not load... NOOOOOOOOOOOOOOOOOOOOOO!!!!!!!!");
return;
}
AudioClip val2 = val.LoadAsset<AudioClip>("Assets/CodeJoel/bad-to-the-bone.mp3");
GameObject val3 = val.LoadAsset<GameObject>("Assets/CodeJoel/JoelRagdoll.prefab");
AudioSource val4 = val3.AddComponent<AudioSource>();
JoelItem = ScriptableObject.CreateInstance<Item>();
if (JoelConfig.Bind<bool>("Joel Settings", "DropSFX", true, "Man, I'm dead.").Value)
{
JoelItem.dropSFX = val2;
}
if (JoelConfig.Bind<bool>("Joel Settings", "GrabSFX", false, "Man, I'm dead.").Value)
{
JoelItem.grabSFX = val2;
}
JoelItem.spawnPrefab = val3;
JoelItem.requiresBattery = false;
JoelItem.isScrap = true;
JoelItem.itemName = "Joel";
JoelItem.minValue = JoelConfig.Bind<int>("Joel Settings", "MinValue", 150, "The game naturally has a multiplier of 0.4x, which means the default 150 is actually 60.").Value;
JoelItem.maxValue = JoelConfig.Bind<int>("Joel Settings", "MaxValue", 200, "The game naturally has a multiplier of 0.4x, which means the default 200 is actually 80.").Value;
JoelItem.allowDroppingAheadOfPlayer = true;
((Object)JoelItem).name = "JoelItem";
JoelItem.canBeInspected = true;
JoelItem.itemSpawnsOnGround = true;
JoelItem.meshVariants = (Mesh[])(object)new Mesh[0];
JoelItem.materialVariants = (Material[])(object)new Material[0];
JoelItem.weight = JoelConfig.Bind<float>("Joel Settings", "Weight", 1.5f, (ConfigDescription)null).Value;
JoelItem.grabAnim = "HoldLung";
JoelItem.useAnim = "";
JoelItem.pocketAnim = "";
JoelItem.throwAnim = "";
JoelItem.toolTips = new string[1] { "Man, I'm dead." };
JoelItem.restingRotation = Vector3.zero;
JoelItem.isConductiveMetal = JoelConfig.Bind<bool>("Joel Settings", "AttractsLightning", true, "Joel says F### YOU.").Value;
JoelItem.twoHanded = JoelConfig.Bind<bool>("Joel Settings", "TwoHanded", true, (ConfigDescription)null).Value;
JoelItem.twoHandedAnimation = JoelItem.twoHanded;
JoelItem.syncGrabFunction = false;
JoelItem.syncUseFunction = false;
JoelItem.syncDiscardFunction = false;
JoelItem.syncInteractLRFunction = false;
JoelItem.itemId = 0;
GameObject gameObject = ((Component)val3.transform.Find("JoelBody/ScanNode")).gameObject;
if ((Object)(object)gameObject.GetComponent<ScanNodeProperties>() == (Object)null)
{
ScanNodeProperties val5 = gameObject.AddComponent<ScanNodeProperties>();
val5.headerText = "Joel";
val5.minRange = JoelConfig.Bind<int>("Joel Settings", "ScanMinRange", 1, (ConfigDescription)null).Value;
val5.maxRange = JoelConfig.Bind<int>("Joel Settings", "ScanMaxRange", 15, (ConfigDescription)null).Value;
val5.nodeType = 2;
val5.requiresLineOfSight = false;
}
if ((Object)(object)val3.GetComponent<PhysicsProp>() == (Object)null)
{
PhysicsProp val6 = val3.AddComponent<PhysicsProp>();
((GrabbableObject)val6).insertedBattery = new Battery(false, 0f);
((GrabbableObject)val6).itemProperties = JoelItem;
((GrabbableObject)val6).grabbable = true;
((GrabbableObject)val6).propBody = val3.GetComponent<Rigidbody>();
((GrabbableObject)val6).propColliders = (Collider[])(object)new Collider[2]
{
(Collider)((Component)val3.transform.Find("Joel/spine")).GetComponent<BoxCollider>(),
(Collider)gameObject.GetComponent<BoxCollider>()
};
}
MLS.LogInfo((object)"Loaded Joel.");
harmony.PatchAll(typeof(SpawnJoel));
}
}
internal class SpawnJoel
{
[HarmonyPatch(typeof(GameNetworkManager), "Start")]
[HarmonyPostfix]
public static void GNM_Start(GameNetworkManager __instance)
{
((Component)__instance).GetComponent<NetworkManager>().AddNetworkPrefab(Joel.JoelItem.spawnPrefab);
}
[HarmonyPatch(typeof(StartOfRound), "Awake")]
[HarmonyPostfix]
public static void SOR_Awake(StartOfRound __instance)
{
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: 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_0128: Expected O, but got Unknown
Joel.JoelItem.itemIcon = (from x in Resources.FindObjectsOfTypeAll<Sprite>()
where ((Object)x).name == "ScrapItemIcon2"
select x).First();
if (!__instance.allItemsList.itemsList.Contains(Joel.JoelItem))
{
__instance.allItemsList.itemsList.Add(Joel.JoelItem);
}
SelectableLevel[] levels = __instance.levels;
foreach (SelectableLevel val in levels)
{
if (!(val.PlanetName == "") && val.spawnEnemiesAndScrap && !val.spawnableScrap.Any((SpawnableItemWithRarity x) => (Object)(object)x.spawnableItem == (Object)(object)Joel.JoelItem))
{
val.spawnableScrap.Add(new SpawnableItemWithRarity
{
spawnableItem = Joel.JoelItem,
rarity = Joel.JoelConfig.Bind<int>("Planet " + val.PlanetName, "JoelSpawnWeight", 30, "Typically a value from 0 to 100, it determines how much more likely Joel will spawn compared to other scrap.").Value
});
}
}
}
[HarmonyPatch(typeof(GrabbableObject), "Update")]
[HarmonyPrefix]
public static void Update(GrabbableObject __instance)
{
if (!(__instance.itemProperties.itemName != "Joel"))
{
}
}
[HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> AllowGrabbingComplexScrap(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Callvirt && (MethodInfo)list[i].operand == AccessTools.Method(typeof(GameObject), "GetComponent", (Type[])null, new Type[1] { typeof(GrabbableObject) }))
{
list[i].operand = AccessTools.Method(typeof(GameObject), "GetComponentInParent", (Type[])null, new Type[1] { typeof(GrabbableObject) });
break;
}
}
return list.AsEnumerable();
}
}
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resource1
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
ResourceManager resourceManager = new ResourceManager("CodeJoel.Resource1", typeof(Resource1).Assembly);
resourceMan = resourceManager;
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal static byte[] CodeJoel
{
get
{
object @object = ResourceManager.GetObject("CodeJoel", resourceCulture);
return (byte[])@object;
}
}
internal static string JoelAssetBundle => ResourceManager.GetString("JoelAssetBundle", resourceCulture);
internal Resource1()
{
}
}