I got a response from my friend Michael, who told me lots of details about strings and pointers and C. I realized that the crashes are random and happen because of memory mismanagement in the "con()" function which I found on stackoverflow (I'm still not blaming anyone but myself :P).
Well, he recommended that I try (again) with std::string, but the problem is that c_str() returns a "const char *", but all of the HL code works with "char *", so I shot him an email to find out if he had a solution to that as well.
When he replied, he told me that he had been researching in Russian forums, finding an interesting entry that basically says that you can either use an ALLOC_STRING macro (to work with some kind of virtual machine stuff inherited from Quake 1), or hardcoding the string in the code. Let me quote him real quick, because I found this fascinating:
Anything else can potentially crash the game. Without allocating memory inside Half-Life's string buffer using ALLOC_STRING, the game would not save the newly created string itself, but only a pointer to the variable. And when the variable gets deleted (for example, when associated entity gets deleted) the game will crash. The article notes that "every GoldSrc coder will encounter this sooner or later" and that "this error probably killed more GoldSrc mods than any other".
He discarded both our previous methods (std::string and my concatenation function that I found on stackoverflow) and simply wrote a replacement using the C macro language. It now looks like this:
#define BUTTON_PATH(FILENAME) ( (halfquake_part()==1) ? "buttons/hq1" FILENAME : ((halfquake_part()==2) ? "buttons/hq2" FILENAME : "buttons/hq3" FILENAME) )
It compiled, it didn't crash - and the button sounds WORKED! :D
So I decided to do the same with the door sounds. And what can I say, it's never been so good hearing the correct sounds in Halfquake Amen. xD
I'd have recorded a video, but it sounds exactly what it should sound like, so there wasn't really anything to show. :D
In any case, with my newly acquired knowledge thanks to Michael (send him some good words on twitter :D), I can finally make sure all the sounds are fine. Hopefully.
To wind down a little, I decided to fix some smaller issues next.
1) I increased the draw distance in hq2_4 (it obviously wasn't high enough):
2) I tried fixing the trigger_push in hq2_27 (hopefully final game stopper :D), but then I noticed that the whole map was pitch black now, probably due to adding WHITE to lights.rad.
It looked a little creepy :D There's supposed to be absolutely no light source in the map, so that everything is lit up exactly the same. Anyway, I fixed that by replacing WHITE with the "near white" wall texture. Now it looks the same as before, and the trigger_push works as well.
3) I fixed being able to get stuck next to that lamp thing in hq2_14.
4) I fixed all seven diary camera distances (hq2_2, hq2_7, hq2_9, hq2_12, hq2_15, hq2_17, hq2_21), but I noticed a few grammar mistakes in the diary texts. I can fix those easily (I can swap out letters in photoshop, so I don't even have to recreate the original font and stuff - (it's Verdana though xD)), but ... I may try to improve the quality of the displayed text with higher resolution textures. That's something for way later though and a Super Nice To Have³.
5) I fixed not being able to casually walk on the first "S" of the letter field in the beginning of HQA. Interestingly, there already was a counter-measure for dying if you don't jump, which was an extended trigger_once, so that the letter "S" pops up slightly before you would step into the trigger_hurt, but for some reason it triggered too late now (may be a difference between WON HL and Steam HL). I extruded the trigger_once even further in front of the field, and now you can again walk on the first "S" again without having to jump.
6) I fixed the intro camera in hq2, which cut off the logo:
I also fixed the "jazzymike" texture in the intro, which had some gray noise in the background. There's still an issue with the mouth movements of the three NPCs while talking (they're missing), but that'll be something for another time.
To be continued... (<