Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Settings to in-game menu, and rewrite pause menu in Lua #14785

Closed
wants to merge 12 commits into from

Conversation

swagtoy
Copy link
Contributor

@swagtoy swagtoy commented Jun 26, 2024

#14781 was an utter failure, so I'm following up with a new PR that:

  • Moves the pause menu formspec into Lua
  • Doesn't require any C++ rewriting of the settings menu now, as requested.

Also will add settings to the in-game menu (i haven't done it yet, but hold on a moment).

image

As my old PR said:

In the past, you need to quit the current game to change settings. This is tedious, especially when on servers where you need to re-enter your password. It's also frustrating as you can't fine-tune settings such as FOV.

Also, we can probably remove the "Sound" subsection. We could also move all the "Controls" configuration to this settings menu (which also lets us tweak controls on the main menu.. 2 birds dead with 1 stone!)

Not everything here is sunshines. The first case is removing client->modsLoaded from game.cpp. My change will likely force enable client modding, removing the need for a setting such as enable_client_modding. Will there be any side effects of enabling client side modding by default?

Hoping this really fixes #6722, #3165, and #6922.

There is also an opportunity to cleanup the pause menu, perhaps giving the controls text a much-needed facelift.

There was some mention on IRC of letting mods add new buttons, in a similar fashion to how sfinv works. I really like this idea and I'd be happy to implement it with no additional cost.

How to test

  1. In minetest.conf, set enable_client_modding to true (this wont be the case later?)
  2. Start a world
  3. Press ESC

@swagtoy swagtoy marked this pull request as draft June 26, 2024 23:41
swagtoy added 5 commits June 26, 2024 23:02
Also exposes Lua's io functions to the client
Probably should add a method for changing the FOV but I am tired. This also works with /set fov ###, so not sure why something like this isn't done already.
@swagtoy
Copy link
Contributor Author

swagtoy commented Jun 27, 2024

FOV changes are applied.

Some shader settings don't apply obviously, but the majority of things i've tested seem to work 🙂

image

I'd like to move my formspec events to Lua though, but I couldn't figure out how to create hooks.

@grorp
Copy link
Member

grorp commented Jun 27, 2024

Here's a version of rollerozxa's POC for the same thing, in case it's useful: grorp@a336186 and grorp@5600624

swagtoy added 3 commits June 27, 2024 10:58
This is really hacky, but it demonstrates that everything works (kinda)
You can force reload graphics by showing the verbose debug page (press F5 a few times). It might be better to bind it to a specific keybind, but this was easier to implement and didn't require taking up another keybind.
@Zughy Zughy added Feature ✨ PRs that add or enhance a feature @ Builtin Concept approved Approved by a core dev: PRs welcomed! UI/UX labels Jun 28, 2024
swagtoy added 3 commits June 28, 2024 16:22
…wireframe debug instead

Still need to nuke the old FSTK settings pages and fix the main menu
@@ -85,6 +87,9 @@ void ClientScripting::InitializeModApi(lua_State *L, int top)
ModApiChannels::Initialize(L, top);
ModApiParticlesLocal::Initialize(L, top);
ModApiClientSound::Initialize(L, top);

ModApiMainMenu::Initialize(L, top);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main menu api is completely unsecured, this is a no-go

Copy link
Contributor Author

@swagtoy swagtoy Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be removed soon. I don't believe this is needed.

NO_MAP_LOCK_REQUIRED;

std::string path = porting::path_share + DIR_DELIM + "builtin" + DIR_DELIM;
lua_pushstring(L, path.c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaks user paths to the secure client environment

{
g_gamecallback->exitToOS();
#ifndef __ANDROID__
RenderingEngine::get_raw_device()->closeDevice();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure the relevant code already calls this, why is this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the android snippet?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wasnt my code.

I agree its weird. I can snip it out though.

{
g_gamecallback->unpause();
//lua_pushboolean(L, true);
return 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect return

@@ -358,6 +367,13 @@ void ScriptApiSecurity::initializeSecurityClient()
copy_safe(L, os_whitelist, sizeof(os_whitelist));
lua_setfield(L, -3, "os");
lua_pop(L, 1); // Pop old OS

// Copy safe OS functions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these functions are absolutely not safe and allow unsandboxed access to the client filesystem

Copy link
Contributor Author

@swagtoy swagtoy Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove this soon. Dont be fooled by this comment. It should say "Copy safe IO functions"

src/script/cpp_api/s_security.cpp Show resolved Hide resolved
@DragonWrangler1
Copy link
Contributor

DragonWrangler1 commented Jul 5, 2024

I'll compile and test later.

Edit: Ok. So I compiled it and tested.

First when going into settings if you click Hide: temporary settings. It crashes.
Second. I don't think that you should require client modding, since some servers don't allow that, and the menu won't open without it.

@swagtoy
Copy link
Contributor Author

swagtoy commented Jul 5, 2024

@sfan5 I'm going to add a new function to just read the file of the settingtypes.txt without needing to expose io. Is this okay to you? Will allow me to remove the insecure exposure.

@swagtoy
Copy link
Contributor Author

swagtoy commented Jul 5, 2024

First when going into settings if you click Hide: temporary settings. It crashes. Second. I don't think that you should require client modding, since some servers don't allow that, and the menu won't open without it.

There's no other way for me to rewrite this in Lua without enabling client modding, I think. The only other way would be to create an entirely new Lua context. Or to lie to the server...

First when going into settings if you click Hide: temporary settings. It crashes.

Thanks. I think there are a few ways to crash the game. I'll have to mess more with it.

@swagtoy swagtoy mentioned this pull request Sep 12, 2024
8 tasks
@swagtoy
Copy link
Contributor Author

swagtoy commented Oct 6, 2024

@grorp Again...

@grorp
Copy link
Member

grorp commented Oct 6, 2024

I'll steal an old comment to explain:

WIP pull requests without progress or need for discussion are typically closed after some time. I'm just marking it so we don't forget to close it if nothing new happens.
#11470 (comment)

EDIT: Discovered that going strictly by the rules, there are still 3 months left, so removing the label again.

@swagtoy
Copy link
Contributor Author

swagtoy commented Oct 6, 2024

@sfan5 Hey, i discussed it on mt dev irc, but should we add a new security layer for the main menu or the "game", i suppose? maybe even separate some bits of code? This will help me stub some work for the new main menu PRs, and will prevent me from writing crappy functions and exposing them on the server side to say, get the users settings and junk.

it needs to be done at some point if we want to switch to offering game-specific customization of the main menus (discussed with greenxenith over discord unfortunately) without needing to hack over security. It would help this PR too. Was even thinking of providing an extra flag to CSM or something to make a client side mod "menu safe"

@sfan5
Copy link
Collaborator

sfan5 commented Oct 6, 2024

@sfan5 I'm going to add a new function to just read the file of the settingtypes.txt without needing to expose io. Is this okay to you?

Sure

but should we add a new security layer for the main menu or the "game", i suppose?

CSM already has a security layer and I don't see how the mainmenu is relevant here.

@swagtoy
Copy link
Contributor Author

swagtoy commented Oct 6, 2024

@sfan5 I'm going to add a new function to just read the file of the settingtypes.txt without needing to expose io. Is this okay to you?

Sure

but should we add a new security layer for the main menu or the "game", i suppose?

CSM already has a security layer and I don't see how the mainmenu is relevant here.

see this PR and how I've had to break security to get it to work

soon people will download main menus from games which are pretty insecure atm i think

@sfan5
Copy link
Collaborator

sfan5 commented Oct 6, 2024

and that is related how exactly?

@swagtoy
Copy link
Contributor Author

swagtoy commented Oct 6, 2024

Oh you replied to another thing, my bad.

I just wanted to know if we should make a new security layer that is more secure than the Client layer because we are going to let games customize the pause menu and main menu. Games you can download from the CDB

@sfan5
Copy link
Collaborator

sfan5 commented Oct 6, 2024

Perspectively we should have main and pause menu customization but it's too early to say how the implementation will look.

@swagtoy
Copy link
Contributor Author

swagtoy commented Oct 7, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@ Builtin Concept approved Approved by a core dev: PRs welcomed! Feature ✨ PRs that add or enhance a feature UI/UX
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more settings to the pause menu.
6 participants