Skip to content

Instantly share code, notes, and snippets.

@OatmealDome
Last active April 17, 2024 17:28
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save OatmealDome/3215077c3d254b145d270c6eb78c6b58 to your computer and use it in GitHub Desktop.
Save OatmealDome/3215077c3d254b145d270c6eb78c6b58 to your computer and use it in GitHub Desktop.

Half-Life 2 on the Switch

This is a guide for running Half-Life 2 on your Switch. Please be aware that this isn't a great way of playing Half-Life 2 - do not expect this mod to work perfectly.

Thank you to Bringus Studios for fixing save files not showing up!

NOTE: I am assuming that you have basic knowledge about how modding games on the Switch works. I will not provide support for questions like "how do I install Atmosphère / CFW", "how do I make an emuMMC", "how do I extract games", etc. For help with modding your console, see the NH Switch Guide.

WARNING: While this mod should be fairly safe to use, I do not take any responsibility if your Portal save data is deleted, you get banned from Nintendo Switch Online, or if your Switch explodes.

Instructions

You will need:

  • A modded Switch
  • 7-Zip
  • A copy of Portal: Companion Collection
  • A copy of Half-Life 2 (I used the Android version, the PC one might work)

Let's get started.

  1. Dump the Portal 1 title and extract its romfs to somewhere on your PC.
  2. Extract the game.zip archive to a folder.
  3. Delete the portal and nxcontent/portal folders from the extracted archive folder. We don't need them.
  4. Rename the nxcontent/hl2 folder to nxcontent/portal.
  5. (OPTIONAL) Open nxcontext/rom_boot_params.txt in your favourite text editor and add the following to the end of the file:
+sv_unlockedchapters
15
  1. Copy the hl2/maps folder from your Half-Life 2 game files to hl2 in the extracted archive folder.
  2. Copy the hl2/sound/music folder from your Half-Life 2 game files to hl2/sound in the extracted archive folder.
  3. Rename the hl2 folder to portal.
  4. Rename the portal/resource/hl2_<your language>.txt file to portal/resource/portal_<your language>.txt.
  5. Open the following files in your favourite text editor and replace all instances of hl2 with portal:
  • portal/gameinfo.txt
  • portal/scripts/titles.txt
  • portal/resource/portal_<your language>.txt
  1. Create a new ZIP archive using 7-Zip with the folders portal, nxcontent, and platform. (You can easily do this by by selecting all three folders in File Manager -> right click to open the context menu -> open the 7-Zip menu -> select "Add to xyz.zip".)
  2. Rename the new archive to game.zip if it isn't named that already.
  3. Open the new game.zip file and verify that you see the folders portal, nxcontent, and platform in the root. If you do not see these folders, you did not create the ZIP file correctly.

image

  1. Create the folder atmosphere/contents/01007BB017812000/romfs on your microSD card.
  2. Copy the game.zip file into the romfs folder you created in the previous step.
  3. Create the folder atmosphere/nro_patches/portal on your microSD card.
  4. Download this IPS patch and move it into the portal folder you created in the previous step. Do not change the file name. It must be named A74E2D73E62E187F0F0422482BD37ED8F0FA0777000000000000000000000000.ips to work properly.
  5. Start Portal 1 on your Switch. It should boot into Half-Life 2.

Troubleshooting

Half-Life 2 doesn't boot!

Ensure that you have followed every step (paying special attention to comments in bold) and placed all files in their correct places.

Also, if you aren't using 7-Zip, try using it. I used Archive Utility on macOS once and it didn't work.

It doesn't work on yuzu or Ryujinx!

Yuzu is not able to boot Portal 1 or 2 at the time of writing (July 2, 2022). The relevant bug report for yuzu is located here.

If you are using Ryujinx, update to version 1.1.166 or newer.

Why does my health regenerate automatically?

You are playing as a Portal player, which is programmed to regenerate health over time.

Can I run Half-Life 2: Episode 1 and Episode 2?

Kinda.

Just add the episodic and ep2 folders to the game.zip, and change -game hl2 to -game episodic (for Episode 1) or -game ep2 (for Episode 2) in rom_boot_params.txt.

However, be warned - Episode 1 and 2 are very unstable and like to crash.

Can I run Team Fortress 2 / Counter-Strike Source / Left 4 Dead 1 or 2 / (insert some other Source engine game here)?

Probably not, at least without a significant amount of effort. The main problem here is that the client.nro and server.nro files only contain code for Portal and the Half-Life 2 games. They do not contain the code for any other games.

That being said, you can probably get their maps to load in Portal or Half-Life 2. It might be necessary to do some conversion between file formats for things like models. (I believe some other Source engine branches have their own modified model format?)

Known Issues

Here is a list of the known issues with this mod:

  • The game randomly crashes.
  • NPCs don't animate correctly while walking.
  • The Combine's guns don't do any damage to the player.
  • Health regenerates over time, like in Portal.
  • In-game cameras drawn onto surfaces don't render at the correct places, if they even appear at all.
  • The game stutters a lot, possibly due to shader compilation.
  • After a map loads, the game has to rebuild the node graph.

