Skip to content

Commit

Permalink
Add more customizable weapon configs, refactor, add breaching rounds …
Browse files Browse the repository at this point in the history
…open all doors option
  • Loading branch information
dvize committed Apr 8, 2024
1 parent 4c67c44 commit 9b34717
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 503 deletions.
22 changes: 14 additions & 8 deletions BackdoorBandit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>
</DefineConstants>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand All @@ -32,6 +31,7 @@
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
Expand Down Expand Up @@ -140,11 +140,17 @@
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "F:\SPT-AKI-DEV\BepInEx\plugins\dvize.BackdoorBandit\$(TargetName).dll"

if $(ConfigurationName) == Debug (
if "$(ConfigurationName)" == "Debug" (
echo Debug build
copy "$(TargetDir)$(TargetName).pdb" "F:\SPT-AKI-DEV\BepInEx\plugins\dvize.BackdoorBandit\$(TargetName).pdb"
) else (
) else if "$(ConfigurationName)" == "Release" (
echo Release build
del "F:\SPT-AKI-DEV\BepInEx\plugins\dvize.BackdoorBandit\$(TargetName).pdb"
)
</PostBuildEvent>
if exist "F:\SPT-AKI-DEV\BepInEx\plugins\dvize.BackdoorBandit\$(TargetName).pdb" (
echo Failed to delete PDB file.
) else (
echo PDB file deleted successfully.
)
)</PostBuildEvent>
</PropertyGroup>
</Project>
76 changes: 44 additions & 32 deletions DamageUtility.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Comfort.Common;
using DoorBreach;
using EFT;
using EFT.Ballistics;
using EFT.Interactive;
using EFT.InventoryLogic;
using EFT;
using UnityEngine;
using DoorBreach;

