Skip to content

Commit

Permalink
Merge pull request #210 from automuteus/TownOfUs
Browse files Browse the repository at this point in the history
Town of us
  • Loading branch information
CarbonNeuron committed May 26, 2021
2 parents e711a96 + 53e0e3a commit 033a6ed
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 27 deletions.
5 changes: 5 additions & 0 deletions AUCapture-WPF/AUCapture-WPF.csproj
Expand Up @@ -54,6 +54,8 @@
<None Remove="Resources\Misc\Transparent_Nebula.png" />
<None Remove="Resources\Misc\voteCancel.png" />
<None Remove="Resources\Misc\voteConfirm.png" />
<None Remove="Resources\missingtex.png" />
<None Remove="Resources\rainbowtex.png" />
<None Remove="SplashScreens\capture-splashscreen-lovely.png" />
<None Remove="SplashScreens\SplashScreenDouche.png" />
<None Remove="SplashScreens\SplashScreenLovely.png" />
Expand All @@ -62,6 +64,8 @@

<ItemGroup>
<EmbeddedResource Include="Resources\AutoMuteUs_PK.asc" />
<Resource Include="Resources\missingtex.png" />
<Resource Include="Resources\rainbowtex.png" />
</ItemGroup>

<ItemGroup>
Expand All @@ -77,6 +81,7 @@
<PackageReference Include="PgpCore" Version="5.2.0" />
<PackageReference Include="SharedMemory" Version="2.2.3" />
<PackageReference Include="SharpVectors" Version="1.7.1" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
<PackageReference Include="WpfScreenHelper" Version="1.0.0" />
</ItemGroup>

Expand Down
15 changes: 11 additions & 4 deletions AUCapture-WPF/App.xaml.cs
Expand Up @@ -49,6 +49,13 @@ public partial class App : Application
Header = $"Capture version: {v.FileMajorPart}.{v.FileMinorPart}.{v.FileBuildPart}.{v.FilePrivatePart}\n",
Footer = $"\nCapture version: {v.FileMajorPart}.{v.FileMinorPart}.{v.FileBuildPart}.{v.FilePrivatePart}"
};
var consoleOutput = new NLog.Targets.ColoredConsoleTarget("Console") {
UseDefaultRowHighlightingRules = true,
DetectConsoleAvailable = true,
Header = $"Capture version: {v.FileMajorPart}.{v.FileMinorPart}.{v.FileBuildPart}.{v.FilePrivatePart}\n",
Footer = $"\nCapture version: {v.FileMajorPart}.{v.FileMinorPart}.{v.FileBuildPart}.{v.FilePrivatePart}"
};
LoggingConfig.AddRule(LogLevel.Debug, LogLevel.Fatal, consoleOutput);
LoggingConfig.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
NLog.LogManager.Configuration = LoggingConfig;
}
Expand Down Expand Up @@ -77,13 +84,13 @@ public void PlaySound(string URL)
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
SetupLoggingConfig();

var args = e.Args;

// needs to be the first call in the program to prevent weird bugs
if (Settings.PersistentSettings.debugConsole)
AllocConsole();

if (Settings.PersistentSettings.debugConsole)
AllocConsole();
SetupLoggingConfig();
var uriStart = IPCAdapter.getInstance().HandleURIStart(e.Args);

switch (uriStart)
Expand Down
181 changes: 164 additions & 17 deletions AUCapture-WPF/Converters/PlayerColorToBrush.cs
Expand Up @@ -4,13 +4,15 @@
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using AmongUsCapture;
using MahApps.Metro.Controls;

