Skip to content

Instantly share code, notes, and snippets.

@Tsugami
Last active June 3, 2022 19:35
Show Gist options
  • Save Tsugami/daf7ca6345957ca32b66fdb5a064cde6 to your computer and use it in GitHub Desktop.
Save Tsugami/daf7ca6345957ca32b66fdb5a064cde6 to your computer and use it in GitHub Desktop.
Change MHFrontier hosts Batch file

Batch file to update the hosts file with MHF addresses

How to use:

  1. Copy this file to your machine
  2. open cmd in the folder you pasted the file
  3. Run the below command in cmd to setup your a server
setup.bat 26.220.184.112 pewpewdojo-server

Todo:

  • Update hosts
  • Reset IE cache
  • Start Game
@echo off
set usage="Invalid usage, try: setup.bat <ip-address> <server-name>"
if "%1" == "" (
echo %usage%
pause
exit /b 1
)
if "%2" == "" (
echo %usage%
pause
exit /b 1
)
set "host=%1"
set "host_name=%2"
setlocal EnableExtensions DisableDelayedExpansion
set "host_path=%SYSTEMROOT%\System32\drivers\etc\hosts"
set "backup_host_path=%SYSTEMROOT%\System32\drivers\etc\hosts.backup"
set "credits=- Added by https://gist.github.com/Tsugami/daf7ca6345957ca32b66fdb5a064cde6"
set adresses[0]=mhfg.capcom.com.tw
set adresses[1]=mhf-n.capcom.com.tw
set adresses[2]=cog-members.mhf-z.jp
set adresses[3]=www.capcom-onlinegames.jp
set adresses[4]=srv-mhf.capcom-networks.jp
setlocal EnableDelayedExpansion
echo Creating backup of hosts file...
copy /b %host_path% %backup_host_path%
call :ChangeHosts
pause
exit /B %ERRORLEVEL%
:ChangeHosts
for /l %%i in (0,1,4) do (
findstr /vi !adresses[%%i]! "!host_path!" >> "%host_path%.tmp"
if %ERRORLEVEL% == 0 (
echo Removed !adresses[%%i]! address from hosts file...
) else (
echo - !adresses[%%i]! was not found in hosts
)
@REM addd new host entry
echo !host! !adresses[%%i]! # !host_name! !credits! >> "%host_path%.tmp"
del "!host_path!"
ren "!host_path!.tmp" "hosts"
echo - !adresses[%%i]! was changed to !host!
)
exit /B 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment