Skip to content

Commit df3da49

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/development'
2 parents 5825d8a + 334dbc8 commit df3da49

File tree

8 files changed

+151
-5
lines changed

8 files changed

+151
-5
lines changed

components/asset_util/common/ff.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,15 @@ int FF_FFExtractFiles(BYTE* searchData, DWORD searchSize)
277277

278278
if (Str_EndsWith(rawfileString, ".wav"))
279279
{
280-
if (g_extractSounds.ValueBool())
280+
if (!g_extractSounds.ValueBool())
281281
{
282-
Snd_Header* snd_info = (Snd_Header*)(rawfileString - sizeof(Snd_Header));
283-
FF_FFExtractSoundFile(snd_info, rawfileString);
282+
searchData = (BYTE*)rawfileString + strlen(rawfileString) + 1;
283+
continue;
284284
}
285+
286+
Snd_Header* snd_info = (Snd_Header*)(rawfileString - sizeof(Snd_Header));
287+
FF_FFExtractSoundFile(snd_info, rawfileString);
285288
searchData = (BYTE*)rawfileString + strlen(rawfileString) + 1;
286-
continue;
287289
}
288290

289291
//

components/game_mod/dllmain.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ BOOL GameMod_Init()
7272
PatchMemory(0x00887575, (PBYTE)"\x90\x90\x90\x90\x90", 5); // "Party_StopParty"
7373
PatchMemory(0x0043C6DB, (PBYTE)"\x90\x90\x90\x90\x90", 5); // "Clearing migration data\n"
7474
PatchMemory(0x0051B809, (PBYTE)"\x90\x90\x90\x90\x90", 5); // "Failed to log on.\n"
75+
PatchMemory(0x00659EDC, (PBYTE)"\x90\x90\x90\x90\x90", 5); // "Live_UpdateUiPopup: %s\n"
7576

7677
//
7778
// EXE_TOOFEWPLAYERS in a party game
@@ -277,6 +278,13 @@ BOOL GameMod_Init()
277278
CL_GetServerIPAddress_o = (CL_GetServerIPAddress_t)Detours::X86::DetourFunction((PBYTE)0x0053BE60, (PBYTE)&CL_GetServerIPAddress);
278279
Detours::X86::DetourFunction((PBYTE)0x00890E23, (PBYTE)&mfh_CG_DrawBackdropServerInfo);
279280

281+
//
282+
// Live radiant initialization hook
283+
//
284+
#if _UNSTABLE
285+
Detours::X86::DetourFunction((PBYTE)0x004B7870, (PBYTE)&RadiantRemoteInit);
286+
#endif
287+
280288
//
281289
// Increase PMem size
282290
//

components/game_mod/game_mod.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<ClCompile Include="patch_common.cpp" />
101101
<ClCompile Include="patch_usefastfile.cpp" />
102102
<ClCompile Include="patch_reflections.cpp" />
103+
<ClCompile Include="radiant_remote.cpp" />
103104
<ClCompile Include="reshade.cpp" />
104105
<ClCompile Include="r_cinematic.cpp" />
105106
<ClCompile Include="r_material_load_obj.cpp" />
@@ -124,6 +125,7 @@
124125
<ClInclude Include="patch_common.h" />
125126
<ClInclude Include="patch_usefastfile.h" />
126127
<ClInclude Include="patch_reflections.h" />
128+
<ClInclude Include="radiant_remote.h" />
127129
<ClInclude Include="reshade.h" />
128130
<ClInclude Include="r_cinematic.h" />
129131
<ClInclude Include="r_material_load_obj.h" />
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include "stdafx.h"
2+
3+
HANDLE liveUpdateThread;
4+
5+
int& savedCommandCount = *(int *)0x0251AE58;
6+
auto savedCommands = (RadiantCommand *)0x02507990;
7+
int& gCommandCount = *(int *)0x251AE50;
8+
auto gCommands = (RadiantCommand *)0x02517D90;
9+
int& gObjectMappingCount = *(int *)0x0251AE60;
10+
auto gObjectMapping = (RadaintToGameMapping *)0x2507180;
11+
12+
void RadiantRemoteInit()
13+
{
14+
savedCommandCount = 0;
15+
memset(savedCommands, 0, sizeof(RadiantCommand) * 128);
16+
17+
gCommandCount = 0;
18+
memset(gCommands, 0, sizeof(RadiantCommand) * 24);
19+
20+
gObjectMappingCount = 0;
21+
memset(gObjectMapping, 0, sizeof(RadaintToGameMapping) * 128);
22+
23+
if (!liveUpdateThread)
24+
liveUpdateThread = CreateThread(nullptr, 0, RadiantRemoteThread, nullptr, 0, nullptr);
25+
}
26+
27+
DWORD WINAPI RadiantRemoteThread(LPVOID Arg)
28+
{
29+
// Initialize winsock if the game hasn't yet
30+
WSADATA wsaData;
31+
32+
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR)
33+
{
34+
Com_PrintError(1, "LiveRadiant: WSAStartup failed\n");
35+
return 0;
36+
}
37+
38+
// Create a UDP socket
39+
SOCKET udpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
40+
41+
if (udpSocket == INVALID_SOCKET)
42+
{
43+
Com_PrintError(1, "LiveRadiant: Socket creation failed\n");
44+
return 0;
45+
}
46+
47+
// Bind socket to any incoming address on port 3700
48+
sockaddr_in addrSender;
49+
sockaddr_in addrIn;
50+
addrIn.sin_family = AF_INET;
51+
addrIn.sin_port = htons(3700);
52+
addrIn.sin_addr.s_addr = htonl(INADDR_ANY);
53+
54+
if (bind(udpSocket, (SOCKADDR *)&addrIn, sizeof(addrIn)) == SOCKET_ERROR)
55+
{
56+
Com_PrintError(1, "LiveRadiant: Failed to bind socket\n");
57+
closesocket(udpSocket);
58+
return 0;
59+
}
60+
61+
Com_Printf(1, "LiveRadiant: Socket bound on port 3700\n");
62+
63+
while (true)
64+
{
65+
char recvBuf[2048];
66+
memset(recvBuf, 0, sizeof(recvBuf));
67+
68+
int fromSize = sizeof(sockaddr_in);
69+
int recvSize = recvfrom(udpSocket, recvBuf, sizeof(recvBuf), 0, (SOCKADDR *)&addrSender, &fromSize);
70+
71+
if (recvSize == SOCKET_ERROR)
72+
{
73+
Com_PrintError(1, "LiveRadiant: Socket receive from failed\n");
74+
break;
75+
}
76+
77+
// Data received from network, now tell the game
78+
Sys_EnterCriticalSection((CriticalSection)61);
79+
{
80+
RadiantCommand *c = (RadiantCommand *)&recvBuf;
81+
82+
if (c->type != RADIANT_COMMAND_CAMERA)
83+
Com_Printf(1, "Command %d %d:\n%s\n", c->type, c->liveUpdateId, c->strCommand);
84+
85+
// Insert in global array
86+
memcpy(&gCommands[gCommandCount++], c, sizeof(RadiantCommand));
87+
}
88+
Sys_LeaveCriticalSection((CriticalSection)61);
89+
}
90+
91+
shutdown(udpSocket, 2 /*SD_BOTH*/);
92+
closesocket(udpSocket);
93+
return 0;
94+
}

components/game_mod/radiant_remote.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
3+
enum RadiantCommandType
4+
{
5+
RADIANT_COMMAND_SELECT = 0x0,
6+
RADIANT_COMMAND_DESELECT = 0x1,
7+
RADIANT_COMMAND_UPDATE_SELECTED = 0x2,
8+
RADIANT_COMMAND_UPDATE = 0x3,
9+
RADIANT_COMMAND_CREATE = 0x4,
10+
RADIANT_COMMAND_DELETE = 0x5,
11+
RADIANT_COMMAND_CAMERA = 0x6,
12+
};
13+
14+
struct RadiantCommand
15+
{
16+
RadiantCommandType type;
17+
int liveUpdateId;
18+
char strCommand[512];
19+
};
20+
21+
struct RadaintToGameMapping
22+
{
23+
int fromRadiantId;
24+
int liveUpdateId;
25+
int gameId;
26+
int cg_gameId;
27+
};
28+
29+
static_assert(sizeof(RadiantCommand) == 520, "Size check");
30+
static_assert(sizeof(RadaintToGameMapping) == 16, "Size check");
31+
32+
void RadiantRemoteInit();
33+
DWORD WINAPI RadiantRemoteThread(LPVOID Arg);

components/game_mod/stdafx.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include <intrin.h>
77
#include <Psapi.h>
88
#include <shellapi.h>
9+
#include <winsock.h>
10+
11+
#pragma comment(lib, "ws2_32.lib")
912

1013
//
1114
// Shared files
@@ -35,6 +38,7 @@
3538
#include "r_reflection_probe.h"
3639
#include "r_material_load_obj.h"
3740
#include "threads.h"
41+
#include "radiant_remote.h"
3842

3943
#include "win_localize.h"
4044
#include "win_exception.h"

components/game_mod/ui_main_pc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bool __cdecl UI_LoadModArenas()
2525
return false;
2626
}
2727

28-
if (fileSize <= ARENA_FILE_MAX_SIZE)
28+
if (fileSize > ARENA_FILE_MAX_SIZE)
2929
{
3030
Com_PrintWarning(13, "Customized arena file size is too big to load > %d: %s\n", ARENA_FILE_MAX_SIZE, "mod.arena");
3131
FS_FCloseFile(fileHandle); //Fix for leaked handles

components/game_mod/win_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ enum CriticalSection
88
typedef void(__cdecl* Sys_EnterCriticalSection_t)(CriticalSection critSect);
99
static Sys_EnterCriticalSection_t Sys_EnterCriticalSection = (Sys_EnterCriticalSection_t)0x005FEA60;
1010

11+
typedef void(__cdecl* Sys_LeaveCriticalSection_t)(CriticalSection critSect);
12+
static Sys_LeaveCriticalSection_t Sys_LeaveCriticalSection = (Sys_LeaveCriticalSection_t)0x0056D400;
13+
1114
void __cdecl Sys_OutOfMemErrorInternal(const char *filename, int line);

0 commit comments

Comments
 (0)