11use std:: ffi:: OsStr ;
2+ use std:: fs:: File ;
3+ use std:: io:: { BufRead , BufReader } ;
24use std:: iter:: once;
35use std:: os:: windows:: prelude:: OsStrExt ;
46use std:: ptr;
@@ -101,6 +103,44 @@ fn bf2042_message_action(message_to_send: &str) {
101103 }
102104}
103105
106+ fn get_config_key ( chat : & str , defaults : u16 ) -> u16 {
107+ let docs = dirs_next:: document_dir ( ) ;
108+ match docs {
109+ Some ( docs) => {
110+ match File :: open ( format ! (
111+ "{}\\ Battlefield 2042\\ settings\\ PROFSAVE_profile" ,
112+ docs. to_str( ) . unwrap( )
113+ ) ) {
114+ Ok ( f) => {
115+ let f = BufReader :: new ( f) ;
116+ for line in f. lines ( ) {
117+ let line = line. unwrap_or_default ( ) ;
118+ if line. starts_with ( & format ! ( "GstKeyBinding.default.{}.0.button" , chat) ) {
119+ return match line. split ( ' ' ) . last ( ) . unwrap_or ( "" ) . parse ( ) {
120+ Ok ( key_code) => key_code,
121+ Err ( _) => {
122+ log:: error!( "Keycode in config invalid, using defaults..." ) ;
123+ defaults
124+ }
125+ } ;
126+ }
127+ }
128+ log:: error!( "Keybind not found in config of game, using defaults..." ) ;
129+ defaults
130+ }
131+ Err ( _) => {
132+ log:: error!( "Cant open profsave of bf2042 at \" {}\\ Battlefield 2042\\ settings\\ PROFSAVE_profile\" , using defaults..." , docs. to_str( ) . unwrap( ) ) ;
133+ defaults
134+ }
135+ }
136+ }
137+ None => {
138+ log:: error!( "Can't find documents folder, using defaults..." ) ;
139+ defaults
140+ }
141+ }
142+ }
143+
104144// https://gist.github.com/dretax/fe37b8baf55bc30e9d63
105145pub fn send_message (
106146 cfg : & structs:: SeederConfig ,
@@ -116,6 +156,14 @@ pub fn send_message(
116156 SetForegroundWindow ( game_info. game_process ) ;
117157 ShowWindow ( game_info. game_process , 9 ) ;
118158 sleep ( Duration :: from_millis ( 1808 ) ) ;
159+ let squad_key = match game_name == "Battlefield™ 2042" {
160+ true => get_config_key ( "GstKeyBinding.default.ConceptSquadChat.0.button" , 0x26 ) ,
161+ false => 0x26 ,
162+ } ;
163+ let team_key = match game_name == "Battlefield™ 2042" {
164+ true => get_config_key ( "GstKeyBinding.default.ConceptTeamChat.0.button" , 0x25 ) ,
165+ false => 0x25 ,
166+ } ;
119167
120168 match cfg. chat_type {
121169 structs:: ChatType :: Announce => {
@@ -127,15 +175,17 @@ pub fn send_message(
127175 }
128176 structs:: ChatType :: Public => {
129177 if game_name == "Battlefield™ 2042" {
130- send_keys:: key_enter ( 0x26 , 50 ) ;
131- sleep ( Duration :: from_secs ( 1 ) ) ;
132- message_action ( current_message, 0x0F ) ;
178+ send_keys:: key_enter ( squad_key, 50 ) ;
179+ sleep ( Duration :: from_secs ( 3 ) ) ;
180+ let tab_key =
181+ get_config_key ( "GstKeyBinding.default.ConceptChat.1.button" , 0x0F ) ;
182+ message_action ( current_message, tab_key) ;
133183 } else {
134- message_action ( current_message, 0x24 ) ;
184+ message_action ( current_message, squad_key ) ;
135185 }
136186 }
137- structs:: ChatType :: Team => message_action ( current_message, 0x25 ) ,
138- structs:: ChatType :: Squad => message_action ( current_message, 0x26 ) ,
187+ structs:: ChatType :: Team => message_action ( current_message, team_key ) ,
188+ structs:: ChatType :: Squad => message_action ( current_message, squad_key ) ,
139189 }
140190
141191 ShowWindow ( game_info. game_process , 6 ) ;
0 commit comments