refactor: consolidate utils
This commit is contained in:
parent
0ed5557be0
commit
f0f002d694
|
@ -1,44 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Numerics;
|
|
||||||
|
|
||||||
namespace XIVChatPlugin {
|
|
||||||
public static class Extensions {
|
|
||||||
public static string ToHexString(this IEnumerable<byte> bytes, bool upper = false, string separator = "") {
|
|
||||||
return string.Join(separator, bytes.Select(b => b.ToString(upper ? "X2" : "x2")));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Vector4> ToColours(this byte[] bytes) {
|
|
||||||
var colours = new List<Vector4>();
|
|
||||||
|
|
||||||
var colour = new Vector4(0f, 0f, 0f, 1f);
|
|
||||||
for (var i = 0; i < bytes.Length; i++) {
|
|
||||||
var idx = i % 3;
|
|
||||||
|
|
||||||
if (i != 0 && idx == 0) {
|
|
||||||
colours.Add(colour);
|
|
||||||
colour = new Vector4(0f, 0f, 0f, 1f);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (idx) {
|
|
||||||
case 0:
|
|
||||||
colour.X = bytes[i] / 255f;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
colour.Y = bytes[i] / 255f;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
colour.Z = bytes[i] / 255f;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ApplicationException("unreachable code reached");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
colours.Add(colour);
|
|
||||||
|
|
||||||
return colours;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +1,46 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
namespace XIVChatPlugin {
|
namespace XIVChatPlugin {
|
||||||
internal static class Util {
|
internal static class Util {
|
||||||
|
public static string ToHexString(this IEnumerable<byte> bytes, bool upper = false, string separator = "") {
|
||||||
|
return string.Join(separator, bytes.Select(b => b.ToString(upper ? "X2" : "x2")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Vector4> ToColours(this byte[] bytes) {
|
||||||
|
var colours = new List<Vector4>();
|
||||||
|
|
||||||
|
var colour = new Vector4(0f, 0f, 0f, 1f);
|
||||||
|
for (var i = 0; i < bytes.Length; i++) {
|
||||||
|
var idx = i % 3;
|
||||||
|
|
||||||
|
if (i != 0 && idx == 0) {
|
||||||
|
colours.Add(colour);
|
||||||
|
colour = new Vector4(0f, 0f, 0f, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (idx) {
|
||||||
|
case 0:
|
||||||
|
colour.X = bytes[i] / 255f;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
colour.Y = bytes[i] / 255f;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
colour.Z = bytes[i] / 255f;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ApplicationException("unreachable code reached");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
colours.Add(colour);
|
||||||
|
|
||||||
|
return colours;
|
||||||
|
}
|
||||||
|
|
||||||
public static int IndexOfCount(this string source, char toFind, int position) {
|
public static int IndexOfCount(this string source, char toFind, int position) {
|
||||||
var index = -1;
|
var index = -1;
|
||||||
for (var i = 0; i < position; i++) {
|
for (var i = 0; i < position; i++) {
|
||||||
|
|
|
@ -31,18 +31,18 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DalamudPackager" Version="1.2.1"/>
|
<PackageReference Include="DalamudPackager" Version="1.2.1" />
|
||||||
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.18.2"/>
|
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.18.2" />
|
||||||
<PackageReference Include="MessagePack" Version="2.2.85"/>
|
<PackageReference Include="MessagePack" Version="2.2.85" />
|
||||||
<PackageReference Include="Sodium.Core" Version="1.2.3"/>
|
<PackageReference Include="Sodium.Core" Version="1.2.3" />
|
||||||
<PackageReference Include="System.Threading.Channels" Version="5.0.0"/>
|
<PackageReference Include="System.Threading.Channels" Version="5.0.0" />
|
||||||
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11"/>
|
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\XIVChatCommon\XIVChatCommon.csproj"/>
|
<ProjectReference Include="..\XIVChatCommon\XIVChatCommon.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Target Name="CopyNativeLibraries" AfterTargets="AfterBuild">
|
<Target Name="CopyNativeLibraries" AfterTargets="AfterBuild">
|
||||||
<Copy SourceFiles="Resources\lib\libsodium.dll" DestinationFolder="$(OutDir)"/>
|
<Copy SourceFiles="Resources\lib\libsodium.dll" DestinationFolder="$(OutDir)" />
|
||||||
<Copy SourceFiles="Resources\lib\xivchat_native_tools.dll" DestinationFolder="$(OutDir)"/>
|
<Copy SourceFiles="Resources\lib\xivchat_native_tools.dll" DestinationFolder="$(OutDir)" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in New Issue