If you want to try and fix some of these issues, see the next section for potentially useful information.

Technical Details & Potential Improvements

Here's the technical stuff that some people might be interested in.

How was the Portal 1 port achieved?

The Switch version of Portal 1 appears to be based on the NVIDIA Shield version made by NVIDIA Lightspeed Studios.

The main executable in the exefs is a launcher for the Source engine. All NROs (the Switch's version of DLL files) are present in the romfs in the nro folder on the romfs.

All game files are compressed into a single ZIP archive called game.zip. The nxcontent folder in game.zip appears to contain game files that should be overriden specifically on the Switch, along with various other files like shader binaries and caches. The rom_boot_params.txt file in nxcontent contains the command line arguments (and console variables / commands) that are passed to the engine.

Are you able to open the developer console?

Yes, if you add -console to the rom_boot_params.txt file. However, while the console appears, it is seemingly impossible to interact with it. (Plugging in a USB keyboard does nothing.)

What does that IPS patch do?

It removes this call to PointCameraSetupVisibility in CHL2_Player::SetupVisibility() from server.nro. I'm not sure why this crashes.

Here's the specific patch code, if you're interested:

005465D8 1F2003D5 // NOP

What happens when the game randomly crashes?

As far as I can tell, most of the random crashes appear to occur in CUtlMultiList<T, I>::Alloc() called by some AI behaviour class (possibly CAI_SimpleBehavior or a subclass?). I believe this likely means that either the "exhausted index range" or "exhausted memory allocator" errors are occurring, but I haven't confirmed this yet.

How do I debug a crash?

Atmosphère will create crash logs with full stack traces and register dumps in atmosphere/crash_reports on the microSD card. It is also possible to attach the GDB debugger to the game's process. Use these tools to debug crashes.

I managed to fix something!

Great! If you could let me know, that would be awesome. (My Twitter is @OatmealDome, or you can click here to send me an e-mail.) Also, if you release something based on my work, I'd appreciate if you give me a shoutout.

@BringusStudios
Copy link

You will need the software GCFScape to open the vpk files, the music is in hl2_sound_misc_dir.vpk

@deejay87
Copy link

deejay87 commented Jul 7, 2022

Thanks, i try this

@fireflamesniper
Copy link

Can confirm PC Hl2 boots. Just need to extract all the vpks hl2 includes with itself.

@deejay87
Copy link

deejay87 commented Jul 8, 2022

If you load a save , you have the message at the right A.I Disabled
2022070817550200-79E776949C0A6C2BB247E169725582D5
]
I don't remember if it's "normal" :) i have all this games long time ago, i play a little the first episode and at one moment the message appear

@BringusStudios
Copy link

That's weird... Did you put -dev in your rom_boot_params.txt? That happens to me when I'm making maps on the PC version but I'm in dev mode there

@deejay87
Copy link

deejay87 commented Jul 8, 2022

i have test lot of setup of files yes, add +exec on this file, add autoexec.cfg , test with "ai_norebuildgraph" etc, nothing want to work, i have just create this AI Disabled everytime if i setup like i say :)
This problem is know from long time yes, but removed when you use it on console
Oh something else i see is this
2022070819265100-79E776949C0A6C2BB247E169725582D5

@NathGab68
Copy link

NathGab68 commented Jul 11, 2022

Hey, I need help, I have the nsp game file (portal 1) but I can't open it with win-rar or 7zip.

@BringusStudios
Copy link

BringusStudios commented Jul 11, 2022 via email

@NathGab68
Copy link

NathGab68 commented Jul 11, 2022

I use nxdumptool, and when a want click on "Dump installed SD card/ eMMC content" there is "keys file unaviable at "sdmc:/switch/prod.keys". Option disabled" so I can't dump my nsp game files

@BringusStudios
Copy link

BringusStudios commented Jul 11, 2022 via email

@NathGab68
Copy link

Oh, you just need to dump your switch keys first. It's pretty easy if you just Google it

On Mon, Jul 11, 2022, 9:38 AM NathGab68 @.> wrote: @.* commented on this gist. ------------------------------ I use nxdumptool, and when a want click on "Dump installed SD card/ eMMC content" there is "keys file unaviable at "sdmc:/switch/prod.keys"" so I can't dump my nsp game files — Reply to this email directly, view it on GitHub https://gist.github.com/3215077c3d254b145d270c6eb78c6b58#gistcomment-4228086, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZ5326DTJ2IPJAXY6M3GFG3VTREYXANCNFSM52ROIZRQ . You are receiving this because you commented.Message ID: @.***>

It work now, thank you

@ActualMandM
Copy link

ActualMandM commented Jul 12, 2022

It doesn't work on yuzu or Ryujinx!
Both yuzu and Ryujinx are not able to boot Portal 1 or 2 at the time of writing (July 2, 2022).

Just wanted to mention that recent Ryujinx versions can boot both 1 and 2 now. Unsure about yuzu.

Portal
Portal 2

@OatmealDome
Copy link
Author

@ActualMandM Thank you for letting me know. I've updated the guide.

