Skip to content

Commit

Permalink
Merge branch 'main' into feature/Show_equpped_titan
Browse files Browse the repository at this point in the history
  • Loading branch information
IncPlusPlus authored Oct 1, 2021
2 parents 77b5e4f + 7992532 commit 2b768ab
Show file tree
Hide file tree
Showing 20 changed files with 554 additions and 553 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Titanfall 2 Discord Rich Presence
# Titanfall 2 Discord Rich Presence

This project aims to allow for Discord's Rich Presence feature to work with Titanfall 2. This is accomplished in a very hacky way. Specifically, known memory addresses are directly read from by this program. Yes, you read that right. I had to mess around in Cheat Engine to find the right memory addresses to read various values from. It's incredibly hacky but at least the code is relatively elegant if I say so myself.

Expand Down Expand Up @@ -52,7 +51,7 @@ Currently this is officially supported only on Windows. However, I've been infor
4. Have fun!

## Supported Game Modes
While this project _is_ stable, it isn't **_nearly_** complete yet. Multiplayer game data isn't easy to track down in memory. For this reason, this project has a limited set of game modes that it supports. You can still play the unsupported game modes. It won't cause any problems. However, only the supported game modes will show your score and other info on Discord. For the list of supported games, see [#45](https://github.com/IncPlusPlus/titanfall2-rp/issues/45).
While this project _is_ stable, it isn't quite complete yet. Multiplayer game data isn't easy to track down in memory. For this reason, this project has a limited amount of data it can retrieve about a given game mode. This is really more of a side note and doesn't affect everyday use. For the list of supported game modes, see [#45](https://github.com/IncPlusPlus/titanfall2-rp/issues/45).

## Known Issues
See [the bugs area](https://github.com/IncPlusPlus/titanfall2-rp/issues?q=is%3Aopen+is%3Aissue+label%3Abug) for all the known issues at this time.
Expand All @@ -71,9 +70,13 @@ This section is just for developers. If you only want to _use_ this program, see

To build this project, run `dotnet publish`.

To run this project, run the exe file from `[PROJECT_ROOT_DIR]\titanfall2-rp\bin\Debug\net5.0\win10-x64\publish` (where PROJECT_ROOT_DIR is the directory where you cloned this project) which was created when you ran `dotnet publish`.
To only run this project, run the exe file from `[PROJECT_ROOT_DIR]\Windows\bin\Debug\net5.0-windows\win10-x64\publish` (where PROJECT_ROOT_DIR is the directory where you cloned this project) which was created when you ran `dotnet publish`.

If you change anything in the ZipExtractor project, the changes will only be reflected after running `dotnet publish ZipExtractor` because of where the main `titanfall2-rip` project expects it to be (for use as an embedded resource).
If you change anything in the ZipExtractor project, the changes will only be reflected after running `dotnet publish ZipExtractor` because of where the main `titanfall2-rp` project expects it to be (for use as an embedded resource).

## Building on Linux
Building on Linux works the same way as on Windows. However, the exe you create will have the auto-updating feature disabled on Windows.
Building on Linux allows you to build only the Wine project. This is because you can't build WPF and WinForms projects on .NET 5.0 on Linux (as far as I'm aware).

To create a fully-fledged executable for running in Wine, run `dotnet publish ZipExtractor && dotnet publish Wine`. Your exe will be located at `[PROJECT_ROOT_DIR]\Wine\bin\Debug\net5.0\win10-x64\publish\titanfall2-rp-Wine.exe`.

If you are only trying to _run_ the Wine project (i.e. inside of your IDE), you need to run `dotnet publish ZipExtractor; dotnet build Wine`.
39 changes: 33 additions & 6 deletions Windows/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.ComponentModel;
using System.Reflection;
using System.Windows;
using System.Windows.Forms;
using Common;
using log4net;
using titanfall2_rp.updater;
using Xamarin.Forms;
using Xamarin.Forms.Platform.WPF;
Expand All @@ -16,15 +18,35 @@ namespace titanfall2_rp.Windows
/// </summary>
public partial class App
{
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod()!.DeclaringType);
private NotifyIcon? _notifyIcon;
private RichPresenceManager? _program;
private bool _isExit;

protected override void OnStartup(StartupEventArgs e)
{
Forms.Init();
_program = new RichPresenceManager();
_program.Begin();

base.OnStartup(e);
try
{
Forms.Init();
}
catch (Exception exception)
{
Log.Fatal("Failed at Forms.Init()", exception);
throw;
}

try
{
base.OnStartup(e);
}
catch (Exception exception)
{
Log.Fatal("Failed at base.OnStartup(e)", exception);
throw;
}

_notifyIcon = new NotifyIcon();
_notifyIcon.MouseDoubleClick += NotifyIconOnDoubleClick;
Expand All @@ -33,10 +55,15 @@ protected override void OnStartup(StartupEventArgs e)
_notifyIcon.Visible = true;
_notifyIcon.Text = "Titanfall 2 Discord Rich Presence";

CreateContextMenu();

_program = new RichPresenceManager();
_program.Begin();
try
{
CreateContextMenu();
}
catch (Exception exception)
{
Log.Fatal("Failed at CreateContextMenu()", exception);
throw;
}
}

