From 211a9440f4ec9bd49d49bbd44679729aac5aa7ce Mon Sep 17 00:00:00 2001 From: Ryan Cloherty Date: Wed, 29 Dec 2021 19:37:34 -0500 Subject: [PATCH] Add FreeForAll.cs I think this is how the scoring system is implemented? --- titanfall2-rp/MpGameStats/FreeForAll.cs | 65 +++++++++++++++++++++++++ titanfall2-rp/MpStats.cs | 25 ++++++---- 2 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 titanfall2-rp/MpGameStats/FreeForAll.cs diff --git a/titanfall2-rp/MpGameStats/FreeForAll.cs b/titanfall2-rp/MpGameStats/FreeForAll.cs new file mode 100644 index 0000000..5db31e3 --- /dev/null +++ b/titanfall2-rp/MpGameStats/FreeForAll.cs @@ -0,0 +1,65 @@ +using Process.NET; + +namespace titanfall2_rp.MpGameStats +{ + public class FreeForAll : MpStats + { + public FreeForAll(Titanfall2Api tf2Api, ProcessSharp processSharp) : base(tf2Api, processSharp) + { + } + + /// + /// The score of "team 1" is actually just the current user's score + /// + /// + public override int GetTeam1Score() + { + return GetScore(GetMyIdOnServer()); + } + + /// + /// The score of "team 2" is actually the score of the player with the highest score + /// + /// + public override int GetTeam2Score() + { + return GetHighestScoreInGameIgnoringPlayer(GetMyIdOnServer()); + } + + /// + /// Get the score of a user. + /// + /// the id of the player, leave blank to use the current player + /// the user's score + private int GetScore(int playerId = -1) + { + var id = playerId < 0 ? GetMyIdOnServer() : playerId; + return Sharp.Memory.Read(Tf2Api.EngineDllBaseAddress + MpOffsets.FreeForAll.Score + + (id * MpOffsets.FreeForAll.AttritionStatsPlayerIdOffset)); + } + + private int GetHighestScoreInGameIgnoringPlayer(int playerIdToIgnore = -1) + { + var currentHighest = int.MinValue; + // Loop through all the score slots + for (var i = 0; i < 64; i++) + { + // Skip the player whose ID we were instructed to ignore + if (i == playerIdToIgnore) + { + continue; + } + + var playerScore = GetScore(i); + // If the known highest score turns out to be lower than this player's score... + if (playerScore > currentHighest) + { + // Set the known highest to be that new highest score + currentHighest = playerScore; + } + } + + return currentHighest; + } + } +} \ No newline at end of file diff --git a/titanfall2-rp/MpStats.cs b/titanfall2-rp/MpStats.cs index 78b0dcc..56327b2 100644 --- a/titanfall2-rp/MpStats.cs +++ b/titanfall2-rp/MpStats.cs @@ -15,15 +15,15 @@ namespace titanfall2_rp /// public abstract class MpStats { - private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod()!.DeclaringType); - private protected const string HelpMeBruh = "Getting this value is not supported. " + "If you want this to be possible, you'll need to contribute this yourself or tell me how the heck to get it."; - private protected readonly Titanfall2Api Tf2Api; + private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod()!.DeclaringType); private protected readonly ProcessSharp Sharp; + private protected readonly Titanfall2Api Tf2Api; + protected MpStats(Titanfall2Api titanfall2Api, ProcessSharp processSharp) { Tf2Api = titanfall2Api; @@ -202,6 +202,7 @@ public static MpStats Of(Titanfall2Api titanfall2Api, ProcessSharp sharp) GameMode.fd_master => new FrontierDefense(titanfall2Api, sharp), GameMode.fd_insane => new FrontierDefense(titanfall2Api, sharp), GameMode.solo => throw new ArgumentException("Tried to get multiplayer details for the campaign"), + GameMode.ffa => new FreeForAll(titanfall2Api, sharp), _ => ReportGameModeFailure(gameMode) }; } @@ -310,6 +311,12 @@ internal static class MpOffsets /// internal const int Name = 0x13fa6eb8; + /// + /// This value (multiplied by the player's ID) is added to the last of the + /// when finding a player's name. + /// + internal const int NamePlayerIdIncrement = 0x58; + /// /// The address is really the address to a pointer. Applying these offsets to that pointer /// points to the address with the actual desired value. @@ -320,12 +327,6 @@ internal static int[] NamePointerOffsets get { return new[] { 0x18, 0x50, 0x38, 0x38 }; } } - /// - /// This value (multiplied by the player's ID) is added to the last of the - /// when finding a player's name. - /// - internal const int NamePlayerIdIncrement = 0x58; - public static class Attrition { internal const int Kills = 0x1123D27C; @@ -333,5 +334,11 @@ public static class Attrition internal const int Score = 0x1123D510; internal const int AttritionStatsPlayerIdOffset = 0x4; } + + public static class FreeForAll + { + internal const int Score = Attrition.Score; + internal const int AttritionStatsPlayerIdOffset = Attrition.AttritionStatsPlayerIdOffset; + } } } \ No newline at end of file