Files
isaac-port/generated-src/network_manager.cpp
T
shweetandClaude Opus 5.5 3ce74c6e2d Reconstruction layout: generated-src/ (generated) and src/ (curated), CMake, the first takeover: RNG
The decompiled C++ tree moves to generated-src/ (classes.h, C++20); src/ is for code written by hand. A curated function
defines the generated declaration and starts its comment with its address, and source_tree.py stops emitting that body.
src/rng.cpp takes over RNG (SetSeed, the constructor, Next, RandomInt, RandomFloat, Shuffle) with the shift table read
from the exe as a constexpr array; src/log.h names KAGE_LogMessage's levels (1 INFO, 2 NET, 4 WARN, 8 ERROR, 16 ASSERT,
from its prefix jump table). CMakeLists.txt builds src/*.cpp against generated-src/classes.h (clean with -Wall -Wextra).
structs.hpp and headers.py are retired: scripts/merge_fields.py writes the merged field list, classes.h checks the layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 21:10:23 -05:00

350 lines
14 KiB
C++

#include "classes.h"
// 00a78770
void * NetworkManager::receive_message(void *outMessage, byte channel, byte isRemove)
{
int *piVar1;
byte *flagPtr;
undefined4 extraout_ECX;
undefined4 extraout_ECX_00;
undefined4 senderIdLow;
int *node;
undefined1 findResult [8];
void *foundNode;
undefined4 local_48;
undefined4 local_44;
uint local_40;
uint local_3c;
uint senderId;
uint local_34;
void *blockedSenders;
undefined4 local_2c;
int *lockedMutex;
uint local_24;
undefined4 local_20;
int *queue;
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
undefined4 *entry;
int header;
bool isAllowed;
uint senderIdLow;
puStack_c = &LAB_00b1425e;
local_10 = ExceptionList;
ExceptionList = &local_10;
piVar1 = GHIDRA_CAST<int *>((GHIDRA_INT(this) + 0x38));
local_8 = 0;
local_20 = 0;
lockedMutex = piVar1;
if (piVar1 == GHIDRA_CAST<int *>(0x0)) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("Invalid mutex object specified"));
senderIdLow = extraout_ECX;
}
else {
(**(code **)(*piVar1 + 0xc))(0xffffffff,__security_cookie ^ GHIDRA_UINT((findResult + 0x50)));
senderIdLow = extraout_ECX_00;
}
local_8 = 1;
KAGE::SmartPointer<MessageData>::reset(senderIdLow);
local_20 = 1;
blockedSenders = (void *)0x0;
local_2c = 0;
blockedSenders = operator_new(0x20);
*(void **)blockedSenders = blockedSenders;
*(void **)(GHIDRA_CAST<char *>(blockedSenders) + 4) = blockedSenders;
*(void **)(GHIDRA_CAST<char *>(blockedSenders) + 8) = blockedSenders;
*GHIDRA_CAST<undefined2 *>((GHIDRA_CAST<char *>(blockedSenders) + 0xc)) = 0x101;
queue = GHIDRA_CAST<int *>((GHIDRA_INT(this) + 0x30));
local_8 = CONCAT31((*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))),2);
node = *GHIDRA_CAST<int **>(*queue);
if (node != GHIDRA_CAST<int *>(*queue)) {
do {
senderIdLow = *GHIDRA_CAST<uint *>(node[2]);
local_34 = (GHIDRA_CAST<uint *>(node[2]))[1];
senderId = senderIdLow;
local_24 = local_34;
FUN_00731ee0(findResult,&senderId);
if ((((*GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(foundNode) + 0xd)) == '\0') &&
(*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(foundNode) + 0x14)) <= local_24)) &&
((*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(foundNode) + 0x14)) < local_24 ||
(*GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(foundNode) + 0x10)) <= senderIdLow)))) && (foundNode != blockedSenders)) {
local_3c = local_24;
local_40 = senderIdLow;
flagPtr = map_u64_bool_subscript(&blockedSenders,GHIDRA_CAST<ulonglong *>(&local_40));
if (*flagPtr != 0) goto LAB_00a7887b;
isAllowed = false;
}
else {
LAB_00a7887b:
isAllowed = true;
}
entry = GHIDRA_CAST<undefined4 *>(node[2]);
header = *GHIDRA_CAST<int *>((*GHIDRA_CAST<int *>(entry[2]) + 0x14));
if (*GHIDRA_CAST<byte *>((header + 5)) == channel) {
if ((entry[3] == 0) || (((*GHIDRA_CAST<byte *>((header + 4)) & 1) == 0 || (isAllowed)))) {
KAGE::SmartPointer<Multiplayer>::operator_assign(node + 2);
if (isRemove != 0) {
FUN_00a793c0(&channel,node);
}
break;
}
LAB_00a788d1:
local_48 = *entry;
local_44 = entry[1];
flagPtr = map_u64_bool_subscript(&blockedSenders,GHIDRA_CAST<ulonglong *>(&local_48));
*flagPtr = 0;
}
else if ((entry[3] != 0) && ((*GHIDRA_CAST<byte *>((header + 4)) & 1) != 0)) goto LAB_00a788d1;
node = GHIDRA_CAST<int *>(*node);
} while (node != GHIDRA_CAST<int *>(*queue));
}
FID_conflict__Erase_tree<fuzzer::fuzzer_allocator<std::_Tree_node<fuzzer::TracePC::PCTableEntry_const*,void*>_>_>
(&blockedSenders,
(fuzzer_allocator<std::_Tree_node<unsigned_int,void*>_> *)&blockedSenders,
*(_Tree_node<unsigned_int,void*> **)(GHIDRA_INT(blockedSenders) + 4));
operator_delete(blockedSenders,0x20);
local_8 = 3;
(**(code **)(*piVar1 + 0x10))();
ExceptionList = local_10;
return outMessage;
}
// 00a78a10
void NetworkManager::receive_packet(ulonglong *sender, void *buffer, int size)
{
int iVar1;
char isLastRef;
undefined4 *puVar2;
void *newConnection;
undefined4 uVar3;
int *piVar4;
int *piVar5;
undefined4 extraout_ECX;
undefined4 extraout_ECX_00;
int *piVar6;
undefined1 local_40 [4];
undefined1 local_3c [4];
int *local_38;
undefined1 local_34 [4];
int *local_30;
void *local_2c;
int *connectionRefCount;
int message;
int *messageRefCount;
int *local_1c;
int *local_18;
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
local_8 = 0xffffffff;
puStack_c = &LAB_00b142ee;
local_10 = ExceptionList;
ExceptionList = &local_10;
local_18 = GHIDRA_CAST<int *>(0x0);
(**(code **)(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x10)) + 0xc))
(0xffffffff,__security_cookie ^ GHIDRA_UINT((local_34 + 0x30)));
FUN_00731ee0(local_40,sender);
if (*GHIDRA_CAST<char *>((GHIDRA_CAST<char *>(local_38) + 0xd)) == '\0') {
if ((GHIDRA_UINT(local_38[5]) <= *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(sender) + 4))) &&
((piVar6 = local_38, GHIDRA_UINT(local_38[5]) < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(sender) + 4)) ||
(GHIDRA_UINT(local_38[4]) <= GHIDRA_UINT(*sender))))) goto LAB_00a78a78;
}
piVar6 = *GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(this) + 8));
LAB_00a78a78:
KAGE::SmartPointer<ConnectionBase>::SmartPointer(extraout_ECX);
local_8 = 0;
if (piVar6 != *GHIDRA_CAST<int **>((GHIDRA_CAST<char *>(this) + 8))) {
puVar2 = GHIDRA_CAST<undefined4 *>(FUN_00a79360(piVar6 + 6));
piVar6 = GHIDRA_CAST<int *>(puVar2[1]);
puVar2[1] = connectionRefCount;
newConnection = (void *)*puVar2;
*puVar2 = local_2c;
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 1;
local_2c = newConnection;
connectionRefCount = piVar6;
if (((local_30 != GHIDRA_CAST<int *>(0x0)) &&
(isLastRef = (**(code **)(*local_30 + 0xc))(), isLastRef != '\0')) &&
(g_connectionReleaseFn != (void *)0x0)) {
(*g_connectionReleaseFn)(local_34);
}
local_8 = (*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(GHIDRA_UINT(local_8))) + 0x1))) << 8;
}
(**(code **)(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x10)) + 0x10))();
if (local_2c == (void *)0x0) {
if ((*GHIDRA_CAST<byte *>((GHIDRA_CAST<char *>(buffer) + 4)) & 1) == 0) {
(**(code **)(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x38)) + 0xc))(0xffffffff);
newConnection = operator_new(0x20);
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 2;
if (newConnection == (void *)0x0) {
uVar3 = 0;
}
else {
uVar3 = FUN_00a59d50(buffer,size,sender);
}
local_8 = (*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(GHIDRA_UINT(local_8))) + 0x1))) << 8;
FUN_00a2a690(uVar3);
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 3;
FUN_00a2a510(&local_1c);
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 4;
if (((local_18 != GHIDRA_CAST<int *>(0x0)) &&
(isLastRef = (**(code **)(*local_18 + 0xc))(), isLastRef != '\0')) &&
(g_multiplayerRelease != (void *)0x0)) {
(*g_multiplayerRelease)(&local_1c);
}
local_8 = (*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(GHIDRA_UINT(local_8))) + 0x1))) << 8;
(**(code **)(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x38)) + 0x10))();
}
}
else {
KAGE::Network::Connection::send_message(local_2c,&message,buffer,(void *)size);
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 5;
if (message != 0) {
piVar6 = GHIDRA_CAST<int *>((GHIDRA_INT(this) + 0x38));
(**(code **)(*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x38)) + 0xc))(0xffffffff);
FUN_00a2a510(&message);
(**(code **)(*piVar6 + 0x10))();
if ((*GHIDRA_CAST<int *>((message + 0xc)) == 0) ||
((*GHIDRA_CAST<byte *>((*GHIDRA_CAST<int *>((**GHIDRA_CAST<int **>((message + 8)) + 0x14)) + 4)) & 1) == 0)) {
uVar3 = KAGE::SmartPointer<MessageData>::reset(extraout_ECX_00);
local_8 = 7;
local_18 = GHIDRA_CAST<int *>(0x2);
}
else {
uVar3 = FUN_00a590c0(local_3c);
local_8 = CONCAT31((*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))),6);
local_18 = GHIDRA_CAST<int *>(0x1);
}
KAGE::SmartPointer<Multiplayer>::operator_assign(uVar3);
if ((GHIDRA_UINT(local_18) & 2) != 0) {
local_18 = GHIDRA_CAST<int *>((GHIDRA_UINT(local_18) & 0xfffffffd));
local_8 = 8;
if (((local_30 != GHIDRA_CAST<int *>(0x0)) &&
(isLastRef = (**(code **)(*local_30 + 0xc))(), isLastRef != '\0')) &&
(g_multiplayerRelease != (void *)0x0)) {
(*g_multiplayerRelease)(local_34);
}
}
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))) = 0;
if ((GHIDRA_UINT(local_18) & 1) != 0) {
local_8 = 9;
if (((local_38 != GHIDRA_CAST<int *>(0x0)) &&
(isLastRef = (**(code **)(*local_38 + 0xc))(), isLastRef != '\0')) &&
(g_multiplayerRelease != (void *)0x0)) {
(*g_multiplayerRelease)(local_3c);
}
}
if (message != 0) {
do {
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 5;
(**(code **)(*piVar6 + 0xc))(0xffffffff);
iVar1 = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x30));
if (*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x34)) == 0xfffffff) {
/* WARNING: Subroutine does not return */
std::_Xlength_error("list too long");
}
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 10;
local_18 = GHIDRA_CAST<int *>(0x0);
local_1c = GHIDRA_CAST<int *>((GHIDRA_INT(this) + 0x30));
piVar4 = operator_new(0x10);
local_18 = piVar4;
FUN_008ef1d0(&message);
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 5;
*GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x34)) = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 0x34)) + 1;
local_18 = GHIDRA_CAST<int *>(0x0);
puVar2 = *GHIDRA_CAST<undefined4 **>((iVar1 + 4));
*piVar4 = iVar1;
piVar4[1] = GHIDRA_INT(puVar2);
*GHIDRA_CAST<int **>((iVar1 + 4)) = piVar4;
*puVar2 = piVar4;
(**(code **)(*piVar6 + 0x10))();
uVar3 = FUN_00a590c0(local_34);
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 0xc;
piVar5 = GHIDRA_CAST<int *>(FUN_008ef1d0(uVar3));
piVar4 = GHIDRA_CAST<int *>(piVar5[1]);
piVar5[1] = GHIDRA_INT(messageRefCount);
iVar1 = *piVar5;
*piVar5 = message;
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 0xd;
message = iVar1;
messageRefCount = piVar4;
if (((local_38 != GHIDRA_CAST<int *>(0x0)) &&
(isLastRef = (**(code **)(*local_38 + 0xc))(), isLastRef != '\0')) &&
(g_multiplayerRelease != (void *)0x0)) {
(*g_multiplayerRelease)(local_3c);
}
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 0xe;
if (((local_30 != GHIDRA_CAST<int *>(0x0)) &&
(isLastRef = (**(code **)(*local_30 + 0xc))(), isLastRef != '\0')) &&
(g_multiplayerRelease != (void *)0x0)) {
(*g_multiplayerRelease)(local_34);
}
(*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x0))) = 5;
} while (message != 0);
FUN_00a59200();
}
}
local_8 = CONCAT31((*GHIDRA_CAST<undefined1 *>((GHIDRA_CAST<char *>(&(local_8)) + 0x1))),0xf);
if (((messageRefCount != GHIDRA_CAST<int *>(0x0)) &&
(isLastRef = (**(code **)(*messageRefCount + 0xc))(), isLastRef != '\0')) &&
(g_multiplayerRelease != (void *)0x0)) {
(*g_multiplayerRelease)(&message);
}
}
local_8 = 0x10;
if (((connectionRefCount != GHIDRA_CAST<int *>(0x0)) &&
(isLastRef = (**(code **)(*connectionRefCount + 0xc))(), isLastRef != '\0')) &&
(g_connectionReleaseFn != (void *)0x0)) {
(*g_connectionReleaseFn)(&local_2c);
}
ExceptionList = local_10;
return;
}
// 00a790b0
void * NetworkManager::get_peer(void *outPeer, ulonglong *userId)
{
int *piVar1;
undefined1 lowerBound [8];
int node;
int *mutexRef;
void *local_10;
undefined1 *puStack_c;
undefined4 local_8;
local_8 = 0xffffffff;
puStack_c = &LAB_00b1436d;
local_10 = ExceptionList;
ExceptionList = &local_10;
piVar1 = GHIDRA_CAST<int *>((GHIDRA_INT(this) + 0x10));
mutexRef = piVar1;
if (piVar1 == GHIDRA_CAST<int *>(0x0)) {
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("Invalid mutex object specified"));
}
else {
(**(code **)(*piVar1 + 0xc))(0xffffffff,__security_cookie ^ GHIDRA_UINT((lowerBound + 0x1c)));
}
local_8 = 0;
FUN_00731ee0(lowerBound,userId);
if (*GHIDRA_CAST<char *>((node + 0xd)) == '\0') {
if ((*GHIDRA_CAST<uint *>((node + 0x14)) <= *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(userId) + 4))) &&
((*GHIDRA_CAST<uint *>((node + 0x14)) < *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(userId) + 4)) ||
(*GHIDRA_CAST<uint *>((node + 0x10)) <= GHIDRA_UINT(*userId))))) goto LAB_00a79132;
}
node = *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 8));
LAB_00a79132:
if (node == *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(this) + 8))) {
KAGE::SmartPointer<ConnectionBase>::SmartPointer(node);
local_8 = 2;
}
else {
FUN_00a79360(node + 0x18);
local_8 = 1;
}
(**(code **)(*piVar1 + 0x10))();
ExceptionList = local_10;
return outPeer;
}