Skip to content

Commit

Permalink
remove the memory reader to allow it to work with EAAC
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Oct 22, 2024
1 parent d48443d commit 31cc7ca
Show file tree
Hide file tree
Showing 19 changed files with 200 additions and 954 deletions.
30 changes: 0 additions & 30 deletions Battlefield rich presence/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,5 @@ public static ServerInfo GetCurrentServer(string playerName, Resources.Statics.G
}
return JsonConvert.DeserializeObject<ServerInfo>(responseContent);
}

public static void PostPlayerlist(GameReader.CurrentServerReader currentServerReader, Guid guid)
{
var payload = new
{
guid = guid.ToString(),
serverinfo = new
{
name = currentServerReader.ServerName,
gameId = currentServerReader.GameId
},
teams = new
{
team1 = currentServerReader.PlayerListsTeam1,
team2 = currentServerReader.PlayerListsTeam2,
scoreteam1 = currentServerReader.ServerScoreTeam1,
scoreteam2 = currentServerReader.ServerScoreTeam2,
scoreteam1FromKills = currentServerReader.Team1ScoreFromKill,
scoreteam2FromKills = currentServerReader.Team2ScoreFromKill,
scoreteam1FromFlags = currentServerReader.Team1ScoreFromFlags,
scoreteam2FromFlags = currentServerReader.Team2ScoreFromFlags,
}
};
string dataString = JsonConvert.SerializeObject(payload);
string jwtData = Jwt.Create(dataString);
string stringPayload = JsonConvert.SerializeObject(new { data = jwtData });
StringContent httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");
HttpResponseMessage httpResponse = new HttpClient().PostAsync("https://api.gametools.network/seederplayerlist/bf1", httpContent).Result;
_ = httpResponse.Content.ReadAsStringAsync().Result;
}
}
}
6 changes: 3 additions & 3 deletions Battlefield rich presence/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@
<setting name="Guid" serializeAs="String">
<value>00000000-0000-0000-0000-000000000000</value>
</setting>
<setting name="GatherServerInfo" serializeAs="String">
<value>False</value>
</setting>
<setting name="bf2042" serializeAs="String">
<value />
</setting>
<setting name="bf1" serializeAs="String">
<value />
</setting>
</BattlefieldRichPresence.Properties.Settings>
</userSettings>
</configuration>
6 changes: 3 additions & 3 deletions Battlefield rich presence/Battlefield rich presence.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<RootNamespace>BattlefieldRichPresence</RootNamespace>
<IsWebBootstrapper>false</IsWebBootstrapper>
Expand Down Expand Up @@ -66,8 +66,8 @@
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
<PackageReference Include="System.Console" Version="4.3.1" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="7.0.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="System.Linq.Expressions" Version="4.3.0" />
<PackageReference Include="System.Memory" Version="4.5.5" />
Expand Down
1 change: 0 additions & 1 deletion Battlefield rich presence/ChangePrensence/Frostbite3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public static void Update(DiscordRpcClient client, DateTime startTime, GameInfo
{
buttons.Add(new Button { Label = "View server", Url = $"https://gametools.network/servers/{apiName}/gameid/{extraInfo.GameId}/pc" });
}


presence.Buttons = buttons.ToArray();
client.SetPresence(presence);
Expand Down
5 changes: 2 additions & 3 deletions Battlefield rich presence/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace BattlefieldRichPresence
internal class Config
{
public Structs.GamesPlayerName PlayerNames;
public bool GatherServerInfo;
public Guid Guid;

public Config()
Expand All @@ -24,27 +23,27 @@ public Config()
public void Refresh()
{
Guid = Settings.Default.Guid;
GatherServerInfo = Settings.Default.GatherServerInfo;
PlayerNames = new Structs.GamesPlayerName()
{
Bfbc2 = Settings.Default.bfbc2,
Bf3 = Settings.Default.bf3,
Bf4 = Settings.Default.bf4,
Bfh = Settings.Default.bfh,
Bf1 = Settings.Default.bf1,
Bf5 = Settings.Default.bf5,
Bf2042 = Settings.Default.bf2042
};
}

public void Update()
{
Settings.Default.GatherServerInfo = GatherServerInfo;
Settings.Default.Guid = Guid;

Settings.Default.bfbc2 = PlayerNames.Bfbc2;
Settings.Default.bf3 = PlayerNames.Bf3;
Settings.Default.bf4 = PlayerNames.Bf4;
Settings.Default.bfh = PlayerNames.Bfh;
Settings.Default.bf1 = PlayerNames.Bf1;
Settings.Default.bf5 = PlayerNames.Bf5;
Settings.Default.bf2042 = PlayerNames.Bf2042;
Settings.Default.Save();
Expand Down
38 changes: 1 addition & 37 deletions Battlefield rich presence/DiscordPresence.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using BattlefieldRichPresence.ChangePrensence;
using BattlefieldRichPresence.GameReader;
using BattlefieldRichPresence.Resources;
using BattlefieldRichPresence.Structs;
using DiscordRPC;
Expand Down Expand Up @@ -122,42 +121,7 @@ public void Update()
{
GameInfo gameInfo = Game.IsRunning();
StartStopDiscord(gameInfo);
if (gameInfo.Game == Statics.Game.Bf1)
{
CurrentServerReader currentServerReader = new CurrentServerReader();
if (currentServerReader.HasResults)
{
if (currentServerReader.PlayerListsAll.Count > 0 && currentServerReader.ServerName != "")
{
ServerInfo serverInfo = new ServerInfo
{
Name = currentServerReader.ServerName,
NumPlayers = currentServerReader.PlayerListsAll.Count,
MaxPlayers = 0,
JoinLinkWeb = ""
};
UpdatePresence(gameInfo, serverInfo);

// send info to gametools about server to show in detailed serverinfo page when enabled (privacy reasons)
if (_config.GatherServerInfo)
{
try
{
Api.PostPlayerlist(currentServerReader, this._config.Guid);
}
catch (Exception)
{

}
}
}
else
{
UpdatePresenceInMenu(gameInfo);
}
}
}
else if (Statics.NewTitles.Contains(gameInfo.Game))
if (Statics.NewTitles.Contains(gameInfo.Game))
{
try
{
Expand Down
Loading

0 comments on commit 31cc7ca

Please sign in to comment.