Skip to content

Commit 343e538

Browse files
committed
Updated s_cache_file_security_globals
Some in progress `scenario_tags_load` security logic
1 parent b2fe7d1 commit 343e538

File tree

1 file changed

+31
-42
lines changed

1 file changed

+31
-42
lines changed

game/source/cache/cache_files.cpp

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -290,45 +290,34 @@ long __cdecl cache_file_get_global_tag_index(tag group_tag)
290290
//return NONE;
291291
}
292292

293-
void __cdecl cache_file_get_path(char const* mapname, char* buffer, long buffer_size)
293+
//.text:00501850 ;
294+
//.text:00501870 ; c_static_string<256>* __cdecl cache_file_get_path(c_static_string<256>* result, char const* scenario_name)
295+
296+
void __cdecl cache_file_get_path(char const* scenario_name, char* cache_file_path, long cache_file_path_size)
294297
{
295-
INVOKE(0x005018C0, cache_file_get_path, mapname, buffer, buffer_size);
298+
INVOKE(0x005018C0, cache_file_get_path, scenario_name, cache_file_path, cache_file_path_size);
296299

297-
//csnzprintf(buffer, buffer_size, "%s%s%s", cache_files_map_directory(), mapname, k_cache_file_extension);
300+
//csnzprintf(cache_file_path, cache_file_path_size, "%s%s%s", cache_files_map_directory(), scenario_name, k_cache_file_extension);
298301
}
299302

300-
#pragma pack(push, 4)
301-
struct s_cache_file_security_globals
303+
struct __declspec(align(8)) s_cache_file_security_globals
302304
{
303-
s_cache_file_header header;
304-
bool valid_content_signature;
305-
c_static_array<dword, 1> hash_sizes;
305+
s_cache_file_header clean_header;
306+
bool hashes_valid;
307+
c_static_array<long, 1> hash_sizes;
306308
c_static_array<void const*, 1> hash_addresses;
307309
c_static_array<s_network_http_request_hash, 1> hashes;
308-
struct
309-
{
310-
dword count;
311-
dword state[5];
312-
byte buffer[64];
313-
dword sha[234];
314-
}
315-
state;
316-
317-
s_network_http_request_hash hash;
310+
byte hash_working_memory[0x400];
311+
s_network_http_request_hash hash_of_hashes;
318312
s_rsa_signature rsa_signature;
319-
byte __data38C4[4];
320313
};
321-
static_assert(0x000038C8 == sizeof(s_cache_file_security_globals));
322-
static_assert(0x00000000 == OFFSETOF(s_cache_file_security_globals, header));
323-
static_assert(0x00003390 == OFFSETOF(s_cache_file_security_globals, valid_content_signature));
314+
static_assert(sizeof(s_cache_file_security_globals) == 0x38C8);
315+
static_assert(0x00000000 == OFFSETOF(s_cache_file_security_globals, clean_header));
316+
static_assert(0x00003390 == OFFSETOF(s_cache_file_security_globals, hashes_valid));
324317
static_assert(0x00003394 == OFFSETOF(s_cache_file_security_globals, hash_sizes));
325318
static_assert(0x00003398 == OFFSETOF(s_cache_file_security_globals, hash_addresses));
326319
static_assert(0x0000339C == OFFSETOF(s_cache_file_security_globals, hashes));
327-
static_assert(0x000033B0 == OFFSETOF(s_cache_file_security_globals, state));
328-
static_assert(0x000037B0 == OFFSETOF(s_cache_file_security_globals, hash));
329320
static_assert(0x000037C4 == OFFSETOF(s_cache_file_security_globals, rsa_signature));
330-
static_assert(0x000038C4 == OFFSETOF(s_cache_file_security_globals, __data38C4));
331-
#pragma pack(pop)
332321