namespace BackdoorBandit
{
internal static class DamageUtility
{
internal static void CheckWeaponAndAmmo(DamageInfo damageInfo, ref bool validDamage, HashSet<string> validWeapons, Func<AmmoTemplate, bool> isRoundValid, Func<DamageInfo, bool> isValidLockHit)
internal static void CheckWeaponAndAmmo(DamageInfo damageInfo, ref bool validDamage, ref HashSet<string> validWeapons, Func<AmmoTemplate, bool> isRoundValid, Func<DamageInfo, bool> isValidLockHit)
{
var material = damageInfo.HittedBallisticCollider.TypeOfMaterial;
var weapon = damageInfo.Weapon.TemplateId;

// Logger.LogInfo($"BB: Actual DamageType is : {damageInfo.DamageType}");

//semi-pleb mode. All regular doors are shootable any weapon except for reinforced doors
if (DoorBreachPlugin.SemiPlebMode.Value && material != MaterialType.MetalThin && material != MaterialType.MetalThick)
Expand All @@ -42,10 +38,36 @@ internal static void CheckWeaponAndAmmo(DamageInfo damageInfo, ref bool validDam

var bulletTemplate = Singleton<ItemFactory>.Instance.ItemTemplates[damageInfo.SourceId] as AmmoTemplate;

//regular valid shotgun round check
if (validWeapons.Contains(weapon) && isRoundValid(bulletTemplate) && isValidLockHit(damageInfo))
#if DEBUG
DoorBreachComponent.Logger.LogInfo($"ammoTemplate: {bulletTemplate.Name}");
DoorBreachComponent.Logger.LogInfo($"BB: Actual DamageType is : {damageInfo.DamageType}");
DoorBreachComponent.Logger.LogInfo($"isValidLockHit: {isValidLockHit(damageInfo)}");
DoorBreachComponent.Logger.LogInfo($"isRoundValid: {isRoundValid(bulletTemplate)}");
DoorBreachComponent.Logger.LogInfo($"weapon used: {damageInfo.Weapon.LocalizedName()}, id: {damageInfo.Weapon.TemplateId}");
DoorBreachComponent.Logger.LogInfo($"validWeapons Contains weapon tpl id: {validWeapons.Contains(weapon).ToString()}");
#endif
//check if weapon is a shotgun and material type is metal
if (!DoorBreachPlugin.BreachingRoundsOpenMetalDoors.Value)
{
if (isBreachingSlug(bulletTemplate) && (material == MaterialType.MetalThin || material == MaterialType.MetalThick))
{
validDamage = false;
return;
}
}

//check if its on the validWeapons hashset and its not a shotgun.. something user added then we need to skip the isRoundValidCheck
if (validWeapons.Contains(weapon) && !isShotgun(damageInfo) && isValidLockHit(damageInfo))
{
validDamage = true;
return;
}
//regular valid weapon and round check
else if (validWeapons.Contains(weapon) && isRoundValid(bulletTemplate) && isValidLockHit(damageInfo))
{
// Logger.LogInfo($"BB: Valid round detected. weapon used: {damageInfo.Weapon.LocalizedName()}");
#if DEBUG
DoorBreachComponent.Logger.LogInfo($"BB: Valid round detected.");
#endif
validDamage = true;

// Additional modifications or actions for specific cases
Expand All @@ -60,48 +82,44 @@ internal static void CheckWeaponAndAmmo(DamageInfo damageInfo, ref bool validDam

internal static void CheckDoorWeaponAndAmmo(DamageInfo damageInfo, ref bool validDamage)
{
CheckWeaponAndAmmo(damageInfo, ref validDamage, DoorBreachComponent.GrenadeLaunchers,
ammo => isHEGrenade(ammo) || isShrapnel(ammo), isValidDoorLockHit);
CheckWeaponAndAmmo(damageInfo, ref validDamage, ref DoorBreachComponent.ApplicableWeapons,
ammo => isHEGrenade(ammo) || isShrapnel(ammo) || isBreachingSlug(ammo), isValidDoorLockHit);
}

internal static void CheckCarWeaponAndAmmo(DamageInfo damageInfo, ref bool validDamage)
{
CheckWeaponAndAmmo(damageInfo, ref validDamage, DoorBreachComponent.GrenadeLaunchers,
ammo => isHEGrenade(ammo) || isShrapnel(ammo), isValidCarTrunkLockHit);
CheckWeaponAndAmmo(damageInfo, ref validDamage, ref DoorBreachComponent.ApplicableWeapons,
ammo => isHEGrenade(ammo) || isShrapnel(ammo) || isBreachingSlug(ammo), isValidCarTrunkLockHit);
}

internal static void CheckLootableContainerWeaponAndAmmo(DamageInfo damageInfo, ref bool validDamage)
{
CheckWeaponAndAmmo(damageInfo, ref validDamage, DoorBreachComponent.GrenadeLaunchers,
ammo => isHEGrenade(ammo) || isShrapnel(ammo), isValidContainerLockHit);
CheckWeaponAndAmmo(damageInfo, ref validDamage, ref DoorBreachComponent.ApplicableWeapons,
ammo => isHEGrenade(ammo) || isShrapnel(ammo) || isBreachingSlug(ammo), isValidContainerLockHit);
}


internal static bool isShrapnel(AmmoTemplate bulletTemplate)
{
DoorBreachComponent.Logger.LogDebug("BB: detected grenade shrapnel");

//check if bulletTemplate is shrapnel and we only want grenade shrapnel not bullet shrapnel
//bulletTemplate._id = "5b44e3f4d4351e003562b3f4";
return (bulletTemplate.FragmentType == "5485a8684bdc2da71d8b4567");
}

internal static bool isHEGrenade(AmmoTemplate bulletTemplate)
{
//Logger.LogDebug("BB: detected HE Grenade");

//check if bulletTemplate is HE Grenade if has ExplosionStrength and only one projectile
return (bulletTemplate.ExplosionStrength > 0
&& bulletTemplate.ProjectileCount == 1);
}

internal static bool isBreachingSlug(AmmoTemplate bulletTemplate)
{
return (bulletTemplate._id == "doorbreacher");
//doorbreach id: 660249a0712c1005a4a3ab41

return (bulletTemplate._id == "660249a0712c1005a4a3ab41");
}
internal static bool isShotgun(DamageInfo damageInfo)
{
//Logger.LogDebug("BB: detected Shotgun: " + (damageInfo.Weapon as Weapon).WeapClass == "shotgun");

//check if weapon is a shotgun

return ((damageInfo.Weapon as Weapon)?.WeapClass == "shotgun");
Expand All @@ -114,7 +132,6 @@ internal static bool isValidDoorLockHit(DamageInfo damageInfo)
//if doorhandle exists and is hit
if (col.GetComponentInParent<Door>().GetComponentInChildren<DoorHandle>() != null)
{
//Logger.LogDebug("BB: doorhandle exists so checking if hit");
Vector3 localHitPoint = col.transform.InverseTransformPoint(damageInfo.HitPoint);
DoorHandle doorHandle = col.GetComponentInParent<Door>().GetComponentInChildren<DoorHandle>();
Vector3 doorHandleLocalPos = doorHandle.transform.localPosition;
Expand All @@ -124,7 +141,6 @@ internal static bool isValidDoorLockHit(DamageInfo damageInfo)
//if doorhandle does not exist then it is a valid hit
else
{
//Logger.LogDebug("BB: doorhandle does not exist so valid hit");
return true;
}

Expand All @@ -138,21 +154,19 @@ internal static bool isValidCarTrunkLockHit(DamageInfo damageInfo)
//if doorhandle exists and is hit
if (col.GetComponentInParent<Trunk>().GetComponentInChildren<DoorHandle>() != null)
{
//Logger.LogDebug("BB: doorhandle exists so checking if hit");
var gameobj = col.GetComponentInParent<Trunk>().gameObject;

//find child game object Lock from gameobj
var carLockObj = gameobj.transform.Find("CarLock_Hand").gameObject;
var lockObj = carLockObj.transform.Find("Lock").gameObject;

float distanceToLock = Vector3.Distance(damageInfo.HitPoint, lockObj.transform.position);
//Logger.LogError("Distance to lock: " + distanceToLock);

return distanceToLock < 0.25f;
}
//if doorhandle does not exist then it is a valid hit
else
{
//Logger.LogDebug("BB: doorhandle does not exist so valid hit");
return true;
}

Expand All @@ -166,20 +180,18 @@ internal static bool isValidContainerLockHit(DamageInfo damageInfo)
//if doorhandle exists and is hit
if (col.GetComponentInParent<LootableContainer>().GetComponentInChildren<DoorHandle>() != null)
{
//Logger.LogDebug("BB: doorhandle exists so checking if hit");
var gameobj = col.GetComponentInParent<LootableContainer>().gameObject;

//find child game object Lock from gameobj
var lockObj = gameobj.transform.Find("Lock").gameObject;

float distanceToLock = Vector3.Distance(damageInfo.HitPoint, lockObj.transform.position);
//Logger.LogError("Distance to lock: " + distanceToLock);
return distanceToLock < 0.25f;
}
//if doorhandle does not exist then it is a valid hit
else
{
//Logger.LogDebug("BB: doorhandle does not exist so valid hit");

return true;
}

Expand Down
39 changes: 33 additions & 6 deletions DoorBreachComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ internal class DoorBreachComponent : MonoBehaviour
private static int inoperatableTrunks = 0;
private static int invalidTrunkLayer = 0;

internal static HashSet<string> GrenadeLaunchers = new HashSet<string>();
internal static HashSet<string> MeleeWeapons = new HashSet<string>();
internal static HashSet<string> GrenadeLaunchers;
internal static HashSet<string> MeleeWeapons;
internal static HashSet<string> ShotgunWeapons;
internal static HashSet<string> OtherWeapons;
internal static HashSet<string> ApplicableWeapons;

internal static ManualLogSource Logger
{
Expand Down Expand Up @@ -60,9 +63,17 @@ public void Awake()
invalidCarTrunks = 0;
inoperatableTrunks = 0;
invalidTrunkLayer = 0;

LoadHashSetFromJson(GrenadeLaunchers, "GrenadeLaunchers.json");
LoadHashSetFromJson(MeleeWeapons, "MeleeWeapons.json");
ApplicableWeapons = new HashSet<string>();
OtherWeapons = new HashSet<string>();
GrenadeLaunchers = new HashSet<string>();
MeleeWeapons = new HashSet<string>();
ShotgunWeapons = new HashSet<string>();

LoadHashSetFromJson(ref GrenadeLaunchers, "GrenadeLaunchers.json");
LoadHashSetFromJson(ref MeleeWeapons, "MeleeWeapons.json");
LoadHashSetFromJson(ref ShotgunWeapons, "ShotgunWeapons.json");
LoadHashSetFromJson(ref OtherWeapons, "OtherWeapons.json");
SetupApplicableWeapons();

ProcessObjectsOfType<Door>("Doors", DoorBreachPlugin.interactiveLayer);
ProcessObjectsOfType<LootableContainer>("Containers", DoorBreachPlugin.interactiveLayer);
Expand Down Expand Up @@ -191,7 +202,7 @@ public static void Enable()
gameWorld.GetOrAddComponent<DoorBreachComponent>();
}
}
private void LoadHashSetFromJson(HashSet<string> hashSet, string jsonFileName)
private void LoadHashSetFromJson(ref HashSet<string> hashSet, string jsonFileName)
{
string dllDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string jsonPath = Path.Combine(dllDirectory, jsonFileName);
Expand All @@ -206,6 +217,22 @@ private void LoadHashSetFromJson(HashSet<string> hashSet, string jsonFileName)
Logger.LogError($"JSON file not found: {jsonFileName}");
}
}

internal static void SetupApplicableWeapons()
{
ApplicableWeapons.UnionWith(DoorBreachComponent.MeleeWeapons);
ApplicableWeapons.UnionWith(DoorBreachComponent.GrenadeLaunchers);
ApplicableWeapons.UnionWith(DoorBreachComponent.ShotgunWeapons);
ApplicableWeapons.UnionWith(DoorBreachComponent.OtherWeapons);
#if DEBUG
//print out applicable weapons hashes to console
Logger.LogInfo("Applicable Weapons:");
foreach (var weapon in ApplicableWeapons)
{
Logger.LogInfo(weapon);
}
#endif
}
}

}
Expand Down
20 changes: 0 additions & 20 deletions DoorBreacher/bundles.json

This file was deleted.

Binary file removed DoorBreacher/bundles/DoorBreacher.bundle
Binary file not shown.
Binary file removed DoorBreacher/bundles/DoorBreacherBox.bundle
Binary file not shown.
15 changes: 0 additions & 15 deletions DoorBreacher/database/locales/en.json

This file was deleted.

14 changes: 0 additions & 14 deletions DoorBreacher/database/templates/handbook.json

This file was deleted.

Loading

0 comments on commit 9b34717

Please sign in to comment.