Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions LethalLib/Modules/Items.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,6 @@
origItem = item;
if (item.isScrap == false)
{

item = item.Clone();
item.isScrap = true;
if (item.maxValue == 0 && item.minValue == 0)
Expand Down Expand Up @@ -635,7 +634,6 @@

item.spawnPrefab = newPrefab;
}

this.item = item;

if (customLevelRarities != null)
Expand Down Expand Up @@ -730,6 +728,7 @@
}

scrapItem = new ScrapItem(spawnableItem, rarity, levelFlags);
ValidateItemProperties(scrapItem.item);

var callingAssembly = Assembly.GetCallingAssembly();
var modDLL = callingAssembly.GetName().Name;
Expand Down Expand Up @@ -767,6 +766,7 @@
}

scrapItem = new ScrapItem(spawnableItem, rarity, levelFlags, levelOverrides);
ValidateItemProperties(scrapItem.item);

var callingAssembly = Assembly.GetCallingAssembly();
var modDLL = callingAssembly.GetName().Name;
Expand All @@ -777,7 +777,7 @@
}

///<summary
///This method registers a scrap item to the game, However it allows you to pass rarity tables, instead of just a single rarity.

Check warning on line 780 in LethalLib/Modules/Items.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'The character(s) ',' cannot be used at this location.'

Check warning on line 780 in LethalLib/Modules/Items.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'Missing equals sign between attribute and attribute value.'

Check warning on line 780 in LethalLib/Modules/Items.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'Missing equals sign between attribute and attribute value.'

Check warning on line 780 in LethalLib/Modules/Items.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'Missing equals sign between attribute and attribute value.'

Check warning on line 780 in LethalLib/Modules/Items.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'Missing equals sign between attribute and attribute value.'

Check warning on line 780 in LethalLib/Modules/Items.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'Missing equals sign between attribute and attribute value.'

Check warning on line 780 in LethalLib/Modules/Items.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'Missing equals sign between attribute and attribute value.'

Check warning on line 780 in LethalLib/Modules/Items.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'Missing equals sign between attribute and attribute value.'

Check warning on line 780 in LethalLib/Modules/Items.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'Missing equals sign between attribute and attribute value.'

Check warning on line 780 in LethalLib/Modules/Items.cs

View workflow job for this annotation

GitHub Actions / Build

XML comment has badly formed XML -- 'Missing equals sign between attribute and attribute value.'
///</summary>
public static void RegisterScrap(Item spawnableItem, Dictionary<Levels.LevelTypes, int>? levelRarities = null, Dictionary<string, int>? customLevelRarities = null)
{
Expand Down Expand Up @@ -805,6 +805,7 @@
}

scrapItem = new ScrapItem(spawnableItem, levelRarities, customLevelRarities);
ValidateItemProperties(scrapItem.item);

var callingAssembly = Assembly.GetCallingAssembly();
var modDLL = callingAssembly.GetName().Name;
Expand All @@ -819,6 +820,8 @@
public static void RegisterShopItem(Item shopItem, TerminalNode buyNode1 = null, TerminalNode buyNode2 = null, TerminalNode itemInfo = null, int price = -1)
{
var item = new ShopItem(shopItem, buyNode1, buyNode2, itemInfo, price);
ValidateItemProperties(item.item);

var callingAssembly = Assembly.GetCallingAssembly();
var modDLL = callingAssembly.GetName().Name;
item.modName = modDLL;
Expand All @@ -832,6 +835,8 @@
public static void RegisterShopItem(Item shopItem, int price = -1)
{
var item = new ShopItem(shopItem, null, null, null, price);
ValidateItemProperties(item.item);

var callingAssembly = Assembly.GetCallingAssembly();
var modDLL = callingAssembly.GetName().Name;
item.modName = modDLL;
Expand All @@ -845,13 +850,26 @@
public static void RegisterItem(Item plainItem)
{
var item = new PlainItem(plainItem);
ValidateItemProperties(item.item);

var callingAssembly = Assembly.GetCallingAssembly();
var modDLL = callingAssembly.GetName().Name;
item.modName = modDLL;

plainItems.Add(item);
}

private static void ValidateItemProperties(Item item)
{
if (item == null)
return;

if (item.weight < 1 || item.weight > 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;
}
}
///<summary>
///Removes a scrap from the given levels.
///This needs to be called after StartOfRound.Awake.
Expand Down