From 5f4abdbf2c98a9b479365089e5d410c45b51a6e9 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sun, 17 Dec 2023 11:24:20 -0500
Subject: [PATCH] Bonk check

---
 indra/newview/llfloaterhexeditor.cpp |  9 +++++-
 indra/newview/llfloaterhexeditor.h   |  6 ++--
 indra/newview/llinventorybridge.cpp  | 48 ++++++++++++++++++----------
 3 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/indra/newview/llfloaterhexeditor.cpp b/indra/newview/llfloaterhexeditor.cpp
index ca61995fa94..a5c10bd7219 100644
--- a/indra/newview/llfloaterhexeditor.cpp
+++ b/indra/newview/llfloaterhexeditor.cpp
@@ -23,6 +23,7 @@
 #include "llviewermenufile.h"
 #include "llviewerregion.h"
 #include "llviewertexturelist.h"
+#include "llviewerinventory.h"
 
 
 LLFloaterHexEditor::LLFloaterHexEditor(const LLSD& key)
@@ -89,13 +90,19 @@ void LLFloaterHexEditor::onOpen(const LLSD& key)
 }
 
 // static
-void LLFloaterHexEditor::download(LLInventoryItem* item, loaded_callback_func onImage, LLGetAssetCallback onAsset)
+void LLFloaterHexEditor::download(LLViewerInventoryItem* item, loaded_callback_func onImage, LLGetAssetCallback onAsset)
 {
     if (item == nullptr)
     {
         LL_WARNS("Hex") << "Could not download null pointer encountered!" << LL_ENDL;
 		return;
     }
+	if (!LLAssetType::lookupIsAssetIDKnowable(item->getType()) || !(item->getIsFullPerm() || gAgent.isGodlikeWithoutAdminMenuFakery()))
+	{
+		LL_WARNS("Hex") << "Insufficient permissions!" << LL_ENDL;
+		return;
+	}
+
     switch (item->getType())
     {
         case LLAssetType::AT_TEXTURE:
diff --git a/indra/newview/llfloaterhexeditor.h b/indra/newview/llfloaterhexeditor.h
index f9c809479fd..01657f1771c 100644
--- a/indra/newview/llfloaterhexeditor.h
+++ b/indra/newview/llfloaterhexeditor.h
@@ -18,6 +18,8 @@
 #include "llinventory.h"
 #include "llviewertexture.h"
 
+class LLViewerInventoryItem;
+
 class LLFloaterHexEditor : public LLFloater
 {
 public:
@@ -26,7 +28,7 @@ class LLFloaterHexEditor : public LLFloater
 	void onOpen(const LLSD& key) override;
 	BOOL postBuild() override;
 
-	LLInventoryItem* mItem;
+	LLViewerInventoryItem* mItem;
 	LLAssetType::EType mAssetType;
 	LLHexEditor* mEditor;
 
@@ -43,7 +45,7 @@ class LLFloaterHexEditor : public LLFloater
 
 
 
-	static void download(LLInventoryItem* item, loaded_callback_func onImage, LLGetAssetCallback onAsset);
+	static void download(LLViewerInventoryItem* item, loaded_callback_func onImage, LLGetAssetCallback onAsset);
 	static void onSaveComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status);
 
 private:
diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp
index fd8163d0e50..eb64394d7d4 100644
--- a/indra/newview/llinventorybridge.cpp
+++ b/indra/newview/llinventorybridge.cpp
@@ -973,10 +973,23 @@ void LLInvFVBridge::getClipboardEntries(bool show_asset_id,
 					is_asset_knowable = LLAssetType::lookupIsAssetIDKnowable(inv_item->getType());
 				}
 				if ( !is_asset_knowable // disable menu item for Inventory items with unknown asset. EXT-5308
-					 || (! ( isItemPermissive() || gAgent.isGodlike() ) )
+					 || (! ( isItemPermissive() || gAgent.isGodlikeWithoutAdminMenuFakery() ) )
 					 || (flags & FIRST_SELECTED_ITEM) == 0)
 				{
 					disabled_items.push_back(std::string("Copy Asset UUID"));
+					is_asset_knowable = false;
+				}
+
+				static LLCachedControl<bool> sPowerfulWizard(gSavedSettings, "AlchemyPowerfulWizard", false);
+				if (is_asset_knowable && sPowerfulWizard)
+				{
+					items.push_back(LLStringExplicit("Extras Separator"));
+					items.push_back(LLStringExplicit("Extras Menu"));
+
+					if (!isItemPermissive())
+					{
+						disabled_items.push_back(LLStringExplicit("Edit Hex"));
+					}
 				}
 			}
 
@@ -1003,17 +1016,6 @@ void LLInvFVBridge::getClipboardEntries(bool show_asset_id,
                     }
                 }
 			}
-            }
-            static LLCachedControl<bool> sPowerfulWizard(gSavedSettings, "AlchemyPowerfulWizard", false);
-            if (show_asset_id && sPowerfulWizard)
-            {
-                items.push_back(LLStringExplicit("Extras Separator"));
-                items.push_back(LLStringExplicit("Extras Menu"));
-				
-				if (!isItemModifyable())
-				{
-                    disabled_items.push_back(LLStringExplicit("Edit Hex"));
-				}
             }
 		}
 
@@ -1971,12 +1973,24 @@ void LLItemBridge::performAction(LLInventoryModel* model, std::string action)
 	}
     else if ("edit_hex" == action)
     {
-        LLInventoryItem* item = model->getItem(mUUID);
-        if (!item) { return; }
+        LLViewerInventoryItem* item = model->getItem(mUUID);
+		bool is_asset_knowable = false;
+		if (item)
+		{
+			is_asset_knowable = LLAssetType::lookupIsAssetIDKnowable(item->getType());
+		}
+		if (!is_asset_knowable
+			|| (!((item && item->getIsFullPerm()) || gAgent.isGodlikeWithoutAdminMenuFakery())))
+		{
+			is_asset_knowable = false;
+		}
 
-        LLFloaterReg::showInstance("asset_hex_editor",
-                                   LLSD().with("inv_id", item->getUUID())
-			                                 .with("asset_type", item->getActualType()));
+		if (is_asset_knowable)
+		{
+			LLFloaterReg::showInstance("asset_hex_editor",
+				LLSD().with("inv_id", item->getUUID())
+				.with("asset_type", item->getActualType()));
+		}
     }
 }
 
-- 
GitLab