-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
43 lines (37 loc) · 1.43 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using BepInEx;
using HarmonyLib;
using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.AI;
namespace ShootableMouthDogs;
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
public void Awake()
{
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} v{PluginInfo.PLUGIN_VERSION} loaded!");
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
}
}
[HarmonyPatch(typeof(Physics))]
public static class PhysicsPatch
{
// Filters out NavMeshAgent hits from SphereCastNonAlloc, since they block gun damage and don't really serve a purpose for raycast detection.
[HarmonyPatch(nameof(Physics.SphereCastNonAlloc))]
[HarmonyPatch(new Type[] { typeof(Ray), typeof(float), typeof(RaycastHit[]), typeof(float), typeof(int), typeof(QueryTriggerInteraction) })]
static void Postfix(RaycastHit[] results, int layerMask, ref int __result)
{
if ((layerMask & 524288) == 0) return; // abort if layerMask doesn't include the one from ShootGun's SphereCastNonAlloc
int hitCount = 0;
for (int i = 0; i < __result; i++)
{
if (results[i].transform?.GetComponent<NavMeshAgent>() == null)
{
if (i > hitCount) results[hitCount] = results[i]; // RaycastHit struct shallow copy
hitCount++;
}
}
__result = hitCount;
}
}