R
RobotoSkunk
Guest
Hello, I tried to encode a JSON file using md5, sha1 and base64 ... the encryption of the file responds perfectly but the decrypted does not respond at all and I wanted to ask for help with this (although no one will answer me) because I tried in many different ways to be able to make this work but I do not get it.
First there is the script that saves the level, this has no problems:
Then there is the script that loads the level in the game, this is the one that is giving me problems:
The load script worked perfectly for me before I added the encryption and decryption system, but now it is giving me a lot of problems. Please, if someone can help me do it ;-;
This is the video where I got the script for saving and loading levels:
First there is the script that saves the level, this has no problems:
Code:
var draggableCount = instance_number(obj_create_obj_editor);
if (file_exists("Nivel" + ".pml")) file_delete("Nivel" + ".pml");
var saveFile = file_text_open_write("Nivel" + ".pml");
for (var i = 0; i < draggableCount; i++){
var instance = instance_find(obj_create_obj_editor, i);
//Convertir instancias en un ds_map
var instanceMap = ds_map_create();
ds_map_add(instanceMap, "x", instance.x);
ds_map_add(instanceMap, "y", instance.y);
ds_map_add(instanceMap, "obj_type", instance.type);
if(instance.type != 1){
if(instance.type != -1){
ds_map_add(instanceMap, "image_xscale", instance.image_xscale);
ds_map_add(instanceMap, "image_yscale", instance.image_yscale);
ds_map_add(instanceMap, "image_angle", instance.image_angle);
}
}
if(instance.type = 3) ds_map_add(instanceMap, "time", instance.time);
if(instance.type = 0) ds_map_add(instanceMap, "ID", instance.ID);
// convertir ds_map en JSON
var JsonInstance = base64_encode(sha1_string_utf8(md5_string_utf8(json_encode(instanceMap))));
file_text_write_string(saveFile, JsonInstance);
file_text_write_string(saveFile, "|");
ds_map_destroy(instanceMap);
}
file_text_close(saveFile);
Code:
if (file_exists("Nivel" + ".pml")){
var worldLoadFile = file_text_open_read("Nivel" + ".pml");
if (!file_text_eof(worldLoadFile)){
var worldMasterData = file_text_read_string(worldLoadFile);
var wordArray = scr_string_split(worldMasterData, "|");
var draggableCount = array_length_1d(wordArray);
if (draggableCount > 0){
for (var i = 0; i < draggableCount; i++){
var draggableJson = wordArray[i];
var draggableMap = base64_decode(sha1_string_unicode(md5_string_unicode(json_decode(draggableJson))));
var _x = ds_map_find_value(draggableMap, "x");
var _y = ds_map_find_value(draggableMap, "y");
var _imageXscale = ds_map_find_value(draggableMap, "image_xscale");
var _imageYscale = ds_map_find_value(draggableMap, "image_yscale");
var _imageAngle = ds_map_find_value(draggableMap, "image_angle");
var obj_type = ds_map_find_value(draggableMap, "obj_type");
var _time = ds_map_find_value(draggableMap, "time");
var _ID = ds_map_find_value(draggableMap, "ID");
switch(obj_type){
case -1:
var obj = obj_room_properties;
break;
case 0:
var obj = obj_block;
break;
case 1:
var obj = obj_player;
break;
case 2:
var obj = obj_springboard;
break;
case 3:
var obj = obj_power_gravity;
break;
case 4:
var obj = obj_special_block_1;
break;
case 5:
var obj = obj_saw;
break;
case 6:
var obj = obj_saw_base;
break;
case 7:
var obj = obj_killzone;
break;
case 8:
var obj = obj_gun;
break;
case 9:
var obj = obj_cannon;
break;
case 10:
var obj = obj_spike;
break;
case 11:
var obj = obj_laser_gun;
break;
default:
var obj = obj_editor_bug;
_imageXscale = 1;
_imageYscale = 1;
_imageAngle = 0;
break;
}
var new_inst = instance_create(_x, _y, obj);
if(obj_type != 1){
if(obj_type != -1){
new_inst.image_xscale = _imageXscale;
new_inst.image_yscale = _imageYscale;
new_inst.image_angle = _imageAngle;
}
}
if(obj_type = 0){
new_inst.ID = _ID;
}
if(obj_type = 3){
new_inst.time = _time;
}
ds_map_destroy(draggableMap);
}
}
}
file_text_close(worldLoadFile);
}
This is the video where I got the script for saving and loading levels: