upload
This commit is contained in:
commit
1c7a8cf25f
579 files changed
+83196
No files matched your search
@@ -0,0 +1,5 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public sealed record AngledBar(RectangleF Rect, float Degrees);
|
||||
@@ -0,0 +1,225 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairCode
|
||||
{
|
||||
private const string Prefix = "PXC-";
|
||||
|
||||
private const string Alphabet = "23456789ABCDEFGHJKMNPQRSTUVWXYZ#";
|
||||
|
||||
private const int ShortValueCount = 10;
|
||||
|
||||
private const int LongValueCount = 13;
|
||||
|
||||
private const int LongestValueCount = 18;
|
||||
|
||||
private const int ShortBodyLength = 21;
|
||||
|
||||
private const int LongBodyLength = 27;
|
||||
|
||||
private const int LongestBodyLength = 37;
|
||||
|
||||
private const int ArmTop = 1;
|
||||
|
||||
private const int ArmBottom = 2;
|
||||
|
||||
private const int ArmLeft = 4;
|
||||
|
||||
private const int ArmRight = 8;
|
||||
|
||||
private const int Circle = 16;
|
||||
|
||||
private const int Dot = 32;
|
||||
|
||||
private const int Outline = 64;
|
||||
|
||||
private const int DiagonalArms = 128;
|
||||
|
||||
private const int ChevronArms = 256;
|
||||
|
||||
private const int OffsetBias = 200;
|
||||
|
||||
public static string Encode(CrosshairConfig c)
|
||||
{
|
||||
int resolvedRotationDegrees = c.ResolvedRotationDegrees;
|
||||
int num = 0;
|
||||
if (c.ResolvedArmTop)
|
||||
{
|
||||
num |= 1;
|
||||
}
|
||||
if (c.ResolvedArmBottom)
|
||||
{
|
||||
num |= 2;
|
||||
}
|
||||
if (c.ResolvedArmLeft)
|
||||
{
|
||||
num |= 4;
|
||||
}
|
||||
if (c.ResolvedArmRight)
|
||||
{
|
||||
num |= 8;
|
||||
}
|
||||
if (c.ResolvedShowCircle)
|
||||
{
|
||||
num |= 0x10;
|
||||
}
|
||||
if (c.ResolvedCentreDot)
|
||||
{
|
||||
num |= 0x20;
|
||||
}
|
||||
if (c.Outline)
|
||||
{
|
||||
num |= 0x40;
|
||||
}
|
||||
if (resolvedRotationDegrees == 45)
|
||||
{
|
||||
num |= 0x80;
|
||||
}
|
||||
if (c.Chevron)
|
||||
{
|
||||
num |= 0x100;
|
||||
}
|
||||
int colourArgb = c.ColourArgb;
|
||||
int num2 = c.OutlineThicknessTenths ?? 10;
|
||||
int resolvedOffsetX = c.ResolvedOffsetX;
|
||||
int resolvedOffsetY = c.ResolvedOffsetY;
|
||||
int resolvedDotOpacity = c.ResolvedDotOpacity;
|
||||
int num3 = c.ResolvedOutlineColourArgb & 0xFFFFFF;
|
||||
bool flag = c.Chevron || (resolvedRotationDegrees != 0 && resolvedRotationDegrees != 45) || resolvedDotOpacity != 100 || num3 != 0;
|
||||
bool flag2 = flag || resolvedRotationDegrees == 45 || num2 != 10 || resolvedOffsetX != 0 || resolvedOffsetY != 0;
|
||||
int[] array = new int[18]
|
||||
{
|
||||
num,
|
||||
Tenths(c.ResolvedSize),
|
||||
Tenths(c.ResolvedThickness),
|
||||
Tenths(c.ResolvedGap),
|
||||
Tenths(c.ResolvedDotSize),
|
||||
Tenths(c.ResolvedCircleRadius),
|
||||
Math.Clamp(c.Opacity, 0, 100),
|
||||
(colourArgb >> 16) & 0xFF,
|
||||
(colourArgb >> 8) & 0xFF,
|
||||
colourArgb & 0xFF,
|
||||
Math.Clamp(num2, 0, 40),
|
||||
resolvedOffsetX + 200,
|
||||
resolvedOffsetY + 200,
|
||||
resolvedRotationDegrees,
|
||||
resolvedDotOpacity,
|
||||
(num3 >> 16) & 0xFF,
|
||||
(num3 >> 8) & 0xFF,
|
||||
num3 & 0xFF
|
||||
};
|
||||
int num4;
|
||||
if (flag)
|
||||
{
|
||||
num4 = 18;
|
||||
}
|
||||
else
|
||||
{
|
||||
num4 = (flag2 ? 13 : 10);
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder(num4 * 2 + 1);
|
||||
int[] subArray = array[..num4];
|
||||
for (int i = 0; i < subArray.Length; i++)
|
||||
{
|
||||
int num5 = Math.Clamp(subArray[i], 0, 1023);
|
||||
stringBuilder.Append("23456789ABCDEFGHJKMNPQRSTUVWXYZ#"[num5 / 32]);
|
||||
stringBuilder.Append("23456789ABCDEFGHJKMNPQRSTUVWXYZ#"[num5 % 32]);
|
||||
}
|
||||
stringBuilder.Append("23456789ABCDEFGHJKMNPQRSTUVWXYZ#"[Checksum(stringBuilder.ToString())]);
|
||||
return "PXC-" + stringBuilder;
|
||||
}
|
||||
|
||||
public static bool TryDecode(string? code, out CrosshairConfig crosshair)
|
||||
{
|
||||
crosshair = new CrosshairConfig();
|
||||
if (string.IsNullOrWhiteSpace(code))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text = ShareCodeText.Normalize(code).Trim().ToUpperInvariant();
|
||||
if (!text.StartsWith("PXC-", StringComparison.Ordinal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
string text2 = text.Substring("PXC-".Length);
|
||||
int num = text2.Length switch
|
||||
{
|
||||
21 => 10,
|
||||
27 => 13,
|
||||
37 => 18,
|
||||
_ => 0,
|
||||
};
|
||||
if (num == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int[] array = new int[text2.Length];
|
||||
for (int i = 0; i < text2.Length; i++)
|
||||
{
|
||||
array[i] = "23456789ABCDEFGHJKMNPQRSTUVWXYZ#".IndexOf(text2[i]);
|
||||
if (array[i] < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (array[num * 2] != Checksum(text2.Substring(0, num * 2)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int[] array2 = new int[num];
|
||||
for (int j = 0; j < num; j++)
|
||||
{
|
||||
array2[j] = array[j * 2] * 32 + array[j * 2 + 1];
|
||||
}
|
||||
int num2 = array2[0];
|
||||
crosshair = new CrosshairConfig
|
||||
{
|
||||
ArmTop = ((num2 & 1) != 0),
|
||||
ArmBottom = ((num2 & 2) != 0),
|
||||
ArmLeft = ((num2 & 4) != 0),
|
||||
ArmRight = ((num2 & 8) != 0),
|
||||
ShowCircle = ((num2 & 0x10) != 0),
|
||||
CentreDot = ((num2 & 0x20) != 0),
|
||||
Outline = ((num2 & 0x40) != 0),
|
||||
Diagonal = ((num2 & 0x80) != 0),
|
||||
Opacity = Math.Clamp(array2[6], 10, 100),
|
||||
ColourArgb = (-16777216 | ((array2[7] & 0xFF) << 16) | ((array2[8] & 0xFF) << 8) | (array2[9] & 0xFF))
|
||||
};
|
||||
crosshair.SetSizeTenths(Math.Clamp(array2[1], 5, 300));
|
||||
crosshair.SetThicknessTenths(Math.Clamp(array2[2], 5, 100));
|
||||
crosshair.SetGapTenths(Math.Clamp(array2[3], 0, 300));
|
||||
crosshair.DotSizeTenths = Math.Clamp(array2[4], 5, 100);
|
||||
crosshair.CircleRadiusTenths = Math.Clamp(array2[5], 10, 400);
|
||||
if (num >= 13)
|
||||
{
|
||||
crosshair.OutlineThicknessTenths = Math.Clamp(array2[10], 0, 40);
|
||||
crosshair.OffsetXPx = Math.Clamp(array2[11] - 200, -200, 200);
|
||||
crosshair.OffsetYPx = Math.Clamp(array2[12] - 200, -200, 200);
|
||||
}
|
||||
if (num == 18)
|
||||
{
|
||||
crosshair.Chevron = (num2 & 0x100) != 0;
|
||||
crosshair.SetRotationDegrees(Math.Clamp(array2[13], 0, 90));
|
||||
crosshair.DotOpacity = Math.Clamp(array2[14], 10, 100);
|
||||
crosshair.OutlineColourRgb = ((array2[15] & 0xFF) << 16) | ((array2[16] & 0xFF) << 8) | (array2[17] & 0xFF);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int Tenths(float value)
|
||||
{
|
||||
return Math.Clamp((int)Math.Round(value * 10f), 0, 1023);
|
||||
}
|
||||
|
||||
private static int Checksum(string body)
|
||||
{
|
||||
int num = 0;
|
||||
for (int i = 0; i < body.Length; i++)
|
||||
{
|
||||
num += ("23456789ABCDEFGHJKMNPQRSTUVWXYZ#".IndexOf(body[i]) + 1) * (2 * i + 1);
|
||||
}
|
||||
return num % 32;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
using System;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public sealed class CrosshairConfig
|
||||
{
|
||||
public const int MaxOffsetPx = 200;
|
||||
|
||||
public string Name { get; set; } = "New crosshair";
|
||||
|
||||
public CrosshairShape Shape { get; set; }
|
||||
|
||||
public bool? ArmTop { get; set; }
|
||||
|
||||
public bool? ArmBottom { get; set; }
|
||||
|
||||
public bool? ArmLeft { get; set; }
|
||||
|
||||
public bool? ArmRight { get; set; }
|
||||
|
||||
public bool? ShowCircle { get; set; }
|
||||
|
||||
public bool Diagonal { get; set; }
|
||||
|
||||
public int? DotSizeTenths { get; set; }
|
||||
|
||||
public int? CircleRadiusTenths { get; set; }
|
||||
|
||||
public int Opacity { get; set; } = 100;
|
||||
|
||||
private bool LegacyHasArms
|
||||
{
|
||||
get
|
||||
{
|
||||
CrosshairShape shape = Shape;
|
||||
if (shape == CrosshairShape.Cross || shape == CrosshairShape.T)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ResolvedArmTop => ArmFrom(ArmTop, Shape == CrosshairShape.Cross);
|
||||
|
||||
public bool ResolvedArmBottom => ArmFrom(ArmBottom, LegacyHasArms);
|
||||
|
||||
public bool ResolvedArmLeft => ArmFrom(ArmLeft, LegacyHasArms);
|
||||
|
||||
public bool ResolvedArmRight => ArmFrom(ArmRight, LegacyHasArms);
|
||||
|
||||
public bool ResolvedShowCircle => ShowCircle ?? (Shape == CrosshairShape.Circle);
|
||||
|
||||
public bool ResolvedCentreDot
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!CentreDot)
|
||||
{
|
||||
return Shape == CrosshairShape.Dot;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public float ResolvedDotSize => (float)(DotSizeTenths ?? ((int)Math.Round(ResolvedThickness * 10f))) / 10f;
|
||||
|
||||
public float ResolvedCircleRadius => (float)(CircleRadiusTenths ?? ((int)Math.Round((ResolvedGap + ResolvedSize) * 10f))) / 10f;
|
||||
|
||||
public int ResolvedColourArgb
|
||||
{
|
||||
get
|
||||
{
|
||||
int num = (byte)((ColourArgb >> 24) & 0xFF) * Math.Clamp(Opacity, 0, 100) / 100;
|
||||
return (ColourArgb & 0xFFFFFF) | (num << 24);
|
||||
}
|
||||
}
|
||||
|
||||
public int ColourArgb { get; set; } = -16711834;
|
||||
|
||||
public int Size { get; set; } = 8;
|
||||
|
||||
public int Thickness { get; set; } = 2;
|
||||
|
||||
public int Gap { get; set; } = 4;
|
||||
|
||||
public int? SizeTenths { get; set; }
|
||||
|
||||
public int? ThicknessTenths { get; set; }
|
||||
|
||||
public int? GapTenths { get; set; }
|
||||
|
||||
public float ResolvedSize => (float)(SizeTenths ?? (Size * 10)) / 10f;
|
||||
|
||||
public float ResolvedThickness => (float)(ThicknessTenths ?? (Thickness * 10)) / 10f;
|
||||
|
||||
public float ResolvedGap => (float)(GapTenths ?? (Gap * 10)) / 10f;
|
||||
|
||||
public bool Outline { get; set; } = true;
|
||||
|
||||
public int? OutlineThicknessTenths { get; set; }
|
||||
|
||||
public float ResolvedOutlineThickness
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Outline)
|
||||
{
|
||||
return (float)(OutlineThicknessTenths ?? 10) / 10f;
|
||||
}
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public int? OffsetXPx { get; set; }
|
||||
|
||||
public int? OffsetYPx { get; set; }
|
||||
|
||||
public int ResolvedOffsetX => Clamp(OffsetXPx);
|
||||
|
||||
public int ResolvedOffsetY => Clamp(OffsetYPx);
|
||||
|
||||
public bool CentreDot { get; set; }
|
||||
|
||||
public bool Chevron { get; set; }
|
||||
|
||||
public int? RotationDegrees { get; set; }
|
||||
|
||||
public int ResolvedRotationDegrees => Math.Clamp(RotationDegrees ?? (Diagonal ? 45 : 0), 0, 90);
|
||||
|
||||
public int? DotOpacity { get; set; }
|
||||
|
||||
public int ResolvedDotOpacity => Math.Clamp(DotOpacity ?? 100, 10, 100);
|
||||
|
||||
public int ResolvedDotColourArgb
|
||||
{
|
||||
get
|
||||
{
|
||||
int resolvedColourArgb = ResolvedColourArgb;
|
||||
int num = ((resolvedColourArgb >> 24) & 0xFF) * ResolvedDotOpacity / 100;
|
||||
return (resolvedColourArgb & 0xFFFFFF) | (num << 24);
|
||||
}
|
||||
}
|
||||
|
||||
public int? OutlineColourRgb { get; set; }
|
||||
|
||||
public int ResolvedOutlineColourArgb => -1107296256 | (OutlineColourRgb.GetValueOrDefault() & 0xFFFFFF);
|
||||
|
||||
public string? ImagePath { get; set; }
|
||||
|
||||
public int ImageScalePercent { get; set; } = 100;
|
||||
|
||||
public bool UsesImage => ImageCrosshair.Load(ImagePath) != null;
|
||||
|
||||
private bool ArmFrom(bool? saved, bool legacyDefault)
|
||||
{
|
||||
return saved ?? legacyDefault;
|
||||
}
|
||||
|
||||
public void SetSizeTenths(int tenths)
|
||||
{
|
||||
SizeTenths = tenths;
|
||||
Size = LegacyPixels(tenths, 1);
|
||||
}
|
||||
|
||||
public void SetThicknessTenths(int tenths)
|
||||
{
|
||||
ThicknessTenths = tenths;
|
||||
Thickness = LegacyPixels(tenths, 1);
|
||||
}
|
||||
|
||||
public void SetGapTenths(int tenths)
|
||||
{
|
||||
GapTenths = tenths;
|
||||
Gap = LegacyPixels(tenths, 0);
|
||||
}
|
||||
|
||||
private static int LegacyPixels(int tenths, int floor)
|
||||
{
|
||||
return Math.Max(floor, (int)Math.Round((double)tenths / 10.0, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
private static int Clamp(int? value)
|
||||
{
|
||||
return Math.Clamp(value.GetValueOrDefault(), -200, 200);
|
||||
}
|
||||
|
||||
public void SetRotationDegrees(int degrees)
|
||||
{
|
||||
int num = Math.Clamp(degrees, 0, 90);
|
||||
RotationDegrees = num;
|
||||
Diagonal = num > 22 && num < 68;
|
||||
}
|
||||
|
||||
public CrosshairConfig Clone()
|
||||
{
|
||||
return (CrosshairConfig)MemberwiseClone();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using VibranceHud.Licensing;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairGallery
|
||||
{
|
||||
public enum Family
|
||||
{
|
||||
Dot,
|
||||
X,
|
||||
Ring,
|
||||
Cross,
|
||||
Funny
|
||||
}
|
||||
|
||||
public sealed record GalleryItem(string Id, string Name, Family Group, CrosshairConfig Config);
|
||||
|
||||
public static IReadOnlyList<GalleryItem> All => ServedCrosshairs.Designs;
|
||||
|
||||
public static void Apply(CrosshairConfig target, GalleryItem item)
|
||||
{
|
||||
CrosshairConfig config = item.Config;
|
||||
target.ArmTop = config.ResolvedArmTop;
|
||||
target.ArmBottom = config.ResolvedArmBottom;
|
||||
target.ArmLeft = config.ResolvedArmLeft;
|
||||
target.ArmRight = config.ResolvedArmRight;
|
||||
target.CentreDot = config.ResolvedCentreDot;
|
||||
target.DotSizeTenths = config.DotSizeTenths;
|
||||
target.ShowCircle = config.ResolvedShowCircle;
|
||||
target.CircleRadiusTenths = config.CircleRadiusTenths;
|
||||
target.Diagonal = config.Diagonal;
|
||||
target.RotationDegrees = config.RotationDegrees;
|
||||
target.Chevron = config.Chevron;
|
||||
target.SetSizeTenths(config.SizeTenths ?? 80);
|
||||
target.SetThicknessTenths(config.ThicknessTenths ?? 20);
|
||||
target.SetGapTenths(config.GapTenths ?? 40);
|
||||
bool flag = !config.ResolvedArmTop && !config.ResolvedArmBottom && !config.ResolvedArmLeft && !config.ResolvedArmRight;
|
||||
target.Shape = ((config.ResolvedShowCircle && !config.ResolvedArmLeft) ? CrosshairShape.Circle : (flag ? CrosshairShape.Dot : ((!config.ResolvedArmTop) ? CrosshairShape.T : CrosshairShape.Cross)));
|
||||
}
|
||||
|
||||
public static GalleryItem? Matching(CrosshairConfig c)
|
||||
{
|
||||
return All.FirstOrDefault((GalleryItem item) => item.Config.ResolvedArmTop == c.ResolvedArmTop && item.Config.ResolvedArmBottom == c.ResolvedArmBottom && item.Config.ResolvedArmLeft == c.ResolvedArmLeft && item.Config.ResolvedArmRight == c.ResolvedArmRight && item.Config.ResolvedCentreDot == c.ResolvedCentreDot && item.Config.ResolvedShowCircle == c.ResolvedShowCircle && item.Config.ResolvedRotationDegrees == c.ResolvedRotationDegrees && item.Config.Chevron == c.Chevron && Near(item.Config.ResolvedSize, c.ResolvedSize) && Near(item.Config.ResolvedThickness, c.ResolvedThickness) && Near(item.Config.ResolvedGap, c.ResolvedGap) && (!c.ResolvedCentreDot || Near(item.Config.ResolvedDotSize, c.ResolvedDotSize)) && (!c.ResolvedShowCircle || Near(item.Config.ResolvedCircleRadius, c.ResolvedCircleRadius)));
|
||||
}
|
||||
|
||||
private static bool Near(float a, float b)
|
||||
{
|
||||
return Math.Abs(a - b) < 0.05f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairGeometry
|
||||
{
|
||||
public const float ChevronDegrees = 45f;
|
||||
|
||||
private const float AntiAliasMargin = 1f;
|
||||
|
||||
public static CrosshairShapes Build(CrosshairConfig c)
|
||||
{
|
||||
float num = Math.Max(0.5f, c.ResolvedThickness);
|
||||
float num2 = Math.Max(0.5f, c.ResolvedSize);
|
||||
float num3 = Math.Max(0f, c.ResolvedGap);
|
||||
float num4 = num / 2f;
|
||||
List<RectangleF> list = new List<RectangleF>();
|
||||
List<AngledBar> list2 = new List<AngledBar>();
|
||||
RectangleF? circle = null;
|
||||
RectangleF rectangleF = new RectangleF(0f - (num3 + num2), 0f - num4, num2, num);
|
||||
RectangleF rectangleF2 = new RectangleF(num3, 0f - num4, num2, num);
|
||||
if (c.ResolvedArmLeft)
|
||||
{
|
||||
if (c.Chevron)
|
||||
{
|
||||
list2.Add(new AngledBar(rectangleF, -45f));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(rectangleF);
|
||||
}
|
||||
}
|
||||
if (c.ResolvedArmRight)
|
||||
{
|
||||
if (c.Chevron)
|
||||
{
|
||||
list2.Add(new AngledBar(rectangleF2, 45f));
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(rectangleF2);
|
||||
}
|
||||
}
|
||||
if (c.ResolvedArmBottom)
|
||||
{
|
||||
list.Add(new RectangleF(0f - num4, num3, num, num2));
|
||||
}
|
||||
if (c.ResolvedArmTop)
|
||||
{
|
||||
list.Add(new RectangleF(0f - num4, 0f - (num3 + num2), num, num2));
|
||||
}
|
||||
if (c.Chevron && c.ResolvedArmLeft && c.ResolvedArmRight && num3 <= 0f)
|
||||
{
|
||||
list2.Add(new AngledBar(new RectangleF(0f - num4, 0f - num4, num, num), 45f));
|
||||
}
|
||||
if (c.ResolvedShowCircle)
|
||||
{
|
||||
float num5 = Math.Max(0.5f, c.ResolvedCircleRadius);
|
||||
circle = new RectangleF(0f - num5, 0f - num5, num5 * 2f, num5 * 2f);
|
||||
}
|
||||
int dotIndex = -1;
|
||||
if (c.ResolvedCentreDot)
|
||||
{
|
||||
float num6 = Math.Max(0.5f, c.ResolvedDotSize);
|
||||
list.Add(new RectangleF((0f - num6) / 2f, (0f - num6) / 2f, num6, num6));
|
||||
dotIndex = list.Count - 1;
|
||||
}
|
||||
int resolvedOffsetX = c.ResolvedOffsetX;
|
||||
int resolvedOffsetY = c.ResolvedOffsetY;
|
||||
if (resolvedOffsetX != 0 || resolvedOffsetY != 0)
|
||||
{
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
list[i] = Offset(list[i], resolvedOffsetX, resolvedOffsetY);
|
||||
}
|
||||
for (int j = 0; j < list2.Count; j++)
|
||||
{
|
||||
list2[j] = list2[j] with
|
||||
{
|
||||
Rect = Offset(list2[j].Rect, resolvedOffsetX, resolvedOffsetY)
|
||||
};
|
||||
}
|
||||
if (circle.HasValue)
|
||||
{
|
||||
RectangleF valueOrDefault = circle.GetValueOrDefault();
|
||||
circle = Offset(valueOrDefault, resolvedOffsetX, resolvedOffsetY);
|
||||
}
|
||||
}
|
||||
PointF pivot = new PointF(resolvedOffsetX, resolvedOffsetY);
|
||||
float num7 = c.ResolvedRotationDegrees;
|
||||
return new CrosshairShapes(list, circle, Bounds(list, circle, list2, pivot, 0f, 0f))
|
||||
{
|
||||
Angled = list2,
|
||||
DotIndex = dotIndex,
|
||||
RotationDegrees = num7,
|
||||
Pivot = pivot,
|
||||
DrawnBounds = Bounds(list, circle, list2, pivot, num7, 0f)
|
||||
};
|
||||
}
|
||||
|
||||
public static Size OverlaySize(CrosshairConfig c)
|
||||
{
|
||||
Bitmap bitmap = ImageCrosshair.Load(c.ImagePath);
|
||||
if (bitmap != null)
|
||||
{
|
||||
float num = (float)Math.Max(1, c.ImageScalePercent) / 100f;
|
||||
float num2 = (float)bitmap.Width * num + (float)(Math.Abs(c.ResolvedOffsetX) * 2);
|
||||
float num3 = (float)bitmap.Height * num + (float)(Math.Abs(c.ResolvedOffsetY) * 2);
|
||||
float num4 = c.ResolvedOutlineThickness * 2f + 4f;
|
||||
return new Size(Math.Max(8, (int)Math.Ceiling(num2 + num4)), Math.Max(8, (int)Math.Ceiling(num3 + num4)));
|
||||
}
|
||||
CrosshairShapes crosshairShapes = Build(c);
|
||||
float num5 = crosshairShapes.Bounds.Width;
|
||||
float num6 = crosshairShapes.Bounds.Height;
|
||||
if (c.Diagonal)
|
||||
{
|
||||
num5 *= 1.4142f;
|
||||
num6 *= 1.4142f;
|
||||
}
|
||||
num5 += (float)(Math.Abs(c.ResolvedOffsetX) * 2);
|
||||
num6 += (float)(Math.Abs(c.ResolvedOffsetY) * 2);
|
||||
float num7 = c.ResolvedOutlineThickness * 2f + 4f;
|
||||
int val = (int)Math.Ceiling(num5 + num7);
|
||||
int val2 = (int)Math.Ceiling(num6 + num7);
|
||||
float resolvedOutlineThickness = c.ResolvedOutlineThickness;
|
||||
float ringGrow = ((!crosshairShapes.Circle.HasValue) ? 0f : (Math.Max(0.5f, c.ResolvedThickness) / 2f + resolvedOutlineThickness));
|
||||
RectangleF rectangleF = Bounds(crosshairShapes.Bars, crosshairShapes.Circle, crosshairShapes.Angled, crosshairShapes.Pivot, crosshairShapes.RotationDegrees, resolvedOutlineThickness, ringGrow);
|
||||
float num8 = Math.Max(Math.Abs(rectangleF.Left), Math.Abs(rectangleF.Right)) + 1f;
|
||||
float num9 = Math.Max(Math.Abs(rectangleF.Top), Math.Abs(rectangleF.Bottom)) + 1f;
|
||||
return new Size(Math.Max(8, Math.Max(val, (int)Math.Ceiling(num8 * 2f))), Math.Max(8, Math.Max(val2, (int)Math.Ceiling(num9 * 2f))));
|
||||
}
|
||||
|
||||
private static RectangleF Offset(RectangleF r, float dx, float dy)
|
||||
{
|
||||
return new RectangleF(r.X + dx, r.Y + dy, r.Width, r.Height);
|
||||
}
|
||||
|
||||
private static RectangleF Bounds(IReadOnlyList<RectangleF> bars, RectangleF? circle, IReadOnlyList<AngledBar> angled, PointF pivot, float rotation, float grow, float ringGrow = 0f)
|
||||
{
|
||||
if (bars.Count == 0 && !circle.HasValue && angled.Count == 0)
|
||||
{
|
||||
return RectangleF.Empty;
|
||||
}
|
||||
float minX = float.MaxValue;
|
||||
float minY = float.MaxValue;
|
||||
float maxX = float.MinValue;
|
||||
float maxY = float.MinValue;
|
||||
foreach (RectangleF bar in bars)
|
||||
{
|
||||
Take(bar, rotation);
|
||||
}
|
||||
foreach (AngledBar item3 in angled)
|
||||
{
|
||||
Take(item3.Rect, rotation + item3.Degrees);
|
||||
}
|
||||
if (circle.HasValue)
|
||||
{
|
||||
RectangleF valueOrDefault = circle.GetValueOrDefault();
|
||||
RectangleF rectangleF = ((ringGrow > 0f) ? RectangleF.Inflate(valueOrDefault, ringGrow, ringGrow) : valueOrDefault);
|
||||
TakePoint(rectangleF.Left, rectangleF.Top);
|
||||
TakePoint(rectangleF.Right, rectangleF.Bottom);
|
||||
}
|
||||
return new RectangleF(minX, minY, maxX - minX, maxY - minY);
|
||||
void Take(RectangleF r, float degrees)
|
||||
{
|
||||
RectangleF rectangleF2 = ((grow > 0f) ? RectangleF.Inflate(r, grow, grow) : r);
|
||||
if (degrees == 0f)
|
||||
{
|
||||
TakePoint(rectangleF2.Left, rectangleF2.Top);
|
||||
TakePoint(rectangleF2.Right, rectangleF2.Bottom);
|
||||
}
|
||||
else
|
||||
{
|
||||
double num = (double)degrees * Math.PI / 180.0;
|
||||
double num2 = Math.Cos(num);
|
||||
double num3 = Math.Sin(num);
|
||||
(float, float)[] array = new (float, float)[4]
|
||||
{
|
||||
(rectangleF2.Left, rectangleF2.Top),
|
||||
(rectangleF2.Right, rectangleF2.Top),
|
||||
(rectangleF2.Right, rectangleF2.Bottom),
|
||||
(rectangleF2.Left, rectangleF2.Bottom)
|
||||
};
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
(float, float) tuple = array[i];
|
||||
float item = tuple.Item1;
|
||||
float item2 = tuple.Item2;
|
||||
double num4 = item - pivot.X;
|
||||
double num5 = item2 - pivot.Y;
|
||||
TakePoint((float)((double)pivot.X + num4 * num2 - num5 * num3), (float)((double)pivot.Y + num4 * num3 + num5 * num2));
|
||||
}
|
||||
}
|
||||
}
|
||||
void TakePoint(float x, float y)
|
||||
{
|
||||
minX = Math.Min(minX, x);
|
||||
minY = Math.Min(minY, y);
|
||||
maxX = Math.Max(maxX, x);
|
||||
maxY = Math.Max(maxY, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairLimits
|
||||
{
|
||||
public const int MinSizeTenths = 5;
|
||||
|
||||
public const int MaxSizeTenths = 300;
|
||||
|
||||
public const int DefaultSizeTenths = 80;
|
||||
|
||||
public const int MinThicknessTenths = 5;
|
||||
|
||||
public const int MaxThicknessTenths = 100;
|
||||
|
||||
public const int DefaultThicknessTenths = 20;
|
||||
|
||||
public const int MinGapTenths = 0;
|
||||
|
||||
public const int MaxGapTenths = 300;
|
||||
|
||||
public const int DefaultGapTenths = 40;
|
||||
|
||||
public const int MinDotTenths = 5;
|
||||
|
||||
public const int MaxDotTenths = 100;
|
||||
|
||||
public const int MinRingTenths = 10;
|
||||
|
||||
public const int MaxRingTenths = 400;
|
||||
|
||||
public const int MinOpacity = 10;
|
||||
|
||||
public const int MaxOpacity = 100;
|
||||
|
||||
public const int DefaultOpacity = 100;
|
||||
|
||||
public const int MinOutlineTenths = 0;
|
||||
|
||||
public const int MaxOutlineTenths = 40;
|
||||
|
||||
public const int DefaultOutlineTenths = 10;
|
||||
|
||||
public const int MinImageScale = 25;
|
||||
|
||||
public const int MaxImageScale = 400;
|
||||
|
||||
public const int MinRotationDegrees = 0;
|
||||
|
||||
public const int MaxRotationDegrees = 90;
|
||||
|
||||
public const int DefaultRotationDegrees = 0;
|
||||
|
||||
public const int MinDotOpacity = 10;
|
||||
|
||||
public const int MaxDotOpacity = 100;
|
||||
|
||||
public const int DefaultDotOpacity = 100;
|
||||
|
||||
public const int DefaultOutlineColourRgb = 0;
|
||||
|
||||
public const int OutlineAlpha = 190;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairPresets
|
||||
{
|
||||
public const int White = -1;
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairRender
|
||||
{
|
||||
private static readonly int ClassicOutlineArgb = -1107296256;
|
||||
|
||||
public static void Draw(Graphics g, CrosshairConfig config)
|
||||
{
|
||||
Bitmap bitmap = ImageCrosshair.Load(config.ImagePath);
|
||||
if (bitmap != null)
|
||||
{
|
||||
DrawImage(g, config, bitmap);
|
||||
return;
|
||||
}
|
||||
CrosshairShapes shapes = CrosshairGeometry.Build(config);
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
Color color = Color.FromArgb(config.ResolvedColourArgb);
|
||||
SolidBrush fill = new SolidBrush(color);
|
||||
try
|
||||
{
|
||||
int resolvedOutlineColourArgb = config.ResolvedOutlineColourArgb;
|
||||
Color color2 = Color.FromArgb(resolvedOutlineColourArgb);
|
||||
SolidBrush halo = new SolidBrush(color2);
|
||||
try
|
||||
{
|
||||
bool hasDot = shapes.DotIndex >= 0;
|
||||
bool fadedDot = hasDot && config.ResolvedDotOpacity < 100;
|
||||
SolidBrush dotFill = new SolidBrush(Color.FromArgb(config.ResolvedDotColourArgb));
|
||||
try
|
||||
{
|
||||
SolidBrush dotHalo = new SolidBrush(Color.FromArgb(color2.A * config.ResolvedDotOpacity / 100, color2.R, color2.G, color2.B));
|
||||
try
|
||||
{
|
||||
float outline = config.ResolvedOutlineThickness;
|
||||
float num = Math.Max(0.5f, config.ResolvedThickness);
|
||||
if (outline > 0f)
|
||||
{
|
||||
bool oneShape = resolvedOutlineColourArgb != ClassicOutlineArgb || shapes.Angled.Count > 0;
|
||||
GraphicsPath armsOutline = ((oneShape | fadedDot) ? Arms(shapes, outline, oneShape && !fadedDot) : null);
|
||||
try
|
||||
{
|
||||
Turned(g, shapes.Pivot, shapes.RotationDegrees, () =>
|
||||
{
|
||||
if (oneShape)
|
||||
{
|
||||
g.FillPath(halo, armsOutline);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < shapes.Bars.Count; i++)
|
||||
{
|
||||
if (i != shapes.DotIndex)
|
||||
{
|
||||
g.FillRectangle(halo, RectangleF.Inflate(shapes.Bars[i], outline, outline));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasDot)
|
||||
{
|
||||
RectangleF rect = RectangleF.Inflate(shapes.Bars[shapes.DotIndex], outline, outline);
|
||||
if (fadedDot)
|
||||
{
|
||||
GraphicsState gstate = g.Save();
|
||||
g.SetClip(armsOutline, CombineMode.Exclude);
|
||||
g.FillRectangle(dotHalo, rect);
|
||||
g.Restore(gstate);
|
||||
}
|
||||
else if (!oneShape)
|
||||
{
|
||||
g.FillRectangle(halo, rect);
|
||||
}
|
||||
}
|
||||
});
|
||||
RectangleF? circle = shapes.Circle;
|
||||
if (circle.HasValue)
|
||||
{
|
||||
RectangleF valueOrDefault = circle.GetValueOrDefault();
|
||||
using Pen pen = new Pen(color2, num + outline * 2f);
|
||||
g.DrawEllipse(pen, valueOrDefault);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (armsOutline != null)
|
||||
{
|
||||
((IDisposable)armsOutline).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
GraphicsPath armsFill = Arms(shapes, 0f, withDot: false);
|
||||
try
|
||||
{
|
||||
Turned(g, shapes.Pivot, shapes.RotationDegrees, () =>
|
||||
{
|
||||
g.FillPath(fill, armsFill);
|
||||
if (hasDot)
|
||||
{
|
||||
g.FillRectangle(dotFill, shapes.Bars[shapes.DotIndex]);
|
||||
}
|
||||
});
|
||||
RectangleF? circle = shapes.Circle;
|
||||
if (circle.HasValue)
|
||||
{
|
||||
RectangleF valueOrDefault2 = circle.GetValueOrDefault();
|
||||
using Pen pen2 = new Pen(color, num);
|
||||
g.DrawEllipse(pen2, valueOrDefault2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (armsFill != null)
|
||||
{
|
||||
((IDisposable)armsFill).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (dotHalo != null)
|
||||
{
|
||||
((IDisposable)dotHalo).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (dotFill != null)
|
||||
{
|
||||
((IDisposable)dotFill).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (halo != null)
|
||||
{
|
||||
((IDisposable)halo).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (fill != null)
|
||||
{
|
||||
((IDisposable)fill).Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static GraphicsPath Arms(CrosshairShapes shapes, float grow, bool withDot)
|
||||
{
|
||||
GraphicsPath graphicsPath = new GraphicsPath(FillMode.Winding);
|
||||
for (int i = 0; i < shapes.Bars.Count; i++)
|
||||
{
|
||||
if (i != shapes.DotIndex || withDot)
|
||||
{
|
||||
graphicsPath.AddRectangle((grow > 0f) ? RectangleF.Inflate(shapes.Bars[i], grow, grow) : shapes.Bars[i]);
|
||||
}
|
||||
}
|
||||
foreach (AngledBar item in shapes.Angled)
|
||||
{
|
||||
using GraphicsPath graphicsPath2 = new GraphicsPath(FillMode.Winding);
|
||||
graphicsPath2.AddRectangle((grow > 0f) ? RectangleF.Inflate(item.Rect, grow, grow) : item.Rect);
|
||||
using Matrix matrix = new Matrix();
|
||||
matrix.RotateAt(item.Degrees, shapes.Pivot);
|
||||
graphicsPath2.Transform(matrix);
|
||||
graphicsPath.AddPath(graphicsPath2, connect: false);
|
||||
}
|
||||
return graphicsPath;
|
||||
}
|
||||
|
||||
private static void Turned(Graphics g, PointF pivot, float degrees, Action draw)
|
||||
{
|
||||
if (degrees == 0f)
|
||||
{
|
||||
draw();
|
||||
return;
|
||||
}
|
||||
GraphicsState gstate = g.Save();
|
||||
int num;
|
||||
if (pivot.X == 0f)
|
||||
{
|
||||
num = ((pivot.Y != 0f) ? 1 : 0);
|
||||
if (num == 0)
|
||||
{
|
||||
goto IL_004f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
num = 1;
|
||||
}
|
||||
g.TranslateTransform(pivot.X, pivot.Y);
|
||||
goto IL_004f;
|
||||
IL_004f:
|
||||
g.RotateTransform(degrees);
|
||||
if (num != 0)
|
||||
{
|
||||
g.TranslateTransform(0f - pivot.X, 0f - pivot.Y);
|
||||
}
|
||||
draw();
|
||||
g.Restore(gstate);
|
||||
}
|
||||
|
||||
private static void DrawImage(Graphics g, CrosshairConfig config, Image image)
|
||||
{
|
||||
float num = (float)Math.Max(1, config.ImageScalePercent) / 100f;
|
||||
float num2 = (float)image.Width * num;
|
||||
float num3 = (float)image.Height * num;
|
||||
float num4 = config.ResolvedOffsetX;
|
||||
float num5 = config.ResolvedOffsetY;
|
||||
InterpolationMode interpolationMode = g.InterpolationMode;
|
||||
PixelOffsetMode pixelOffsetMode = g.PixelOffsetMode;
|
||||
g.InterpolationMode = InterpolationMode.NearestNeighbor;
|
||||
g.PixelOffsetMode = PixelOffsetMode.Half;
|
||||
int num6 = Math.Clamp(config.Opacity, 0, 100);
|
||||
if (num6 >= 100)
|
||||
{
|
||||
g.DrawImage(image, (0f - num2) / 2f + num4, (0f - num3) / 2f + num5, num2, num3);
|
||||
}
|
||||
else
|
||||
{
|
||||
using ImageAttributes imageAttributes = new ImageAttributes();
|
||||
ColorMatrix colorMatrix = new ColorMatrix
|
||||
{
|
||||
Matrix33 = (float)num6 / 100f
|
||||
};
|
||||
imageAttributes.SetColorMatrix(colorMatrix);
|
||||
g.DrawImage(image, new Rectangle((int)((0f - num2) / 2f) + (int)num4, (int)((0f - num3) / 2f) + (int)num5, (int)num2, (int)num3), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
|
||||
}
|
||||
g.InterpolationMode = interpolationMode;
|
||||
g.PixelOffsetMode = pixelOffsetMode;
|
||||
}
|
||||
|
||||
public static void Draw(Graphics g, CrosshairConfig config, Rectangle target)
|
||||
{
|
||||
Draw(g, config, target, 1f);
|
||||
}
|
||||
|
||||
public static void Draw(Graphics g, CrosshairConfig config, Rectangle target, float maxScale)
|
||||
{
|
||||
RectangleF bounds = CrosshairGeometry.Build(config).Bounds;
|
||||
float num = maxScale;
|
||||
if (bounds.Width > 0f && bounds.Height > 0f)
|
||||
{
|
||||
num = Math.Min(maxScale, 0.82f * Math.Min((float)target.Width / bounds.Width, (float)target.Height / bounds.Height));
|
||||
}
|
||||
GraphicsState gstate = g.Save();
|
||||
g.SetClip(target);
|
||||
g.TranslateTransform((float)target.X + (float)target.Width / 2f, (float)target.Y + (float)target.Height / 2f);
|
||||
g.ScaleTransform(num, num);
|
||||
Draw(g, config);
|
||||
g.Restore(gstate);
|
||||
}
|
||||
|
||||
public static void DrawCheckerboard(Graphics g, Rectangle rect, int cell)
|
||||
{
|
||||
using Region clip = g.Clip;
|
||||
g.SetClip(rect, CombineMode.Intersect);
|
||||
using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(255, 58, 58, 64)))
|
||||
{
|
||||
using SolidBrush solidBrush2 = new SolidBrush(Color.FromArgb(255, 78, 78, 86));
|
||||
for (int i = rect.Top; i < rect.Bottom; i += cell)
|
||||
{
|
||||
for (int j = rect.Left; j < rect.Right; j += cell)
|
||||
{
|
||||
g.FillRectangle((((j - rect.Left) / cell + (i - rect.Top) / cell) % 2 == 0) ? solidBrush : solidBrush2, j, i, cell, cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
g.Clip = clip;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public sealed class CrosshairService : IDisposable
|
||||
{
|
||||
private const int QUNS_RUNNING_D3D_FULL_SCREEN = 3;
|
||||
|
||||
private CrosshairWindow? _window;
|
||||
|
||||
private readonly Func<CrosshairWindow> _newWindow;
|
||||
|
||||
public bool IsVisible { get; private set; }
|
||||
|
||||
public CrosshairConfig Config { get; private set; } = new CrosshairConfig();
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
private static extern int SHQueryUserNotificationState(out int state);
|
||||
|
||||
public CrosshairService()
|
||||
: this(() => new CrosshairWindow())
|
||||
{
|
||||
}
|
||||
|
||||
internal CrosshairService(Func<CrosshairWindow> newWindow)
|
||||
{
|
||||
_newWindow = newWindow;
|
||||
}
|
||||
|
||||
public static bool IsExclusiveFullscreen()
|
||||
{
|
||||
try
|
||||
{
|
||||
int state;
|
||||
return SHQueryUserNotificationState(out state) == 0 && state == 3;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Apply(CrosshairConfig config)
|
||||
{
|
||||
Config = config;
|
||||
if (IsVisible)
|
||||
{
|
||||
_window?.Apply(config);
|
||||
}
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
if (_window == null)
|
||||
{
|
||||
_window = _newWindow();
|
||||
}
|
||||
_ = _window.Handle;
|
||||
_window.Apply(Config);
|
||||
if (!_window.Visible)
|
||||
{
|
||||
_window.Show();
|
||||
}
|
||||
IsVisible = true;
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
_window?.Hide();
|
||||
IsVisible = false;
|
||||
}
|
||||
|
||||
public void Toggle()
|
||||
{
|
||||
if (IsVisible)
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
Show();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_window?.Dispose();
|
||||
_window = null;
|
||||
IsVisible = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public enum CrosshairShape
|
||||
{
|
||||
Cross,
|
||||
Dot,
|
||||
Circle,
|
||||
T
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public enum CrosshairShapeKind
|
||||
{
|
||||
Cross,
|
||||
T,
|
||||
Circle,
|
||||
Dot,
|
||||
Chevron
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class CrosshairShapeKinds
|
||||
{
|
||||
public static IReadOnlyList<CrosshairShapeKind> All { get; } = new CrosshairShapeKind[5]
|
||||
{
|
||||
CrosshairShapeKind.Cross,
|
||||
CrosshairShapeKind.T,
|
||||
CrosshairShapeKind.Circle,
|
||||
CrosshairShapeKind.Dot,
|
||||
CrosshairShapeKind.Chevron
|
||||
};
|
||||
|
||||
public static void Apply(CrosshairConfig config, CrosshairShapeKind kind)
|
||||
{
|
||||
config.CentreDot = config.ResolvedCentreDot;
|
||||
switch (kind)
|
||||
{
|
||||
case CrosshairShapeKind.Cross:
|
||||
SetParts(config, top: true, bottom: true, left: true, right: true, ring: false, chevron: false);
|
||||
config.Shape = CrosshairShape.Cross;
|
||||
break;
|
||||
case CrosshairShapeKind.T:
|
||||
SetParts(config, top: false, bottom: true, left: true, right: true, ring: false, chevron: false);
|
||||
config.Shape = CrosshairShape.T;
|
||||
break;
|
||||
case CrosshairShapeKind.Circle:
|
||||
SetParts(config, top: false, bottom: false, left: false, right: false, ring: true, chevron: false);
|
||||
config.Shape = CrosshairShape.Circle;
|
||||
break;
|
||||
case CrosshairShapeKind.Dot:
|
||||
SetParts(config, top: false, bottom: false, left: false, right: false, ring: false, chevron: false);
|
||||
config.CentreDot = true;
|
||||
config.Shape = CrosshairShape.Dot;
|
||||
break;
|
||||
case CrosshairShapeKind.Chevron:
|
||||
SetParts(config, top: false, bottom: false, left: true, right: true, ring: false, chevron: true);
|
||||
config.Shape = CrosshairShape.Cross;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static CrosshairShapeKind? Of(CrosshairConfig c)
|
||||
{
|
||||
bool resolvedArmTop = c.ResolvedArmTop;
|
||||
bool resolvedArmBottom = c.ResolvedArmBottom;
|
||||
bool resolvedArmLeft = c.ResolvedArmLeft;
|
||||
bool resolvedArmRight = c.ResolvedArmRight;
|
||||
bool resolvedShowCircle = c.ResolvedShowCircle;
|
||||
if (c.Chevron)
|
||||
{
|
||||
if (!(resolvedArmLeft & resolvedArmRight) || resolvedArmTop || resolvedArmBottom || resolvedShowCircle)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return CrosshairShapeKind.Chevron;
|
||||
}
|
||||
bool flag = !resolvedArmTop && !resolvedArmBottom && !resolvedArmLeft && !resolvedArmRight;
|
||||
if (resolvedShowCircle)
|
||||
{
|
||||
if (!flag)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return CrosshairShapeKind.Circle;
|
||||
}
|
||||
if (resolvedArmTop & resolvedArmBottom & resolvedArmLeft & resolvedArmRight)
|
||||
{
|
||||
return CrosshairShapeKind.Cross;
|
||||
}
|
||||
if (!resolvedArmTop & resolvedArmBottom & resolvedArmLeft & resolvedArmRight)
|
||||
{
|
||||
return CrosshairShapeKind.T;
|
||||
}
|
||||
if (flag && c.ResolvedCentreDot)
|
||||
{
|
||||
return CrosshairShapeKind.Dot;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void SetParts(CrosshairConfig c, bool top, bool bottom, bool left, bool right, bool ring, bool chevron)
|
||||
{
|
||||
c.ArmTop = top;
|
||||
c.ArmBottom = bottom;
|
||||
c.ArmLeft = left;
|
||||
c.ArmRight = right;
|
||||
c.ShowCircle = ring;
|
||||
c.Chevron = chevron;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public sealed record CrosshairShapes(IReadOnlyList<RectangleF> Bars, RectangleF? Circle, RectangleF Bounds)
|
||||
{
|
||||
public IReadOnlyList<AngledBar> Angled { get; init; } = Array.Empty<AngledBar>();
|
||||
|
||||
public int DotIndex { get; init; } = -1;
|
||||
|
||||
public float RotationDegrees { get; init; }
|
||||
|
||||
public PointF Pivot { get; init; }
|
||||
|
||||
public RectangleF DrawnBounds { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public sealed class CrosshairWindow : Form
|
||||
{
|
||||
private struct POINT
|
||||
{
|
||||
public int X;
|
||||
|
||||
public int Y;
|
||||
}
|
||||
|
||||
private struct SIZE
|
||||
{
|
||||
public int cx;
|
||||
|
||||
public int cy;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
private struct BLENDFUNCTION
|
||||
{
|
||||
public byte BlendOp;
|
||||
|
||||
public byte BlendFlags;
|
||||
|
||||
public byte SourceConstantAlpha;
|
||||
|
||||
public byte AlphaFormat;
|
||||
}
|
||||
|
||||
private struct BITMAPINFOHEADER
|
||||
{
|
||||
public uint biSize;
|
||||
|
||||
public int biWidth;
|
||||
|
||||
public int biHeight;
|
||||
|
||||
public ushort biPlanes;
|
||||
|
||||
public ushort biBitCount;
|
||||
|
||||
public uint biCompression;
|
||||
|
||||
public uint biSizeImage;
|
||||
|
||||
public int biXPelsPerMeter;
|
||||
|
||||
public int biYPelsPerMeter;
|
||||
|
||||
public uint biClrUsed;
|
||||
|
||||
public uint biClrImportant;
|
||||
}
|
||||
|
||||
private const int WS_EX_LAYERED = 524288;
|
||||
|
||||
private const int WS_EX_TRANSPARENT = 32;
|
||||
|
||||
private const int WS_EX_TOOLWINDOW = 128;
|
||||
|
||||
private const int WS_EX_NOACTIVATE = 134217728;
|
||||
|
||||
private const int WS_EX_TOPMOST = 8;
|
||||
|
||||
private const int ULW_ALPHA = 2;
|
||||
|
||||
private const byte AC_SRC_OVER = 0;
|
||||
|
||||
private const byte AC_SRC_ALPHA = 1;
|
||||
|
||||
private const uint DIB_RGB_COLORS = 0u;
|
||||
|
||||
private const uint BI_RGB = 0u;
|
||||
|
||||
private CrosshairConfig _config = new CrosshairConfig();
|
||||
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
{
|
||||
CreateParams createParams = base.CreateParams;
|
||||
createParams.ExStyle |= 134742184;
|
||||
return createParams;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool ShowWithoutActivation => true;
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern bool UpdateLayeredWindow(nint hwnd, nint hdcDst, ref POINT pptDst, ref SIZE psize, nint hdcSrc, ref POINT pptSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern nint GetDC(nint hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int ReleaseDC(nint hWnd, nint hDC);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern nint CreateCompatibleDC(nint hDC);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern bool DeleteDC(nint hdc);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern nint SelectObject(nint hdc, nint h);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern bool DeleteObject(nint ho);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern nint CreateDIBSection(nint hdc, ref BITMAPINFOHEADER pbmi, uint iUsage, out nint ppvBits, nint hSection, uint dwOffset);
|
||||
|
||||
[DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
|
||||
private static extern void CopyMemory(nint dest, nint src, uint count);
|
||||
|
||||
public CrosshairWindow()
|
||||
{
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
ShowInTaskbar = false;
|
||||
TopMost = true;
|
||||
StartPosition = FormStartPosition.Manual;
|
||||
SetStyle(ControlStyles.Opaque, value: true);
|
||||
}
|
||||
|
||||
protected override void OnPaintBackground(PaintEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public void Apply(CrosshairConfig config)
|
||||
{
|
||||
_config = config;
|
||||
Redraw();
|
||||
}
|
||||
|
||||
public void Redraw()
|
||||
{
|
||||
if (!IsHandleCreated)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Size size = CrosshairGeometry.OverlaySize(_config);
|
||||
int width = size.Width;
|
||||
int height = size.Height;
|
||||
Rectangle bounds = Screen.FromPoint(System.Windows.Forms.Cursor.Position).Bounds;
|
||||
int left = bounds.Left + (bounds.Width - width) / 2;
|
||||
int top = bounds.Top + (bounds.Height - height) / 2;
|
||||
using Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
|
||||
using (Graphics graphics = Graphics.FromImage(bitmap))
|
||||
{
|
||||
graphics.TranslateTransform((float)width / 2f, (float)height / 2f);
|
||||
CrosshairRender.Draw(graphics, _config);
|
||||
}
|
||||
Push(bitmap, left, top);
|
||||
}
|
||||
|
||||
private void Push(Bitmap bmp, int left, int top)
|
||||
{
|
||||
nint dC = GetDC(IntPtr.Zero);
|
||||
nint num = CreateCompatibleDC(dC);
|
||||
nint num2 = IntPtr.Zero;
|
||||
nint h = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
BITMAPINFOHEADER pbmi = new BITMAPINFOHEADER
|
||||
{
|
||||
biSize = (uint)Marshal.SizeOf<BITMAPINFOHEADER>(),
|
||||
biWidth = bmp.Width,
|
||||
biHeight = -bmp.Height,
|
||||
biPlanes = 1,
|
||||
biBitCount = 32,
|
||||
biCompression = 0u
|
||||
};
|
||||
num2 = CreateDIBSection(dC, ref pbmi, 0u, out var ppvBits, IntPtr.Zero, 0u);
|
||||
if (num2 != IntPtr.Zero && ppvBits != IntPtr.Zero)
|
||||
{
|
||||
BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppPArgb);
|
||||
try
|
||||
{
|
||||
CopyMemory(ppvBits, bitmapData.Scan0, (uint)(bmp.Width * bmp.Height * 4));
|
||||
}
|
||||
finally
|
||||
{
|
||||
bmp.UnlockBits(bitmapData);
|
||||
}
|
||||
h = SelectObject(num, num2);
|
||||
SIZE psize = new SIZE
|
||||
{
|
||||
cx = bmp.Width,
|
||||
cy = bmp.Height
|
||||
};
|
||||
POINT pptSrc = new POINT
|
||||
{
|
||||
X = 0,
|
||||
Y = 0
|
||||
};
|
||||
POINT pptDst = new POINT
|
||||
{
|
||||
X = left,
|
||||
Y = top
|
||||
};
|
||||
BLENDFUNCTION pblend = new BLENDFUNCTION
|
||||
{
|
||||
BlendOp = 0,
|
||||
BlendFlags = 0,
|
||||
SourceConstantAlpha = byte.MaxValue,
|
||||
AlphaFormat = 1
|
||||
};
|
||||
UpdateLayeredWindow(Handle, dC, ref pptDst, ref psize, num, ref pptSrc, 0, ref pblend, 2);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
ReleaseDC(IntPtr.Zero, dC);
|
||||
if (num2 != IntPtr.Zero)
|
||||
{
|
||||
SelectObject(num, h);
|
||||
DeleteObject(num2);
|
||||
}
|
||||
DeleteDC(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace VibranceHud.Crosshair;
|
||||
|
||||
public static class ImageCrosshair
|
||||
{
|
||||
public const int MaxSidePx = 512;
|
||||
|
||||
private static readonly ConcurrentDictionary<string, Bitmap?> _cache = new ConcurrentDictionary<string, Bitmap>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public static Bitmap? Load(string? path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (_cache.TryGetValue(path, out Bitmap value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
Bitmap bitmap = Decode(path);
|
||||
if (bitmap != null)
|
||||
{
|
||||
_cache.TryAdd(path, bitmap);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private static Bitmap? Decode(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using MemoryStream stream = new MemoryStream(File.ReadAllBytes(path));
|
||||
using Bitmap bitmap = new Bitmap(stream);
|
||||
if (bitmap.Width > 512 || bitmap.Height > 512)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Bitmap(bitmap);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClearCache()
|
||||
{
|
||||
_cache.Clear();
|
||||
}
|
||||
|
||||
public static bool TryImport(string? sourcePath, string storeDir, out string stored, out string error)
|
||||
{
|
||||
stored = "";
|
||||
if (string.IsNullOrWhiteSpace(sourcePath) || !File.Exists(sourcePath))
|
||||
{
|
||||
error = "That file could not be found.";
|
||||
return false;
|
||||
}
|
||||
Bitmap bitmap;
|
||||
try
|
||||
{
|
||||
using MemoryStream stream = new MemoryStream(File.ReadAllBytes(sourcePath));
|
||||
bitmap = new Bitmap(stream);
|
||||
}
|
||||
catch
|
||||
{
|
||||
error = "That file is not an image PlexusX can read. PNG works best, because it can have a transparent background.";
|
||||
return false;
|
||||
}
|
||||
Bitmap value = bitmap;
|
||||
try
|
||||
{
|
||||
if (bitmap.Width > 512 || bitmap.Height > 512)
|
||||
{
|
||||
error = $"That image is {bitmap.Width}×{bitmap.Height}. The largest a crosshair may be is {512}×{512} - anything bigger costs frames " + "in every game, which is the opposite of the point.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
((IDisposable)value)?.Dispose();
|
||||
}
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(storeDir);
|
||||
string path = "crosshair-" + ShortHash(File.ReadAllBytes(sourcePath)) + Path.GetExtension(sourcePath);
|
||||
string text = Path.Combine(storeDir, path);
|
||||
File.Copy(sourcePath, text, overwrite: true);
|
||||
_cache.TryRemove(text, out value);
|
||||
stored = text;
|
||||
error = "";
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = "The image is fine, but it could not be saved: " + ex.Message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string ShortHash(byte[] bytes)
|
||||
{
|
||||
using SHA256 sHA = SHA256.Create();
|
||||
return Convert.ToHexString(sHA.ComputeHash(bytes), 0, 6).ToLowerInvariant();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user