|
1 | 1 | #include "networking/logic/network_arbitration.hpp" |
2 | 2 |
|
| 3 | +#include "cseries/cseries_events.hpp" |
3 | 4 | #include "memory/module.hpp" |
| 5 | +#include "networking/online/online_arbitration_windows.hpp" |
| 6 | +#include "networking/session/network_managed_session.hpp" |
4 | 7 |
|
| 8 | +//REFERENCE_DECLARE_ARRAY(0x0189C4D8, char const*, g_network_arbitration_status_string, k_network_arbitration_status_count); |
5 | 9 | REFERENCE_DECLARE(0x0228E520, s_network_arbitration_globals, network_arbitration_globals); |
6 | 10 |
|
| 11 | +HOOK_DECLARE(0x004D9AB0, network_arbitration_get_results); |
| 12 | +HOOK_DECLARE(0x004D9B20, network_arbitration_get_status); |
7 | 13 | HOOK_DECLARE(0x004D9B60, network_arbitration_initiate); |
8 | 14 |
|
9 | 15 | void __cdecl network_arbitration_destory() |
10 | 16 | { |
11 | | - INVOKE(0x004D9A90, network_arbitration_destory); |
| 17 | + //INVOKE(0x004D9A90, network_arbitration_destory); |
| 18 | + |
| 19 | + csmemset(&network_arbitration_globals, 0, sizeof(network_arbitration_globals)); |
| 20 | + network_arbitration_globals.arbitration_managed_session_index = NONE; |
| 21 | +} |
| 22 | + |
| 23 | +bool __cdecl network_arbitration_get_results(int32 managed_session_index, s_arbitration_registration_result* registration_result) |
| 24 | +{ |
| 25 | + //return INVOKE(0x004D9AB0, network_arbitration_get_results, managed_session_index, registration_result); |
| 26 | + |
| 27 | + ASSERT(managed_session_index != NONE); |
| 28 | + ASSERT(registration_result); |
| 29 | + |
| 30 | + if (managed_session_index != network_arbitration_globals.arbitration_managed_session_index) |
| 31 | + { |
| 32 | + event(_event_error, "networking:leaderboards:arbitration: failed to get arbitration result, session mismatch [0x%08X != 0x%08X]", |
| 33 | + managed_session_index, |
| 34 | + network_arbitration_globals.arbitration_managed_session_index); |
| 35 | + |
| 36 | + return false; |
| 37 | + } |
| 38 | + |
| 39 | + if (network_arbitration_globals.arbitration_status != _network_arbitration_status_registered) |
| 40 | + { |
| 41 | + event(_event_error, "networking:leaderboards:arbitration: failed to get arbitration result, arbitration state not registered [0x%08X %s]", |
| 42 | + managed_session_index, |
| 43 | + g_network_arbitration_status_string[network_arbitration_globals.arbitration_status]); |
| 44 | + |
| 45 | + return false; |
| 46 | + } |
| 47 | + |
| 48 | + *registration_result = network_arbitration_globals.registration_result; |
| 49 | + return true; |
12 | 50 | } |
13 | 51 |
|
14 | | -//.text:004D9AB0 ; bool __cdecl network_arbitration_get_results(int32, s_arbitration_registration_result*) |
15 | | -//.text:004D9B20 ; e_network_arbitration_status __cdecl network_arbitration_get_status() |
| 52 | +e_network_arbitration_status __cdecl network_arbitration_get_status() |
| 53 | +{ |
| 54 | + //return INVOKE(0x004D9B20, network_arbitration_get_status); |
| 55 | + |
| 56 | + return network_arbitration_globals.arbitration_status; |
| 57 | +} |
16 | 58 |
|
17 | 59 | bool __cdecl network_arbitration_initialize() |
18 | 60 | { |
19 | | - return INVOKE(0x004D9B30, network_arbitration_initialize); |
| 61 | + //return INVOKE(0x004D9B30, network_arbitration_initialize); |
| 62 | + |
| 63 | + memset(&network_arbitration_globals, 0, sizeof(network_arbitration_globals)); |
| 64 | + network_arbitration_globals.arbitration_managed_session_index = NONE; |
| 65 | + network_arbitration_globals.initialized = true; |
| 66 | + return true; |
20 | 67 | } |
21 | 68 |
|
22 | 69 | bool __cdecl network_arbitration_initiate(int32 managed_session_index, uns64 nonce) |
23 | 70 | { |
24 | 71 | //return INVOKE(0x004D9B60, network_arbitration_initiate, managed_session_index, nonce); |
25 | 72 |
|
26 | | - network_arbitration_globals.arbitration_status = _network_arbitration_status_registered; |
27 | | - network_arbitration_globals.managed_session_index = managed_session_index; |
| 73 | + ASSERT(managed_session_index != NONE); |
| 74 | + ASSERT(nonce); |
| 75 | + ASSERT(network_arbitration_get_status() != _network_arbitration_status_registration_in_progress); |
| 76 | + |
| 77 | + network_arbitration_globals.arbitration_status = _network_arbitration_status_registration_failed; |
| 78 | + network_arbitration_globals.arbitration_managed_session_index = managed_session_index; |
| 79 | + |
| 80 | + void* session_handle = NULL; |
| 81 | + if (!managed_session_get_handle(managed_session_index, &session_handle)) |
| 82 | + { |
| 83 | + event(_event_warning, "networking:leaderboards:arbitration: failed to get session handle for session 0x%08X", |
| 84 | + managed_session_index); |
| 85 | + |
| 86 | + return false; |
| 87 | + } |
| 88 | + |
| 89 | + if (!online_arbitration_initiate_registration(session_handle, nonce)) |
| 90 | + { |
| 91 | + event(_event_warning, "networking:leaderboards:arbitration: failed to initiate registration for session 0x%08X", |
| 92 | + managed_session_index); |
| 93 | + |
| 94 | + return false; |
| 95 | + } |
| 96 | + |
| 97 | + network_arbitration_globals.arbitration_status = _network_arbitration_status_registration_in_progress; |
28 | 98 | return true; |
29 | 99 | } |
30 | 100 |
|
31 | 101 | void __cdecl network_arbitration_update() |
32 | 102 | { |
33 | | - INVOKE(0x004D9BB0, network_arbitration_update); |
| 103 | + //INVOKE(0x004D9BB0, network_arbitration_update); |
| 104 | + |
| 105 | + network_arbitration_update_registration(); |
| 106 | +} |
| 107 | + |
| 108 | +void __cdecl network_arbitration_update_registration() |
| 109 | +{ |
| 110 | + //INVOKE(0x004D9BE0, network_arbitration_update_registration); |
| 111 | + |
| 112 | + if (network_arbitration_globals.arbitration_status != _network_arbitration_status_registration_in_progress) |
| 113 | + { |
| 114 | + return; |
| 115 | + } |
| 116 | + |
| 117 | + e_online_arbitration_registration_status status = online_arbitration_registration_get_status(); |
| 118 | + switch (status) |
| 119 | + { |
| 120 | + case _online_arbitration_registration_none: |
| 121 | + { |
| 122 | + event(_event_error, "networking:leaderboards:arbitration: registration failed for session 0x%08X (unexpected result)", |
| 123 | + network_arbitration_globals.arbitration_managed_session_index); |
| 124 | + |
| 125 | + network_arbitration_globals.arbitration_status = _network_arbitration_status_registration_failed; |
| 126 | + } |
| 127 | + break; |
| 128 | + case _online_arbitration_registration_in_progress: |
| 129 | + { |
| 130 | + event(_event_warning, "networking:leaderboards:arbitration: registration failed for session 0x%08X", |
| 131 | + network_arbitration_globals.arbitration_managed_session_index); |
| 132 | + |
| 133 | + network_arbitration_globals.arbitration_status = _network_arbitration_status_registration_failed; |
| 134 | + } |
| 135 | + break; |
| 136 | + case _online_arbitration_registration_complete_success: |
| 137 | + { |
| 138 | + event(_event_message, "networking:leaderboards:arbitration: registration completed for session 0x%08X", |
| 139 | + network_arbitration_globals.arbitration_managed_session_index); |
| 140 | + |
| 141 | + if (!online_arbitration_registration_get_result(&network_arbitration_globals.registration_result)) |
| 142 | + { |
| 143 | + event(_event_message, "networking:leaderboards:arbitration: registration completed, but we failed to get results for session 0x%08X", |
| 144 | + network_arbitration_globals.arbitration_managed_session_index); |
| 145 | + |
| 146 | + network_arbitration_globals.arbitration_status = _network_arbitration_status_registration_failed; |
| 147 | + break; |
| 148 | + } |
| 149 | + |
| 150 | + network_arbitration_globals.arbitration_status = _network_arbitration_status_registered; |
| 151 | + } |
| 152 | + break; |
| 153 | + case _online_arbitration_registration_complete_failed: |
| 154 | + { |
| 155 | + event(_event_message, "networking:leaderboards:arbitration: registration completed, but we failed to get results for session 0x%08X", |
| 156 | + network_arbitration_globals.arbitration_managed_session_index); |
| 157 | + |
| 158 | + network_arbitration_globals.arbitration_status = _network_arbitration_status_registration_failed; |
| 159 | + } |
| 160 | + break; |
| 161 | + default: |
| 162 | + { |
| 163 | + event(_event_error, "networking:leaderboards:arbitration: registration failed for session 0x%08X (unexpected result)", |
| 164 | + network_arbitration_globals.arbitration_managed_session_index); |
| 165 | + |
| 166 | + network_arbitration_globals.arbitration_status = _network_arbitration_status_registration_failed; |
| 167 | + } |
| 168 | + break; |
| 169 | + } |
34 | 170 | } |
35 | 171 |
|
36 | | -//.text:004D9BE0 ; void __cdecl network_arbitration_update_registration() |
| 172 | +char const* g_network_arbitration_status_string[k_network_arbitration_status_count] |
| 173 | +{ |
| 174 | + "arbitration-status-none", |
| 175 | + "arbitration-status-registration-in-progress", |
| 176 | + "arbitration-status-registered", |
| 177 | + "arbitration-status-registration-failed" |
| 178 | +}; |
37 | 179 |
|
0 commit comments