1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
use std::ptr::NonNull;
use windows::Win32::Foundation::FILETIME;
use crate::{
DLList, DLVector,
cs::{CSRandXorshift, MultiplayRole},
dlcr::{AESDecrypter, AESEncrypter, DLSerialCipherKey},
dlkr::{DLAllocator, DLPlainLightMutex},
dltx::{DLInplaceStr, DLUTF16StringKind},
fd4::FD4Time,
};
use shared::{F32Vector3, IsEmpty, MaybeEmpty, OwnedPtr};
use super::{BlockId, CSEzTask, CSEzUpdateTask, P2PEntityHandle};
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
/// Various states for an online lobby to be in.
///
/// Source of name: Sekiro Debug Menu
pub enum LobbyState {
None = 0x0,
TryToCreateSession = 0x1,
FailedToCreateSession = 0x2,
Host = 0x3,
TryToJoinSession = 0x4,
FailedToJoinSesion = 0x5,
Client = 0x6,
OnLeaveSession = 0x7,
FailedToLeaveSession = 0x8,
}
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum ProtocolState {
/// セッションに参加してない
///
/// Not joined in session
None = 0x0,
/// マルチプレイ開始チェック
///
/// Check to start multiplayer
JoinCheck = 0x1,
/// 初期同期データ受信待ち
///
/// Wait to receive initial synchronization data
WaitInitData = 0x2,
/// 召喚メッセージ
///
/// Wait for summon message display to complete
WaitReloadWait = 0x3,
/// 再ロード開始~キャラ初期化まで待ち
///
/// Wait from reload start to character initialization
WaitReload = 0x4,
/// キャラ初期化~再ロード完了まで待ち
///
/// Wait from character initialization to reload completion
WaitReload2 = 0x5,
/// マルチプレイ中
///
/// In multiplayer
Ingame = 0x6,
/// マルチ継続しつつマップ再入場中
///
/// Re-entering map while continuing multiplayer
WaitReentryToMap = 0x7,
}
#[repr(C)]
#[shared::singleton("CSSessionManager")]
pub struct CSSessionManager {
vftable: usize,
unk8: u32,
pub lobby_state: LobbyState,
pub protocol_state: ProtocolState,
unk14: f32,
unk18: u8,
unk19: u8,
unk1a: u8,
unk1b: u8,
unk1c: u8,
unk1d: u8,
unk1e: u8,
unk1f: u8,
unk20: u32,
unk24: u32,
unk28: u32,
unk2c: u32,
unk30: usize,
map_active_synchronizer: usize,
voice_chat_manager: usize,
allocator: &'static DLAllocator,
unk50: NonNull<Self>,
unk58: u32,
unk5c: u32,
manager_impl_steam: usize,
unk68: bool,
pub players: DLVector<SessionManagerPlayerEntry>,
pub host_player: MaybeEmpty<SessionManagerPlayerEntryBase>,
unk160: usize,
unk168: usize,
/// Player limit for current session.
/// Set to 4 in open world and 6 in quickmatch arena.
pub session_player_limit: u32,
unk174: u32,
unk178: u8,
unk179: u8,
unk17a: u8,
unk17b: u8,
unk17c: u32,
player_data_man: usize,
/// Used to warp players back to the latest valid multiplay area in case they step out of it.
pub stay_in_multiplay_area_warp_data: OwnedPtr<CSStayInMultiplayAreaWarpData>,
unk190: usize,
protocol_state_1_timeout: FD4Time,
protocol_state_2_timeout: FD4Time,
unk1b8: usize,
unk1c0: u8,
unk1c1: u8,
unk1c2: u8,
unk1c3: u8,
unk1c4: f32,
unk1c8: u16,
unk1ca: u8,
unk1cb: u8,
unk1cc: f32,
unk1d0: f32,
unk1d4: f32,
unk1d8: f32,
unk1dc: u32,
pub update_task: CSEzUpdateTask<CSEzTask, Self>,
unk208: CSEzUpdateTask<CSEzTask, Self>,
unk230: i8,
unk231: u8,
unk232: u8,
unk233: u8,
unk234: u32,
pub serial_cipher_key: OwnedPtr<DLSerialCipherKey>,
pub aes_encrypter: OwnedPtr<AESEncrypter>,
pub aes_decrypter: OwnedPtr<AESDecrypter>,
unk250: u32,
unk254: u32,
unk258: u32,
/// This field is set to 1 on init and never changed.
/// If it's not 1, all sessions will use this value instead of the default session player limit.
pub session_player_limit_override: u32,
/// P2P Send queue? Seems unused? Maybe left-over from DS2?
p2p_send_queue: CSSessionManagerP2PSendQueue,
pub mutex: DLPlainLightMutex,
unk2d0: f32,
unk2d4: f32,
/// Contain statistics about the inbound packet queue, seems unused.
p2p_inbound_queue_stats: Option<OwnedPtr<CSSessionManagerP2PInboundQueueStats>>,
unk2e0: u32,
/// Seems to be a total for the amount of packet bytes in some fashion?
unk2e4: u32,
unk2e8: u32,
unk2ec: u8,
pub enable_p2p_queue_stats: bool,
unk2ee: u8,
unk2ef: u8,
unk2f0: DLList<()>,
unk308: u16,
unk30a: u16,
unk30c: u32,
unk310: i32,
unk314: u32,
unk318: u32,
unk31c: u32,
unk320: u16,
unk322: u16,
unk324: i32,
unk328: i32,
unk32c: u32,
/// Next fields seem to be some collection?
unk330: &'static DLAllocator,
unk338: Option<OwnedPtr<()>>,
unk340: u32,
unk344: u32,
unk348: u16,
unk34a: u16,
unk34c: i32,
unk350: f32,
unk354: u32,
}
#[repr(C)]
pub struct SessionManagerPlayerEntryBase {
internal_thread_steam_connection: usize,
internal_thread_steam_socket: usize,
pub steam_id: u64,
pub steam_name: DLInplaceStr<DLUTF16StringKind, 64>,
connection_ref_info: usize,
voice_chat_member_ref_info: usize,
}
unsafe impl IsEmpty for SessionManagerPlayerEntryBase {
fn is_empty(base: &MaybeEmpty<SessionManagerPlayerEntryBase>) -> bool {
// Check whether steam_id is 0
*unsafe { base.as_non_null().cast::<u64>().offset(2).as_ref() } == 0
}
}
#[repr(C)]
pub struct SessionManagerPlayerEntry {
pub base: SessionManagerPlayerEntryBase,
/// Index in networked player game data list, will be -1 for host.
pub game_data_index: i32,
/// Character id for all EMEVD and other character related stuff.
pub character_event_id: u32,
unkd8: usize,
pub horse_entity_handle: P2PEntityHandle,
/// Is this entry for the host of the session?
pub is_host: bool,
/// Is this entry for the local player?
/// Gets checked in a bunch of places to see if it should use the local PlayerGameData
/// instead of a remote one by the game data index.
pub is_local_player: bool,
pub join_wait: bool,
pub check: bool,
unkec: u8,
pub rebreak_in: bool,
/// If true, prevents host sending emevd event sync packets (104) to this player.
pub disable_emk_sync: bool,
unkef: [u8; 0xd],
/// [MultiplayRole] this player had before starting a pseudo multiplayer ceremony.
/// Used to restore the [MultiplayRole] after the ceremony ends.
pub pre_ceremony_multiplay_role: MultiplayRole,
}
#[repr(C)]
pub struct StayInMultiplayFadeTrackerEntry {
/// Steam ID of the player who is currently in warp and should not be rendered.
pub steam_id: u64,
/// Time in seconds until the player should be rendered again.
pub fade_time: f32,
_pad: [u8; 4],
}
#[repr(C)]
/// Object used to warp players back to the latest valid multiplay area in case they step out of it.
pub struct CSStayInMultiplayAreaWarpData {
/// Vector of remote player warp trackers.
/// Used to check when player rendering should be disabled using bitflag on ChrIns at 0x1c5.
/// When warp time is 0, player rendering is enabled back.
pub player_fade_tracker: DLVector<StayInMultiplayFadeTrackerEntry>,
/// Sent by host to clients on connect in packet 90 (0x5A).
/// Contains the ID of the play area the host was in when the client connected.
/// If current multiplay area ID has different boss ID than this one, player will be warped to latest stored position.
/// Setting this to 0 will disable this.
pub multiplay_start_area_id: u32,
unk24: u32,
stay_in_multiplay_area_warp_step: [u8; 0xc8],
/// Last position player was before stepping out of the multiplay area, relative to the map.
/// Read from GameMan and uses same logic as bloodstains.
pub saved_position: F32Vector3,
/// Last BlockId player was before stepping out of the multiplay area.
/// Read from GameMan and uses same logic as bloodstains.
pub saved_block_id: BlockId,
/// Delay before the player is warped back to the safe position.
/// Used for fadeout effect and updated by task.
/// This is set to 0 when the player is warped back.
pub warp_request_delay: f32,
/// Setting this to true will completely disable multiplay area restrictions,
/// allowing player to go anywhere on the map.
pub disable_multiplay_restriction: bool,
/// Controls if the player should be warped back to the saved position.
/// False when falling, or doing something else that can mess up the warp.
pub is_warp_possible: bool,
_pad: [u8; 0x2],
}
#[repr(C)]
pub struct CSSessionManagerP2PSendQueue {
pub queue: DLVector<CSSessionManagerP2PSendQueueEntry>,
unk20: CSSessionManager0x20,
/// [crate::cs::GameMan::rand_xorshift]
pub rand_xor_shift: NonNull<CSRandXorshift>,
unk38: u32,
unk3c: u32,
}
#[repr(C)]
pub struct CSSessionManagerP2PSendQueueEntry {
/// Recipient's steam ID.
pub recipient: u64,
pub packet_bytes: *mut u8,
pub packet_length: u32,
pub packet_type: u8,
unk15: u8,
_pad16: u16,
}
#[repr(C)]
pub struct CSSessionManager0x20 {
time_1: FILETIME,
time_2: FILETIME,
}
#[repr(C)]
pub struct CSSessionManagerP2PInboundQueueStats {
/// Seems to keep track of the amount of packets waiting in-queue.
pending_packet_count: u32,
/// Seems to keep track of the amount of raw bytes in the queue.
pending_packet_bytes: u32,
unk8: u32,
unkc: u32,
}