This commit is contained in:
2026-02-12 15:09:07 -05:00
parent dd2d7a3abe
commit c320e8d993
13 changed files with 9168 additions and 30 deletions

View File

@@ -18,6 +18,45 @@ end
local config = safeRequire("OFBlockConfig")
local spawnProfile = safeRequire("OFSpawnProfile")
local sourceCatalog = safeRequire("OFSourceCatalog")
local function buildLookupSet(values)
local lookup = {}
if type(values) ~= "table" then
return lookup
end
for _, value in ipairs(values) do
local s = tostring(value):lower()
lookup[s] = true
end
return lookup
end
local attachmentTypeLookup = buildLookupSet(sourceCatalog.attachments)
local magazineTypeLookup = buildLookupSet(sourceCatalog.magazines)
local function isMagazineType(itemType)
local s = tostring(itemType or ""):lower()
if s == "" then
return false
end
if magazineTypeLookup[s] then
return true
end
if s:sub(1, 10) == "base.clip_" then
return true
end
if s:find("magazine", 1, true) then
return true
end
if s:find("drum", 1, true) then
return true
end
if s:find("clip", 1, true) then
return true
end
return false
end
local function trim(value)
if type(value) ~= "string" then
@@ -40,6 +79,25 @@ local function normalizeItemType(value)
return "Base." .. s
end
local function getMagazinePartAlias(itemType)
local normalized = normalizeItemType(itemType)
if not normalized then
return nil
end
local lowered = normalized:lower()
if not isMagazineType(lowered) then
return nil
end
if lowered:sub(1, 10) == "base.clip_" then
return nil
end
local short = normalized:match("^Base%.(.+)$")
if not short or short == "" then
return nil
end
return "Base.Clip_" .. short
end
local function normalizePrefix(value)
local s = trim(value)
if not s or s == "" then
@@ -271,9 +329,16 @@ local ruleMatchers = compileRules(config.rules, aliasMap)
local function compileSpawnProfile(rawProfile)
local managedItemSet = {}
local disabledManagedItemSet = {}
local placementsByList = {}
local managedCount = 0
local function clearPlacementsForItem(itemType)
for _, entries in pairs(placementsByList) do
entries[itemType] = nil
end
end
local function addPlacement(listName, itemType, rawWeight)
local cleanList = trim(listName)
local weight = tonumber(rawWeight)
@@ -303,9 +368,18 @@ local function compileSpawnProfile(rawProfile)
end
if entry.enabled == false then
disabledManagedItemSet[lowered] = true
local partAlias = getMagazinePartAlias(normalized)
if partAlias then
managedItemSet[partAlias:lower()] = true
disabledManagedItemSet[partAlias:lower()] = true
end
clearPlacementsForItem(normalized)
return
end
disabledManagedItemSet[lowered] = nil
if type(entry.placements) == "table" then
if entry.placements[1] then
for _, row in ipairs(entry.placements) do
@@ -337,10 +411,10 @@ local function compileSpawnProfile(rawProfile)
end
end
return managedItemSet, placementsByList, managedCount
return managedItemSet, disabledManagedItemSet, placementsByList, managedCount
end
local managedSpawnItems, profilePlacementsByList, managedSpawnItemCount = compileSpawnProfile(spawnProfile)
local managedSpawnItems, disabledManagedSpawnItems, profilePlacementsByList, managedSpawnItemCount = compileSpawnProfile(spawnProfile)
local function isRuleActive(rule, nowEpoch)
if not rule.enabled then
@@ -389,6 +463,51 @@ local function shouldBlock(listName, itemType, nowEpoch)
return false
end
local function shouldBlockByRulesOnly(listName, itemType, nowEpoch)
local listLower = (trim(listName) or "unknown"):lower()
local itemLower = normalizeItemType(itemType)
if not itemLower then
return false
end
itemLower = itemLower:lower()
if itemMatches(itemLower, globalMatcher) then
return true
end
for _, entry in ipairs(byListMatchers) do
if entry.pattern ~= "" and listMatchesPattern(listLower, entry.pattern) and itemMatches(itemLower, entry.matcher) then
return true
end
end
for _, rule in ipairs(ruleMatchers) do
if isRuleActive(rule, nowEpoch) and listMatches(listLower, rule.listPatterns) and itemMatches(itemLower, rule.matcher) then
return true
end
end
return false
end
local function isWeaponPartBlockedForUpgrades(itemType, nowEpoch)
local normalized = normalizeItemType(itemType)
if not normalized then
return false
end
local lowered = normalized:lower()
if not attachmentTypeLookup[lowered] and not isMagazineType(lowered) then
return false
end
if disabledManagedSpawnItems[lowered] then
return true
end
return shouldBlockByRulesOnly("GGSWeaponUpgrades", normalized, nowEpoch)
end
local function removeBlockedEntries(items, listName, nowEpoch)
if type(items) ~= "table" then
return 0
@@ -503,6 +622,52 @@ local function applyProfilePlacements()
return added
end
local function removeBlockedAttachmentEntries(entries, nowEpoch)
if type(entries) ~= "table" then
return 0
end
local removed = 0
for i = #entries, 1, -1 do
local value = entries[i]
if type(value) == "string" and isWeaponPartBlockedForUpgrades(value, nowEpoch) then
table.remove(entries, i)
removed = removed + 1
end
end
return removed
end
local function patchWeaponUpgradeAttachmentSources(nowEpoch)
local removed = 0
if type(GGSWeaponUpgrades) == "table" and type(GGSWeaponUpgrades.Lists) == "table" then
for _, listDef in pairs(GGSWeaponUpgrades.Lists) do
if type(listDef) == "table" then
if type(listDef.items) == "table" then
removed = removed + removeBlockedAttachmentEntries(listDef.items, nowEpoch)
elseif listDef[1] ~= nil then
removed = removed + removeBlockedAttachmentEntries(listDef, nowEpoch)
end
end
end
end
if type(WeaponUpgrades) == "table" then
for _, listDef in pairs(WeaponUpgrades) do
if type(listDef) == "table" then
if type(listDef.items) == "table" then
removed = removed + removeBlockedAttachmentEntries(listDef.items, nowEpoch)
elseif listDef[1] ~= nil then
removed = removed + removeBlockedAttachmentEntries(listDef, nowEpoch)
end
end
end
end
return removed
end
local function patchAllDistributions()
local nowEpoch = nil
if os and os.time then
@@ -513,13 +678,14 @@ local function patchAllDistributions()
removed = removed + patchProceduralDistributions(nowEpoch)
removed = removed + patchNestedDistributionTree("SuburbsDistributions", SuburbsDistributions, nowEpoch)
removed = removed + patchNestedDistributionTree("VehicleDistributions", VehicleDistributions, nowEpoch)
local upgradeAttachmentRemoved = patchWeaponUpgradeAttachmentSources(nowEpoch)
local added = applyProfilePlacements()
if ItemPickerJava and ItemPickerJava.Parse then
ItemPickerJava.Parse()
end
print(string.format("[OFDistributionBlocker] Removed %d entries and added %d profile entries (managed items: %d).", removed, added, managedSpawnItemCount))
print(string.format("[OFDistributionBlocker] Removed %d distro entries, removed %d upgrade attachments, and added %d profile entries (managed items: %d).", removed, upgradeAttachmentRemoved, added, managedSpawnItemCount))
end
Events.OnInitWorld.Add(patchAllDistributions)

View File

@@ -1,8 +1,8 @@
name=Opinionated Firearms
id=opinionated_firearms
id=hrsys_opinionated_firearms
author=Riggs0
modversion=1.0.0
versionMin=42.12.13
require=GaelGunStore_ALPHA
require=\GaelGunStore_ALPHA
description=Opinionated Firearms spawn distribution controller for GaelGunStore (B42).