Skip to content

Commit f404311

Browse files
committed
update to the same gatherer
1 parent 91684a8 commit f404311

File tree

6 files changed

+532
-16
lines changed

6 files changed

+532
-16
lines changed

Battlefield rich presence.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Global
1313
Release|x64 = Release|x64
1414
EndGlobalSection
1515
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16-
{C4714C39-39F4-47F9-9874-74A6CB2F59E6}.Debug|x64.ActiveCfg = Release|Any CPU
17-
{C4714C39-39F4-47F9-9874-74A6CB2F59E6}.Debug|x64.Build.0 = Release|Any CPU
16+
{C4714C39-39F4-47F9-9874-74A6CB2F59E6}.Debug|x64.ActiveCfg = Debug|Any CPU
17+
{C4714C39-39F4-47F9-9874-74A6CB2F59E6}.Debug|x64.Build.0 = Debug|Any CPU
1818
{C4714C39-39F4-47F9-9874-74A6CB2F59E6}.Release|x64.ActiveCfg = Release|Any CPU
1919
{C4714C39-39F4-47F9-9874-74A6CB2F59E6}.Release|x64.Build.0 = Release|Any CPU
2020
{B5A1A568-AD26-4987-80ED-3B7270BD94D5}.Debug|x64.ActiveCfg = Debug

