Create Minecraft launcher from scratch (c + + open source)

Source: Internet
Author: User



Create from scratch Minecraft Starter (c + + Open source )





Novice Racing the ~~~,MC launcher source, freely build their own exclusive MC launcher, this is not easy language, is C + + ... The analysis principle, the key source code all has the detailed annotation, the coding good package broadcasts, therefore said the messy incomparable ...







Baidu Network disk: Http://pan.baidu.com/s/1i3UDOXn



CSDN Download: http://download.csdn.net/detail/u010661060/9376136





Mclauncher (public version) Launcher interface:












The code is all open source and has detailed comments:









Tested platforms: Windows7 64-bit, windowsxp, can be run on all two platforms.





Test MC Startup version: Minecraft1.7.10 pure version, Minecraft1.7.10 Forge version can be started, reasonable words, other versions of the game may also start ...





Special Note:



Because the use of QT platform software, compiled exe files need a lot of praise Platform Library, so that the initiator is larger than the general and the Launcher directory is very confusing, in order to solve this problem, has all the library files and EXE packaged into a new EXE file, Just click MClauncher.exe to run. Note that will be blind than report poison, directly ignore can ...







After a lot of hardships finally out of their own starter, although there are countless bugs, but at least can use ...






At first, I do not know anything, in the Internet a large number of search MC initiator source code, MC startup principle. The source of the search is still quite a lot of, but most of the language is easy to write, under a lot of down. However, do not understand the easy language, Leng did not understand how to start. After thinking about Google to find a bit of source code, but there are GFW, can not afford to buy a VPN, a lot of web pages are not open, and the most important thing is to see not understand English ah. Later in a forum to see a reply, said to start the MC, the analysis of the JSON file inside can be, see this sentence, the production of MC Launcher finally have a look.





First of all start Analysis MC Initiator starting parameters, refer to the Melody Starter, open the Melody Starter Debug switch, you can get the initiator to the game parameters. Of course, you can also open cmd, enter "WMIC process where caption=" Javaw.exe "get Caption,commandline/value>d:\canshu.txt" parameter when initiator starts, To get the initiator parameters.





Before looking at the MC initiator parameters, let's take a look at running jar package parameter passing and dependency analysis.



In order to understand the MC parameter passing, specially made a small Java program simulation MC Game, so do not need to do this small parameter test in the huge MC game.





Mini-game startup script:



JAVA-XMX1024M-DPLAYER.NAME=BLUECAT-CP Helloframe.jar Helloframe



Parametric analysis:



-xmx1024m: Represents the JVM maximum heap memory value (do not understand, anyway, according to other people's copy on the line ...) )






-dplayer.name: (using-d<name>=<value> to set System attribute values) here to pass the game parameters, in the Java program can be used: System.getproperty ("Player.name") Get its value so that you can display the player's name on the test window.





-CP: The class search path for directories and Zip/jar files, followed by the jar package on which the main function executes, and the jar package in which it resides, in no order.





Last parameter: Specifies the class helloframe where the main function is located, and if the class is in the package, preceded by the package name, the class name is only written.





Now look at the real minecraft startup parameters, too long, in terms of the segment.





First paragraph:



C:\Program Files\java\jre7\bin\javaw.exe



(Javaw.exe with full path)





Second paragraph:



-xmx1024m



-dfml.ignoreinvalidminecraftcertificates=true



-dfml.ignorepatchdiscrepancies=true



-djava.library.path= ". Minecraft\natives"



(Heap memory and related system variable settings)





Third paragraph:



-CP "... (Omit 10,000 jar packages here) ... 1.7.10-forge10.13.2.1230.jar "



(Depends on the jar package)





Fourth paragraph:



Net.minecraft.launchwrapper.Launch



(The class where main is located)





Fifth paragraph:



--username BlueCat



--version 1.7.10-forge10.13.2.1230



--gamedir. Minecraft



--assetsdir. minecraft\assets



--assetindex 1.7.10



--uuid ${auth_uuid}



--accesstoken ${auth_access_token}



--userproperties {}



--usertype legacy



--tweakclass Cpw.mods.fml.common.launcher.FMLTweaker



(Game parameters, minecraftarguments in JSON file)





In the simulation applet, except for the fifth paragraph no simulation, the others are similar.



When you start the game, pass these parameters to start the game, these parameters can be obtained from the JSON file, of course, some of the parameters are fixed some of their own settings, such as the game name itself set it.





The JSON file mentioned in the. minecraft\versions\1.7.10\ Directory is 1.7.10.json





The important parameters are here, so the initiator is going to parse the JSON file, get the value, convert it to the startup parameter, and pass it on to the JVM. So, do the initiator do the most is the string processing, I am a dish chicken, C + + and QT are dabbler, smattering, do not know what good method. Anyway, a lot of places are stupid, the code is also written quite messy, think of what to write, write to the end even I do not understand the idea, so look at the source code may be more puzzling, but the key methods are commented. When reading the source code, remember that the purpose of everything is to convert a string of characters in JSON into the appropriate startup parameters. So when you see the code in the blind JB do loop or suddenly minus 1 o'clock, do not Meng Circle, ~_~. About the principle of the initiator said so much, more view source code, haha ~ ~ ~.





Oh, yes, there are some things.



1, is to hope that you help test the launcher, the bug sent to my mailbox [email protected], thank you!



May not fix the bug as soon as possible, because there are more important things to do, should not touch the launcher for a long time recently.





2, the public version of the existing bug:



(1) There is a window sliding bug when the startup version is selected, similar.





This bug, I temporarily helpless, I just a dish chicken, in the continuous study ...



(2) The automatic setting of the memory option is false, is fixed set to 1024m, I do not know how to do.



(3) Java path automatic search algorithm has yet to be strengthened, which is not really a bug, is only to find the system environment variables in path contained in the Java path, testing on other computers have failed.





3, about the production of the initiator process of a bit of egg pain problem



First in the QT4 on the interface of the launcher, most of the buttons with a false connection, and then to parse the JSON file only to find that QT4 no JSON-related classes, JSON-related classes from the QT5 began to have. So ran to the official web under the latest version of the Qt5.5.1 (MinGW version), compiled a program to run it led to QT Creater has not been responding, it is really very painful. Later changed to Qt5.0.2 didn't have this problem, but this version of the release compiled to be installed in the computer without QT run very troublesome, much more library files. So, another Qt5.5.0, or there has been a problem that has not been answered. So, finally compile debugging with Qt5.0.2, and then use Qt5.5.0 to compile the test on another computer ...






4, the last point, refer to the Melody Launcher when there is a natives folder, which is put in a few DLL files, do not know what the use, anyway, is not the start, the melody is missing is downloaded over. In this case, I am extracting the files from the relevant jar package into this directory, so a unzip32.exe program is built into the public launcher.





Start-up is from scratch, many places are not very understanding, there are some places to do some foolish, but also hope that Daniel can guide twos, thank you!!!



Create Minecraft launcher from scratch (c + + open source)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.