Skip to content

Commit

Permalink
Added whitelists, and also prevented duplicate magazines from being a…
Browse files Browse the repository at this point in the history
…dded to firearms
  • Loading branch information
devyndamonster committed Jul 29, 2021
1 parent 9fe39f2 commit 6453bd0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion MagazinePatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down
34 changes: 30 additions & 4 deletions Scripts/CompatibleMagazineCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ public CompatibleMagazineCache()
BlacklistEntries = new Dictionary<string, MagazineBlacklistEntry>();
}

public void PrintBlacklist()
{
if(BlacklistEntries.coun)
}

public void AddMagazineData(FVRFireArmMagazine mag)
{
Expand Down Expand Up @@ -148,8 +144,11 @@ public class MagazineBlacklistEntry
{
public string FirearmID;
public List<string> MagazineBlacklist = new List<string>();
public List<string> MagazineWhitelist = new List<string>();
public List<string> ClipBlacklist = new List<string>();
public List<string> ClipWhitelist = new List<string>();
public List<string> RoundBlacklist = new List<string>();
public List<string> RoundWhitelist = new List<string>();

public MagazineBlacklistEntry()
{
Expand All @@ -159,5 +158,32 @@ public bool IsItemBlacklisted(string itemID)
{
return MagazineBlacklist.Contains(itemID) || ClipBlacklist.Contains(itemID) || RoundBlacklist.Contains(itemID);
}

public bool IsMagazineAllowed(string itemID)
{
if(MagazineWhitelist.Count > 0 && (!MagazineWhitelist.Contains(itemID))) return false;

if (MagazineBlacklist.Contains(itemID)) return false;

return true;
}

public bool IsClipAllowed(string itemID)
{
if (ClipWhitelist.Count > 0 && (!ClipWhitelist.Contains(itemID))) return false;

if (ClipBlacklist.Contains(itemID)) return false;

return true;
}

public bool IsRoundAllowed(string itemID)
{
if (RoundWhitelist.Count > 0 && (!RoundWhitelist.Contains(itemID))) return false;

if (RoundWhitelist.Contains(itemID)) return false;

return true;
}
}
}
21 changes: 3 additions & 18 deletions Scripts/MagazinePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,25 +420,10 @@ private static void ApplyMagazineCache(CompatibleMagazineCache magazineCache, Di

foreach (string mag in entry.CompatibleMagazines)
{

//true && (!true || !true)
if (IM.OD.ContainsKey(mag) && ((!blacklist.ContainsKey(firearm.ItemID)) || (!blacklist[firearm.ItemID].MagazineBlacklist.Contains(mag))))
if (IM.OD.ContainsKey(mag) && (!firearm.CompatibleMagazines.Any(o => o.ItemID == mag)) && ((!blacklist.ContainsKey(firearm.ItemID)) || blacklist[firearm.ItemID].IsMagazineAllowed(mag)))
{
FVRObject magazineObject = IM.OD[mag];

if (entry.FirearmID == "SKSClassic")
{
PatchLogger.Log("Caching (" + entry.FirearmID + ") with mag (" + mag + ")", PatchLogger.LogType.General);
PatchLogger.Log($"Is item in blacklist : {blacklist.ContainsKey(firearm.ItemID)}", PatchLogger.LogType.General);

if (blacklist.ContainsKey(firearm.ItemID))
{
PatchLogger.Log($"Is mag in blacklist : {blacklist[firearm.ItemID].MagazineBlacklist.Contains(mag)}", PatchLogger.LogType.General);
}

}


firearm.CompatibleMagazines.Add(magazineObject);
if (magazineCache.AmmoObjects.ContainsKey(mag)) magazineObject.MagazineCapacity = magazineCache.AmmoObjects[mag].Capacity;

Expand All @@ -449,7 +434,7 @@ private static void ApplyMagazineCache(CompatibleMagazineCache magazineCache, Di
}
foreach (string clip in entry.CompatibleClips)
{
if (IM.OD.ContainsKey(clip) && (!blacklist.ContainsKey(firearm.ItemID) || !blacklist[firearm.ItemID].ClipBlacklist.Contains(clip)))
if (IM.OD.ContainsKey(clip) && (!firearm.CompatibleClips.Any(o => o.ItemID == clip)) && ((!blacklist.ContainsKey(firearm.ItemID)) || blacklist[firearm.ItemID].IsClipAllowed(clip)))
{
FVRObject clipObject = IM.OD[clip];

Expand All @@ -463,7 +448,7 @@ private static void ApplyMagazineCache(CompatibleMagazineCache magazineCache, Di
}
foreach (string bullet in entry.CompatibleBullets)
{
if (IM.OD.ContainsKey(bullet) && (!blacklist.ContainsKey(firearm.ItemID) || !blacklist[firearm.ItemID].RoundBlacklist.Contains(bullet)))
if (IM.OD.ContainsKey(bullet) && (!firearm.CompatibleSingleRounds.Any(o => o.ItemID == bullet)) && ((!blacklist.ContainsKey(firearm.ItemID)) || blacklist[firearm.ItemID].IsRoundAllowed(bullet)))
{
firearm.CompatibleSingleRounds.Add(IM.OD[bullet]);
}
Expand Down

0 comments on commit 6453bd0

Please sign in to comment.