Battlefield rich presence/Battlefield rich presence.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net6.0-windows</TargetFramework>
3+
<TargetFramework>net7.0-windows</TargetFramework>
44
<OutputType>WinExe</OutputType>
55
<RootNamespace>BattlefieldRichPresence</RootNamespace>
66
<IsWebBootstrapper>false</IsWebBootstrapper>
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
namespace BattlefieldRichPresence.GameReader
2+
{
3+
internal class Chat
4+
{
5+
public const int OFFSET_CHAT_LAST_SENDER = 0x138;
6+
public const int OFFSET_CHAT_LAST_CONTENT = 0x140;
7+
8+
/// <summary>
9+
/// Determine whether the Battlefield 1 chat box is open
10+
/// </summary>
11+
/// <returns></returns>
12+
public static bool GetChatIsOpen()
13+
{
14+
var address = Memory.Read<long>(Memory.GetBaseAddress() + 0x39F1E50);
15+
if (!Memory.IsValid(address))
16+
return false;
17+
address = Memory.Read<long>(address + 0x08);
18+
if (!Memory.IsValid(address))
19+
return false;
20+
address = Memory.Read<long>(address + 0x28);
21+
if (!Memory.IsValid(address))
22+
return false;
23+
address = Memory.Read<long>(address + 0x00);
24+
if (!Memory.IsValid(address))
25+
return false;
26+
address = Memory.Read<long>(address + 0x20);
27+
if (!Memory.IsValid(address))
28+
return false;
29+
address = Memory.Read<long>(address + 0x18);
30+
if (!Memory.IsValid(address))
31+
return false;
32+
address = Memory.Read<long>(address + 0x28);
33+
if (!Memory.IsValid(address))
34+
return false;
35+
address = Memory.Read<long>(address + 0x38);
36+
if (!Memory.IsValid(address))
37+
return false;
38+
address = Memory.Read<long>(address + 0x40);
39+
if (!Memory.IsValid(address))
40+
return false;
41+
42+
return Memory.Read<byte>(address + 0x30) == 0x01;
43+
}
44+
45+
/// <summary>
46+
/// Get the pointer of the chat box, return the pointer if successful, return 0 if failed
47+
/// </summary>
48+
/// <returns></returns>
49+
public static long ChatMessagePointer()
50+
{
51+
var address = Memory.Read<long>(Memory.GetBaseAddress() + 0x3A327E0);
52+
if (!Memory.IsValid(address))
53+
return 0;
54+
address = Memory.Read<long>(address + 0x20);
55+
if (!Memory.IsValid(address))
56+
return 0;
57+
address = Memory.Read<long>(address + 0x18);
58+
if (!Memory.IsValid(address))
59+
return 0;
60+
address = Memory.Read<long>(address + 0x38);
61+
if (!Memory.IsValid(address))
62+
return 0;
63+
address = Memory.Read<long>(address + 0x08);
64+
if (!Memory.IsValid(address))
65+
return 0;
66+
address = Memory.Read<long>(address + 0x68);
67+
if (!Memory.IsValid(address))
68+
return 0;
69+
address = Memory.Read<long>(address + 0xB8);
70+
if (!Memory.IsValid(address))
71+
return 0;
72+
address = Memory.Read<long>(address + 0x10);
73+
if (!Memory.IsValid(address))
74+
return 0;
75+
address = Memory.Read<long>(address + 0x10);
76+
if (!Memory.IsValid(address))
77+
return 0;
78+
else
79+
return address;
80+
}
81+
82+
/// <summary>
83+
/// Get the list of chat boxes, return a pointer if successful, return 0 if failed
84+
/// </summary>
85+
/// <returns></returns>
86+
public static long ChatListPointer()
87+
{
88+
var address = Memory.Read<long>(Memory.GetBaseAddress() + 0x39F1E50);
89+
if (!Memory.IsValid(address))
90+
return 0;
91+
address = Memory.Read<long>(address + 0x70);
92+
if (!Memory.IsValid(address))
93+
return 0;
94+
address = Memory.Read<long>(address + 0x20);
95+
if (!Memory.IsValid(address))
96+
return 0;
97+
address = Memory.Read<long>(address + 0x18);
98+
if (!Memory.IsValid(address))
99+
return 0;
100+
address = Memory.Read<long>(address + 0x28);
101+
if (!Memory.IsValid(address))
102+
return 0;
103+
address = Memory.Read<long>(address + 0x28);
104+
if (!Memory.IsValid(address))
105+
return 0;
106+
address = Memory.Read<long>(address + 0x38);
107+
if (!Memory.IsValid(address))
108+
return 0;
109+
address = Memory.Read<long>(address + 0xD8);
110+
if (!Memory.IsValid(address))
111+
return 0;
112+
address = Memory.Read<long>(address + 0x50);
113+
if (!Memory.IsValid(address))
114+
return 0;
115+
else
116+
return address;
117+
}
118+
119+
public static string GetLastChatSender(out long pSender)
120+
{
121+
pSender = 0;
122+
if (ChatListPointer() != 0)
123+
{
124+
pSender = Memory.Read<long>(ChatListPointer() + OFFSET_CHAT_LAST_SENDER);
125+
return Memory.ReadString(Memory.Read<long>(pSender), 32);
126+
}
127+
return string.Empty;
128+
}
129+
130+
public static string GetLastChatContent(out long pContent)
131+
{
132+
pContent = 0;
133+
if (ChatListPointer() != 0)
134+
{
135+
pContent = Memory.Read<long>(ChatListPointer() + OFFSET_CHAT_LAST_CONTENT);
136+
return Memory.ReadString(Memory.Read<long>(pContent), 256);
137+
}
138+
return string.Empty;
139+
}
140+
}
141+
}

Battlefield rich presence/GameReader/CurrentServerReader.cs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using BattlefieldRichPresence.Resources;
2+
using System;
23
using System.Collections.Generic;
34
using System.Collections.ObjectModel;
45
using System.Linq;
@@ -30,6 +31,12 @@ internal class CurrentServerReader
3031

3132
public string player_vehicle { get; private set; }
3233

