1+ #include <string.h>
2+
3+ #include "imports/avs.h"
4+
5+ #include "launcher/launcher-config.h"
6+
7+ // clang-format off
8+ PSMAP_BEGIN (launcher_bootstrap_psmap )
9+ PSMAP_OPTIONAL (PSMAP_TYPE_STR , struct launcher_bootstrap_config , file ,
10+ "bootstrap /file ", "prop /bootstrap .xml ")
11+ PSMAP_OPTIONAL (PSMAP_TYPE_STR , struct launcher_bootstrap_config , selector ,
12+ "bootstrap /selector ", "")
13+ PSMAP_END
14+
15+ PSMAP_BEGIN (launcher_ea3_ident_psmap )
16+ PSMAP_OPTIONAL (PSMAP_TYPE_STR , struct launcher_bootstrap_config , file ,
17+ "ea3_ident /file ", "prop/ea3-ident.xml" )
18+ PSMAP_END
19+
20+ PSMAP_BEGIN (launcher_app_config_psmap )
21+ PSMAP_OPTIONAL (PSMAP_TYPE_STR , struct launcher_app_config_config , file ,
22+ "app_config /file ", "prop/app-config.xml" )
23+ PSMAP_END
24+
25+ PSMAP_BEGIN (launcher_debug_psmap )
26+ PSMAP_OPTIONAL (PSMAP_TYPE_BOOL , struct launcher_debug_config , remote_debugger ,
27+ "debug /remote_debugger ", false )
28+ PSMAP_OPTIONAL (PSMAP_TYPE_BOOL , struct launcher_debug_config , log_property_configs ,
29+ "debug /log_property_configs ", false )
30+ PSMAP_END
31+ // clang-format on
32+
33+ #define ROOT_NODE "/launcher"
34+
35+ static void _launcher_config_parse_hook_dlls (
36+ const property_node * node ,
37+ const char * node_path ,
38+ char * dlls [MAX_PATH ])
39+ {
40+ int cnt ;
41+ struct property_node * cur ;
42+ struct property_node * next ;
43+ char full_node_path [128 ];
44+
45+ strcpy (full_node_path , ROOT_NODE );
46+ strcat (full_node_path , node_path );
47+ strcat (full_node_path , "/dll" );
48+
49+ cnt = 0 ;
50+ cur = property_search (NULL , node , full_node_path );
51+
52+ while (cur ) {
53+ if (cnt >= LAUNCHER_CONFIG_MAX_HOOK_DLL ) {
54+ log_warning ("Currently not supporting more than %d dlls, skipping remaining" , cnt );
55+ break ;
56+ }
57+
58+ next = property_node_traversal (node , TRAVERSE_NEXT_SEARCH_RESULT );
59+
60+ property_node_read (next , PROPERTY_TYPE_STR , dlls [cnt ], MAX_PATH );
61+
62+ cnt ++ ;
63+ cur = next ;
64+ }
65+ }
66+
67+ void launcher_config_init (struct launcher_config * config )
68+ {
69+ log_assert (config );
70+
71+ strcpy (config -> bootstrap .file , "prop/bootstrap.xml" );
72+ memset (config -> bootstrap .selector , 0 , sizeof (config -> bootstrap .selector ));
73+
74+ strcpy (config -> ea3_ident .file , "prop/ea3-ident.xml" );
75+
76+ strcpy (config -> app_config .file , "prop/app-config.xml" );
77+
78+ memset (config -> hook .hook_dlls , 0 , sizeof (config -> hook .hook_dlls ));
79+ memset (config -> hook .before_hook_dlls , 0 , sizeof (config -> hook .before_hook_dlls ));
80+ memset (config -> hook .iat_hook_dlls , 0 , sizeof (config -> hook .iat_hook_dlls ));
81+
82+ config -> debug .remote_debugger = false;
83+ config -> debug .log_property_configs = false;
84+ }
85+
86+ void launcher_config_load_from_file_path (
87+ const char * filepath ,
88+ struct launcher_config * config )
89+ {
90+ struct property * property ;
91+ struct node * node ;
92+
93+ log_assert (filepath );
94+ log_assert (config );
95+
96+ log_misc ("Loading launcher config from file path: %s" , filepath );
97+
98+ property = property_util_load_file (filepath );
99+
100+ node = property_search (property , 0 , ROOT_NODE );
101+
102+ if (node == NULL ) {
103+ log_fatal ("Root node " ROOT_NODE " in launcher config missing" );
104+ }
105+
106+ if (!property_psmap_import (
107+ NULL , node , & config -> bootstrap , launcher_bootstrap_psmap )) {
108+ log_fatal (ROOT_NODE "/bootstrap: load failed" );
109+ }
110+
111+ if (!property_psmap_import (
112+ NULL , node , & config -> ea3_ident , launcher_ea3_ident_psmap )) {
113+ log_fatal (ROOT_NODE "/ea3_ident: load failed" );
114+ }
115+
116+ if (!property_psmap_import (
117+ NULL , node , & config -> app_config , launcher_app_config_psmap )) {
118+ log_fatal (ROOT_NODE "/app_config: load failed" );
119+ }
120+
121+ _launcher_config_parse_hook_dlls (node , "hook/hook_dlls" , config -> hook .hook_dlls );
122+ _launcher_config_parse_hook_dlls (node , "hook/before_hook_dlls" , config -> hook .before_hook_dlls );
123+ _launcher_config_parse_hook_dlls (node , "hook/iat_hook_dlls" , config -> hook .iat_hook_dlls );
124+
125+ if (!property_psmap_import (
126+ NULL , node , & config -> hook , launcher_ea3_ident_psmap )) {
127+ log_fatal (ROOT_NODE "/hook: load failed" );
128+ }
129+
130+ if (!property_psmap_import (
131+ NULL , node , & config -> debug , launcher_debug_psmap )) {
132+ log_fatal (ROOT_NODE "/debug: load failed" );
133+ }
134+ }
135+
136+ void launcher_config_save_to_file_path (
137+ const struct launcher_config * config ,
138+ const char * filepath )
139+ {
140+ char buffer [4096 ];
141+ struct property * property ;
142+ struct property_node * root_node ;
143+ int i ;
144+
145+ property = property_create (
146+ PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE | PROPERTY_FLAG_CREATE ,
147+ buffer ,
148+ sizeof (buffer ));
149+
150+ root_node = property_node_create (
151+ property , NULL , PROPERTY_TYPE_VOID , ROOT_NODE , 0 );
152+
153+ property_psmap_export (property , root_node , config -> bootstrap , launcher_bootstrap_psmap );
154+ property_psmap_export (property , root_node , config -> ea3_ident , launcher_ea3_ident_psmap );
155+ property_psmap_export (property , root_node , config -> app_config , launcher_app_config_psmap );
156+
157+ property_node_create (property , root_node , PROPERTY_TYPE_VOID , "hook/hook_dlls" , 0 );
158+
159+ for (i = 0 ; i < LAUNCHER_CONFIG_MAX_HOOK_DLL ; i ++ ) {
160+ if (config -> hook .hook_dlls [i ] != '\0' ) {
161+ property_node_create (
162+ property , root_node , PROPERTY_TYPE_STR , "hook/hook_dlls/file" , config -> hook .hook_dlls [i ]);
163+ } else {
164+ break ;
165+ }
166+ }
167+
168+ property_node_create (property , root_node , PROPERTY_TYPE_VOID , "hook/before_hook_dlls" , 0 );
169+
170+ for (i = 0 ; i < LAUNCHER_CONFIG_MAX_HOOK_DLL ; i ++ ) {
171+ if (config -> hook .hook_dlls [i ] != '\0' ) {
172+ property_node_create (
173+ property , root_node , PROPERTY_TYPE_STR , "hook/before_hook_dlls/file" , config -> hook .before_hook_dlls [i ]);
174+ } else {
175+ break ;
176+ }
177+ }
178+
179+ property_node_create (property , root_node , PROPERTY_TYPE_VOID , "hook/iat_hook_dlls" , 0 );
180+
181+ for (i = 0 ; i < LAUNCHER_CONFIG_MAX_HOOK_DLL ; i ++ ) {
182+ if (config -> hook .hook_dlls [i ] != '\0' ) {
183+ property_node_create (
184+ property , root_node , PROPERTY_TYPE_STR , "hook/iat_hook_dlls/file" , config -> hook .iat_hook_dlls [i ]);
185+ } else {
186+ break ;
187+ }
188+ }
189+ }
0 commit comments