VB.Net 自定义 Minecraft 启动器

问题描述 投票:0回答:3

我想在 VB.Net 中为我和我的朋友创建我自己的 Minecraft 启动器。我有这个代码,它为我提供了访问令牌。

Private ACCESS_TOKEN As String
Public Function GetAccessToken() As String
    Return ACCESS_TOKEN
End Function
Public Sub ObtainAccessToken()
    Dim username As String = TextBox1.Text
    Dim password As String = TextBox2.Text
    Dim UUID As String = Guid.NewGuid.ToString()
    Dim httpWebRequest = DirectCast(WebRequest.Create("https://authserver.mojang.com/authenticate"), HttpWebRequest)
    httpWebRequest.ContentType = "application/json"
    httpWebRequest.Method = "POST"

    Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream())
        Dim json As String = (Convert.ToString((Convert.ToString("{""agent"":{""name"":""Minecraft"",""version"":1},""username"":""") & username) + """,""password"":""") & password) + """,""clientToken"":" & ControlChars.Quote & UUID & ControlChars.Quote & "}"

        streamWriter.Write(json)
        streamWriter.Flush()
        streamWriter.Close()

        Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
        Using streamReader = New StreamReader(httpResponse.GetResponseStream())
            Dim result = streamReader.ReadToEnd()
            ACCESS_TOKEN = result
        End Using
    End Using
End Sub

但是我可以用这个访问令牌做什么?如何使用 java 参数直接启动 Minecraft?我想启动minecraft.jar文件。

vb.net access-token minecraft launcher
3个回答
1
投票

在.minecraft文件夹中,所有参数都在version.json中

这是 1.8.8 版本 (.minecraft/versons/1.8.8) 中的 json 片段

"id": "1.8.8",
"time": "2016-06-01T07:45:48-04:00",
"releaseTime": "2015-07-27T06:31:28-04:00",
"type": "release",
"minecraftArguments": "--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} --assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userProperties ${user_properties} --userType ${user_type}"

args位于“minecraftArguments”下,jar文件位于同一目录中,名为1.8.8.jar。


0
投票

这些是我编程的开始:) 我从 Visual Basic 开始,现在我正在学习 C++。这适用于任何想知道如何制作 Minecraft Launcher 的人。

首先您必须下载“游戏文件”,所有内容都有详细记录此处。然后你就可以开始思考如何开始游戏了。

您将需要访问权限和客户端令牌我对代码进行了一些改进:

Imports System.IO
Imports System.Net
Imports System.Web.Script.Serialization ' Add Reference System.Web.Extensions

Module Program

    Public Function Authenticate(ByRef username As String, ByRef password As String) As String

        Dim UUID As String = Guid.NewGuid.ToString()
        Dim Request As HttpWebRequest = DirectCast(WebRequest.Create("https://authserver.mojang.com/authenticate"), HttpWebRequest)
        Request.ContentType = "application/json"
        Request.Method = "POST"

        Using Writer = New StreamWriter(Request.GetRequestStream())

            Dim Json As String = ("{ 'agent': {'name': 'Minecraft', 'version': 1}, 'username': '" + username + "', 'password': '" + password + "', 'clientToken': '" + UUID + "', 'requestUser': true }").Replace("'", Chr(34))

            Writer.Write(Json)
            Writer.Flush()
            Writer.Close()

            Dim Response = DirectCast(Request.GetResponse(), HttpWebResponse)
            Using Reader = New StreamReader(Response.GetResponseStream())
                Return Reader.ReadToEnd()
            End Using

        End Using

    End Function

    Sub Main()

        Dim Response As String = Authenticate("username", "password")
        Dim Serializer As JavaScriptSerializer = New JavaScriptSerializer()

        Dim Dictionary As Dictionary(Of String, Object) = Serializer.Deserialize(Of Dictionary(Of String, Object))(Response)

        Dim AccessToken As String = Dictionary("accessToken")
        Dim ClientToken As String = Dictionary("clientToken")

        Console.WriteLine(AccessToken)
        Console.WriteLine(ClientToken)
        Console.Read()

    End Sub

End Module

在此代码中,您将向 mojang 身份验证服务器发送 HTTP POST 请求,然后使用

JavaScriptSerializer
将响应解析为 json。访问令牌和客户端令牌存储在
AccessToken
ClientToken
变量中。 Mojang 身份验证已记录在此处。然后我建议您从
Process
创建
System.Diagnostics
并像这样启动它:

Public Sub LaunchMinecraft(ByRef AccessToken As String, ByRef ClientToken As String)

    Dim Xmx As String = "4G"
    Dim Xms As String = "2G"
    Dim Title As String = "My Minecraft Instance"
    Dim Version As String = "1.7.10"
    Dim AssetIndex As String = "..." ' AssetIndex obtained from mojang server
    Dim Username As String = "..." ' Minecraft username obtained from mojang server
    Dim Libraries As String = "..." ' Paths to all libraries separated by ;

    Dim JavaProcess As Process = New Process()
    JavaProcess.StartInfo.UseShellExecute = False
    JavaProcess.StartInfo.CreateNoWindow = False
    JavaProcess.StartInfo.FileName = "..." ' Path to javaw.exe or java.exe
    JavaProcess.StartInfo.Arguments = "-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump" +
                            " -Xmx" + Xmx +
                            " -Xms" + Xms +
                            " -Djava.library.path=.//bin/natives" +
                            " -Dminecraft.client.jar=.//bin/modpack.jar" +
                            " -Dminecraft.applet.TargetDirectory=.//" +
                            " -cp .//bin/modpack.jar;" + Libraries + ";.//bin/minecraft.jar" +
                            " -XX:+UnlockExperimentalVMOptions" +
                            " -XX:+UseG1GC -XX:G1NewSizePercent=20" +
                            " -XX:G1ReservePercent=20" +
                            " -XX:MaxGCPauseMillis=50" +
                            " -XX:G1HeapRegionSize=16M" +
                            " net.minecraft.launchwrapper.Launch" +
                            " --gameDir .//" +
                            " --username " + Username +
                            " --assetsDir ..//..//..//cache/assets" +
                            " --assetIndex " + AssetIndex +
                            " --version " + Version +
                            " --uuid " + ClientToken +
                            " --accessToken " + AccessToken +
                            " --userProperties {}" +
                            " --userType mojang" +
                            " --tweakClass cpw.mods.fml.common.launcher.FMLTweaker" +
                            " --title " + Title
    JavaProcess.Start()

End Sub

此代码未经测试,也有相对路径。这只是一个例子。请注意,这是针对经过改装的《我的世界》。希望有帮助!


0
投票

最简单的方法可能就是制作一个 Prism Launcher 的分支。

© www.soinside.com 2019 - 2024. All rights reserved.