Ticket #3637: hash_dump.patch
File hash_dump.patch, 4.3 KB (added by , 8 years ago) |
---|
-
source/ps/Game.cpp
extern GameLoopState* g_AtlasGameLoop; 56 56 57 57 /** 58 58 * Globally accessible pointer to the CGame object. 59 59 **/ 60 60 CGame *g_Game=NULL; 61 // I'm not supposed to be here 62 char g_HashDirectory[2048]; 63 FILE* g_HashFile; 61 64 62 65 /** 63 66 * Constructor 64 67 * 65 68 **/ -
source/ps/Game.h
17 17 18 18 #ifndef INCLUDED_GAME 19 19 #define INCLUDED_GAME 20 20 21 21 #include "ps/Errors.h" 22 #include "ps/Filesystem.h" 22 23 #include <vector> 23 24 24 25 #include "scriptinterface/ScriptVal.h" 25 26 #include "simulation2/helpers/Player.h" 26 27 … … private: 210 211 u32 m_FinalReplayTurn; 211 212 }; 212 213 213 214 extern CGame *g_Game; 214 215 216 // I'm not supposed to be here 217 extern char g_HashDirectory[2048]; 218 extern FILE* g_HashFile; 219 215 220 #endif -
source/simulation2/serialization/HashSerializer.h
17 17 18 18 #ifndef INCLUDED_HASHSERIALIZER 19 19 #define INCLUDED_HASHSERIALIZER 20 20 21 21 #include "BinarySerializer.h" 22 22 #include "network/NetTurnManager.h" 23 23 #include "maths/MD5.h" 24 #include "ps/Game.h" 24 25 25 26 class CHashSerializerImpl 26 27 { 27 28 // We don't care about cryptographic strength, just about detection of 28 29 // unintended changes and about performance, so MD5 is an adequate choice … … class CHashSerializerImpl 30 31 31 32 public: 32 33 size_t GetHashLength(); 33 34 const u8* ComputeHash(); 34 35 35 void Put(const char* UNUSED(name), const u8* data, size_t len) 36 CHashSerializerImpl() 37 { 38 sprintf(g_HashDirectory, "/media/tmpfs2/oos/hash/turn_%u/", g_Game->GetTurnManager()->GetCurrentTurn()); 39 CreateDirectories(g_HashDirectory, 0700); 40 } 41 42 void Put(const char* name, const u8* data, size_t len) 36 43 { 37 m_Hash.Update(data, len); 44 if (!g_HashFile) 45 { 46 // We don't care about the RNG and next entity id field for now 47 debug_printf("Hash file not opened yet!"); 48 return; 49 } 50 51 if (!name) 52 { 53 debug_printf("Bad property name\n"); 54 return; 55 } 56 57 if (data) 58 { 59 fwrite(name, 1, strlen(name), g_HashFile); 60 fwrite(data, 1, len, g_HashFile); 61 62 m_Hash.Update(data, len); 63 } 64 else 65 debug_printf("Bad file or bad data\n"); 38 66 } 39 67 40 68 private: 41 69 HashFunc m_Hash; 42 70 u8 m_HashData[HashFunc::DIGESTSIZE]; -
source/simulation2/system/ComponentManagerSerialization.cpp
bool CComponentManager::DumpDebugState(s 95 95 return true; 96 96 } 97 97 98 98 bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick) 99 99 { 100 // Always do full checks 101 quick = false; 102 100 103 // Hash serialization: this includes the minimal data necessary to detect 101 104 // differences in the state, and ignores things like counts and names 102 105 103 106 // If 'quick' is set, this checks even fewer things, so that it will 104 107 // be fast enough to run every turn but will typically detect any … … bool CComponentManager::ComputeStateHash 129 132 } 130 133 131 134 if (!needsSerialization) 132 135 continue; 133 136 137 // Write the data of every component to a separate file every turn 138 CStr componentName = m_ComponentTypesById.find(cit->first)->second.name; 139 char filename[2048]; 140 sprintf(filename, "%s/%s", g_HashDirectory, componentName.c_str()); 141 g_HashFile = fopen(filename, "wb"); 134 142 serializer.NumberI32_Unbounded("component type id", cit->first); 135 143 136 144 for (std::map<entity_id_t, IComponent*>::const_iterator eit = cit->second.begin(); eit != cit->second.end(); ++eit) 137 145 { 138 146 // Don't serialize local entities … … bool CComponentManager::ComputeStateHash 140 148 continue; 141 149 142 150 serializer.NumberU32_Unbounded("entity id", eit->first); 143 151 eit->second->Serialize(serializer); 144 152 } 153 fclose(g_HashFile); 145 154 } 146 155 147 156 outHash = std::string((const char*)serializer.ComputeHash(), serializer.GetHashLength()); 148 157 149 158 // TODO: catch exceptions