Post news RSS Half-Payne - Game mode accessiblity and Music enhacements

Plenty of new game modes were planned for the next update, but so it's happened that I focused on something else entirely.

Posted by on



Plenty of new game modes were planned for the next update, but so it's happened that I focused on something else entirely.

After last major release I had to rest from working on Half-Payne, but perhaps I was avoiding working on it for too much and some other projects also held it off. It wasn't a complete waste of time though, because I got excited at implementing the features you've seen in this video above, but I still don't like the fact I wasn't focused on game modes in the first place. Anyway, below are some details on Half-Life features that I've never seen implemented before.


Let's be honest - launching custom game modes in Half-Payne is pain. You're supposed to check out the README file and then use console commands - not everyone can do that and with this approach some people will never notice there are custom game modes.

Obviously, GUI (Graphic User Interface) has to be made - you're supposed to launch game modes using windows and buttons like the ones in Half-Life, everyone knows how they work and they get the job done by showing what you can play and game mode rules. The problem is - I couldn't provide this solution, there's no GameUI.dll source code and most likely never will be. Someone may say: "What about VGUI?" and I will answer that after a tiny peek at VGUI I concluded that this nightmare is not worth it, and VGUI is only available when you actually play the game. Imagine creating a dummy map which's only purpose is to provide dumb and clunky VGUI menu, it wasn't worth it.

One day I stumble upon ImGUI - a bloat-free graphical user interface library for C++ . Docs say that it supports SDL, which is what Half-Life using nowadays. I got challenged with question if it's possible to bring ImGUI into Half-Life - the answer is yes.

At first I just copied the ImGUI SDL example to the client.dll source code. I must do it on client because I need to draw ImGUI in the main menu, before the actual game starts (server.dll is not loaded yet). Unfortunately, this resulted in flickering, making the whole thing useless.

The problem was caused by SDL_GL_SwapWindow function call which is a must for ImGUI to be drawn. It wasn't the call itself that caused the problem, but the fact that it was called two times. One time in the engine (hw.dll), and the second time by myself on client, which causes the flickering.

Obviously, the only way I could win is by making the engine somehow execute my ImGUI code before calling SDL_GL_SwapWindow. SoloKiller pointed out that I could put the ImGUI code in TeamFortressViewport::paintBackground() function (name looks unexpected huh?), but it would be only executing while playing the game, which doesn't suit me because I had to draw ImGUI in the main menu, so this was ditched.
The real first step was to find where exactly the CALL SDL_GL_SwapWindow engine's command resorts in the memory. I found it by using APIMonitor, which can trace DLL function calls. By filtering calls only to SDL_GL_SwapWindow, it was no problem to see where the function was called from - see the top of stack trace.

Peeking in the memory itself, there's x86 E8 OP CODE, which means 'call the function by address relative to itself'. First byte is the command itself, next 4 bytes are offset. I just have to calculate the offset to my ImGUI drawing function, you can see how exactly this is done on GitHub (keep in mind the 'origin' is outdated though).

This got me ImGUI test window drawn without flickering, after that I started working on game mode selection window. No more console command bullshit!
It also opens up possibilities of making game mode config maker which will be available right inside the game instead of being separate application.


Maybe you noticed that if you launch whatever Half-Life mod and trigger CD audio - it will just stop playing after level change. Apparently engine checks that if current mod folder is not 'valve' - it actually has to stop the music playback. No idea why this was done, but it sucks.
Obivously the fix could be made by hacking/patching the engine again, like the ImGUI case above, but to be honest I hate hacks like this, they always seem illegal, and in this case it wouldn't let me to do the fancy stuff.

By utilising BASS audio library, I'm gaining better control over sounds and music. Having a total control over music already guarantees that music won't stop when you go through level change. This also allows me to change the way music sounds when slowmotion is active and be able to set music playback back where it was when you load savefiles.
At the moment, there are two effects available for music when slowmotion is active: low pass filter and lower pitch, both of them can be configured. There's also a smooth transition for both effects.
Half-Payne has music directory which is about 25 MBs because the audio consists of .wav files. BASS can play .mp3, which means directory size can be severely lowered.
Expect that I will also implement music playback support for map and custom game mode configs! Playlists and repeat option will most likely will be here too.

I'm also having thoughts on trying to implement dynamic music system, like modern games do. This is something I'd do late in development though.
Note that BASS is used only for music playback, I'm not daring using it to replace engine's sound system.


Goldsource games today can only show one main menu background and it can't be random, but I had a random idea recently that I could rewrite resource/BackgroundLayout.txt and resource/BackgroundLoadingLayout.txt files each time I load up the game, so they point to different background folders. Files are not locked for write so it's definetely possible.
If I succeed - I will add fan backgrounds in the next update.


Today I want to believe that Half-Payne mod is not just about Max Payne meeting Half-Life and Black Mesa, but more about making hacky stuff for vanilla GoldSource that has never been done before, I often call this mod Hack-Payne because of that.

After I'm done with polishing of the new music system, I'm proceeding to work on new gameplay mods as I planned. The problem is - chances I won't meet my original deadline, which is August 31th, I'm afraid it will be pushed to September 31th instead.


Is this sound bug fixed where sounds stay in slow-mo even after you exited slow-mo?

Reply Good karma Bad karma+2 votes
suXin Author

It's related to engine's sound system and thus can't be fixed.

Reply Good karma+4 votes

Heh, would be cool if was third person and all those animations...

Reply Good karma Bad karma+1 vote


Reply Good karma Bad karma+1 vote

Just loaded the mod up for the first time: the GUI for picking custom modes is great.

Reply Good karma Bad karma+1 vote

Hello i installed the mod but when i enter there is no music no tram lady no max voice only the sounds of footsteps and environment

Reply Good karma Bad karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.