private void NotifyIconOnDoubleClick(object? sender, MouseEventArgs e)
Expand Down
7 changes: 7 additions & 0 deletions Windows/Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<!--https://docs.microsoft.com/en-us/answers/questions/296816/self-contained-single-file-does-not-produce-a-sing.html-->
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Nullable>enable</Nullable>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -61,6 +62,12 @@
<ProjectReference Include="..\titanfall2-rp\titanfall2-rp.csproj" />
</ItemGroup>

<ItemGroup>
<!--https://docs.microsoft.com/en-us/dotnet/core/deploying/trim-self-contained#prevent-assemblies-from-being-trimmed-->
<!--Without this, illink gets rid of it and causes WPF to crash as soon as Forms.Init() gets called-->
<TrimmerRootAssembly Include="System.Runtime" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
Expand Down
52 changes: 2 additions & 50 deletions titanfall2-rp/GameDetailsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public static class GameDetailsProvider

public static (string, string, Timestamps?, Assets? assets) GetMultiplayerDetails(Titanfall2Api tf2Api, DateTime gameOpenTimestamp)
{
var currentGameMode = tf2Api.GetGameMode();
var mpStats = tf2Api.GetMultiPlayerGameStats();
string gameDetails = tf2Api.GetGameMode().ToFriendlyString();
string gameState = "";
string gameState = $"{mpStats.GetTeam1Score()}:{mpStats.GetTeam2Score()}";
var timestamps = new Timestamps(gameOpenTimestamp);
var playerInTitan = tf2Api.IsPlayerInTitan();
var assets = new Assets
Expand All @@ -32,54 +32,6 @@ public static (string, string, Timestamps?, Assets? assets) GetMultiplayerDetail
SmallImageKey = playerInTitan ? tf2Api.GetTitan().GetAssetName() : tf2Api.GetMultiPlayerGameStats().GetCurrentFaction().GetAssetName(),
SmallImageText = playerInTitan ? tf2Api.GetTitan().ToFriendlyString() : tf2Api.GetMultiPlayerGameStats().GetCurrentFaction().ToFriendlyString(),
};
switch (currentGameMode)
{
case GameMode.coliseum:
break;
case GameMode.aitdm:
var attritionStats = tf2Api.GetMultiPlayerGameStats().GetAttrition();
gameState = attritionStats.GetTeam1Score() + ":" + attritionStats.GetTeam2Score();
break;
case GameMode.tdm:
break;
case GameMode.cp:
var ampedHardpointStats = tf2Api.GetMultiPlayerGameStats().GetAmpedHardpoint();
gameState = ampedHardpointStats.GetTeam1Score() + ":" + ampedHardpointStats.GetTeam2Score();
break;
case GameMode.at:
var bountyHuntStats = tf2Api.GetMultiPlayerGameStats().GetBountyHunt();
gameState = bountyHuntStats.GetTeam1Score() + ":" + bountyHuntStats.GetTeam2Score();
break;
case GameMode.ctf:
var ctfStats = tf2Api.GetMultiPlayerGameStats().GetCaptureTheFlag();
gameState = ctfStats.GetTeam1Score() + ":" + ctfStats.GetTeam2Score();
break;
case GameMode.lts:
break;
case GameMode.ps:
break;
case GameMode.speedball:
break;
case GameMode.mfd:
break;
case GameMode.ttdm:
var titanBrawlStats = tf2Api.GetMultiPlayerGameStats().GetTitanBrawl();
gameState = titanBrawlStats.GetTeam1Score() + ":" + titanBrawlStats.GetTeam2Score();
break;
case GameMode.fd_easy:
break;
case GameMode.fd_normal:
break;
case GameMode.fd_hard:
break;
case GameMode.fd_insane:
break;
case GameMode.solo:
break;
default:
throw new ArgumentException("Unknown game mode '" + currentGameMode + "'.");
}

return (gameDetails, gameState, timestamps, assets);
}

Expand Down
38 changes: 38 additions & 0 deletions titanfall2-rp/MpGameStats/AmpedHardpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Process.NET;

namespace titanfall2_rp.MpGameStats
{
public class AmpedHardpoint : MpStats
{
public AmpedHardpoint(Titanfall2Api tf2Api, ProcessSharp processSharp) : base(tf2Api, processSharp)
{ }

/// <summary>
/// Get the assault score of the current user.
/// </summary>
/// <returns>the user's assault score</returns>
public int GetMyAssaultScore()
{
throw new NotImplementedException(HelpMeBruh);
}

/// <summary>
/// Get the defense score of the current user.
/// </summary>
/// <returns>the user's defense score</returns>
public int GetMyDefenseScore()
{
throw new NotImplementedException(HelpMeBruh);
}

/// <summary>
/// Get the kill count of the current user.
/// </summary>
/// <returns>the user's kill count</returns>
public int GetMyKills()
{
throw new NotImplementedException(HelpMeBruh);
}
}
}
47 changes: 47 additions & 0 deletions titanfall2-rp/MpGameStats/Attrition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using Process.NET;

namespace titanfall2_rp.MpGameStats
{
public class Attrition : MpStats
{
public Attrition(Titanfall2Api tf2Api, ProcessSharp processSharp) : base(tf2Api, processSharp)
{ }

/// <summary>
/// Get the score of the current user.
/// </summary>
/// <returns>the user's score</returns>
public int GetMyScore()
{
throw new NotImplementedException(HelpMeBruh);
}

/// <summary>
/// Get the pilot kills of the current user.
/// </summary>
/// <returns>the number of pilots the user has killed</returns>
public int GetMyPilotKills()
{
throw new NotImplementedException(HelpMeBruh);
}

/// <summary>
/// Get the titan kills of the current user.
/// </summary>
/// <returns>the number of titans the user has killed</returns>
public int GetMyTitanKills()
{
throw new NotImplementedException(HelpMeBruh);
}

/// <summary>
/// Get the minion kills of the current user.
/// </summary>
/// <returns>the number of minions the user has killed</returns>
public int GetMyMinionKills()
{
throw new NotImplementedException(HelpMeBruh);
}
}
}
38 changes: 38 additions & 0 deletions titanfall2-rp/MpGameStats/BountyHunt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Process.NET;

namespace titanfall2_rp.MpGameStats
{
public class BountyHunt : MpStats
{
public BountyHunt(Titanfall2Api tf2Api, ProcessSharp processSharp) : base(tf2Api, processSharp)
{ }

/// <summary>
/// Get the score of the current user.
/// </summary>
/// <returns>the user's score</returns>
public int GetMyScore()
{
throw new NotImplementedException(HelpMeBruh);
}

/// <summary>
/// Get the bonus of the current user.
/// </summary>
/// <returns>the user's bonus</returns>
public int GetMyBonus()
{
throw new NotImplementedException(HelpMeBruh);
}

/// <summary>
/// Get the kills of the current user.
/// </summary>
/// <returns>the user's kills</returns>
public int GetMyKills()
{
throw new NotImplementedException(HelpMeBruh);
}
}
}
56 changes: 56 additions & 0 deletions titanfall2-rp/MpGameStats/CaptureTheFlag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using Process.NET;

namespace titanfall2_rp.MpGameStats
{
public class CaptureTheFlag : MpStats
{
public CaptureTheFlag(Titanfall2Api tf2Api, ProcessSharp processSharp) : base(tf2Api, processSharp)
{ }

/// <summary>
/// Get whether the game has passed halftime
/// </summary>
/// <returns>true if in the 2nd half, false if halftime hasn't happened yet</returns>
public bool IsInSecondHalf()
{
throw new NotImplementedException(HelpMeBruh);
}

/// <summary>
/// Get the amount of time in seconds remaining in the current half
/// </summary>
/// <returns>the time in seconds remaining in the current half</returns>
public int GetTimeRemainingInHalf()
{
throw new NotImplementedException(HelpMeBruh);
}

/// <summary>
/// Get the number of captures the user has achieved
/// </summary>
/// <returns>the number of captures the user has achieved</returns>
public int GetMyCaptures()
{
throw new NotImplementedException(HelpMeBruh);
}

/// <summary>
/// Get the number of times the user returned their team's flag
/// </summary>
/// <returns>the number of times the user returned their team's flag</returns>
public int GetMyReturns()
{
throw new NotImplementedException(HelpMeBruh);
}

/// <summary>
/// Get the number of kills the user has made
/// </summary>
/// <returns>the number of players the user has killed</returns>
public int GetMyKills()
{
throw new NotImplementedException(HelpMeBruh);
}
}
}
10 changes: 10 additions & 0 deletions titanfall2-rp/MpGameStats/Coliseum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Process.NET;

namespace titanfall2_rp.MpGameStats
{
public class Coliseum : MpStats
{
public Coliseum(Titanfall2Api tf2Api, ProcessSharp processSharp) : base(tf2Api, processSharp)
{ }
}
}
10 changes: 10 additions & 0 deletions titanfall2-rp/MpGameStats/FrontierDefense.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Process.NET;

namespace titanfall2_rp.MpGameStats
{
public class FrontierDefense : MpStats
{
public FrontierDefense(Titanfall2Api tf2Api, ProcessSharp processSharp) : base(tf2Api, processSharp)
{ }
}
}
Loading

0 comments on commit 2b768ab

Please sign in to comment.