1 // Copyright (c) 2012- PPSSPP Project. 2 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, version 2.0 or later versions. 6 7 // This program is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 // GNU General Public License 2.0 for more details. 11 12 // A copy of the GPL 2.0 should have been included with the program. 13 // If not, see http://www.gnu.org/licenses/ 14 15 // Official git repository and contact information can be found at 16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. 17 18 #pragma once 19 20 #include <string> 21 #include <map> 22 #include <vector> 23 24 #include "Common/CommonTypes.h" 25 #include "Common/Log.h" 26 27 class ParamSFOData 28 { 29 public: 30 void SetValue(std::string key, unsigned int value, int max_size); 31 void SetValue(std::string key, std::string value, int max_size); 32 void SetValue(std::string key, const u8* value, unsigned int size, int max_size); 33 34 int GetValueInt(std::string key); 35 std::string GetValueString(std::string key); 36 u8* GetValueData(std::string key, unsigned int *size); 37 38 std::vector<std::string> GetKeys(); 39 std::string GenerateFakeID(std::string filename = ""); 40 GetDiscID()41 std::string GetDiscID() { 42 const std::string discID = GetValueString("DISC_ID"); 43 if (discID.empty()) { 44 std::string fakeID = GenerateFakeID(); 45 WARN_LOG(LOADER, "No DiscID found - generating a fake one: '%s'", fakeID.c_str()); 46 ValueData data; 47 data.type = VT_UTF8; 48 data.s_value = fakeID; 49 values["DISC_ID"] = data; 50 return fakeID; 51 } 52 return discID; 53 } 54 55 bool ReadSFO(const u8 *paramsfo, size_t size); 56 bool WriteSFO(u8 **paramsfo, size_t *size); 57 ReadSFO(const std::vector<u8> & paramsfo)58 bool ReadSFO(const std::vector<u8> ¶msfo) { 59 if (!paramsfo.empty()) { 60 return ReadSFO(¶msfo[0], paramsfo.size()); 61 } else { 62 return false; 63 } 64 } 65 66 int GetDataOffset(const u8 *paramsfo, std::string dataName); 67 68 void Clear(); 69 70 private: 71 enum ValueType 72 { 73 VT_INT, 74 VT_UTF8, 75 VT_UTF8_SPE // raw data in u8 76 }; 77 78 class ValueData 79 { 80 public: 81 ValueType type = VT_INT; 82 int max_size = 0; 83 std::string s_value; 84 int i_value = 0; 85 86 u8* u_value = nullptr; 87 unsigned int u_size = 0; 88 89 void SetData(const u8* data, int size); 90 ~ValueData()91 ~ValueData() { 92 if (u_value) 93 delete[] u_value; 94 } 95 }; 96 97 std::map<std::string,ValueData> values; 98 }; 99 100