swiftlys2/docs/api/ai/
API Reference Shared

Helper

Class
Namespace: SwiftlyS2.Shared · Assembly: SwiftlyS2.CS2.dll
public static class Helper
Inherits object
View source

Methods

AsProtobuf<T>(nint, bool)

Convert the pointer to the protobuf class.

public static T AsProtobuf<T>(nint ptr, bool manuallyAllocated) where T : ITypedProtobuf<T>
Parameters
  • ptrnintThe pointer to the protobuf class.
  • manuallyAllocatedboolWhether the pointer is manually allocated.
Returns
T
The protobuf class.

AsSchema<T>(nint)

Convert the pointer to the schema class.

public static T AsSchema<T>(nint ptr) where T : ISchemaClass<T>
Parameters
  • ptrnintThe pointer to the schema class.
Returns
T
The schema class.

Colored(string)

Replace the color codes in the text with the corresponding color codes.

public static string Colored(this string text)
Parameters
  • textstringThe text to replace the color codes in.
Returns
The text with the color codes replaced.

EstimateTextWidth(string)

Estimates the display width of a text string based on character types.

public static float EstimateTextWidth(string text)
Parameters
  • textstringThe text string to measure.
Returns
The estimated display width in relative units.

GetCharWidth(char)

Estimates the display width of a character based on its type. Inspired by: https://github.com/spectreconsole/wcwidth

public static float GetCharWidth(char c)
Parameters
  • ccharThe character to measure.
Returns
The estimated display width in relative units.

GetSchemaSize<T>()

Get the size of a schema class.

public static int GetSchemaSize<T>() where T : ISchemaClass<T>
Returns
The size of the schema class.

ParseHexColor(string, bool)

Parses a hex color string and returns the RGBA color components.

public static (int? r, int? g, int? b, int? a) ParseHexColor(string hexColor, bool alphaFirst = false)
Parameters
  • hexColorstringThe hex color string to parse.
  • alphaFirstbooloptionalWhether alpha component comes first (ARGB format). Default is false (RGBA format).
Returns
(int? r, int? g, int? b, int? a)
Color components (R, G, B, A) or nulls if invalid. Alpha defaults to 255 for RGB format.