1818#include < ios>
1919#include < io.h>
2020#include < fcntl.h>
21+ #include < stdex.h>
2122
2223std::wstring g_curExeDir;
2324
@@ -223,8 +224,17 @@ namespace api {
223224 HookHandle *allReadyToStart = nullptr ;
224225 std::vector<std::function<void ()>> ALL_READY_TO_START;
225226
227+ std::vector<std::string> EMBER_ARGS;
228+ std::vector<std::string> DK2_ARGS;
229+
226230 int __cdecl proxy_main (int argc, char *argv[]) {
227231 int exitCode = -1 ;
232+ argc = DK2_ARGS.size ();
233+ std::vector<char *> args;
234+ args.reserve (DK2_ARGS.size ());
235+ for (auto &arg : DK2_ARGS) args.push_back ((char *) arg.c_str ());
236+ args.push_back (NULL );
237+ argv = &*args.begin ();
228238
229239 for (auto &F : BEFORE_MAIN) {
230240 exitCode = F (argc, argv);
@@ -237,6 +247,24 @@ namespace api {
237247 return exitCode;
238248 }
239249
250+ std::string findArgValue (const std::string &name) {
251+ for (auto &arg : EMBER_ARGS) {
252+ if (arg.starts_with (name + " =" )) {
253+ return arg.substr (name.length () + 1 );
254+ }
255+ }
256+ return std::string ();
257+ }
258+
259+ bool hasFlag (const std::string &name) {
260+ for (auto &arg : EMBER_ARGS) {
261+ if (arg == name) {
262+ return true ;
263+ }
264+ }
265+ return false ;
266+ }
267+
240268 bool initialize () {
241269#ifdef REVERSE_MODE
242270 AllocConsole ();
@@ -257,6 +285,25 @@ namespace api {
257285 printf (" bootstrap patcher base: %p\n " , g_bootstrap_patcher);
258286 printf (" dk2 base: %p\n " , dk2_base);
259287
288+ int nArgs;
289+ LPWSTR *szArglist = CommandLineToArgvW (GetCommandLineW (), &nArgs);
290+ if (szArglist == NULL ) {
291+ printf (" CommandLineToArgvW failed\n " );
292+ return false ;
293+ }
294+ for (int i = 0 ; i < nArgs; i++) {
295+ std::wstring warg (szArglist[i]);
296+ std::string arg = utf8_encode (warg);
297+ printf (" %d: %ws\n " , i, szArglist[i]);
298+ if (i != 0 && arg.starts_with (" -ember:" )) {
299+ arg = arg.substr (7 );
300+ EMBER_ARGS.push_back (arg);
301+ } else DK2_ARGS.push_back (arg);
302+ }
303+
304+
305+ LocalFree (szArglist);
306+
260307 g_curExeDir.resize (MAX_PATH, L' \0 ' );
261308 if (GetModuleFileNameW (g_bootstrap_patcher, &*g_curExeDir.begin (), MAX_PATH) == 0 ) return false ;
262309 wchar_t *p1 = wcsrchr (&*g_curExeDir.begin (), ' /' );
0 commit comments