0 votes

https://docs.godotengine.org/en/3.1/tutorials/io/encrypting_save_games.html
The docs here are a bit to short and not broad enough to be of help. Here they just use the storevar function in File, but what if I want to encrypt a ConfigFile and use setvalue()?. Tried to apply the same technique directly, but it doesn't seem to work:

var save_path = "res://SaveFile.cfg"
var config = ConfigFile.new()
var load_respone = config.load(save_path)
var file = File.new()

func saveValue(section, key, value):
    file.open_encrypted_with_pass(save_path, File.WRITE, "mypass")
    config.set_value(section, key, value)
    config.save(save_path)
    file.close()

func loadValue(section, key):
    file.open_encrypted_with_pass(save_path, File.READ, "mypass")
    return config.get_value(section, key, 0)
    file.close()
in Engine by (70 points)

1 Answer

0 votes

You don't have to use the File class along with ConfigFile. Try this:

var password = OS.get_unique_id() # works only on this computer
var save_path = "res://SaveFile.cfg"
var config = ConfigFile.new()

# skip this load if the file doesn't exist yet
var error = config.load_encrypted_pass(save_path, password)

config.set_value(section, key, value)
config.save_encrypted_pass(save_path, password)
config.save("res://SaveFile_unencrypted.cfg", password) # for testing
by (32 points)

Ahh I see the problem. I thought ConfigFile didn't have the save or load encrypted functions, because when I want to check the docs I usually just google it and the 3.1 docs apparently shows up when you do that. So I was looking at an outdated docs where ConfigFile seemingly didn't have those functions. Well thanks I can hopefully get it working now.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.