Skip to content

Instantly share code, notes, and snippets.

@ultimape
Created November 6, 2012 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ultimape/4028249 to your computer and use it in GitHub Desktop.
Save ultimape/4028249 to your computer and use it in GitHub Desktop.
newMONC - new Minecraft Offline Name Changer
@echo off
REM Minecraft Name Changer
echo.
echo **************************************************
echo * newMONC *
echo * new Minecraft Offline Name Changer *
echo **************************************************
echo.
echo Play on SMP LAN when minecraft.net is down,
echo or when you don't have internet.
echo.
echo *does NOT modify any minecraft files!*
echo.
echo. Ver: 1.5a (released 2012-11-06)
echo credits to ultimape@gmail.com
echo.
pause
cls
echo.
echo.
echo version 1.0
echo - Initial release.
echo.
echo version 1.1
echo - Made significantly more robust.
echo - cleaned up the java execution
echo - left console running in background to log any messages from MC
echo.
echo version 1.1a(alternate)
echo - added functionality to source from modified local appdata directroy
echo - will look for a .minecraft folder within current directory by default
echo.
echo version 1.2
echo - fixed a bug with not referencing all the minecraft JARs
echo - now asks for passsword so we don't get any annoying "unregistered" bits
echo.
echo version 1.2slow
echo - modified to run with 512mb of ram
echo ( search for both "-Xms512M" "-Xmx512M" if you want to modify )
echo TODO: prompt for custom ram values.
echo.
echo version 1.3slow
echo - Attempts to find java's install location.
echo This is so we don't get "command not found" errors.
echo.
echo version 1.4
echo - Modified to select server jvm if availible, no longer need "slow" option.
echo.
echo version 1.5
echo - removed ask for password since it doesn't work right
echo - fixed error local appdata sourcing by limiting setlocal scope
echo.
echo version 1.5a
echo - added abilty to customize ram values
echo - adjusted some edge cases where local was not unset
echo - added case for JDK 7
echo.
echo *********************************************
echo * Please support Mojang and buy the game! *
echo *********************************************
echo.
pause
cls
goto find_java_location
:find_java_location
echo testing for JRE location in registry
set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
set Cmd=reg query "%KeyName%" /s
for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j
if "%JAVA_HOME%" == "" goto find_java_location_JDK_7
if exist "%JAVA_HOME%\bin\server\" set ifSERVER_flag=-server
:find_java_location_JDK_7
echo testing for JDK 7 in registry
set KeyName=HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.7
set Cmd=reg query "%KeyName%" /s
for /f "tokens=2*" %%i in ('%Cmd% ^| find "JavaHome"') do set JAVA_HOME=%%j
if "%JAVA_HOME%" == "" goto quit_error_no_java_found
set JAVA_HOME=%JAVA_HOME%\..\jre7
if not exist "%JAVA_HOME%\bin\" goto quit_error_no_java_found
if exist "%JAVA_HOME%\bin\server\" set ifSERVER_flag=-server
echo.
echo Found java at the following location:
echo %JAVA_HOME%
if "%ifSERVER_flag%" == "" goto find_mc_jar_location
echo ...and it can run with server mode (better garbage collection settings)
goto find_mc_jar_location
:find_mc_jar_location
echo.
echo locating minecraft install location...
IF EXIST "minecraft.jar" goto found_mc_in_cd
IF EXIST "bin\minecraft.jar" goto found_mc_in_cd_bin
rem this next line checks in the current directory for the .minecraft folder
rem this works due to changing to the APPDATA variable while in local variable mode
SETLOCAL
set APPDATA=%cd%
IF EXIST "%APPDATA%\.minecraft\bin\minecraft.jar" goto found_mc_in_appdata
ENDLOCAL
rem If we get here, then we still have to check the actual APPDATA,
rem so lets get the old APPDATA variable back by revering from local variable
IF EXIST "%APPDATA%\.minecraft\bin\minecraft.jar" goto found_mc_in_appdata
goto quit_error_no_mc_found
:found_mc_in_appdata
set mc_location=%APPDATA%\.minecraft\bin\
echo ...Located Minecraft in default location.
goto located
:found_mc_in_cd
rem this is in case minecraft is installed in a non-standard location.
set mc_location=%~dp0
echo ...Located Minecraft.jar within current directory.
goto located
:found_mc_in_cd_bin
rem this is in case minecraft is installed in a non-standard location.
set mc_location=%~dp0bin\
echo ...Located Minecraft.jar within .\bin subdirectory.
goto located
:located
echo.
echo class path (minecraft.jar location):
echo %mc_location%*
echo.
pause
goto ask_name
:ask_name
cls.
echo Choose your name? Hit [enter] when finished
rem this sets the variable to whatever the user types in
set /p mc_username=
echo.
cls
goto ask_ram
:ask_ram
cls.
echo How much Ram? Hit [Enter] when finished
echo Integer values only. (aka, no decimals)
echo Value will be interpreted in megabytes. I recomend at least 1024
set /p mc_ram=
if "%mc_ram%" == "" set mc_ram=1024
echo.
cls
echo hello %mc_username%!
echo ram is set to %mc_ram%MB
echo.
echo Going to start minecraft now!
echo.
echo.
echo.Press [ctrl]+[c] to abort . . .
pause
goto start_mc
:start_mc
echo.
echo ************************
echo * starting minecraft *
echo ************************
echo %JAVA_HOME%
echo %ifSERVER_flag%
echo %mc_location%
echo %mc_username%
set command_line_entry= "%JAVA_HOME%\bin\java.exe" %ifSERVER_flag% -Xms%mc_ram%M -Xmx%mc_ram%M -Xincgc -cp "%mc_location%minecraft.jar;%mc_location%jinput.jar;%mc_location%lwjgl.jar;%mc_location%lwjgl_util.jar" -Djava.library.path="%mc_location%natives" net.minecraft.client.Minecraft %mc_username%
echo RUNNING: %command_line_entry%
echo **************************************************************
echo * Note: The follow is information from minecraft's console *
echo **************************************************************
pause
%command_line_entry%
echo.
echo.
echo ************************
echo minecraft stopped.
echo.
echo thank you for using newMONC!
echo.
echo.
goto end_cleanup
:quit_error_no_mc_found
echo ***********
echo * ERROR *
echo ***********
echo.
echo minecraft.jar not found
echo ensure minecraft is installed in:
echo %appdata%\.minecraft\
echo with the minecraft.jar existing at
echo %appdata%\.minecraft\bin
echo.
echo alternatively, run this script from the directory where minecraft files are located for it to run that copy
echo.
echo.
goto end_cleanup
:quit_error_no_java_found
echo ***********
echo * ERROR *
echo ***********
echo.
echo Could not locate a valid version of java.
echo.
echo.
goto end_cleanup
:end_cleanup
ENDLOCAL
pause
exit
REM Todo: ask user if he wants to copy this script to that directory
REM Todo: copy script to that directory and create a shortcut in current directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment