This commit is contained in:
2026-02-14 00:13:03 -05:00
parent 5ff5764fa2
commit ad8310f143
15 changed files with 222 additions and 6 deletions

View File

@@ -0,0 +1,134 @@
local OFHotBrassPatch = {
patched = false,
}
local function isPatchToggleEnabled()
local vars = SandboxVars and SandboxVars.OpinionatedFirearms
if vars and vars.HBVCEFAmmoMakerPatch ~= nil then
return vars.HBVCEFAmmoMakerPatch == true
end
return true
end
local function isSessionEligible()
return isPatchToggleEnabled()
end
local function getAmmoMakerFiredCasing(ammoType)
if type(ammoType) ~= "string" or ammoType == "" then
return nil
end
local function partDataToFiredType(partData)
if type(partData) ~= "table" then
return nil
end
local firedType = partData.partFired or partData.partOld
if type(firedType) ~= "string" or firedType == "" then
return nil
end
return firedType
end
if type(ammoMakerAmmoParts) ~= "table" then
return nil
end
if type(ammoMakerGetCasingType) == "function" then
local ok, casingType = pcall(ammoMakerGetCasingType, ammoType)
if ok and type(casingType) == "string" then
local firedType = partDataToFiredType(ammoMakerAmmoParts[casingType])
if firedType then
return firedType
end
end
end
-- Fallback path that doesn't depend on Ammo Maker active-mod resolution.
if type(ammoMakerAmmoTypes) == "table" and type(ammoMakerAmmoData) == "table" then
local ammoDef = ammoMakerAmmoTypes[ammoType]
if type(ammoDef) == "table" and type(ammoDef.ammoTypes) == "table" then
for i = 1, #ammoDef.ammoTypes do
local ammoKey = ammoDef.ammoTypes[i]
local ammoData = ammoMakerAmmoData[ammoKey]
if type(ammoData) == "table" and type(ammoData.casingType) == "string" then
local firedType = partDataToFiredType(ammoMakerAmmoParts[ammoData.casingType])
if firedType then
return firedType
end
end
end
end
end
return nil
end
local function applyPatch()
if OFHotBrassPatch.patched then
return true
end
if not isSessionEligible() then
return false
end
if type(SpentCasingPhysics) ~= "table" then
return false
end
if type(SpentCasingPhysics.getItemToEject) ~= "function" then
return false
end
if type(SpentCasingPhysics.doSpawnCasing) ~= "function" then
return false
end
local originalGetItemToEject = SpentCasingPhysics.getItemToEject
local originalDoSpawnCasing = SpentCasingPhysics.doSpawnCasing
SpentCasingPhysics.getItemToEject = function(ammoType)
local mappedType = getAmmoMakerFiredCasing(ammoType)
if mappedType then
return mappedType
end
return originalGetItemToEject(ammoType)
end
SpentCasingPhysics.doSpawnCasing = function(player, weapon, params, racking, optionalItem)
if not optionalItem and weapon and weapon.getAmmoType then
local ammoType = weapon:getAmmoType()
if ammoType then
local mappedType = getAmmoMakerFiredCasing(tostring(ammoType))
if mappedType then
optionalItem = mappedType
if racking then
-- Force rack ejects to stay as empties for this patch.
racking = false
end
end
end
end
return originalDoSpawnCasing(player, weapon, params, racking, optionalItem)
end
OFHotBrassPatch.patched = true
return true
end
local function tryPatchOnTick()
if OFHotBrassPatch.patched then
Events.OnTick.Remove(tryPatchOnTick)
return
end
applyPatch()
end
Events.OnTick.Add(tryPatchOnTick)

View File

@@ -0,0 +1,70 @@
local BLOCKED_AMMOMAKER_COMMANDS = {
returnCasingsOnAttack = true,
incrementSpendtRoundCount = true,
returnCasingsOnReload = true,
}
local function isPatchToggleEnabled()
local vars = SandboxVars and SandboxVars.OpinionatedFirearms
if vars and vars.HBVCEFAmmoMakerPatch ~= nil then
return vars.HBVCEFAmmoMakerPatch == true
end
return true
end
local function shouldBlockAmmoMakerCasingCommands()
return isPatchToggleEnabled()
end
local function getModuleAndCommand(...)
local argc = select("#", ...)
if argc < 2 then
return nil, nil
end
local firstArg = select(1, ...)
if type(firstArg) == "string" then
return firstArg, select(2, ...)
end
if argc >= 3 then
return select(2, ...), select(3, ...)
end
return nil, nil
end
local function installCommandGate()
if _G.OpinionatedFirearms_AmmoMakerCommandGateInstalled then
return true
end
if type(sendClientCommand) ~= "function" then
return false
end
_G.OpinionatedFirearms_AmmoMakerCommandGateInstalled = true
_G.OpinionatedFirearms_OriginalSendClientCommand = sendClientCommand
sendClientCommand = function(...)
local module, command = getModuleAndCommand(...)
if module == "ammomaker" and BLOCKED_AMMOMAKER_COMMANDS[command] and shouldBlockAmmoMakerCasingCommands() then
return
end
return _G.OpinionatedFirearms_OriginalSendClientCommand(...)
end
return true
end
local function ensureGateOnTick()
if installCommandGate() then
Events.OnTick.Remove(ensureGateOnTick)
end
end
if not installCommandGate() then
Events.OnTick.Add(ensureGateOnTick)
end

View File

@@ -0,0 +1,3 @@
Sandbox_OpinionatedFirearms = "Opinionated Firearms",
Sandbox_HBVCEFAmmoMakerPatch = "Hot Brass -> Ammo Maker Casings",
Sandbox_HBVCEFAmmoMakerPatch_tooltip = "When enabled, Hot Brass ejects Ammo Maker fired casings with Guns93 and will not eject Guns93 casing.",

View File

@@ -0,0 +1,7 @@
VERSION = 1,
option OpinionatedFirearms.HBVCEFAmmoMakerPatch {
type = boolean,
default = true,
page = OpinionatedFirearms,
translation = HBVCEFAmmoMakerPatch,
}