Skip to content

Commit

Permalink
🌟 Show match duration 🌟 (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
IncPlusPlus committed Jan 13, 2022
1 parent 3d05e43 commit 7204808
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
8 changes: 3 additions & 5 deletions titanfall2-rp/GameDetailsProvider.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
ο»Ώusing System;
using DiscordRPC;
ο»Ώusing DiscordRPC;
using titanfall2_rp.enums;

namespace titanfall2_rp
{
public static class GameDetailsProvider
{
public static (string, string, Timestamps?, Assets? assets) GetMultiplayerDetails(Titanfall2Api tf2Api,
DateTime gameOpenTimestamp)
public static (string, string, Timestamps?, Assets? assets) GetMultiplayerDetails(Titanfall2Api tf2Api)
{
var mpStats = tf2Api.GetMultiPlayerGameStats();
var gameMode = tf2Api.GetGameMode();
var gameDetails = gameMode == GameMode.UNKNOWN_GAME_MODE
? $"Game mode: {tf2Api.GetGameModeCodeName()}"
: gameMode.ToFriendlyString();
var gameState = mpStats.GetGameState();
var timestamps = new Timestamps(gameOpenTimestamp);
var timestamps = new Timestamps(mpStats.GetLastServerConnectTime());
var map = Map.FromName(tf2Api.GetMultiplayerMapName());
var playerInTitan = tf2Api.IsPlayerInTitan();
var assets = new Assets
Expand Down
64 changes: 64 additions & 0 deletions titanfall2-rp/MpStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,70 @@ protected int GetMyTeam()
(Tf2Api.ClientDllBaseAddress + EntityOffsets.LocalPlayerBase)) +
EntityOffsets.LocalPlayer.m_iTeamNum);
}

/// <summary>
/// The current game_server_time command output. This doesn't run the command but I think I found some reliable
/// offsets for the value it should return.
///
/// Currently viable offsets:
///
/// These ones look okay. however, I don't think they're guaranteed to be right. Sometimes they just keep on ticking even though they should reset after connecting to a server.
///
/// tier0.g_ClockSpeedSecondsMultiplier+1E8
/// client.dll+C3DB28
/// client.dll+216FD1C
/// client.dll+27B8354
/// client.dll+27B8378
/// client.dll+27B837C
/// client.dll+27B8380
/// client.dll+27B8384
/// client.dll+27B838C
/// client.dll+27B8390
/// client.dll+27FF740
/// client.dll+27FF744
/// client.dll+27FF748
/// client.dll+2A9F064
/// client.dll+2E55F10
/// client.dll+3BE12A4
/// engine.dll+7A5C40
/// engine.dll+7A5C44
/// engine.dll+7A5C48
/// engine.dll+7A5C4C
/// engine.dll+7A5C54
/// engine.dll+7A5C58
/// engine.dll+7A6570
/// engine.dll+7A65FC
/// engine.dll+7A6748
/// engine.dll+7A674C
/// engine.dll+7B6644
/// engine.dll+F84BCF8
/// engine.dll+F84BD80
/// engine.dll+F84BE08
/// engine.dll+FD13C00
/// engine.dll+FD13C2C
/// engine.dll+FD13C58
///
///
/// however, these ones seem to start at the right time when connecting to a match in progress from the server browser
/// client.dll+27FF740
/// client.dll+27FF744
/// client.dll+27FF748
/// client.dll+2A9F064 (this one seems to be a little ahead)
/// </summary>
/// <returns>the number of seconds since the client connected to the current server</returns>
public float GetServerGameTime()
{
return Sharp.Memory.Read<float>(Tf2Api.ClientDllBaseAddress + 0x27FF740);
}

/// <summary>
/// Get the timestamp of the last time the client connected to a server
/// </summary>
/// <returns>a timestamp of the last time the client connected to a server</returns>
public DateTime GetLastServerConnectTime()
{
return DateTimeOffset.Now.UtcDateTime.Subtract(TimeSpan.FromSeconds(GetServerGameTime()));
}
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions titanfall2-rp/PresenceUpdateThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static (string, string, Timestamps?, Assets? assets) GetDetailsAndState(
else if (tf2Api.GetMultiplayerMapName().Equals("mp_lobby"))
{
gameDetails = "In a lobby";
timestamps = new Timestamps(ProcessNetApi.StartTimestamp);
timestamps = new Timestamps(tf2Api.GetMultiPlayerGameStats().GetLastServerConnectTime());
}
else if (tf2Api.GetGameMode() == GameMode.solo)
{
Expand All @@ -140,7 +140,7 @@ private static (string, string, Timestamps?, Assets? assets) GetDetailsAndState(
// Besides mp_lobby, any mp map will be prefixed with mp_. Grab the specific details then!
else if (tf2Api.GetMultiplayerMapName().StartsWith("mp_"))
{
return GameDetailsProvider.GetMultiplayerDetails(tf2Api, ProcessNetApi.StartTimestamp);
return GameDetailsProvider.GetMultiplayerDetails(tf2Api);
}
// Could be main menu, might be some other random thing. This can be cleaned up later
else
Expand Down

0 comments on commit 7204808

Please sign in to comment.