using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Bowmaggedon;
[BepInPlugin("johbenji.Bowmaggedon", "Bowmaggedon", "0.7.0")]
public class BowmaggedonPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(Projectile), "OnProjectileHit")]
public class BowDistancePatch
{
private static void Prefix(Projectile __instance, Character _affectedCharacter, Vector3 _hitPos, Vector3 _hitDir, bool _blocked)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)__instance != (Object)null)
{
Character ownerCharacter = ((EffectSynchronizer)__instance).OwnerCharacter;
if (!((Object)(object)ownerCharacter != (Object)null) || !ownerCharacter.IsLocalPlayer)
{
return;
}
Instance.activeCharacter = ownerCharacter;
float projectileDistance = Instance.getProjectileDistance(ownerCharacter, _hitPos);
if (!((Object)(object)_affectedCharacter != (Object)null) || !((Object)(object)_affectedCharacter != (Object)null))
{
return;
}
Transform transform = ((Component)_affectedCharacter).transform;
if (!((Object)(object)transform != (Object)null))
{
return;
}
CharacterAI component = ((Component)transform).GetComponent<CharacterAI>();
if ((Object)(object)component != (Object)null)
{
AIState currentAiState = component.CurrentAiState;
if ((Object)(object)currentAiState != (Object)null)
{
Instance.AIStateName = ((Object)currentAiState).name;
}
}
}
else
{
Log.LogError((object)"Projectile instance is null");
}
}
}
[HarmonyPatch(typeof(ProjectileWeapon), "HasHit")]
public class BowDamagePatch
{
private static void Prefix(ProjectileWeapon __instance, Character _hitCharacter, Vector3 _hitPos, Vector3 _dir, bool _blocked)
{
if ((Object)(object)__instance != (Object)null && (Object)(object)Instance.activeCharacter != (Object)null)
{
Instance.tweakWeapon = __instance;
Instance.blocked = _blocked;
}
}
}
[HarmonyPatch(typeof(ProjectileItem), "OnExplodeDone")]
public class BowLocationHitPatch
{
private static void Prefix(ProjectileItem __instance, object[] _infos)
{
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Invalid comparison between Unknown and I4
//IL_00e9: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: 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_0150: 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_038e: Unknown result type (might be due to invalid IL or missing references)
//IL_0390: Unknown result type (might be due to invalid IL or missing references)
//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0521: Unknown result type (might be due to invalid IL or missing references)
//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
//IL_0465: Unknown result type (might be due to invalid IL or missing references)
//IL_0467: Unknown result type (might be due to invalid IL or missing references)
//IL_05e3: Unknown result type (might be due to invalid IL or missing references)
if (_infos != null)
{
if (_infos.Length >= 4)
{
if (_infos[0] != null && _infos[1] != null && _infos[2] != null && _infos[3] != null)
{
if (_infos[0].GetType() == typeof(Character) && _infos[1].GetType() == typeof(Vector3) && _infos[2].GetType() == typeof(Vector3) && _infos[3].GetType() == typeof(bool))
{
object obj = _infos[0];
Character val = (Character)((obj is Character) ? obj : null);
Vector3 val2 = (Vector3)_infos[1];
Vector3 direction = (Vector3)_infos[2];
if (!(bool)_infos[3] || (int)__instance.CollisionBehavior != 1)
{
return;
}
Vector3 val3 = val2;
if (!Object.op_Implicit((Object)(object)val))
{
return;
}
RaycastHit val4 = default(RaycastHit);
if (Physics.Raycast(val3, ((Component)__instance.m_projectile).transform.forward, ref val4, 0.5f, LayerMask.GetMask(new string[1] { "RangedHitbox" })) && (Object)(object)UnityEngineExtensions.GetCharacterOwner(((RaycastHit)(ref val4)).collider) == (Object)(object)val)
{
val3 = ((RaycastHit)(ref val4)).point;
}
Collider closestRagdollCollider = val.GetClosestRagdollCollider(val3);
if (!((Object)(object)closestRagdollCollider != (Object)null) || !((Object)(object)((Component)closestRagdollCollider).transform != (Object)null))
{
return;
}
Transform transform = ((Component)closestRagdollCollider).transform;
GameObject gameObject = ((Component)val).gameObject;
if ((Object)(object)gameObject != (Object)null)
{
CharacterAI component = gameObject.GetComponent<CharacterAI>();
if (!((Object)(object)component != (Object)null))
{
return;
}
AIState currentAiState = component.CurrentAiState;
if (!((Object)(object)currentAiState != (Object)null))
{
return;
}
bodyPart bodyPart2 = Instance.getBodyPart(((Object)transform).name);
Character activeCharacter = Instance.activeCharacter;
if (!((Object)(object)activeCharacter != (Object)null))
{
return;
}
ProjectileWeapon tweakWeapon = Instance.tweakWeapon;
if (!((Object)(object)tweakWeapon != (Object)null))
{
return;
}
float num = 1f;
bool flag = false;
bool flag2 = false;
if ((Object)(object)component.CurrentAiState != (Object)null)
{
string aIStateName = Instance.AIStateName;
if (UnityEngineExtensions.Contains(aIStateName, "wander", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(aIStateName, "hiding", StringComparison.OrdinalIgnoreCase))
{
num *= ConfigElements.stealthDamageMultiplier.Value;
flag = true;
}
else if (UnityEngineExtensions.Contains(aIStateName, "suspicious", StringComparison.OrdinalIgnoreCase))
{
num *= 1f + (ConfigElements.stealthDamageMultiplier.Value - 1f) / 2f;
flag = true;
}
else if (UnityEngineExtensions.Contains(aIStateName, "alert", StringComparison.OrdinalIgnoreCase))
{
num *= 1f + (ConfigElements.stealthDamageMultiplier.Value - 1f) / 3f;
flag = true;
}
}
Ammunition arrow = null;
if ((Object)(object)__instance != (Object)null && (Object)(object)__instance.m_item != (Object)null && __instance.m_item is Ammunition)
{
Item item = __instance.m_item;
arrow = (Ammunition)(object)((item is Ammunition) ? item : null);
}
switch (bodyPart2)
{
case bodyPart.Head:
num *= ConfigElements.headshotDamageMultiplier.Value;
flag2 = true;
applyWeaponDamage((Weapon)(object)tweakWeapon, arrow, val, num, ConfigElements.headshotImpactMultiplier.Value, val2, direction);
break;
case bodyPart.Arm:
{
StatusEffectManager statusEffectMngr = val.StatusEffectMngr;
if ((Object)(object)statusEffectMngr != (Object)null)
{
statusEffectMngr.AddStatusEffectBuildUp("Weaken", ConfigElements.weakenMultiple.Value, activeCharacter);
}
if (num > 1f)
{
applyWeaponDamage((Weapon)(object)tweakWeapon, arrow, val, num, 1f, val2, direction);
}
break;
}
case bodyPart.Leg:
{
StatusEffectManager statusEffectMngr2 = val.StatusEffectMngr;
if ((Object)(object)statusEffectMngr2 != (Object)null)
{
statusEffectMngr2.AddStatusEffectBuildUp("Slow Down", ConfigElements.slowdownBuildup.Value, activeCharacter);
}
if (num > 1f)
{
applyWeaponDamage((Weapon)(object)tweakWeapon, arrow, val, num, 1f, val2, direction);
}
break;
}
default:
if (!Instance.blocked && num > 1f)
{
applyWeaponDamage((Weapon)(object)tweakWeapon, arrow, val, num, 1f, val2, direction);
}
break;
}
if (flag)
{
List<Sounds> list = new List<Sounds>();
list.Add((Sounds)51589);
list.Add((Sounds)51590);
list.Add((Sounds)51591);
list = list.OrderBy((Sounds x) => Random.value).ToList();
Global.AudioManager.PlaySoundAtPosition(list[0], ((Component)activeCharacter).transform, 0.2f, 0.5f, 0.5f, 1f, 1f);
}
if (flag2)
{
List<Sounds> list2 = new List<Sounds>();
list2.Add((Sounds)10053);
list2.Add((Sounds)10054);
list2.Add((Sounds)10055);
list2.Add((Sounds)10056);
list2.Add((Sounds)10057);
list2.Add((Sounds)10058);
list2 = list2.OrderBy((Sounds x) => Random.value).ToList();
Global.AudioManager.PlaySoundAtPosition(list2[0], ((Component)activeCharacter).transform, 0.2f, 1f, 1f, 1f, 1f);
}
}
else
{
Log.LogError((object)"Character GameObject is null");
}
}
else
{
Log.LogError((object)"_infos array contains unexpected types");
}
}
else
{
Log.LogError((object)"_infos array contains null elements at some index");
}
}
else
{
Log.LogError((object)"_infos array does not have enough elements. Expected at least 4.");
}
}
else
{
Log.LogError((object)"_infos array is null or has an unexpected length.");
}
}
private static void applyWeaponDamage(Weapon weapon, Ammunition arrow, Character targetCharacter, float damageMultiplier, float impactMultiplier, Vector3 startPosition, Vector3 direction)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
//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_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Expected O, but got Unknown
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
float num = Math.Max(0f, damageMultiplier - 1f);
Log.LogMessage((object)"Apply Weapon Damage Call...");
PunctualDamage val = new PunctualDamage();
float num2 = 0f;
if ((Object)(object)weapon != (Object)null)
{
num2 += weapon.Impact;
}
if ((Object)(object)arrow != (Object)null)
{
num2 += ((Weapon)arrow).Impact;
}
val.Knockback = (impactMultiplier - 1f) * num2;
val.HitInventory = false;
val.IgnoreHalfResistances = false;
List<Types> list = new List<Types>();
list.Add((Types)0);
list.Add((Types)1);
list.Add((Types)3);
list.Add((Types)2);
list.Add((Types)4);
list.Add((Types)5);
list.Add((Types)8);
List<DamageType> list2 = new List<DamageType>();
CharacterStats stats = targetCharacter.Stats;
DamageType val2 = default(DamageType);
DamageType val3 = default(DamageType);
foreach (Types item in list)
{
float num3 = 0f;
if ((Object)(object)arrow != (Object)null && ((Weapon)arrow).Damage.TryGet(item, ref val2))
{
num3 += val2.Damage;
}
if (weapon.Damage.TryGet(item, ref val3))
{
num3 += val3.Damage;
}
if (num3 > 0f)
{
Log.LogMessage((object)$"Damage (in type {item}) before damage penetration: {num3}");
}
DamageType val4 = new DamageType();
val4.Damage = num3 * num;
val4.Type = item;
list2.Add(val4);
}
val.Damages = list2.ToArray();
object[] array = new object[2] { startPosition, direction };
((Effect)val).ActivateLocally(targetCharacter, array);
}
}
public const string GUID = "johbenji.Bowmaggedon";
public const string NAME = "Bowmaggedon";
public const string VERSION = "0.7.0";
internal static ManualLogSource Log;
public bool tweakGetDamage { get; set; }
public bool tweakGetKnockback { get; set; }
public Character activeCharacter { get; set; }
public ProjectileWeapon tweakWeapon { get; set; }
public Ammunition tweakAmmunition { get; set; }
public bool blocked { get; set; } = false;
public string AIStateName { get; set; }
public static BowmaggedonPlugin Instance { get; private set; }
internal void Awake()
{
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
tweakGetDamage = false;
tweakGetKnockback = false;
tweakWeapon = null;
tweakAmmunition = null;
blocked = false;
AIStateName = string.Empty;
ConfigElements.Init(((BaseUnityPlugin)this).Config);
Log = ((BaseUnityPlugin)this).Logger;
new Harmony("johbenji.Bowmaggedon").PatchAll();
}
public float getProjectileDistance(Character character, Vector3 hitpos)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)character == (Object)null)
{
return 0f;
}
bool flag = false;
Vector3 position = ((Component)character).transform.position;
return Vector3.Distance(position, hitpos);
}
private bodyPart getBodyPart(string input)
{
if (UnityEngineExtensions.Contains(input, "head", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(input, "skull", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(input, "horn", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(input, "circle center", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(input, "jaw", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(input, "neck", StringComparison.OrdinalIgnoreCase))
{
return bodyPart.Head;
}
if (UnityEngineExtensions.Contains(input, "leg", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(input, "foot", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(input, "calf", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(input, "tendril", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(input, "thigh", StringComparison.OrdinalIgnoreCase))
{
return bodyPart.Leg;
}
if (UnityEngineExtensions.Contains(input, "arm", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(input, "hand", StringComparison.OrdinalIgnoreCase) || UnityEngineExtensions.Contains(input, "mandibule", StringComparison.OrdinalIgnoreCase))
{
return bodyPart.Arm;
}
return bodyPart.Other;
}
public Character getLocalPlayer()
{
CharacterManager instance = CharacterManager.Instance;
for (int i = 0; i < instance.m_playerCharacters.Count; i++)
{
Character val = instance.m_characters[instance.m_playerCharacters.Values[i]];
if ((Object)(object)val != (Object)null && val.IsLocalPlayer)
{
return val;
}
}
return null;
}
}
internal enum bodyPart
{
Other,
Head,
Leg,
Arm
}
public static class ConfigElements
{
public static ConfigEntry<float> stealthDamageMultiplier;
public static ConfigEntry<float> headshotDamageMultiplier;
public static ConfigEntry<float> headshotImpactMultiplier;
public static ConfigEntry<float> weakenMultiple;
public static ConfigEntry<float> slowdownBuildup;
public static void Init(ConfigFile config)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Expected O, but got Unknown
stealthDamageMultiplier = config.Bind<float>("Multiplier", "Stealth (Damage)", 1.6f, new ConfigDescription("Damage multiplier for regular bow shots fired from stealth. (Vanilla = 1)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), new object[0]));
headshotDamageMultiplier = config.Bind<float>("Multiplier", "Headshot (Damage)", 1.25f, new ConfigDescription("Headshot damage multiplier for regular bow shots. (Vanilla = 1)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 3f), new object[0]));
headshotImpactMultiplier = config.Bind<float>("Multiplier", "Headshot (Impact)", 1.1f, new ConfigDescription("Headshot impact multiplier for regular bow shots. (Vanilla = 1)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 3f), new object[0]));
weakenMultiple = config.Bind<float>("Status Effect", "Weaken (Arms)", 40f, new ConfigDescription("Status buildup for Weaken when hitting the enemy in the arms. (Vanilla = 0)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 150f), new object[0]));
slowdownBuildup = config.Bind<float>("Status Effect", "Slow Down (Legs)", 36f, new ConfigDescription("Status buildup for Slow Down when hitting the enemy in the legs. (Vanilla = 0)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 150f), new object[0]));
}
}