From 099e58f75b3edc036cff9f6cf5587dacaf16e3fc Mon Sep 17 00:00:00 2001
From: "Brad Payne (Vir Linden)" <vir@lindenlab.com>
Date: Tue, 23 Apr 2019 15:13:38 +0100
Subject: [PATCH] SL-10401 - get agent attachment limit from SimulatorFeatures
 if available

---
 indra/llcommon/indra_constants.h    |  1 -
 indra/newview/llcofwearables.cpp    |  3 ++-
 indra/newview/llinventorybridge.cpp |  2 +-
 indra/newview/llvoavatar.cpp        | 25 +++++++++++++++++++++++--
 indra/newview/llvoavatar.h          |  1 +
 5 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/indra/llcommon/indra_constants.h b/indra/llcommon/indra_constants.h
index a00a82aff0a..c0213d7c160 100644
--- a/indra/llcommon/indra_constants.h
+++ b/indra/llcommon/indra_constants.h
@@ -153,7 +153,6 @@ const U8 SIM_ACCESS_DOWN	= 254;
 const U8 SIM_ACCESS_MAX 	= SIM_ACCESS_ADULT;
 
 // attachment constants
-const S32 MAX_AGENT_ATTACHMENTS = 38;
 const U8  ATTACHMENT_ADD = 0x80;
 
 // god levels
diff --git a/indra/newview/llcofwearables.cpp b/indra/newview/llcofwearables.cpp
index 307f93e28c9..b47e0930a3c 100644
--- a/indra/newview/llcofwearables.cpp
+++ b/indra/newview/llcofwearables.cpp
@@ -42,6 +42,7 @@
 #include "llwearableitemslist.h"
 #include "llpaneloutfitedit.h"
 #include "lltrans.h"
+#include "llvoavatarself.h"
 
 static LLPanelInjector<LLCOFWearables> t_cof_wearables("cof_wearables");
 
@@ -330,7 +331,7 @@ void LLCOFWearables::setAttachmentsTitle()
 {
 	if (mAttachmentsTab)
 	{
-		U32 free_slots = MAX_AGENT_ATTACHMENTS - mAttachments->size();
+		U32 free_slots = gAgentAvatarp->getMaxAttachments() - mAttachments->size();
 
 		LLStringUtil::format_map_t args_attachments;
 		args_attachments["[COUNT]"] = llformat ("%d", free_slots);
diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp
index 1987e158509..b3f6d354df4 100644
--- a/indra/newview/llinventorybridge.cpp
+++ b/indra/newview/llinventorybridge.cpp
@@ -6307,7 +6307,7 @@ bool confirm_attachment_rez(const LLSD& notification, const LLSD& response)
 	if (!gAgentAvatarp->canAttachMoreObjects())
 	{
 		LLSD args;
-		args["MAX_ATTACHMENTS"] = llformat("%d", MAX_AGENT_ATTACHMENTS);
+		args["MAX_ATTACHMENTS"] = llformat("%d", gAgentAvatarp->getMaxAttachments());
 		LLNotificationsUtil::add("MaxAttachmentsOnOutfit", args);
 		return false;
 	}
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 321f774210e..c9f2ba1a3c9 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -7036,13 +7036,34 @@ U32 LLVOAvatar::getNumAttachments() const
 	return num_attachments;
 }
 
+//-----------------------------------------------------------------------------
+// getMaxAttachments()
+//-----------------------------------------------------------------------------
+S32 LLVOAvatar::getMaxAttachments() const
+{
+	const S32 MAX_AGENT_ATTACHMENTS = 38;
+
+	S32 max_attach = MAX_AGENT_ATTACHMENTS;
+	
+	if (gAgent.getRegion())
+	{
+		LLSD features;
+		gAgent.getRegion()->getSimulatorFeatures(features);
+		if (features.has("MaxAgentAttachments"))
+		{
+			max_attach = features["MaxAgentAttachments"].asInteger();
+		}
+	}
+	return max_attach;
+}
+
 //-----------------------------------------------------------------------------
 // canAttachMoreObjects()
 // Returns true if we can attach <n> more objects.
 //-----------------------------------------------------------------------------
 BOOL LLVOAvatar::canAttachMoreObjects(U32 n) const
 {
-	return (getNumAttachments() + n) <= MAX_AGENT_ATTACHMENTS;
+	return (getNumAttachments() + n) <= getMaxAttachments();
 }
 
 //-----------------------------------------------------------------------------
@@ -7070,7 +7091,7 @@ S32 LLVOAvatar::getMaxAnimatedObjectAttachments() const
     S32 max_attach = 0;
     if (gSavedSettings.getBOOL("AnimatedObjectsIgnoreLimits"))
     {
-        max_attach = MAX_AGENT_ATTACHMENTS;
+        max_attach = getMaxAttachments(); 
     }
     else
     {
diff --git a/indra/newview/llvoavatar.h b/indra/newview/llvoavatar.h
index deb22617a41..e1ea7c619b7 100644
--- a/indra/newview/llvoavatar.h
+++ b/indra/newview/llvoavatar.h
@@ -809,6 +809,7 @@ class LLVOAvatar :
 	BOOL 				hasHUDAttachment() const;
 	LLBBox 				getHUDBBox() const;
 	void 				resetHUDAttachments();
+	S32					getMaxAttachments() const;
 	BOOL				canAttachMoreObjects(U32 n=1) const;
     S32					getMaxAnimatedObjectAttachments() const;
     BOOL				canAttachMoreAnimatedObjects(U32 n=1) const;
-- 
GitLab