aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Minecraft.Client/Windows64/Windows64_Minecraft.cpp57
-rw-r--r--README.md14
2 files changed, 47 insertions, 24 deletions
diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp
index 9d9537c5..3d5eec00 100644
--- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp
+++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp
@@ -766,33 +766,44 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
//g_iScreenHeight = 544;
}
- // Default username will be "Windows"
- strncpy_s(g_Win64Username, sizeof(g_Win64Username), "Windows", _TRUNCATE);
+ char cmdLineA[1024];
+ strncpy_s(cmdLineA, sizeof(cmdLineA), lpCmdLine, _TRUNCATE);
- char exePath[MAX_PATH] = {};
- GetModuleFileNameA(NULL, exePath, MAX_PATH);
- char* lastSlash = strrchr(exePath, '\\');
- if (lastSlash) *(lastSlash + 1) = '\0';
-
- char filePath[MAX_PATH] = {};
- _snprintf_s(filePath, sizeof(filePath), _TRUNCATE, "%susername.txt", exePath);
+ char *nameArg = strstr(cmdLineA, "-name ");
+ if (nameArg)
+ {
+ nameArg += 6;
+ while (*nameArg == ' ') nameArg++;
+ char nameBuf[17];
+ int n = 0;
+ while (nameArg[n] && nameArg[n] != ' ' && n < 16) { nameBuf[n] = nameArg[n]; n++; }
+ nameBuf[n] = 0;
+ strncpy_s(g_Win64Username, 17, nameBuf, _TRUNCATE);
+ }
- FILE* f = nullptr;
- if (fopen_s(&f, filePath, "r") == 0 && f)
+ char *ipArg = strstr(cmdLineA, "-ip ");
+ if (ipArg)
{
- char buf[128] = {};
- if (fgets(buf, sizeof(buf), f))
- {
- int len = (int)strlen(buf);
- while (len > 0 && (buf[len - 1] == '\n' || buf[len - 1] == '\r' || buf[len - 1] == ' '))
- buf[--len] = '\0';
+ ipArg += 4;
+ while (*ipArg == ' ') ipArg++;
+ char ipBuf[256];
+ int n = 0;
+ while (ipArg[n] && ipArg[n] != ' ' && n < 255) { ipBuf[n] = ipArg[n]; n++; }
+ ipBuf[n] = 0;
+ strncpy_s(g_Win64MultiplayerIP, 256, ipBuf, _TRUNCATE);
+ g_Win64MultiplayerJoin = true;
+ }
- if (len > 0)
- {
- strncpy_s(g_Win64Username, sizeof(g_Win64Username), buf, _TRUNCATE);
- }
- }
- fclose(f);
+ char *portArg = strstr(cmdLineA, "-port ");
+ if (portArg)
+ {
+ portArg += 6;
+ while (*portArg == ' ') portArg++;
+ char portBuf[16];
+ int n = 0;
+ while (portArg[n] && portArg[n] != ' ' && n < 15) { portBuf[n] = portArg[n]; n++; }
+ portBuf[n] = 0;
+ g_Win64MultiplayerPort = atoi(portBuf);
}
}
diff --git a/README.md b/README.md
index 6e9f18ae..e6583e76 100644
--- a/README.md
+++ b/README.md
@@ -33,10 +33,22 @@ Basic LAN multiplayer is available on the Windows build
- Other players on the same LAN can discover the session from the in-game Join Game menu
- Game connections use TCP port `25565` by default
- LAN discovery uses UDP port `25566`
-- You can override your in-game username at launch with `username.txt`
This feature is based on [LCEMP](https://github.com/LCEMP/LCEMP/)
+### Launch Arguments
+
+| Argument | Description |
+|--------------------|----------------------------------------------------------------------------------------------------------------|
+| `-name <username>` | Sets your in-game username |
+| `-ip <address>` | Manually connect to an IP if LAN advertising does not work or if the server cannot be discovered automatically |
+| `-port <port>` | Override the default port if it was changed in the source |
+
+Example:
+```
+Minecraft.Client.exe -name Steve -ip 192.168.0.25 -port 25565
+```
+
## Controls (Keyboard & Mouse)
- **Movement**: `W` `A` `S` `D`