From 250a66dba062f6895bdbd476483f3c8af82a82f1 Mon Sep 17 00:00:00 2001 From: XuuXiao Date: Sat, 10 May 2025 06:32:07 +0100 Subject: [PATCH] added basic item validation with weights --- CHANGELOG.md | 6 ++++++ LethalLib/Modules/Items.cs | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0d350a..0d56459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## LethalLib [1.0.2] + +### Added + +- Validation to scrap and shop items registered with invalid weight values (above 4 and under 1). + ## LethalLib [1.0.1] ### Added diff --git a/LethalLib/Modules/Items.cs b/LethalLib/Modules/Items.cs index 211c427..590aae8 100644 --- a/LethalLib/Modules/Items.cs +++ b/LethalLib/Modules/Items.cs @@ -599,7 +599,6 @@ public ScrapItem(Item item, Dictionary? levelRarities = origItem = item; if (item.isScrap == false) { - item = item.Clone(); item.isScrap = true; if (item.maxValue == 0 && item.minValue == 0) @@ -635,7 +634,6 @@ public ScrapItem(Item item, Dictionary? levelRarities = item.spawnPrefab = newPrefab; } - this.item = item; if (customLevelRarities != null) @@ -730,6 +728,7 @@ public static void RegisterScrap(Item spawnableItem, int rarity, Levels.LevelTyp } scrapItem = new ScrapItem(spawnableItem, rarity, levelFlags); + ValidateItemProperties(scrapItem.item); var callingAssembly = Assembly.GetCallingAssembly(); var modDLL = callingAssembly.GetName().Name; @@ -767,6 +766,7 @@ public static void RegisterScrap(Item spawnableItem, int rarity, Levels.LevelTyp } scrapItem = new ScrapItem(spawnableItem, rarity, levelFlags, levelOverrides); + ValidateItemProperties(scrapItem.item); var callingAssembly = Assembly.GetCallingAssembly(); var modDLL = callingAssembly.GetName().Name; @@ -805,6 +805,7 @@ public static void RegisterScrap(Item spawnableItem, Dictionary 4) + { + Plugin.logger.LogWarning($"Item {item.itemName} has an invalid weight of {item.weight}, resetting to weight of 1, please check the lethal.wiki for how to give an item a valid weight, anything below 1 or above 4 gets reset to 1."); + item.weight = 1; + } + } /// ///Removes a scrap from the given levels. ///This needs to be called after StartOfRound.Awake.