@LittlePlanetCD
Copy link

Just to leave a note here:

Portal and Portal 2 have updated a few days after the last two posts in July, to version 1.0.3.

I couldn't get the patch to work, so I think it might be broken? I'm not sure.

@LittlePlanetCD
Copy link

Nevermind, got the patch to work. it took a bit for it to function, apparently.

@deejay87
Copy link

Nevermind, got the patch to work. it took a bit for it to function, apparently.

what's the patch give ?

@1-dong
Copy link

1-dong commented Mar 2, 2023

For some reason whenever i load a save, it says ai disabled and its literally what it says. Nothing moves, nothing attacks, nothing even
16777779744465857597840016334847
spawns. And isnt there anyway to give the npcs their normal aninations?

@deejay87
Copy link

deejay87 commented Mar 3, 2023

For some reason whenever i load a save, it says ai disabled and its literally what it says. Nothing moves, nothing attacks, nothing even 16777779744465857597840016334847 spawns. And isnt there anyway to give the npcs their normal aninations?

That's what i have if i load a save
https://gist.github.com/OatmealDome/3215077c3d254b145d270c6eb78c6b58?permalink_comment_id=4225630#gistcomment-4225630

@777s3ns3i777
Copy link

I think that you can fix the A.i disabled issue with this. Type these commands into the console.

ai_norebuildgraph 1
ai_resume

Hope this helps some people.

@1-dong
Copy link

1-dong commented Jul 6, 2023

I think that you can fix the A.i disabled issue with this. Type these commands into the console.

ai_norebuildgraph 1 ai_resume

Hope this helps some people.

Ill try and see if it works but i gotta know how to use the console commands on switch

@drang1zzz
Copy link

could you upload the finished zip file or upload it to google drive, I did everything step by step but the game crashes without having time to play the valve screensaver

@1-dong
Copy link

1-dong commented Jul 28, 2023

could you upload the finished zip file or upload it to google drive, I did everything step by step but the game crashes without having time to play the valve screensaver

Maybe you dont have the required firmware installed, you can look up which version you need for portal

@drang1zzz
Copy link

how to switch between weapons?

@icuke
Copy link

icuke commented Aug 3, 2023

You need to create save, open the save folder using DBI and open config.cfg. There you will need to bind weapon switch buttons to some free buttons on joycon, for example i used left and right d-pad buttons:
bind "LEFT" "invnext" bind "RIGHT" "invprev"

@drang1zzz
Copy link

Вам нужно создать save, открыть папку save с помощью DBI и открыть config.cfg. Там вам нужно будет привязать кнопки переключения оружия к некоторым свободным кнопкам на joycon, например, я использовал левую и правую кнопки d-pad: bind "LEFT" "invnext" bind "RIGHT" "invprev"

Thanks!

@thedirptastic
Copy link

Hey, would this work with gmod since it is a mod of HL2?

@dgalvani
Copy link

dgalvani commented Nov 5, 2023

For some reason whenever i load a save, it says ai disabled and its literally what it says. Nothing moves, nothing attacks, nothing even 16777779744465857597840016334847 spawns. And isnt there anyway to give the npcs their normal aninations?

That's what i have if i load a save https://gist.github.com/OatmealDome/3215077c3d254b145d270c6eb78c6b58?permalink_comment_id=4225630#gistcomment-4225630

any luck whit that? i have the same issue. tried a lot of solutions i found, none work, and i dont know if is use the console on switch

@AgentShern
Copy link

will it work on switch lite?

@RayKim1104
Copy link

I made a new game but at the end of loadeing it crashes

@20excal07
Copy link

20excal07 commented Apr 17, 2024

In case anyone comes across this, there's now a much MUCH easier way to do all this.

As a reminder, the LayeredFS directory for Portal 1 is atmosphere/contents/01007BB017812000

  1. Install this atmosphere plugin: https://github.com/masagrator/PortalNXSideLoader (you'll want the one for Portal 1)
  2. Create the rom_boot_params.txt file in romfs/nxcontent/ and fill it with the following (last 2 lines are optional):
dummyExeName
-game
hl2
-glshadersSaveFS
-nodev
-nosteam
+mat_queue_mode
2
+mat_picmip
0
-ignoredxsupportcfg
-dxlevel
90
+r_flashlightdepthtexture
1
+r_portal_stencil_depth
2
+cl_showfps
0
+mat_forceaniso
4
+mat_software_aa_strength 
2
+sv_unlockedchapters
15
  1. Copy the hl2/maps folder from HL2 on Steam to romfs/nxcontent/hl2
    • ( copy the same from the extracted VPK files )
  2. Copy the hl2/sound/music folder from HL2 on Steam to romfs/nxcontent/hl2/sound
    • ( copy the same from the extracted VPK files )
  3. [OPTIONAL] Extract the portal/media folder from the game.zip file that you dumped and put it in romfs/nxcontent/hl2
  4. Install the IPS patch per the original method (see steps 17 & 18). The original link is dead, so get it here via Wayback Machine.
  5. Boot the game and have fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment