iw4x / iw4x-client

GNU General Public License v3.0
123 stars 42 forks source link

[Mods]: Clear fs_game when leaving servers #156

Closed diamante0018 closed 2 weeks ago

diamante0018 commented 2 weeks ago

What does this PR do?

Closes #139

How does this PR change IW4x's behaviour?

Unloads the mod, if loaded, when leaving a server Fixes some bugs I spotted(unterminated Cbuf strings) in the mod list code

Anything else we should know?

As explained in the code #70 does not allow me to unload a mod when leaving a private match

Did you check all the boxes?

diamante0018 commented 2 weeks ago

Hi @Rackover, main feature test showcase on YouTube (Link sent in DMs)

Private Match tested off-camera but works as intended and is explained above.

Rackover commented 2 weeks ago

Is there a reason why ou don't call ClearMods as you originally intended? 🤔 It looks like it would do the trick for your case. Doesn't it?

diamante0018 commented 2 weeks ago

Yes. See comment in code. Besides clear mods is a lambda function so anonymous functions can't be invoked directly. Well actually, just compare the two codes. And see what is missing in clear mods that's not suitable for me

Rackover commented 2 weeks ago

How fool I am to ask you to explain to you why you did something a certain way.

Let me ask again. Consider that I have read your code, and your comments, because in fact I have. Consider that I have already compared the two codes, because in fact I have.

I would like you to assume that when reviewing your code, people (or at least I) don't do it without reading the code - and that therefore, when asking for additional clarifications, telling me to just "read again and see" is pretty pointless. Such comments are a waste of time for everybody involved.

diamante0018 commented 2 weeks ago

Clear mods is used by the menu code, it's a UIScript. So it's only displayed when fs_game is set.

https://github.com/iw4x/iw4x-client/issues/139#issuecomment-2419950420 (menu code was posted here)

So the user has to manually trigger this when going to the menu if a mod was loaded for this to display.

Now this PR is about unloading a mod once leaving a server so a few things need to be checked out

all reasons as to why code from clearmod cannot be reused.

i invite you to check out the clearmod as it's displayed in the iw4x menus as it should make sense why there checking for private match wouldn't make sense (we are on the main menu). The button is at the right bottom corner. To me the clearmods UI script c++ code is specific to cater to this functionality and therefore i'd rather reuse the code in a new function rather than make the clearmod c++ code more complicated since it has it's own execution flow for this specific case.

While my newly added code also has a very specific execution flow because it is run when a user leaves a server and not when we are at the main menu. because of these two differences, I added new code instead of reusing old code.

Desktop Screenshot 2024 10 18 - 10 32 28 84

Rackover commented 2 weeks ago

Yes, I know where that button is and what function is tied to. This simply does not answer my questions:

Reduce, reuse, recycle - less duplicates of codes that do the same thing (why would "new code" be preferable to "old code"? does code rot?), less stuff to maintain - only one correct way to unload a mod, one function that can be called from multiple places that that will unload a mod if necessary, vid_restart if necessary, and you can add the local server check specificity to your event if you want before calling that function.

You know all this! Why pretend you don't, and have me lay it all out? ☹️

Rackover commented 2 weeks ago

Additionally - have you checked that ->modified = true needs to be set after calling Dvar_SetString? Im not really up to date on Dvars so I might be wrong on this. But i feel like this modified flag is set by Dvar_SetString at 0x6478B7. Tell me if this is mistake on my end, i have only very partially labeled this function

diamante0018 commented 2 weeks ago

I see 0x6478B7, I guess it is indeed unnecessary and a bad copy and paste on my end.

Well, if that's what you desire, I will now modify the PR to do what you are suggesting.

diamante0018 commented 2 weeks ago

I have completed testing once again. All is good on my end.

On a side note, it's impossible to find a server that does not have a gazillion menu errors ahah. I'm will be so glad once this PR is merged because who knows how broken their menus are outside of normal gameplay

Desktop Screenshot 2024 10 18 - 13 57 07 18

Rackover commented 2 weeks ago

unrelatedly - there's a crash currently when you leave a game and then try to open the server browser. It's very old and i'm gonna open an issue for it because it definitely hinders usability (currently the game crash if i leave a game then i click "join game")

Rackover commented 2 weeks ago

Tested and it seems to run gracefully, through map rotation aswell, merging