namespace AUCapture_WPF.Converters
{
public class PlayerColorToBrush : IValueConverter
{
private static readonly Dictionary<PlayerColor, SolidColorBrush> BrushMapping = new() {
public class PlayerColorToBrush : IValueConverter {
public static Dictionary<PlayerColor, Brush> BrushMapping = new() {
{ PlayerColor.Red, new SolidColorBrush(Color.FromRgb(197, 17, 17))},
{ PlayerColor.Blue, new SolidColorBrush(Color.FromRgb(19, 46, 209))},
{ PlayerColor.Green, new SolidColorBrush(Color.FromRgb(17, 127, 45))},
Expand All @@ -22,10 +24,50 @@ public class PlayerColorToBrush : IValueConverter
{ PlayerColor.Purple, new SolidColorBrush(Color.FromRgb(107, 47, 187))},
{ PlayerColor.Brown, new SolidColorBrush(Color.FromRgb(113, 73, 30))},
{ PlayerColor.Cyan, new SolidColorBrush(Color.FromRgb(56, 254, 220))},
{ PlayerColor.Lime, new SolidColorBrush(Color.FromRgb(80, 239, 57))}
{ PlayerColor.Lime, new SolidColorBrush(Color.FromRgb(80, 239, 57))},
{ PlayerColor.Watermelon, new SolidColorBrush(Color.FromRgb(168, 50, 62))},
{ PlayerColor.Chocolate, new SolidColorBrush(Color.FromRgb(60, 48, 44))},
{ PlayerColor.SkyBlue, new SolidColorBrush(Color.FromRgb(61, 129, 255))},
{ PlayerColor.Beige, new SolidColorBrush(Color.FromRgb(240, 211, 165))},
{ PlayerColor.HotPink, new SolidColorBrush(Color.FromRgb(236, 61, 255))},
{ PlayerColor.Turquoise, new SolidColorBrush(Color.FromRgb(61, 255, 181))},
{ PlayerColor.Lilac, new SolidColorBrush(Color.FromRgb(186, 161, 255))},
{ PlayerColor.Unknown, null},
{ PlayerColor.Rainbow, null}

};

public static SolidColorBrush RainColorBrush;
public static SolidColorBrush RainColorBrushShaded;

static PlayerColorToBrush() {
var rainbowColor = new SolidColorBrush(Colors.Red);
var rainbowColorShaded = new SolidColorBrush(Colors.Red);
var normalAnimation = GenerateAnimation(false);
var ShadedAnimation = GenerateAnimation(true);
rainbowColor.BeginAnimation(SolidColorBrush.ColorProperty, normalAnimation);
rainbowColorShaded.BeginAnimation(SolidColorBrush.ColorProperty, ShadedAnimation);
RainColorBrush = rainbowColor;
RainColorBrushShaded = rainbowColorShaded;
BrushMapping[PlayerColor.Rainbow] = rainbowColor;
var unknownBrush = new ImageBrush(new BitmapImage(new Uri($"pack://application:,,,/Resources/missingtex.png")));
unknownBrush.TileMode = TileMode.Tile;
unknownBrush.ViewportUnits = BrushMappingMode.Absolute;
unknownBrush.Viewport = new Rect(0, 0, 25, 25);
BrushMapping[PlayerColor.Unknown] = unknownBrush;


}

public static ColorAnimationUsingKeyFrames GenerateAnimation(bool shaded) {
ColorAnimationUsingKeyFrames myAnimation = new ColorAnimationUsingKeyFrames();
myAnimation.KeyFrames = new ColorKeyFrameCollection();
myAnimation.KeyFrames.Add(new RainbowColorKeyFrame(Colors.Red, KeyTime.Uniform, shaded));
myAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(3000));
myAnimation.RepeatBehavior = RepeatBehavior.Forever;
return myAnimation;
}

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var color = value as PlayerColor? ?? PlayerColor.Red;
Expand All @@ -50,33 +92,138 @@ public class PlayerColorToBrushShaded : IValueConverter
return Color.FromArgb(255, (byte) R, (byte) G, (byte) B);
}

private static readonly Dictionary<PlayerColor, SolidColorBrush> BrushMapping = new() {
{ PlayerColor.Red, new SolidColorBrush(Color.FromRgb(197, 17, 17))},
{ PlayerColor.Blue, new SolidColorBrush(Color.FromRgb(19, 46, 209))},
{ PlayerColor.Green, new SolidColorBrush(Color.FromRgb(17, 127, 45))},
{ PlayerColor.Pink, new SolidColorBrush(Color.FromRgb(237, 84, 186))},
{ PlayerColor.Orange, new SolidColorBrush(Color.FromRgb(239, 125, 13))},
{ PlayerColor.Yellow, new SolidColorBrush(Color.FromRgb(245, 245, 87))},
{ PlayerColor.Black, new SolidColorBrush(Color.FromRgb(63, 71, 78))},
{ PlayerColor.White, new SolidColorBrush(Color.FromRgb(214, 224, 240))},
{ PlayerColor.Purple, new SolidColorBrush(Color.FromRgb(107, 47, 187))},
{ PlayerColor.Brown, new SolidColorBrush(Color.FromRgb(113, 73, 30))},
{ PlayerColor.Cyan, new SolidColorBrush(Color.FromRgb(56, 254, 220))},
{ PlayerColor.Lime, new SolidColorBrush(Color.FromRgb(80, 239, 57))}
private static Dictionary<PlayerColor, SolidColorBrush> BrushMapping = new() {
{ PlayerColor.Red, new SolidColorBrush(Color.FromRgb(197, 17, 17))},
{ PlayerColor.Blue, new SolidColorBrush(Color.FromRgb(19, 46, 209))},
{ PlayerColor.Green, new SolidColorBrush(Color.FromRgb(17, 127, 45))},
{ PlayerColor.Pink, new SolidColorBrush(Color.FromRgb(237, 84, 186))},
{ PlayerColor.Orange, new SolidColorBrush(Color.FromRgb(239, 125, 13))},
{ PlayerColor.Yellow, new SolidColorBrush(Color.FromRgb(245, 245, 87))},
{ PlayerColor.Black, new SolidColorBrush(Color.FromRgb(63, 71, 78))},
{ PlayerColor.White, new SolidColorBrush(Color.FromRgb(214, 224, 240))},
{ PlayerColor.Purple, new SolidColorBrush(Color.FromRgb(107, 47, 187))},
{ PlayerColor.Brown, new SolidColorBrush(Color.FromRgb(113, 73, 30))},
{ PlayerColor.Cyan, new SolidColorBrush(Color.FromRgb(56, 254, 220))},
{ PlayerColor.Lime, new SolidColorBrush(Color.FromRgb(80, 239, 57))},
{ PlayerColor.Watermelon, new SolidColorBrush(Color.FromRgb(168, 50, 62))},
{ PlayerColor.Chocolate, new SolidColorBrush(Color.FromRgb(60, 48, 44))},
{ PlayerColor.SkyBlue, new SolidColorBrush(Color.FromRgb(61, 129, 255))},
{ PlayerColor.Beige, new SolidColorBrush(Color.FromRgb(240, 211, 165))},
{ PlayerColor.HotPink, new SolidColorBrush(Color.FromRgb(236, 61, 255))},
{ PlayerColor.Turquoise, new SolidColorBrush(Color.FromRgb(61, 255, 181))},
{ PlayerColor.Lilac, new SolidColorBrush(Color.FromRgb(186, 161, 255))},

};

static PlayerColorToBrushShaded() {
if (PlayerColorToBrush.BrushMapping[PlayerColor.Unknown] is null || PlayerColorToBrush.BrushMapping[PlayerColor.Rainbow] is null) {
var temp1 = new PlayerColorToBrush();
}

}

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var color = value as PlayerColor? ?? PlayerColor.Red;
if (color == PlayerColor.Rainbow) {
return PlayerColorToBrush.RainColorBrushShaded;
}
else if (color == PlayerColor.Unknown) {
return PlayerColorToBrush.BrushMapping[PlayerColor.Unknown];
}
var mainColor = BrushMapping[color];
var shaded = shadeColor(mainColor.Color, -20f);
return new SolidColorBrush(shaded);
}


public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public partial class RainbowColorKeyFrame : ColorKeyFrame
{
#region Constructors

/// <summary>
/// Creates a new LinearColorKeyFrame.
/// </summary>
public RainbowColorKeyFrame(bool shaded) {
Shaded = shaded;
}

/// <summary>
/// Creates a new LinearColorKeyFrame.
/// </summary>
public RainbowColorKeyFrame(Color value)
: base(value)
{
}

public bool Shaded = false;
/// <summary>
/// Creates a new LinearColorKeyFrame.
/// </summary>
public RainbowColorKeyFrame(Color value, KeyTime keyTime, bool shaded)
: base(value, keyTime) {
Shaded = shaded;
}

#endregion

#region Freezable

/// <summary>
/// Implementation of <see cref="System.Windows.Freezable.CreateInstanceCore">Freezable.CreateInstanceCore</see>.
/// </summary>
/// <returns>The new Freezable.</returns>
protected override Freezable CreateInstanceCore()
{
return new RainbowColorKeyFrame(Shaded);
}

#endregion

#region ColorKeyFrame

public static Color Rainbow(double progress)
{
double div = (Math.Abs(progress % 1) * 6);
byte ascending = (byte) ((div % 1) * 255);
byte descending = (byte) (255 - @ascending);

switch ((int) div)
{
case 0:
return Color.FromArgb(255, 255, @ascending, 0);
case 1:
return Color.FromArgb(255, @descending, 255, 0);
case 2:
return Color.FromArgb(255, 0, 255, @ascending);
case 3:
return Color.FromArgb(255, 0, @descending, 255);
case 4:
return Color.FromArgb(255, @ascending, 0, 255);
default: // case 5:
return Color.FromArgb(255, 255, 0, @descending);
}
}

/// <summary>
/// Implemented to linearly interpolate between the baseValue and the
/// Value of this KeyFrame using the keyFrameProgress.
/// </summary>
protected override Color InterpolateValueCore(Color baseValue, double keyFrameProgress) {
var color = Rainbow(keyFrameProgress);
if (Shaded)
{
color = PlayerColorToBrushShaded.shadeColor(color, -20f);
}

return color;
}

#endregion
}
}
Binary file added AUCapture-WPF/Resources/missingtex.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AUCapture-WPF/Resources/rainbowtex.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions AmongUsCapture/Memory/GameMemReader.cs
Expand Up @@ -175,7 +175,7 @@ public class GameMemReader {
else {
// player was here before, we have an old playerInfo to compare against
var oldPlayerInfo = oldPlayers[player.GetPlayerName()];
if (!oldPlayerInfo.GetIsDead() && player.GetIsDead()) // player just died
if (oldPlayerInfo.GetIsDead() != player.GetIsDead()) // player just died
PlayerChanged?.Invoke(this, new PlayerChangedEventArgs {
Action = PlayerAction.Died,
Name = player.GetPlayerName(),
Expand All @@ -184,6 +184,7 @@ public class GameMemReader {
Color = player.GetPlayerColor()
});


if (oldPlayerInfo.ColorId != player.ColorId)
PlayerChanged?.Invoke(this, new PlayerChangedEventArgs {
Action = PlayerAction.ChangedColor,
Expand Down Expand Up @@ -496,7 +497,16 @@ public enum PlayerColor {
Purple = 8,
Brown = 9,
Cyan = 10,
Lime = 11
Lime = 11,
Watermelon = 12,
Chocolate = 13,
SkyBlue = 14,
Beige = 15,
HotPink = 16,
Turquoise = 17,
Lilac = 18,
Rainbow = 19,
Unknown = 999
}

public enum PlayRegion {
Expand Down
28 changes: 24 additions & 4 deletions AmongUsCapture/Memory/Structs/PlayerInfo.cs
@@ -1,25 +1,30 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using AUOffsetManager;
using Discord;
using NLog;

namespace AmongUsCapture
{

public class PlayerInfo
{
public class PlayerInfo {
private static List<uint> UnknownColors = new List<uint>();
public byte PlayerId;
public String PlayerName;
public PlayerColor ColorId;
public PlayerColor ColorId = PlayerColor.Unknown;
public uint HatId;
public uint PetId;
public uint SkinId;
public bool Disconnected;
public IntPtr Tasks;
public bool IsImpostor;
public bool IsDead;
public uint realColorID;
public IntPtr _object; //Assume this always has largest offset
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public PlayerInfo(IntPtr baseAddr, ProcessMemory MemInstance, GameOffsets CurrentOffsets) {
bool LogCastError = false;
unsafe {
var baseAddrCopy = baseAddr;
int last = MemInstance.OffsetAddress(ref baseAddrCopy, 0, 0);
Expand All @@ -32,7 +37,15 @@ public class PlayerInfo
PlayerId = Marshal.ReadByte(buffptr, pOf.PlayerIDOffset);
var NamePTR = MemInstance.is64Bit ? (IntPtr) Marshal.ReadInt64(buffptr, pOf.PlayerNameOffset) : (IntPtr) Marshal.ReadInt32(buffptr, pOf.PlayerNameOffset);
PlayerName = NamePTR == IntPtr.Zero ? "" : MemInstance.ReadString(NamePTR, CurrentOffsets.StringOffsets[0], CurrentOffsets.StringOffsets[1]);
ColorId = (PlayerColor)(uint)Marshal.ReadInt32(buffptr, pOf.ColorIDOffset);
var ColorIdNum = (PlayerColor)(uint)Marshal.ReadInt32(buffptr, pOf.ColorIDOffset);
realColorID = (uint)Marshal.ReadInt32(buffptr, pOf.ColorIDOffset);;
if (Enum.IsDefined(typeof(PlayerColor), ColorIdNum)) {
ColorId = (PlayerColor) ColorIdNum;
}
else {
LogCastError = true;
}

HatId = (uint) Marshal.ReadInt32(buffptr, pOf.HatIDOffset);
PetId = (uint) Marshal.ReadInt32(buffptr, pOf.PetIDOffset);
SkinId = (uint) Marshal.ReadInt32(buffptr, pOf.SkinIDOffset);
Expand All @@ -43,6 +56,13 @@ public class PlayerInfo
_object = Marshal.ReadIntPtr(buffptr, pOf.ObjectOffset);
}
}

if (LogCastError) {
if (!UnknownColors.Contains(realColorID)) {
Logger.Debug($"UNKNOWN COLOR. NAME:{GetPlayerName()}, COLOR: {realColorID}");
UnknownColors.Add(realColorID);
}
}
}
public string GetPlayerName() {
return PlayerName;
Expand Down

0 comments on commit 033a6ed

Please sign in to comment.