MV A couple 4th wall breaking features

I'll be making a horror game based on ransomware, and I need a couple unusual features to go with it.
Just so you know, I've read countless threads about this and I'm aware of why this could be a bad idea. I need to know "how", not "why not to".

The features i need are:
-locking the game into fullscreen with no way of exiting it (neither with f4 nor f11)
-disabling alt+f4
-crashing the game, with an error message [I'm not sure if it's possible, does NWJS even have crash popups?]

Ideally, but optionally:
-disabling the functionality of the windows key (start menu/so that the player can't see the taskbar or exit fullscreen)
-changing the wallpaper
-reading the pc username

Can it be done with just scripts, or do I need plugins to accomplish it?

Lastly, the player will be warned about what the game is capable of, so don't worry about it being detected as possible malware or people not knowing what they're getting into when running it.
It is possible to disable F4:

JavaScript:
const old_onKeyDown = Graphics._onKeyDown;
Graphics._onKeyDown = function(evt) {
	if(evt.keyCode != 115) {
		old_onKeyDown.call(this, evt);
	}
};

It is almost certainly not possible to disable Alt+F4, Alt+Tab, or the Windows key. It may also be impossible to disable F11, but I'm not 100% sure – the approach that disabled F4 might also work for F11 (though the code above doesn't cover it).

If you really want to crash the game with an error message, you could use the following script call:

JavaScript:
SceneManager.catchException(new Error("Your Message Here"))

That'll give you the standard "blurred dark background" that occurs when your game crashes, but note that it doesn't close the game.

I don't think it's possible to change the wallpaper even with plugins. (Maaaybe it could be done if you ship an extra dll with the game? But I don't know anything about that.) Reading the PC's username is possible as long as you're running a downloadable build rather than a web build. For Windows, I think it would be something like this:

JavaScript:
process.env.USERNAME

For Mac or Linux, it would be:

JavaScript:
process.env.USER

You can combine the two like so:

JavaScript:
process.platform == "win32" ? process.env.USERNAME : process.env.USER
It is possible to disable F4:

JavaScript:
const old_onKeyDown = Graphics._onKeyDown;
Graphics._onKeyDown = function(evt) {
    if(evt.keyCode != 115) {
        old_onKeyDown.call(this, evt);
    }
};

It is almost certainly not possible to disable Alt+F4, Alt+Tab, or the Windows key. It may also be impossible to disable F11, but I'm not 100% sure – the approach that disabled F4 might also work for F11 (though the code above doesn't cover it).

If you really want to crash the game with an error message, you could use the following script call:

JavaScript:
SceneManager.catchException(new Error("Your Message Here"))

That'll give you the standard "blurred dark background" that occurs when your game crashes, but note that it doesn't close the game.

I don't think it's possible to change the wallpaper even with plugins. (Maaaybe it could be done if you ship an extra dll with the game? But I don't know anything about that.) Reading the PC's username is possible as long as you're running a downloadable build rather than a web build. For Windows, I think it would be something like this:

JavaScript:
process.env.USERNAME

For Mac or Linux, it would be:

JavaScript:
process.env.USER

You can combine the two like so:

JavaScript:
process.platform == "win32" ? process.env.USERNAME : process.env.USER

Thanks for the answers, where exactly should I put the code that disables f4? Is it just a script I put at the start of the game?
save it as plugin, load it and that's it (simple plug and play).

you can add F11 to it.
JavaScript:
const old_onKeyDown = Graphics._onKeyDown;
Graphics._onKeyDown = function(evt) {
    if([115, 116, 122].contains(evt.keyCode)) return;
    old_onKeyDown.call(this, evt);
};
this should make F4, F5 and F11 useless.
you can add more if you like:

115 = F4
116 = F5
122 = F11
Thanks for the answers, where exactly should I put the code that disables f4? Is it just a script I put at the start of the game?
You can put it in a file and load it as a plugin.

you can add F11 to it.
You certainly can. I'm not confident that it would do anything, as the default version of that function doesn't handle F11. Did you test your code? Does it actually suppress F11? If not, perhaps adding evt.preventDefault() would help. Failing that, maybe editing the package.json? I'm not sure if there are other options, nor what if anything can be done in the package.json to disable default keyboard shortcuts.
Yeah, it is kind of dangerous to disable alt+f4, even if possible. What would you do if a piece of software would freak out and alt+F4 isn't working? I know I would freak out. Forcing a crash as an in-game feature is fun, but actively preventing the user from shutting down the game, that can be seen as a serious red-flag.

I don't think it is possible, though. Alt F4 is hardcoded in windows to prevent malicious software to do harm. So if you try, you might even risk players malware detection software flagging your game as hostile software or even ransomware, because your game would act like suspicious.

I don't know about malware detection, though. I could be terribly wrong, but if I see what kind of behavior in some indie games results in false positives in my own protection software, than blocking alt f4 is right in that alley.

And as a player, if you get a false positive, and you know your defender, then it is an easy fix, but as a dev, you have to account for all kind of defenders for all kind of players. Because many players would not think: "Oh this doesn't work, maybe it is my malware protection." Most will only think: "Oh this doesn't work." and move on, or ask for a refund.

edit: I do realize you said you didn't want a "why not to." 😛 Well, you got one. Just because it might be more trouble than it's worth. The rest: Sure, even if I would personally be angry if a game changes things on my PC without my consent, like a wallpaper, or reading my username. Changing your wallpaper will most likely report in a flag as well, by the way.

Oh, and if this is just for a prank on a friend or something, then I guess disabling alt F4 can be great to make him extra freak out. 😛 Just disable your defender before you run the pranks (or test your prank) because you don't want the prank to fail for all the reasons above.
Oh, and if this is just for a prank on a friend or something, then I guess disabling alt F4 can be great to make him extra freak out. 😛 Just disable your defender before you run the pranks (or test your prank) because you don't want the prank to fail for all the reasons above.

Yeah, that's almost what it's going to be. It's a game i'll be making for a small jam between me and my friends, that's why I want it to feel as freaky and ransomware-like as possible
save it as plugin, load it and that's it (simple plug and play).

you can add F11 to it.
JavaScript:
const old_onKeyDown = Graphics._onKeyDown;
Graphics._onKeyDown = function(evt) {
    if([115, 116, 122].contains(evt.keyCode)) return;
    old_onKeyDown.call(this, evt);
};
this should make F4, F5 and F11 useless.
you can add more if you like:

115 = F4
116 = F5
122 = F11
Thanks, I'll try it tmr when I wake up
I don't think it is possible, though. Alt F4 is hardcoded in windows to prevent malicious software to do harm. So if you try, you might even risk players malware detection software flagging your game as hostile software or even ransomware, because your game would act like suspicious.
Actually, while it's probably true that Alt+F4 is hard-coded in Windows, it's just forwarded on to the program as an event, so if you were programming in C/C++ using WinAPI, it would certainly be possible to disable it. However, with RPGMaker you don't have access to that level of the program; I doubt the underlying Chromium would expose options to disable it. But I don't know for sure.
You certainly can. I'm not confident that it would do anything, as the default version of that function doesn't handle F11. Did you test your code? Does it actually suppress F11? If not, perhaps adding evt.preventDefault() would help. Failing that, maybe editing the package.json? I'm not sure if there are other options, nor what if anything can be done in the package.json to disable default keyboard shortcuts.
now, I didn't test it, but I would also doing it the other way around.

like, the way I did in my CheatEngine.

map your keys on keyPress and keyDown => than check the codes,
if it exit, return to do nothing so alt + F4 does nothing.

I don't know if F11 has something in MV though, but if it does, you can return.
you can also just disable all, as it would be maker contained, F4 blocking would
disable it clean, but still, you can close the game by CTRL + ALT + DEL to open
your taskmanager => abort NWJS there to close the game forcible and its closed.

but if you block that one, than there is also one way left. => system hard reset.
which can't be blocked in any way XD if you do that => unplug the system and
your in again.

but if they want, they can clear all input buttons on the keyboard.
bad thing here, you need to map your buttons before gaining control.
save it as plugin, load it and that's it (simple plug and play).

you can add F11 to it.
JavaScript:
const old_onKeyDown = Graphics._onKeyDown;
Graphics._onKeyDown = function(evt) {
    if([115, 116, 122].contains(evt.keyCode)) return;
    old_onKeyDown.call(this, evt);
};
this should make F4, F5 and F11 useless.
you can add more if you like:

115 = F4
116 = F5
122 = F11
it doesn't seem to disable f5, for some reason. Is there another way?
I did have a feeling that might not work. You could look into the settings in package.json and see if any of those will help. I didn't look closely, just found the reference, so I can't say whether or not it'll help.

Since the nwjs in RPGMaker MV is quite old, it's possible that not all the settings on that page will work in MV, but probably most of them do.
other way to use the code instead:

JavaScript:
const old_onKeyDown = Graphics._onKeyDown;
Graphics._onKeyDown = function(evt) {
    if(["AltLeft", "F4", "F5", "F11"].contains(evt.code)) return;
    old_onKeyDown.call(this, evt);
};
Maybe even go a step further:

JavaScript:
const old_onKeyDown = Graphics._onKeyDown;
Graphics._onKeyDown = function(evt) {
    if(["AltLeft", "F4", "F5", "F11"].contains(evt.code)) {
        evt.preventDefault();
        return;
    }
    old_onKeyDown.call(this, evt);
};
JavaScript:
SceneManager.catchException(new Error("Your Message Here"))

Is there a way to trigger some kind of a Windows error popup? The game will only be released as a downloadable windows build, so it'd make sense to include one.

I've also thought of something else: Is there a way to make the game detect that it has already been played on the device? perhaps by creating a file in a folder like appdata? And then checking for its existence?

Also, is it possible to open cmd from the game? I feel like that'd add some spook to it
Is there a way to trigger some kind of a Windows error popup? The game will only be released as a downloadable windows build, so it'd make sense to include one.
Not that I'm aware of. There is alert("text here") but I suspect that doesn't quite fit.

I've also thought of something else: Is there a way to make the game detect that it has already been played on the device? perhaps by creating a file in a folder like appdata? And then checking for its existence?
I think you can just put something new in ConfigManager for that? Something like…

JavaScript:
const old_makeCfg = ConfigManager.makeData, old_applyCfg = ConfigManager.applyData;
ConfigManager.makeData = function() {
    var config = old_makeCfg.call(this);
    config.playedBefore = ConfigManager.playedBefore || false;
};
ConfigManager.applyData = function(config) {
    old_applyCfg.call(config);
    ConfigManager.playedBefore = config.playedBefore || false;
};

That would be added as a plugin. It's not quite finished, you still need to figure out where to put ConfigManager.playedBefore = true. It could be a script call in an event that triggers on New Game, but there are other possibilities too, depending on how exactly you want it to work.

Also, is it possible to open cmd from the game? I feel like that'd add some spook to it
I think this is probably possible using NodeJS APIs but I'm not quite sure how it would be done. Try googling something like "shell open NodeJS",
That would be added as a plugin. It's not quite finished, you still need to figure out where to put ConfigManager.playedBefore = true. It could be a script call in an event that triggers on New Game, but there are other possibilities too, depending on how exactly you want it to work.
Will it persist even upon deleting all the downloaded game files?

I think this is probably possible using NodeJS APIs but I'm not quite sure how it would be done. Try googling something like "shell open NodeJS",
I've tried using this code as a script:

JavaScript:
const child_process = require('child_process')
let stdout
stdout = child_process.execFileSync('%windir%\system32\cmd.exe', ['arg0', 'arg1'])
console.log(stdout.toString())
try {
  stdout = child_process.execFileSync('%windir%\system32\cmd.exe', ['arg0', 'badarg'])
} catch(e) {
  console.log(e.status)
  console.log(e.stdout.toString())
  console.log(e.stderr.toString())
}

but it gives me this error:

1767186378431.png
Is there a way to make the game detect that it has already been played on the device?
best way to pull this is off is a game variable (global) or global switch with
olivia metaControl so you can start the game, if its one, you can do so in a text message.

this message can be removed if the persistent file is removed.

creating a file => bad way as it can be removed manually as well.
Will it persist even upon deleting all the downloaded game files?
By default, save files are stored in the game folder, so no it won't. But it's not hard to make save files be stored in AppData instead. You can use this plugin for that.

I've tried using this code as a script:

JavaScript:
const child_process = require('child_process')
let stdout
stdout = child_process.execFileSync('%windir%\system32\cmd.exe', ['arg0', 'arg1'])
console.log(stdout.toString())
try {
  stdout = child_process.execFileSync('%windir%\system32\cmd.exe', ['arg0', 'badarg'])
} catch(e) {
  console.log(e.status)
  console.log(e.stdout.toString())
  console.log(e.stderr.toString())
}

That won't work because it doesn't expand the windir variable, so it's looking for a folder actually called "%windir%" instead. You'll need to manually expand it yourself like this:

JavaScript:
stdout = child_process.execFileSync(process.env.WINDIR + '\system32\cmd.exe', ['arg0', 'arg1'])
That won't work because it doesn't expand the windir variable, so it's looking for a folder actually called "%windir%" instead. You'll need to manually expand it yourself like this:

JavaScript:
stdout = child_process.execFileSync(process.env.WINDIR + '\system32\cmd.exe', ['arg0', 'arg1'])


1767201179217.png


it now gives me this error, it looks like rmmv just skips over the slashes?

Original thread: https://forums.rpgmakerweb.com/threads/a-couple-4th-wall-breaking-features.181623/