mirror of
				https://github.com/N64Recomp/N64ModernRuntime.git
				synced 2025-10-30 08:02:29 +00:00 
			
		
		
		
	Compare commits
	
		
			4 commits
		
	
	
		
			3069d33446
			...
			bf05c8d9a5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | bf05c8d9a5 | ||
|   | 31462bf08b | ||
|   | 7cabbf8333 | ||
|   | b87f1e5412 | 
					 3 changed files with 17 additions and 42 deletions
				
			
		|  | @ -544,7 +544,7 @@ namespace recomp { | |||
|         void reset_hooks(); | ||||
|         void run_hook(uint8_t* rdram, recomp_context* ctx, size_t hook_slot_index); | ||||
| 
 | ||||
|         ModOpenError parse_manifest(ModManifest &ret, const std::vector<char> &manifest_data, std::string &error_param, recomp::config::Config *config); | ||||
|         ModOpenError parse_manifest(ModManifest &ret, const std::vector<char> &manifest_data, std::string &error_param, recomp::config::Config *config = nullptr); | ||||
|         CodeModLoadError validate_api_version(uint32_t api_version, std::string& error_param); | ||||
| 
 | ||||
|         void initialize_mods(); | ||||
|  |  | |||
|  | @ -148,9 +148,6 @@ void Config::add_enum_option( | |||
| 
 | ||||
|     ConfigOptionEnum option_enum = {{}, default_value}; | ||||
| 
 | ||||
|     // Note: this is a bit too predictive since this calls add_option
 | ||||
|     size_t option_index = schema.options.size(); | ||||
| 
 | ||||
|     for (const auto &option : options) { | ||||
|         assert(option_enum.can_add_option(option.key, option.value) && "Duplicate enum option key or value."); | ||||
|         option_enum.options.push_back(option); | ||||
|  | @ -282,10 +279,10 @@ void Config::try_call_option_change_callback(const std::string& option_id, Confi | |||
| } | ||||
| 
 | ||||
| void Config::set_option_value(const std::string& option_id, ConfigValueVariant value) { | ||||
|     ConfigStorage &storage = requires_confirmation ? temp_storage : storage; | ||||
|     ConfigStorage &conf_storage = requires_confirmation ? temp_storage : storage; | ||||
| 
 | ||||
|     auto it = storage.value_map.find(option_id); | ||||
|     if (it != storage.value_map.end()) { | ||||
|     auto it = conf_storage.value_map.find(option_id); | ||||
|     if (it != conf_storage.value_map.end()) { | ||||
|         ConfigValueVariant prev_value = it->second; | ||||
|         it->second = value; | ||||
| 
 | ||||
|  | @ -338,6 +335,9 @@ nlohmann::json Config::get_storage_json() const { | |||
|         } | ||||
| 
 | ||||
|         switch (option.type) { | ||||
|         case ConfigOptionType::None: { | ||||
|             break; | ||||
|         } | ||||
|         case ConfigOptionType::Enum: { | ||||
|             auto &option_enum = std::get<ConfigOptionEnum>(option.variant); | ||||
|             auto found_opt = option_enum.find_option_from_value(std::get<uint32_t>(value)); | ||||
|  | @ -469,7 +469,10 @@ bool Config::load_config(std::function<bool(nlohmann::json &)> validate_callback | |||
|         if (requires_confirmation) { | ||||
|             revert_temp_config(); | ||||
|         } | ||||
|         if (!is_mod_config) { | ||||
|             // Only save default config for non-mod configs
 | ||||
|             save_config(); | ||||
|         } | ||||
|         derive_all_config_option_dependencies(); | ||||
|         clear_config_option_updates(); | ||||
|         loaded_config = true; | ||||
|  |  | |||
|  | @ -6,35 +6,6 @@ | |||
| #include "librecomp/files.hpp" | ||||
| #include "librecomp/mods.hpp" | ||||
| 
 | ||||
| static bool read_json(std::ifstream input_file, nlohmann::json &json_out) { | ||||
|     if (!input_file.good()) { | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     try { | ||||
|         input_file >> json_out; | ||||
|     } | ||||
|     catch (nlohmann::json::parse_error &) { | ||||
|         return false; | ||||
|     } | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
| static bool read_json_with_backups(const std::filesystem::path &path, nlohmann::json &json_out) { | ||||
|     // Try reading and parsing the base file.
 | ||||
|     if (read_json(std::ifstream{ path }, json_out)) { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     // Try reading and parsing the backup file.
 | ||||
|     if (read_json(recomp::open_input_backup_file(path), json_out)) { | ||||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     // Both reads failed.
 | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| recomp::mods::ZipModFileHandle::~ZipModFileHandle() { | ||||
|     if (file_handle) { | ||||
|         fclose(file_handle); | ||||
|  | @ -716,11 +687,6 @@ recomp::mods::ModOpenError recomp::mods::parse_manifest(ModManifest& ret, const | |||
|         return current_error; | ||||
|     } | ||||
| 
 | ||||
|     if (config != nullptr) { | ||||
|         config->set_id(ret.mod_id); | ||||
|         config->set_mod_version(ret.version.to_string()); | ||||
|     } | ||||
| 
 | ||||
|     // Authors
 | ||||
|     current_error = try_get_vec<json::string_t>(ret.authors, manifest_json, authors_key, true, error_param); | ||||
|     if (current_error != ModOpenError::Good) { | ||||
|  | @ -943,6 +909,8 @@ recomp::mods::ModOpenError recomp::mods::ModContext::open_mod_from_manifest(ModM | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     mod_config.set_id(manifest.mod_id); | ||||
|     mod_config.set_mod_version(manifest.version.to_string()); | ||||
|     // Read the mod config if it exists.
 | ||||
|     parse_mod_config_storage(manifest.mod_id, mod_config); | ||||
| 
 | ||||
|  | @ -1051,6 +1019,10 @@ std::string recomp::mods::error_to_string(ModOpenError error) { | |||
|             return "Duplicate mod found"; | ||||
|         case ModOpenError::WrongGame: | ||||
|             return "Mod is for a different game"; | ||||
|         case ModOpenError::InvalidDisableOptionDependency: | ||||
|             return "Invalid disable option dependency in mod.json"; | ||||
|         case ModOpenError::InvalidHiddenOptionDependency: | ||||
|             return "Invalid hidden option dependency in mod.json"; | ||||
|         case ModOpenError::DuplicateEnumStrings: | ||||
|             return "Duplicate enum strings found in mod.json (enum strings are case insensitive)"; | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue