Тёмный

I was COMPLETELY WRONG about saves in Godot... ( ; - ;) 

GDQuest
Подписаться 260 тыс.
Просмотров 64 тыс.
50% 1

Learn to Code from Zero, With Godot: gdquest.mavenseed.com/courses...
Godot Node Essentials (ultimate cookbook): gdquest.mavenseed.com/courses...
---
📚 THE LINKS
Open-source save demo project: gdquest.github.io/godot-demos...
---
👥 CREDITS
Video edited by Nesi: / nesiawesomeness
---
💌 JOIN US
Come chat on Discord: / discord
Follow us on Twitter: / nathangdquest
---
📝 CC-BY LICENSE
This video is licensed under the CC-By 4.0 license: creativecommons.org/licenses/...
You can attribute it to "CC-By 4.0 - GDQuest and contributors - www.gdquest.com/"

Опубликовано:

 

18 июл 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 183   
@SurealG
@SurealG 2 года назад
Its really cool when people recognise their mistakes makes me like this channel even more
@swishfish8858
@swishfish8858 2 года назад
Disagree, teachers making such big mistakes makes me more wary of trusting them. Don't reward people's failures.
@asdaaaaaaaaaaaaaasd
@asdaaaaaaaaaaaaaasd 2 года назад
@@swishfish8858 "Don't reward people's failures". Talking like the comment is saying: "Ohhh thank you so much for teaching us wrong." Obviously they are "rewarding" the correction.
@swishfish8858
@swishfish8858 2 года назад
@@asdaaaaaaaaaaaaaasd If someone is wrong, they are wrong. It doesn't matter if they admit it or not. Being a wrong teacher makes you a bad teacher. Period.
@asdaaaaaaaaaaaaaasd
@asdaaaaaaaaaaaaaasd 2 года назад
@@swishfish8858 I won't push this subject more since you're seeing what you want to see, so this is my last reply. In the rest of your life dear Swish Fish, you are going to be wrong 100% this is going to happen. No one is an anime or a movie character in this world we live. And at that point you'll see how wise and hard it is to admit and CORRECT what you did wrong. Such a shame we get scared of being wrong in such things as knowing something.
@Gdquest
@Gdquest 2 года назад
With this logic, every programming teacher would be a bad teacher then. Programming is so complex every single programmer makes mistakes. As for this very topic, the thing is for some people this kind of relative user security is very important, but in reality no user is safe the moment they download files from untrusted sources. The best you can do is mitigate the issue. Some companies don't even try, for example Minecraft mods can run arbitrary code - they get shared and downloaded a lot more than save games.
@Dark_Peace
@Dark_Peace 2 года назад
Me : stores save data in Json Everyone : bad idea, bad practice, use resources Me now : *overexagerated air of superiority*
@Raul-pg1pf
@Raul-pg1pf Год назад
Same
@Chspas
@Chspas 4 месяца назад
how do you store objects in JSON? I'm struggling with this
@Dark_Peace
@Dark_Peace 4 месяца назад
@@Chspas you can't. Depending on what you need, you can find workarounds.
@brian-thomasrogers4308
@brian-thomasrogers4308 2 года назад
Becareful with XML as that could lead to what is known as the Billion Laughs or XXE if you are doing server side stuff. JSON is far more safe if that's the route you want to go down.
@Gdquest
@Gdquest 2 года назад
You can find the open-source demo and updated save game guide here: gdquest.github.io/godot-demos-2022/save-game/ In the next video, we'll share a simple trick to optimize your 2D. Stay tuned!
@PatrickChoi
@PatrickChoi День назад
Hi, the page doesn't work anymore, is there a new version?`thanks!
@galacticgon925
@galacticgon925 6 месяцев назад
Also note You can use .res or .tres files .res will put the data into unreadable in a text file but data that it uses .tres will put the data into readable data in a text file I think use tres for things you dont care about being edited, or while debugging/testing/building the game maybe change it to .res when you are sharing a build/version of the game Maybe have code that lets you just change one line that will affect all of them to be tres or res so you dont have to go through updating .tres or .res in your code just do it one time, to easily swap back and forth. Maybe even save the .tres and .res files in different folders or something to make it easy to make sure you have no .tres files in your shared projects so people cannot edit the data. This is just a thought!
@codemonster8443
@codemonster8443 2 года назад
I save my game data as serialized binary data. It's a hassle to impliment all of that with read and write but it's security and file size is top notch.
@ofulgor
@ofulgor Год назад
Do you have a link to a tutorial or something?
@v44n7
@v44n7 Год назад
would love to know how you do it!
@kennethferland5579
@kennethferland5579 5 месяцев назад
Yea JSON/XML are intended for human readable/editable data, such as for game modding. They have no buisness in savegame files which should be UN-editable by nature and need to be as size efficient as possible for storage and loading.
@lyghtkruz
@lyghtkruz 2 года назад
Safe is relative, anyone downloading a saved game from a random website always has the possibility of it having a virus. I'm not saying that we shouldn't take preventative measures to make sure our code is safer for the end user, but at some point, it is the end user's responsibility.
@mendelovitch
@mendelovitch 2 года назад
This reminds me of how the machine learning community is using Python pickle files to distribute neural networks. Python pickle files may hold malicious code. It is a bad practice and you should use inert formats like JSON instead.
@rompevuevitos222
@rompevuevitos222 2 года назад
Godot should have some sort of security system that allows you to disable file operations, maybe a project setting or whatnot atm it's extra dangerous with multiplayer At least a way for the project to check if a script contains File related stuff, allowing you to prevent loading of resources that do
@Gdquest
@Gdquest 2 года назад
There are functions that are secure by default bytes2var and var2bytes, as mentioned in the video, and you would use those to send data over the network. But yeah it'd be cool if resources had a safe mode in the future because right now this issue affects even ConfigFile.
@BryceDixonDev
@BryceDixonDev 2 года назад
Data permissions have been a thing at the OS level for at least 50 years. There's no reason Godot shouldn't be able to say "Load this resource, but treat it as data and ignore all functions/code" the same way I can set the permissions flags of a file in Linux to 666 to make it non-executable.
@nathanlamaire
@nathanlamaire 2 года назад
It won't be much of changes since memory vulnerability is much more complex than you may have envisioned (this type of bug is nothing new, and we are dealing with this all the time) Dealing with binaries in native way won't gonna have practical security no matter how hard you have tried to protect it.
@hudsonator7259
@hudsonator7259 7 месяцев назад
It would be nice if you could disable scripts in resources like that, and just make it easier to write safe code and easier to read. Or even if you could disable certain callbakc functions like _init, _ready, _process or _physics_process.
@bestesthd
@bestesthd 2 года назад
2 solutions popped into my head while watching the video. 1. If saving in a text format rather than binary, first open the save file as text rather than with the ResourceLoader. Scan it for malicious keywords (like func!) so no dangerous code can be executed. Some method of filtering the types allowed would be welcome though (like banning Callables in Godot 4). 2. Generate a key for the save file and make sure you get the same key on load, preferably in a compiled language so nobody can figure out what goes into it exactly. The raw contents of the file from that key onwards would play a part in addition to manually putting together many different variables. The downside is that, outside of small edits to stats that can be easily calculated by the user, tampering with save files is impossible this way. But downloading existing saves is no problem.
@notkamui9749
@notkamui9749 Год назад
the second solution is called a checksum, if people wanna search it out. To be noted that this will not prevent people from sharing complete save files ; this kind of issue is unavoidable unfortunately, but at least, one cannot partially edit their files, because it will fail the checksum.
@antimari22
@antimari22 2 года назад
If you save ends up dictionary, what's the point using resource? Why not use dictionary from begin to end?
@Gdquest
@Gdquest 2 года назад
In this video mostly for compatibility with the previous one. In general, for the structured data and full autocompletion + type support throughout my codebase, though you could use plain Reference instances for that then.
@dibaterman
@dibaterman 28 дней назад
Glad you corrected this, I saw your other video, goes to show you though that you can't just follower what you see on YT. There are other YTers one comes to mind more vividly whose argument was "Godot does it so this is the intended way." You can and will hit the same issue with var_to_file if you are including code there. In my saves I serialize all my data into a dictionary and just var to file that without including objects. This way he information must be de-serialized for that layer of safety.
@gillesroudiere541
@gillesroudiere541 2 года назад
Well, to make things more precise, your previous approach was perfectly fine for locally saved games. If a hacker has access to the saved games, it means they could simply alter the game's scripts too by editing the pck's content or the binary manually. Some already hacked Sonic Colors Ultimate using this technique. So there's not really a security increase here. This new approach makes more sense if you have to upload the saved game to a server, but the server will still have to check itself if the received JSON is using the expected format anyway. I guess JSON is a little bit easier to parse than Godot resource files but, theoretically, it should not be impossible to parse and verify a sent Godot .tres file. So in the end, I think your previous method was perfectly fine. The new one maybe makes it a little bit more complex to inject code in the game, but it does not increase security in a significant manner IMO. It's basically the equivalent of local save game encryption, as it "obfuscates" things a little bit but won't stop anyone determined enough to hack your game.
@kevinscales
@kevinscales 2 года назад
Even if it's local, people can share save files online. Sure, you shouldn't download files from people you don't trust, but people will. People will assume that save files will be safe to download.
@Gdquest
@Gdquest 2 года назад
It's because some people care very much about players having the ability to e.g. share a save file and download it from an untrusted source safely. Basically that's the case the video covers.
@armyofchickens6062
@armyofchickens6062 Год назад
How would you make the main playerdata resource file that everything like position and all that would be written and loadable? having hella issues with it not wanting to write anything and someone told me id have to look into it, but im just not understanding anything at all bc most videos i come across all of that is already made and it just goes to creating the save resource. plz help
@AbstractObserver
@AbstractObserver 9 месяцев назад
XML-Injection is a very common security risk. I don't know how complete is the XML interpreter on Godot, but if it has half the features XML usually has it can very well do things like code execution, code injection, downloads, etc. Stick to JSON.
@akjkjkak
@akjkjkak Год назад
Hey! Thanks for this. Do you know if it is still a problem in Godot4?
@simonsaysgray
@simonsaysgray 9 месяцев назад
I was asking myself the same thing.
@BenjaminDiefenbach
@BenjaminDiefenbach 2 месяца назад
I was able to replicate in 4.2.1 just now after copying the code from the video into a resource I had been testing saving data to.
@teamdoodz
@teamdoodz 2 года назад
Unity (technically c#, but I found that this issue is most common in Unity) has this issue too with the BinaryFormatter class. There are some pretty big games (untitled goose sim for example) that had issues with RCE.
@sheepcommander_
@sheepcommander_ 7 месяцев назад
interesting
@SCDev-kh3qo
@SCDev-kh3qo Год назад
Why is it necessary to to declare character = Character.new() again on line 65? Isn't it already declared at the beginning of the script?
@4steroid
@4steroid 9 месяцев назад
The demo project no longer exists :( Can you reupload it? I was just starting to understand inventories and json!
@skilletborne
@skilletborne 9 месяцев назад
How can we access the save game demo these days? The link in the description leads to a 404 error
@cya-dev
@cya-dev 6 месяцев назад
Any updates on this? Are resources still unsafe?
@4Robato
@4Robato 6 месяцев назад
Do we have to do this for Godot 4 as well?
@terrawest9500
@terrawest9500 11 месяцев назад
I'm curious if this vulnerability still exists in godot 4.x?
@dungeonrobot
@dungeonrobot 11 месяцев назад
A but late but how does this make Config Files vulnerable?
@klaesregis7487
@klaesregis7487 2 года назад
With this in mind. How would you go about letting users mod your game with resources? Is there the same risk?
@Gdquest
@Gdquest 2 года назад
Yeah, the risks are the same but you can't do much about it. Minecraft mods let you write any Java code so there's 0 security there. Skyrim mods have some protection but there have been exploits, and if the mod comes with an installer, well the installer can do anything. Generally speaking, as soon as players download files from the web, it is unsafe. With the savegame thing, the truth is if someone wants, they can share an executable and say "hey to put this save in the game, double click the file."
@RenderingUser
@RenderingUser 2 года назад
@@Gdquest what if we make a custom loader that just takes set variable values (isnt this just possible with JSON) that way no code can be executed right?
@klaesregis7487
@klaesregis7487 Год назад
@@RenderingUserthat is what I personnally do. JSON files for conversatios with even some custom code when parsed and ini files for the rest of the 90% of the config. You do indeed need to make some custom loaders.
@underscore-dash
@underscore-dash Год назад
@@RenderingUser You can do that but in that case modders might have a problem with the limited capabilities your loader would have. Let's say you made a platformer game and enabled modders to add blocks with custom textures and given them the option to set some variables for the player when being touched. If a modder wanted to add guns for whatever reason they still wouldn't be able to do so. The same goes for Minecraft mods: While you can create a datapack to run some ingame commands you still can't add such things as keybinds. Every system that doesn't allow you to completely modify the game's code has some limitations some modder will have trouble with.
@RenderingUser
@RenderingUser Год назад
@@underscore-dash I'm not making a game large enough to mod anyway
@terrylyn
@terrylyn Год назад
How does Unity avoid this problem?
@hashtag9990
@hashtag9990 2 года назад
how is this any different than sharedPreferences?
@DogveloperGames
@DogveloperGames 2 года назад
I dont usually comment on YT, but saving is a massive thing to figure out how to do and on the last project I started, I tried a thing and seemed to be successful on it. for this project I save on godot by generating a JSON file with the variables of the script I wanna save. example: # generating array with the variables: const baseFilePath = "res://SaveData/" var file_name = "res://SaveData/slot1" var data := {} var s_slot := 1 func save(): for v in globals.get_script().get_script_property_list(): saveData(v.name, globals.get(v.name)) # (globals being the script I'm pulling from) # then on the saveData function it goes: func saveData(variableName, value): var dir = Directory.new() dir.remove("res://SaveData/slot" + str(s_slot)) data[variableName] = value var file = File.new() file.open(file_name,File.WRITE) file.store_string(to_json(data)) file.close() # probably not the most elegant way to do it, doesnt even encrypt the data, but it seems to work. # This passes the current values to the savefile and it is easy to add more variables later in development, since it is grabbing everything from the script. # And then to load I search the variables of the "in game" script on the json file with: func loadData(): var file = File.new() if file.file_exists(file_name): file.open(file_name, File.READ) var savefileData = parse_json(file.get_as_text()) file.close() if typeof(savefileData) == TYPE_DICTIONARY: data = savefileData for v in globals.get_script().get_script_property_list(): var name = v.name globals.set(name, data[name]) print(globals.inventory) get_tree().paused = false globals.load_room(data.room, str2var(data.position), str2var(data.rotation)) # And with that, we never add new code to the game script, as it will search for the immutable internal names ignoring anything that is not part of those names. Once the load_room(), that is basically a change_scene with some extra oomph, runs, the level is loaded, the position/rotation of the player is set and all the global variables (ie. health, ammo, already picked up objects) are set to their loaded values as globals is a singleton. # doing this way, I assume, takes out the risk of having extra code injected while remaining simple and modular, instead of referencing every value I wanna save by hand. # sorry for the long comment, jsut wanted to share the way I go about doing this process. # if there are any exploits with this way of doing the safe file, please let me know.
@Gdquest
@Gdquest 2 года назад
Thanks for sharing!
@stesproject
@stesproject Год назад
Two questions: 1. Is the issue concerning only for saving files online (eg for multiplayer games)? 2. Isn't the json file easily editable by the player? How can we make it unreadable to prevent the player from cheating the game changing the values in the json save file?
@auroraRealms
@auroraRealms Год назад
Make the Game Server feed a new JSON file with the proper variables to the Game Console at the start of the game. So if anybody tries to tweak the variables, they will get overwritten at the start of the game. From there, just use streaming game play data. I use and/or bitwise operators and enumerators to keep the game state to be described in a single integer. The only other data that needs to be sent are coordinates, Game Console IDs, and Character IDs.
@Loogable
@Loogable 5 месяцев назад
I now have made a frankenstein solution with this... I have whole objects as binary in my JSON dictionary, where it was too tedious to unwrap. Those could also be injected with malicious code. But I encrypt the save file with unique user passwords so it should be alright.
@DeeJayLSP
@DeeJayLSP 2 года назад
Godot has the inst2dict() and dict2inst(), which are able to convert Objects into Dictionary and vice-versa, are they good to use in saves?
@DeeJayLSP
@DeeJayLSP 2 года назад
I have a save workflow that looks like the following: - Get save data using inst2dict(). - Convert using var2str() on debug builds, or var2bytes() on release - Save to a regular text file on debug (it will not be a JSON, but will easily be readable like one) or an encrypted data file on release To load, you just need to get the file data, convert it back to a dictionary and return it with inst2dict(). With inst2dict, you don't need to manually modify the base dictionary everytime
@DeeJayLSP
@DeeJayLSP 2 года назад
Since var2bytes disallows objects, I believe it's possible to check if the instance dictionary is trying to load some malicious script.
@andrewpozenel2931
@andrewpozenel2931 2 года назад
Yes, but you know that the downside of JSON and XML is that they're human-readable text format... so anyone in this instance can open it up in any text editor and therefore cheat / hack the game... While when the binary format is used, the less amount of people can modify it and also harder it is...
@Gdquest
@Gdquest 2 года назад
You could also encrypt, binary or simple encryption are easy to bypass but they're very simple and will prevent most players from editing the saves, if you really mind that. All you have to do is call File.open_encrypted() instead of File.open() to load and write the data.
@rexanity_template
@rexanity_template 2 года назад
@@Gdquest isn't that method removed
@alabvix
@alabvix 2 года назад
Yeah, but what is the point to hack a game that you are trying to beat? If the player wants to do that, for me is fine.
@andrewpozenel2931
@andrewpozenel2931 2 года назад
@@alabvix Everyone is tryna protect their own work (models, scripts, ...) if one can... There is absolutely no guarantee that those protective measures make the game unhackable, but it keeps 3/4 of the snooping people out.. The ones who have skill, knowledge and the will to crack / hack something will do it, despite the security measures that the game has..
@alabvix
@alabvix 2 года назад
@@andrewpozenel2931 yeah man, I got your point. I was thinking in terms of my current project, a very specific one when we won't have security requiriments. So, I think a best way can be create a lib for encrypt/decrypt data for Godot, but probably someone already did this or think about. Anyway, have a great day man!
@TommyLikeTom
@TommyLikeTom 2 года назад
Very informative, thanks
@Ivan33I
@Ivan33I 2 года назад
Hi! I'm using the ResourceSaver to save the game. Then I copy the content using the File.open_encrypted_with_pass to encrypt the content. Anyone knows if I can be hacked that way? Thanks!
@killpidone
@killpidone 2 года назад
Someone could extract your encryption pass
@Gdquest
@Gdquest 2 года назад
What you could do is open the file as text before loading it with the resource loader and ensure there's no _init function or embedded code resource or that it tries to load an external file you don't recognize. If you see anything indicating code, then you return and don't load the save. That'd be one way to at least have a simple protection, but I can't say if it doesn´t leave the door open to any potential exploits or whatnot.
@DogsRNice
@DogsRNice 2 года назад
I somehow managed to search for this channel 55 seconds after it uploaded lol
@rgreening
@rgreening 2 года назад
I wonder if it’s possible to override the resource saver/loader to include a key for encrypting the save file and then decrypt it using that key. If you have your game generate a local key and then the save is created with that key, then in theory you shouldn’t be able to open the new file as the keys won’t match (I’m oversimplifying). At any rate I prefer the resource approach over json. I may have to look at whether this key idea holds water or not. ;)
@Gdquest
@Gdquest 2 года назад
I'd prefer using resources too. Not sure if this would work. I would rather add a safeguard to prevent loading any resource that has code or loads another resource: open the tres file first at text and ensure there's no pattern suggesting code in there. _init, or one of the script resources. Something like that. I'm just not sure if this is 100% safe so couldn't recommend it in the video.
@veto_5762
@veto_5762 2 года назад
Im not sure but i think godot has a way to encrypt files by using an encryption key as a string, you can make a personal encryption key so the save file can only be decrypted with the user computer generated key, the only thing would be making key generator complex enough to not repeat keys which with external tools can be easily done, also saving the key somewhere where cannot be changed or exposed
@conner_wood
@conner_wood Год назад
Hackers could always get the crypto keys that are hardcoded or generated. Unless you have it talk to a server that generates the key so the client, the game, has no idea what the key is.
@auroraRealms
@auroraRealms Год назад
I don't convert my dictionary data to anything other than JSON. I load the dictionary into an autoload script, and use the data from that for the entire game. Since it is always available, it saves and retrieves the game configuration across all the menus, and is available during game play. This way, any variable that needs to be configurable can be placed in the dictionary/JSON file and be changed through menus, or by power users who want to tweak the game using JSON. I have two types of network data; High Security Authentication, and minimized unsecured game play streaming data. The game play data can be considered somewhat secure, because using bitwise and/or operators (and enumerators to see what is going on) I can put 64 data members in a single integer. So game play data could be a list, or dictionary, with few floating point numbers for coordinates, an integer to describe the character/game state, and an id to find the character in the game.
@Waliente
@Waliente 6 месяцев назад
there is no way to make saving/loading method with resources secure?
@Chspas
@Chspas 4 месяца назад
Have you found an answer to this?
@Evan842Complex
@Evan842Complex 2 года назад
Any example of maybe using Firebase to save your save data?
@denshitenshi
@denshitenshi 4 дня назад
Do you know a way to save InputEvents using json? As in user-defined keybinds? Most people suggest using a resource but this exploit seems very under-reported
@Gdquest
@Gdquest 4 дня назад
For user-defined key bindings, the risk would not be relevant. People have to download a malicious file and manually replace it in their copy of the game for a risk to exist. Also note there is a small plugin you can use to mitigate the issue when loading resources if you prefer. If you want to save anything using JSON you have to convert the Godot data to a dictionary that you can then convert from and to JSON.
@alexlealch
@alexlealch 2 года назад
Is this 'correction' in the Kickstarter course?
@Gdquest
@Gdquest 2 года назад
Not yet, this video and updated demo are just out. I need to think about it. We will at least explain the caveats in the lessons but I´d rather not complicate things for students there. Note that we have plans to eventually replace some series, so this needs some thoughts.
@leiserfernandezgallo5033
@leiserfernandezgallo5033 2 года назад
Can't the resource file be encrypted? If so there is not how to inject code but from the encripter itself.
@Gdquest
@Gdquest 2 года назад
That's not much more protection against someone with bad intentions. You can always easily find the encryption key, decrypt the save data, inject the code, encrypt again, and put it online.
@Paruthi.618
@Paruthi.618 2 года назад
Thanks for sharing
@user-is9fu2js1l
@user-is9fu2js1l 3 месяца назад
So godot 4 us out, did they release that json+resource system?
@Gdquest
@Gdquest 3 месяца назад
Do you mean can you load resources safely now? No, but you can search the asset store for "Godot Safe Resource Loader". I haven't tested it myself but the plugin author is very reliable.
@redthepencilmonster7011
@redthepencilmonster7011 2 месяца назад
​@@Gdquest Godotneers' (creator of said plugin) video on the subject of saving/loading was so thorough! I loved it. He doesn't promise 100% that the Safe Resource Loader is impossible to circumvent, just that he doesn't know a way to do so yet
@christianbrenner984
@christianbrenner984 2 года назад
Why is there no option to just disable loading of scripts?
@Gdquest
@Gdquest 2 года назад
Resources initially were intended to be used inside Godot projects, and not for external save files or as a format to exchange files. Someone could probably contribute this feature and it'd be welcome.
@sslaxx
@sslaxx 2 года назад
Or disable it outside of res:// altogether, which might be the more secure route.
@adhamfouad1274
@adhamfouad1274 2 года назад
guys please i need a way to make a voice typing in godot please
@logoninternet
@logoninternet 2 года назад
I almost hate to say it, but problems like this are why code signing was invented.
@tale2502
@tale2502 2 года назад
Hi Pls how can I add animation my game(coding)
@donatoclemente4421
@donatoclemente4421 2 года назад
I would recommend googling or searching on RU-vid for animation in godot. I would also recommend researching the AnimationPlayer node
@tale2502
@tale2502 2 года назад
@@donatoclemente4421 ok thanks
@BartoszBielecki
@BartoszBielecki Год назад
Is there a sane/safe method of supporting mods for the game? I mean exposing some interface of the game, allowing modders to use Godot to create new logic (because why not facilitate already existing tool) and then (safely) loading the mod? I guess if we only limit ourselves to data-driven approach then I guess we can always use json, but we lose scriptability.
@Gdquest
@Gdquest Год назад
Mods can never be 100% safe because players download and share them on the web. Regardless of your data format, anyone malicious can make an executable claiming to make mods easy to install and put malware in it. On your side, you could mitigate that in two ways: 1. If you want to safeguard programming, you can code sandboxed programming tools, like the event sheets in RPG maker. It's quite a bit of work and it will limit modders, so it's a tradeoff. 2. You could have an official repository of whitelisted mods. Then it means you need to review every mod update and ensure no malicious code is included. Something like the nexus websites for the elder scrolls. But it's never 100% safe either.
@holleey
@holleey 2 года назад
now if only there was an API that supports Godot's native type serialization, disallows objects by default, and comes with support for encryption as an extra. :) imho File (store_var and get_var) is generally the most suitable API for savegame serialization and I am surprised it's not being mentioned. I wouldn't recommend JSON or XML unless you need to interface with external applications/servers.
@Gdquest
@Gdquest 2 года назад
Thanks, I just didn't know there was the option to prevent object parsing with File.get_var. It's good to know. At least that way you can directly store and get vectors and whatnot. I hope we get the option to serialize object fields without code at some point too!
@redthepencilmonster7011
@redthepencilmonster7011 2 года назад
Neat. I'm a noob, so low-level basics like this are a bit confusing to me. Two questions: 1) Does using "File.store_var" and ".get_var" effectively render Resources and JSON irrelevant for saving data in single-player games? 2) Do statically-typed equivalents like ".get_64" and such have the same security benefits as ".get_var"?
@L4Vo5
@L4Vo5 2 года назад
@@redthepencilmonster7011 1) Not entirely, as store_var doesn't produce something that is human readable. You may want curious players to be able to manually edit save files (or you may specifically NOT want that. Up to you) 2) Yes, those are fully safe
@redthepencilmonster7011
@redthepencilmonster7011 2 года назад
@@L4Vo5 Thanks for the reply. If this is the case, why don't the docs indicate "allow_objects = false" by default for statically-typed variants? Is it because they thought that this would be self-evident, or because there's actually no need for such a safeguard with static types? Excuse my ignorance (^_^;)
@L4Vo5
@L4Vo5 2 года назад
@@redthepencilmonster7011 It's because there's no need. get_var doesn't immediately know what kind of variable it's getting, so it has to also get the variable's type from the file itself. Since it could be any type, there's a safeguard in case it's an Object (which could have code). Meanwhile, get_64 knows it will only ever get an integer. An integer can't be an object or have code of its own. The docs even say that the function reads exactly 64 bits and interprets them as an integer. Meaning, at no point does it "ask" the file what type the variable is, like get_var does. You could be reading complete meaningless garbage, but you will never get anything out of it that isn't an integer. So there's no danger in that case, and the idea of "decoding an object" or "storing code" doesn't even make sense.
@Theraot
@Theraot 2 года назад
I'm glad this is happening.
@Chevifier
@Chevifier 2 года назад
It was too good to be true😂 When I saw your video on saving with resources I was so happy I dont have to use File class anymore but I guess Ill stick with that method.
@geoffreymegardon5624
@geoffreymegardon5624 2 года назад
To save in json or xml, which are local text files, still does not prevent players to unlock paid content they did not paid for. If you make a game with online community/monetary features, I would suggest to save your data in a remote database. Also, I think it would be nice to highlight the cases where it is okay to save/load locally with godot’s solution (offline game, or even simple multiplayer games with no community/monetary aspect). In these sort of games, only the player can modify their save files, and it only affect their own experience. As soon as you have online community feature, shops and monetary reward, you would need to save your data in a database.
@jacobpipers
@jacobpipers Год назад
json can be encrypt the json file.
@Dxpress_
@Dxpress_ Год назад
Yup, but regarding something like paid content, that's less an issue with _how_ data is saved and more with _where_ data is saved. You can still use JSON or XML or whichever format you'd like for saving data, but the key part is that the data _must_ be saved remotely, like you mentioned.
@HansFriedrich532
@HansFriedrich532 Год назад
​@@jacobpipers Encrypted by the client. Nothing is stopping you from writing you own JSON, encrypting it with the same format and replacing your save file. He's right, nothing is safe as long as it's on the user's computer. The only way is to use a database. In the case of paid content, you'll also need to make sure to avoid including the paid content in the base game and only download it from your servers as needed. It's a common flaw in games, especially Unity-made games which can be easily decompiled and DLCs can be unlocked this way. For a solo game with trading between players like Diablo 3 used to work, you basically need the game to be always online even if it's a solo game. Every action needs to be validated by your server, to avoid clients cheating in their sessions and breaking the market. That's why it was strange seeing people complaining about Diablo 3 being always online for a solo game, because that's the only way to do it
@unfa00
@unfa00 Год назад
@@HansFriedrich532 How ironic that a "DLC" which literarly means "DownLoadable Content" is shipped with a game and only unlocked via a purchase.
@vaalalves
@vaalalves 8 месяцев назад
I'm not sure whether you still reply to old videos, but here's the thing though: If you need to save textures and the kinds, the resource method is the only way to do it no? You could save the textures as images in a path and then save the path, but that's soooo hacky and weird.
@anispinner
@anispinner 2 года назад
For game saves, you probably want to use some binary format with basic encryption or at least encoding, so it won't be that easily user modifiable as editing JSON file using notepad. But for loading and saving your config file, this tutorial is a great example!
@angolin9352
@angolin9352 Год назад
Why is it a problem if a player wants to hack their own save? As long as they're not giving themselves competitive advantages in multiplayer (i.e., hacking themselves the best weapons or exploiting stat calcs that save the stat instead of doing/checking the math on load), why should the devs get to tell the players how they're allowed to have or bypass fun?
@anispinner
@anispinner Год назад
The easier is to change something the more chances it will be changed by the user. And the more changes they'll make outside - the less they'll want to grind it ingame. Think about it this way - giving player an ability to change their stats straight inside a game. The game will be much fun? Very doubtful. Storing those stats in the JSON document is barely different.
@angolin9352
@angolin9352 Год назад
​@@anispinner I still fail to see how it's the devs' job to stop the player from modifying their game in single-player, though. If somebody, especially on a third or fourth playthrough, wants to give themselves the best weapons in the game against the first boss, or remove some forced upgrades as part of a challenge run, or set impossible combinations of story flags to see how the game reacts, who are the devs to say "No! You can only have fun the way we WANT you to have fun!" It's one of the reasons Nintendo doesn't make games as good as they used to: They got so focused on intended fun that overall fun got caught in the crossfire. Also, what about unlockables? If you play a game at a friend's house and unlock, say, a secret character on their file, why not unlock it on yours too? Sometimes save files corrupt, or cloud saves get reverted and set your progress back. Who are the devs to say I have to have the starting roster again or go back to level 3 when I was in the last world? Technological ability != moral right.
@GorblinRat
@GorblinRat Месяц назад
@@angolin9352 Cus they made the game, simple as that really. You can dislike it if you want, but that's really all there is to it.
@KyleSzklenski
@KyleSzklenski 2 года назад
Great video and good points made by everyone!
@Riazey
@Riazey Год назад
Would you perhaps be open to doing a video on saves with encryption? There's not a ton of videos/helpful and clear guides on it for Godot and it's really good for say helping deter people from cheating or giving themselves steam achievements etc. so I think a lot of people could benefit from it~ ^-^
@RenderingUser
@RenderingUser 2 года назад
ill still make custom files and file loaders for saves
@Dastmema
@Dastmema 2 года назад
Isn't easier to just change the format that the resource is written to disk? Kinda similar to what you did with the JSON layer, but using the resource directly without worrying about that extra layer
@Gdquest
@Gdquest 2 года назад
It's the act of loading resources that causes the code to run, not the details of the file format or extension themselves, so that wouldn't work considering that Godot runs code when loading resources right now.
@Dastmema
@Dastmema 2 года назад
@@Gdquest I mean, you can use ResourceFormat* to do exactly the same as what you did on the video, I wanted to know if doing that is easier than writting an extra loader/saver step
@torgo_
@torgo_ Месяц назад
I don't understand, this seems more like an issue for players who are downloading weird programs/save files from sketchy websites, rather than an problem on the developer end? Like, your average indie gamedev isn't going to have the scenario of their game infecting players' computers if they simply don't hide a virus inside the game?
@johnrussell6971
@johnrussell6971 Год назад
I had no idea resources were capable of arbitrary code execution...Makes sense, though.
@paimonbutter
@paimonbutter 2 года назад
but someone would have to modify the resource to insert a virus
@Gdquest
@Gdquest 2 года назад
Yes, this is only about save games people download from untrusted sources, as mentioned at the start of the video.
@inkajoo
@inkajoo Год назад
Shouldn't it be possible to use resources as before but filter out everything but the safe stuff when loading it?
@leomotta5376
@leomotta5376 9 месяцев назад
still, players can access the json file and change the save file
@thefufuu3157
@thefufuu3157 9 месяцев назад
you can use an encryption/ decryption key its build in godot ... for singleplayer games its the user decision ... for multiplayer you can store the key on a server ... and fe bind it to a steam account that way its pretty hard to change anything
Месяц назад
Any file can be malicious. I think this isn't a real reason to not use resources for saving
@jumpsneak
@jumpsneak Месяц назад
Thats just stupid. In your opinion its equally unsafe to use a text file as using resources, where you can execute malicious code? You could literally install a trojan via Resources. A text file cannot.
Месяц назад
​@@jumpsneak give me legal consent to infect your computer and I'll send you a txt file
@TheSkypeConverser
@TheSkypeConverser Месяц назад
i wish u deleted the other vid or linked to this one. i just wrote off JSON for no reason 😭
@TheSkypeConverser
@TheSkypeConverser Месяц назад
wow now ur explaining json to me thank you 😢
@therealcherrypapa
@therealcherrypapa Месяц назад
bro I was writing notes like "json = bad" lmao
@galaxyguy4247
@galaxyguy4247 2 года назад
When you already built a whole game with resources:
@Pablo-V
@Pablo-V 2 года назад
To err is human, and I think all of us here commend you for actually correcting yourself when needed. Great job!
@adamcolejones
@adamcolejones 7 месяцев назад
You should probably take the other video down. It's still recommended and some people are still using it without reading the description for the link to this video.
@erinlane1769
@erinlane1769 9 месяцев назад
Good video! But honestly, if the vulnerability as I understand it is that only people who are downloading saves from online are at risk then to my mind that's an end-user problem. You can't walk through a minefield and pretend you won't step on one. That said, I might be misunderstanding the issue and I think an online or multiplayer game would have much more risk than say a singleplayer offline game and would be worth investing much more time and effort into security. In any case I respect you putting a correction video out and you got a subscriber!
@DanielTheFox
@DanielTheFox 8 месяцев назад
You have a point there. However, users that don't have in-depth IT knowledge might receive the save game from a "friend" and just drop it in their app data folder without opening it to check if it contains harmful code. In the end, it's going to be your game that gets the bad reputation. So considering this is time well spent in my opinion! 😉
@Dharengo
@Dharengo 2 года назад
What about binary?
@Gdquest
@Gdquest 2 года назад
Same problem if you use the resource loader, but I think it's mentioned in the video that the built-in var2bytes and bytes2var functions are safe by default.
@Galomortalbr
@Galomortalbr Год назад
yeah, i guess godot resources is not the best thing ever
@nathanlamaire
@nathanlamaire 2 года назад
I already expected this to happen, since Godot is written in C++, which, by default, has no memory security built-in in mind. Dealing with binaries in native will eventually leads to vulnerability if the source of the file is untrusted. (Godot already put side notes on this but people rarely pay attention on it, including many of famous Godot tutorial makers), and it's also part of reason that Godot suggest saving files in standardised/human-readable formats (like, JSON) rather than this type of "easy" way, although it's not the best way to do it.
@Speed-TV
@Speed-TV Год назад
How to save in godot: Just press ctrl+S simple.
@jamajnasoares5702
@jamajnasoares5702 2 месяца назад
C# users: this bullshit class doesnt even exist. Don't waste your time.
@zetronman
@zetronman 2 года назад
LOL, someone yelled at me in the Godot discord for telling them to save gamestate with JSON because it'll be more interoperable with whatever they may want to do in the future. Do I post this video there?
@sslaxx
@sslaxx 2 года назад
They might've watched the original GDQuest video about this in the first place. At this point I think Resource and its ilk should be forbidden to be saved to/loaded from user://.
@jlewwis1995
@jlewwis1995 2 года назад
If godot supported writing normal binary files without having to go through resources this wouldn't be an issue 🙄
@donatoclemente4421
@donatoclemente4421 2 года назад
I wonder if this would be do-able with the C# ver? I would assume so, although I've yet to move over from gdscript.
@Calinou
@Calinou 2 года назад
This is already possible with the File class, which allows you to write text and binary files with any structure. There's also built-in support for compression and/or encryption. It's less convenient to use the File class compared to custom resources, but it's more flexible and likely allows for tighter data packing in certain circumstances.
@KyleLuce
@KyleLuce 2 года назад
I write binary saves all the time without Resources. Just File.store_*()
@AlexValder
@AlexValder 2 года назад
@@Calinou you theoretically can use in-memory Resource object, but serialize and encrypt it. But I'm usually using C# in Godot, so in my case it's better to write just classes that handle it
@Gdquest
@Gdquest 2 года назад
@@Calinou To add to Calinou's answer, you can use var2bytes to instantly convert, say, entire dictionaries to binary, and bytes2var to do it the other way around. By default, this function prevents serializing objects (e.g. resources) so it doesn't have the same issues as resources or other similar functions (var2str for instance).
@imaroughgempdx
@imaroughgempdx Год назад
I say let people edit their savefiles in single player games. Too much energy is put in to stopping people from cheating when there are very simple ways to get around it ALL. If they are motivated enough to find the save file, they will be motivated enough to download Cheat Engine. To me, once the game is in a player's hands, it is theirs to do what they please with. If cheating makes it more fun for them, great! Why should I care? When devs make a big deal about it it feels like Big Brother is mad you aren't playing his game the way he wants.
@IrregularToaster
@IrregularToaster Год назад
did you not actually watch the video? the issue isn't cheating, it's arbitrary code execution
@PaulSpades
@PaulSpades Год назад
My God, you still have it wrong. Your default data management is crap. You need a global game state structure. That should include chapter/level/scene, narrative path, resources/achievements/weapons/inventory, character class/stats/position/action, interactable objects status, maybe enemy/npc stats/spawning positions. Some of these can reset on load - not important on game save/load. All of these should be reset for a separate play trough (new game), some may be random seed generated. The exact storage system needs to be compatible with the target system: A database (or a whole load of servers, or cloud provider) for multiplayer hosted games, or whatever Mac OS, Android, Switch, Playstation expects (windows is a mess - use what's easiest, linux expect some sort of file in the user/home path). I know Android apps are generally expected to tie the save states to a google account. Online games need to process state on the server and save it with an account system and into a database. There's no going around it. On the client you just get display and sound playback and send input. Make sure you figure out what is an object or action in the world and needs to be on the server, and what is an effect (that lives on the client). For game prototypes and game jams use whatever you can get away with - csv, resources(serialized objects are indeed dangerous if your game revives functions), json. I expect the minimal single player commercial game to save system settings in whatever is simpler, and game state to either json or sqlite or a custom binary format.
@aftdawn
@aftdawn Год назад
well, make your own tutorial vid on this then
@godlee4888
@godlee4888 Год назад
Lost straight from the beginning. Make stuff more simplified, or explain what things are. You started off with json and im already done.
@viv-ribbon
@viv-ribbon 2 года назад
You should remove your previous video - it's outright dangerous to spread the old information and there's no guarantee everyone who clicks on the old one will make their way to this video
@Gdquest
@Gdquest 2 года назад
Actually the previous way is OK too, it's not that dangerous. In truth, there's no absolute safety the moment players download files online, so I'm making this mostly for the people for whom it's really important.
Далее
Seven Minutes to Decide On Godot 4 in 2024
7:36
Просмотров 158 тыс.
Разбудили Любимой Песней 😂
00:14
How to use Classes in Godot! - Intermediate Tutorial
8:46
10+2 AWESOME ADDONS for GODOT 4
8:36
Просмотров 131 тыс.
A new way to generate worlds (stitched WFC)
10:51
Просмотров 517 тыс.
Optimizing my Game so it Runs on a Potato
19:02
Просмотров 490 тыс.
How to SAVE & LOAD Game Data Easily in Godot 4
6:09
Просмотров 27 тыс.
We made Vampire Survivors BUT in 10 Lines of Code
7:08
I Made The Hardest Puzzle Game Ever
13:48
Просмотров 273 тыс.
5 Games Made in Godot To Inspire You
5:02
Просмотров 30 тыс.