Archipelago.MultiClient.Net.Analyzers 1.3.0

dotnet add package Archipelago.MultiClient.Net.Analyzers --version 1.3.0                
NuGet\Install-Package Archipelago.MultiClient.Net.Analyzers -Version 1.3.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Archipelago.MultiClient.Net.Analyzers" Version="1.3.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Archipelago.MultiClient.Net.Analyzers --version 1.3.0                
#r "nuget: Archipelago.MultiClient.Net.Analyzers, 1.3.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Archipelago.MultiClient.Net.Analyzers as a Cake Addin
#addin nuget:?package=Archipelago.MultiClient.Net.Analyzers&version=1.3.0

// Install Archipelago.MultiClient.Net.Analyzers as a Cake Tool
#tool nuget:?package=Archipelago.MultiClient.Net.Analyzers&version=1.3.0                

Archipelago.MultiClient.Net.Analyzers

Source analyzers, fixes, and code generation for the Archipelago.MultiClient.Net library.

Analyzers and Diagnostics

MULTICLIENT001 - DataStorageElement assigned outside of DataStorageHelper

This warning is intended to prevent bugs which may be caused by misuse of DataStorageHelper. The Archipelago network protocol allows batching several data storage operations in an atomic fashion. In order to support this, DataStorageHelper only sends a packet to the server when a DataStorageElement, containing the batched operations, is re-assigned back to the DataStorageHelper. This means that storing a DataStorageElement into a variable can cause undesirable side effects on the element, as well as prevent it from being sent to the server at all. Instead, it is recommended to use a compound assignment operator to apply edits directly to the DataStorageHelper.

This analyzer also offers a corresponding fix action "Make DataStorage access inline" on variable declarations, which will remove the offending declaration and inline it at all usage sites.

Incorrect Code:

// MULTICLIENT001
DataStorageElement elem = session.DataStorage[Scope.Slot, "MyData"];
elem.Initialize(0);
// This will never make it to the server
elem += 2;

Fixed Code:

session.DataStorage[Scope.Slot, "MyData"].Initialize(0);
// This will make it to the server
session.DataStorage[Scope.Slot, "MyData"] += 2;

MULTICLIENT002 - Use HasFlag when comparing ItemFlags

This warning is intended to prevent bugs when comparing ItemFlags. Because item classification is a flag, an item might have multiple flag values set, such as ItemFlags.Advancement | ItemFlags.Trap. In such scenarios, a comparison like item.Flags == ItemFlags.Advancement does not capture the programmer's intent ("is this item a progression item"). Instead, HasFlag should be used to perform the comparison. ItemFlags.Filler is exempt from this rule because it has the value 0 and HasFlag(0) always returns true.

This analyzer also offers a corresponding fix action "Use HasFlag" on offending comparisons that contain a constant on exactly one side of the comparison. These comparisons will be replaced with a matching HasFlag check.

Incorrect Code:

// MULTICLIENT002
return item.Flags == ItemFlags.Advancement;

Fixed Code:

return item.Flags.HasFlag(ItemFlags.Advancement);

Source Generators

Data Storage Properties

Due to the verbosity of DataStorageHelper's API, it is commonly desirable to assign a DataStorageElement to a variable for repeated access. Unfortunately, this does not work for most use cases, and there is an analyzer to prevent misuse of the API. This package offers a source generator to create a thin wrapper around the data storage API which is also considered an acceptable use by the MULTICLIENT001 analyzer. Note in the example below that you must have a session defined in a scope that is available to members of the containing class - again, this is only a thin wrapper so you have bring your own session.

Example Usage:

partial class MyClass
{
	private ArchipelagoSession session;

	[DataStorageProperty(nameof(session), Scope.Slot, "MyScopedData")]
	private readonly DataStorageElement _myScopedData;

	[DataStorageProperty(nameof(session), "MyGlobalData")]
	private readonly DataStorageElement _myGlobalData;

	public void DoStuff()
	{
		MyScopedData.Initialize(0);
		MyGlobalData += 2;
	}
}
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.0 242 9/22/2024
1.2.0 168 8/25/2024
1.1.0 142 8/17/2024
1.0.0 118 8/12/2024