diff --git a/PKHeX.Core/Editing/Showdown/ShowdownSet.cs b/PKHeX.Core/Editing/Showdown/ShowdownSet.cs
index 62a3ea4fb..952ddf78e 100644
--- a/PKHeX.Core/Editing/Showdown/ShowdownSet.cs
+++ b/PKHeX.Core/Editing/Showdown/ShowdownSet.cs
@@ -10,7 +10,6 @@ namespace PKHeX.Core
///
public sealed class ShowdownSet : IBattleTemplate
{
- private static readonly string[] genders = {"M", "F", ""};
private static readonly string[] StatNames = { "HP", "Atk", "Def", "SpA", "SpD", "Spe" };
private static readonly string[] Splitters = {"\r\n", "\n"};
private static readonly string[] StatSplitters = { " / ", " " };
@@ -268,8 +267,13 @@ private string GetStringFirstLine(string form)
specForm = specForm.Replace("♀", "-F");
string result = GetSpeciesNickname(specForm);
- if (Gender is 0 or 1) // omit genderless or nonspecific
- result += $" ({genders[Gender]})";
+
+ // omit genderless or nonspecific
+ if (Gender is 1)
+ result += " (F)";
+ else if (Gender is 0)
+ result += " (M)";
+
if (HeldItem > 0)
{
var items = Strings.GetItemStrings(Format);
diff --git a/PKHeX.Core/Util/FlagUtil.cs b/PKHeX.Core/Util/FlagUtil.cs
index 17713c850..55fe21222 100644
--- a/PKHeX.Core/Util/FlagUtil.cs
+++ b/PKHeX.Core/Util/FlagUtil.cs
@@ -5,17 +5,31 @@
///
public static class FlagUtil
{
+ ///
+ /// Gets the requested from the byte at .
+ ///
+ /// Buffer to read
+ /// Offset of the byte
+ /// Bit to read
public static bool GetFlag(byte[] arr, int offset, int bitIndex)
{
bitIndex &= 7; // ensure bit access is 0-7
return (arr[offset] >> bitIndex & 1) != 0;
}
+ ///
+ /// Sets the requested value to the byte at .
+ ///
+ /// Buffer to modify
+ /// Offset of the byte
+ /// Bit to write
+ /// Bit flag value to set
public static void SetFlag(byte[] arr, int offset, int bitIndex, bool value)
{
bitIndex &= 7; // ensure bit access is 0-7
- arr[offset] &= (byte)~(1 << bitIndex);
- arr[offset] |= (byte)((value ? 1 : 0) << bitIndex);
+ var current = arr[offset] & ~(1 << bitIndex);
+ var newValue = current | ((value ? 1 : 0) << bitIndex);
+ arr[offset] = (byte)newValue;
}
}
-}
\ No newline at end of file
+}
diff --git a/PKHeX.Core/Util/PathUtil.cs b/PKHeX.Core/Util/PathUtil.cs
index fb7d3453d..d32e852cf 100644
--- a/PKHeX.Core/Util/PathUtil.cs
+++ b/PKHeX.Core/Util/PathUtil.cs
@@ -4,6 +4,10 @@ namespace PKHeX.Core
{
public static partial class Util
{
+ ///
+ /// Cleans the local by removing any invalid filename characters.
+ ///
+ /// New string without any invalid characters.
public static string CleanFileName(string fileName)
{
return string.Concat(fileName.Split(Path.GetInvalidFileNameChars()));
diff --git a/PKHeX.Core/Util/ResourceUtil.cs b/PKHeX.Core/Util/ResourceUtil.cs
index 30a761eec..132adc84f 100644
--- a/PKHeX.Core/Util/ResourceUtil.cs
+++ b/PKHeX.Core/Util/ResourceUtil.cs
@@ -137,6 +137,10 @@ public static bool IsStringListCached(string fileName, out string[] result)
return stringListCache.TryGetValue(fileName, out result);
}
+ ///
+ /// Loads a text into the program with a value of .
+ ///
+ /// Caches the result array for future fetches.
public static string[] LoadStringList(string file, string? txt)
{
if (txt == null)
@@ -144,6 +148,7 @@ public static string[] LoadStringList(string file, string? txt)
string[] raw = txt.Split('\n');
for (int i = 0; i < raw.Length; i++)
{
+ // check for extra trimming; not all resources are "clean" with only \n line breaks.
var line = raw[i];
if (line.Length == 0)
continue;
diff --git a/Tests/PKHeX.Core.Tests/Util/ConvertUtilTests.cs b/Tests/PKHeX.Core.Tests/Util/ConvertUtilTests.cs
index 886c613ae..7239eac45 100644
--- a/Tests/PKHeX.Core.Tests/Util/ConvertUtilTests.cs
+++ b/Tests/PKHeX.Core.Tests/Util/ConvertUtilTests.cs
@@ -73,4 +73,41 @@ public void CheckConvertBCD_Big(uint raw, int expect)
data.SequenceEqual(newData).Should().BeTrue();
}
}
+
+ public class FlagUtilTests
+ {
+ [Theory]
+ [InlineData(1, 0, 0)]
+ [InlineData(2, 0, 1)]
+ [InlineData(0x8000_0000, 3, 7)]
+ public void GetSetFlag(uint raw, int byteIndex, int bitIndex)
+ {
+ var data = BitConverter.GetBytes(raw);
+ var value = Core.FlagUtil.GetFlag(data, byteIndex, bitIndex);
+ value.Should().Be(true);
+
+ var copy = new byte[data.Length];
+ Core.FlagUtil.SetFlag(copy, byteIndex, bitIndex, true);
+ copy.SequenceEqual(data).Should().BeTrue();
+ }
+
+ [Theory]
+ [InlineData(0x7FFF_FFFE, 0, 0)]
+ public void ClearFlag(uint raw, int byteIndex, int bitIndex)
+ {
+ var data = BitConverter.GetBytes(raw);
+ var value = Core.FlagUtil.GetFlag(data, byteIndex, bitIndex);
+ value.Should().Be(false);
+
+ // does nothing on empty
+ var copy = new byte[data.Length];
+ Core.FlagUtil.SetFlag(copy, byteIndex, bitIndex, false);
+ copy.All(z => z == 0).Should().BeTrue();
+
+ // doesn't clear any other flag
+ copy = (byte[])data.Clone();
+ Core.FlagUtil.SetFlag(copy, byteIndex, bitIndex, false);
+ copy.SequenceEqual(data).Should().BeTrue();
+ }
+ }
}