Skip to content

Commit

Permalink
[ProcTypeAPI] Mirror DamageAPI changes to bounds check (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
KingEnderBrine authored Jan 25, 2025
1 parent 150eb3e commit de90674
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion R2API.ProcType/ModdedProcType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public enum ModdedProcType : int
/// Represents an invalid value of <see cref="ModdedProcType"/>.
/// </summary>
/// <remarks>All negative values of <see cref="ModdedProcType"/> are considered invalid.</remarks>
Invalid = -1
Invalid = 0
}
27 changes: 20 additions & 7 deletions R2API.ProcType/ProcTypeAPI.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;
using HG;
Expand Down Expand Up @@ -64,7 +65,9 @@ public static ModdedProcType ReserveProcType()
{
throw new IndexOutOfRangeException($"Reached the ModdedProcType limit ({int.MaxValue})! Please contact R2API developers to increase the limit");
}
return (ModdedProcType)ModdedProcTypeCount++;

ModdedProcTypeCount++;
return (ModdedProcType)ModdedProcTypeCount;
}

/// <summary>
Expand All @@ -73,13 +76,16 @@ public static ModdedProcType ReserveProcType()
/// <exception cref="ArgumentOutOfRangeException"><paramref name="procType"/> is invalid</exception>
public static void AddModdedProc(ref this ProcChainMask procChainMask, ModdedProcType procType)
{
if (procType <= ModdedProcType.Invalid || (int)procType >= ModdedProcTypeCount)
if (procType <= ModdedProcType.Invalid || (int)procType > ModdedProcTypeCount)
{
throw new ArgumentOutOfRangeException(nameof(procType));
ProcTypePlugin.Logger.LogError($"Parameter '{nameof(procType)}' with value {procType} is out of range of registered types (1-{ModdedProcTypeCount})\n{new StackTrace(true)}");
return;
}

SetHooks();

procType--;

byte[] mask = ProcTypeInterop.GetModdedMask(procChainMask);
byte[] value;
int i = (int)procType >> 3;
Expand Down Expand Up @@ -115,12 +121,16 @@ public static void AddModdedProc(ref this ProcChainMask procChainMask, ModdedPro
/// <exception cref="ArgumentOutOfRangeException"><paramref name="procType"/> is invalid</exception>
public static void RemoveModdedProc(ref this ProcChainMask procChainMask, ModdedProcType procType)
{
if (procType <= ModdedProcType.Invalid || (int)procType >= ModdedProcTypeCount)
if (procType <= ModdedProcType.Invalid || (int)procType > ModdedProcTypeCount)
{
throw new ArgumentOutOfRangeException(nameof(procType));
ProcTypePlugin.Logger.LogError($"Parameter '{nameof(procType)}' with value {procType} is out of range of registered types (1-{ModdedProcTypeCount})\n{new StackTrace(true)}");
return;
}

SetHooks();

procType--;

byte[] mask = ProcTypeInterop.GetModdedMask(procChainMask);
if (mask == null)
{
Expand Down Expand Up @@ -178,11 +188,14 @@ public static void RemoveModdedProc(ref this ProcChainMask procChainMask, Modded
public static bool HasModdedProc(this ProcChainMask procChainMask, ModdedProcType procType)
#pragma warning restore R2APISubmodulesAnalyzer // Public API Method is not enabling the hooks if needed.
{
if (procType <= ModdedProcType.Invalid || (int)procType >= ModdedProcTypeCount)
if (procType <= ModdedProcType.Invalid || (int)procType > ModdedProcTypeCount)
{
throw new ArgumentOutOfRangeException(nameof(procType));
ProcTypePlugin.Logger.LogError($"Parameter '{nameof(procType)}' with value {procType} is out of range of registered types (1-{ModdedProcTypeCount})\n{new StackTrace(true)}");
return false;
}

procType--;

byte[] mask = ProcTypeInterop.GetModdedMask(procChainMask);
if (mask == null)
{
Expand Down
3 changes: 3 additions & 0 deletions R2API.ProcType/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ R2API.ProcType patches RoR2.ProcChainMask to store additional data and this data

## Changelog

### '1.0.2'
* Changed bounds check and minimum proc type value to make it easier to notice when using unregistered proc type.

### '1.0.1'
* Fix NuGet package

Expand Down
2 changes: 1 addition & 1 deletion R2API.ProcType/thunderstore.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ schemaVersion = "0.0.1"
[package]
namespace = "RiskofThunder"
name = "R2API_ProcType"
versionNumber = "1.0.1"
versionNumber = "1.0.2"
description = "API for registering proc types"
websiteUrl = "https://github.com/risk-of-thunder/R2API"
containsNsfwContent = false
Expand Down

0 comments on commit de90674

Please sign in to comment.