333322
s_cache_file_security_globals* __cdecl cache_file_get_security_globals()
334323
{
@@ -340,7 +329,7 @@ void const* __cdecl cache_file_globals_get_tag_cache_base_address()
340329
//return INVOKE(0x00501930, cache_file_globals_get_tag_cache_base_address);
341330

342331
if (!g_cache_file_globals.tags_loaded)
343-
return nullptr;
332+
return NULL;
344333

345334
return g_cache_file_globals.tag_cache_base_address;
346335
}
@@ -1302,45 +1291,45 @@ bool __cdecl scenario_tags_load(char const* scenario_path)
13021291
//{
13031292
// main_loop_pregame();
13041293
//
1305-
// security_globals->valid_content_signature = false;
1294+
// s_cache_file_security_globals* security_state = security_globals;
1295+
// security_globals->hashes_valid = false;
13061296
//
13071297
// csmemset(&security_globals->hashes[0], 0xBB, sizeof(s_network_http_request_hash));
1308-
// csmemset(&security_globals->hash, 0xCC, sizeof(s_network_http_request_hash));
1298+
// csmemset(&security_globals->hash_of_hashes, 0xCC, sizeof(s_network_http_request_hash));
13091299
// csmemset(&security_globals->rsa_signature, 0xDD, sizeof(s_rsa_signature));
13101300
//
1311-
// s_cache_file_security_globals* v6 = security_globals;
1312-
// v6->header = header_copy;
1313-
// cache_file_builder_security_clean_header(&v6->header);
1301+
// security_state->clean_header = header_copy;
1302+
// cache_file_builder_security_clean_header(&security_state->clean_header);
13141303
//
1315-
// v6->hash_sizes[0] = sizeof(s_cache_file_header);
1316-
// v6->hash_addresses[0] = v6;
1304+
// security_state->hash_sizes[0] = sizeof(s_cache_file_header);
1305+
// security_state->hash_addresses[0] = security_state;
1306+
// byte* hash_working_memory = security_state->hash_working_memory;
13171307
//
13181308
// long v7 = sizeof(s_cache_file_header);
1319-
// decltype(v6->state)* hash_state = &v6->state;
1320-
// if (security_incremental_hash_begin(&v6->state, sizeof(*hash_state), 1))
1309+
// if (security_incremental_hash_begin(hash_working_memory, 0x400, true))
13211310
// {
13221311
// do
13231312
// {
13241313
// long v8 = v7;
13251314
// if (v7 > 0x100000)
13261315
// v8 = 0x100000;
13271316
//
1328-
// security_incremental_hash_update(hash_state, sizeof(*hash_state), v6, v8);
1317+
// security_incremental_hash_update(hash_working_memory, 0x400, security_state, v8);
13291318
// main_loop_pregame();
13301319
//
13311320
// v7 -= v8;
1332-
// v6 = (s_cache_file_security_globals*)offset_pointer(v6, v8);
1321+
// security_state = (s_cache_file_security_globals*)offset_pointer(security_state, v8);
13331322
//
13341323
// } while (v7 > 0);
1335-
// security_incremental_hash_finish(hash_state, sizeof(*hash_state), &v6->hashes[0]);
1324+
// security_incremental_hash_finish(hash_working_memory, 0x400, &security_state->hashes[0]);
13361325
// }
13371326
//
1338-
// security_calculate_hash(&security_globals->hashes, sizeof(s_network_http_request_hash), 1, &security_globals->hash);
1327+
// security_calculate_hash(&security_globals->hashes, sizeof(s_network_http_request_hash), 1, &security_globals->hash_of_hashes);
13391328
// security_globals->rsa_signature = g_cache_file_globals.header.rsa_signature;
13401329
//
13411330
// main_loop_pregame();
13421331
//
1343-
// success = security_rsa_compute_and_verify_signature(&security_globals->hash, &security_globals->rsa_signature);
1332+
// success = security_rsa_compute_and_verify_signature(&security_globals->hash_of_hashes, &security_globals->rsa_signature);
13441333
//}
13451334

13461335
if (success)
@@ -1354,7 +1343,7 @@ bool __cdecl scenario_tags_load(char const* scenario_path)
13541343

13551344
if (success)
13561345
{
1357-
security_globals->valid_content_signature = true;
1346+
security_globals->hashes_valid = true;
13581347

13591348
cache_file_tags_fixup_all_instances();
13601349

0 commit comments

Comments
 (0)