34+
public long PSender { get; private set; }
35+
public long PContent { get; private set; }
36+
public string ChatSender { get; private set; }
37+
public string ChatContent { get; private set; }
38+
39+
3340
public CurrentServerReader()
3441
{
3542
PlayerListsAll = new List<Structs.PlayerList>();
@@ -67,7 +74,7 @@ public void Refresh()
6774

6875
for (int i = 0; i < 74; i++)
6976
{
70-
List<string> WeaponSlot = new List<string>();
77+
List<Dictionary<string, string>> WeaponSlot = new List<Dictionary<string, string>>();
7178
var pClientPlayerBA = Player.GetPlayerById(i);
7279
if (!Memory.IsValid(pClientPlayerBA))
7380
continue;
@@ -79,8 +86,13 @@ public void Refresh()
7986
var playerName = Memory.ReadString(pClientPlayerBA + 0x40, 64); // Name
8087
var m_teamId = Memory.Read<int>(pClientPlayerBA + 0x1C34); // Player currentt team
8188
var m_playerIndex = Memory.Read<byte>(pClientPlayerBA + 0x1D7C); // Player server index
82-
var PersionID = Memory.Read<long>(pClientPlayerBA + 0x38); // PersonaId
83-
var SquadID = Memory.Read<int>(pClientPlayerBA + 0x1E50); // Unknown
89+
var spectator = Memory.Read<byte>(pClientPlayerBA + 0x1C31);
90+
var personaId = Memory.Read<long>(pClientPlayerBA + 0x38); // PersonaId
91+
var squadID = Memory.Read<int>(pClientPlayerBA + 0x1E50); // Unknown
92+
93+
var offset = Memory.Read<long>(pClientPlayerBA + 0x11A8);
94+
offset = Memory.Read<long>(offset + 0x28);
95+
var playerClass = Statics.getPlayerClass(Memory.ReadString(offset, 64)); // player class
8496

8597
var pClientVehicleEntity = Memory.Read<long>(pClientPlayerBA + 0x1D38);
8698
if (Memory.IsValid(pClientVehicleEntity))
@@ -94,6 +106,9 @@ public void Refresh()
94106
player_vehicle = null;
95107

96108
var pClientSoldierEntity = Memory.Read<long>(pClientPlayerBA + 0x1D48);
109+
if (!Memory.IsValid(pClientSoldierEntity))
110+
playerClass = Statics.getPlayerClass("");
111+
97112
var pClientSoldierWeaponComponent = Memory.Read<long>(pClientSoldierEntity + 0x698);
98113
var m_handler = Memory.Read<long>(pClientSoldierWeaponComponent + 0x8A8);
99114

@@ -109,7 +124,7 @@ public void Refresh()
109124
var weapon_id = Memory.ReadString(offset0, 64);
110125
if (weapon_id != "")
111126
{
112-
WeaponSlot.Add(weapon_id);
127+
WeaponSlot.Add(Statics.getItem(weapon_id));
113128
}
114129
}
115130
}
@@ -120,19 +135,22 @@ public void Refresh()
120135
teamId = m_teamId,
121136
mark = m_playerIndex,
122137
platoon = new Structs.Platoon()
123-
{
138+
{
124139
icon = platoonUrl,
125140
name = platoonName,
126141
tag = platoonTag
127142
},
128-
squad_id = SquadID,
143+
player_class = playerClass,
144+
Spectator = spectator,
145+
squad_id = squadID,
146+
squad_name = Statics.getSquadName(squadID),
129147
rank = 0,
130148
name = playerName,
131-
player_id = PersionID,
149+
player_id = personaId,
132150
kills = 0,
133151
deaths = 0,
134152
score = 0,
135-
vehicle = player_vehicle,
153+
vehicle = Statics.getItem(player_vehicle),
136154
weapons = WeaponSlot
137155
});
138156
}
@@ -151,8 +169,6 @@ public void Refresh()
151169

152170
var Mark = Memory.Read<byte>(pClientScoreOffset + 0x300);
153171
var Rank = Memory.Read<int>(pClientScoreOffset + 0x304);
154-
if (Rank == 0)
155-
continue;
156172
var Kill = Memory.Read<int>(pClientScoreOffset + 0x308);
157173
var Dead = Memory.Read<int>(pClientScoreOffset + 0x30C);
158174
var Score = Memory.Read<int>(pClientScoreOffset + 0x314);
@@ -204,6 +220,15 @@ public void Refresh()
204220
RefreshTime = DateTime.Now;
205221
HasResults = true;
206222

223+
string sender = GameReader.Chat.GetLastChatSender(out long pSender);
224+
string content = GameReader.Chat.GetLastChatContent(out long pContent);
225+
226+
PSender = pSender;
227+
PContent = pContent;
228+
229+
ChatSender = sender;
230+
ChatContent = content;
231+
207232
Memory.CloseHandle();
208233
}
209234
else

0 commit comments

Comments
 (0)