Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/development'
Browse files Browse the repository at this point in the history
  • Loading branch information
SE2Dev committed Sep 23, 2016
2 parents 5825d8a + 334dbc8 commit df3da49
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 5 deletions.
10 changes: 6 additions & 4 deletions components/asset_util/common/ff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,15 @@ int FF_FFExtractFiles(BYTE* searchData, DWORD searchSize)

if (Str_EndsWith(rawfileString, ".wav"))
{
if (g_extractSounds.ValueBool())
if (!g_extractSounds.ValueBool())
{
Snd_Header* snd_info = (Snd_Header*)(rawfileString - sizeof(Snd_Header));
FF_FFExtractSoundFile(snd_info, rawfileString);
searchData = (BYTE*)rawfileString + strlen(rawfileString) + 1;
continue;
}

Snd_Header* snd_info = (Snd_Header*)(rawfileString - sizeof(Snd_Header));
FF_FFExtractSoundFile(snd_info, rawfileString);
searchData = (BYTE*)rawfileString + strlen(rawfileString) + 1;
continue;
}

//
Expand Down
8 changes: 8 additions & 0 deletions components/game_mod/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ BOOL GameMod_Init()
PatchMemory(0x00887575, (PBYTE)"\x90\x90\x90\x90\x90", 5); // "Party_StopParty"
PatchMemory(0x0043C6DB, (PBYTE)"\x90\x90\x90\x90\x90", 5); // "Clearing migration data\n"
PatchMemory(0x0051B809, (PBYTE)"\x90\x90\x90\x90\x90", 5); // "Failed to log on.\n"
PatchMemory(0x00659EDC, (PBYTE)"\x90\x90\x90\x90\x90", 5); // "Live_UpdateUiPopup: %s\n"

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

//
// Live radiant initialization hook
//
#if _UNSTABLE
Detours::X86::DetourFunction((PBYTE)0x004B7870, (PBYTE)&RadiantRemoteInit);
#endif

//
// Increase PMem size
//
Expand Down
2 changes: 2 additions & 0 deletions components/game_mod/game_mod.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<ClCompile Include="patch_common.cpp" />
<ClCompile Include="patch_usefastfile.cpp" />
<ClCompile Include="patch_reflections.cpp" />
<ClCompile Include="radiant_remote.cpp" />
<ClCompile Include="reshade.cpp" />
<ClCompile Include="r_cinematic.cpp" />
<ClCompile Include="r_material_load_obj.cpp" />
Expand All @@ -124,6 +125,7 @@
<ClInclude Include="patch_common.h" />
<ClInclude Include="patch_usefastfile.h" />
<ClInclude Include="patch_reflections.h" />
<ClInclude Include="radiant_remote.h" />
<ClInclude Include="reshade.h" />
<ClInclude Include="r_cinematic.h" />
<ClInclude Include="r_material_load_obj.h" />
Expand Down
94 changes: 94 additions & 0 deletions components/game_mod/radiant_remote.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include "stdafx.h"

HANDLE liveUpdateThread;

int& savedCommandCount = *(int *)0x0251AE58;
auto savedCommands = (RadiantCommand *)0x02507990;
int& gCommandCount = *(int *)0x251AE50;
auto gCommands = (RadiantCommand *)0x02517D90;
int& gObjectMappingCount = *(int *)0x0251AE60;
auto gObjectMapping = (RadaintToGameMapping *)0x2507180;

void RadiantRemoteInit()
{
savedCommandCount = 0;
memset(savedCommands, 0, sizeof(RadiantCommand) * 128);

gCommandCount = 0;
memset(gCommands, 0, sizeof(RadiantCommand) * 24);

gObjectMappingCount = 0;
memset(gObjectMapping, 0, sizeof(RadaintToGameMapping) * 128);

if (!liveUpdateThread)
liveUpdateThread = CreateThread(nullptr, 0, RadiantRemoteThread, nullptr, 0, nullptr);
}

DWORD WINAPI RadiantRemoteThread(LPVOID Arg)
{
// Initialize winsock if the game hasn't yet
WSADATA wsaData;

if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR)
{
Com_PrintError(1, "LiveRadiant: WSAStartup failed\n");
return 0;
}

// Create a UDP socket
SOCKET udpSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

if (udpSocket == INVALID_SOCKET)
{
Com_PrintError(1, "LiveRadiant: Socket creation failed\n");
return 0;
}

// Bind socket to any incoming address on port 3700
sockaddr_in addrSender;
sockaddr_in addrIn;
addrIn.sin_family = AF_INET;
addrIn.sin_port = htons(3700);
addrIn.sin_addr.s_addr = htonl(INADDR_ANY);

if (bind(udpSocket, (SOCKADDR *)&addrIn, sizeof(addrIn)) == SOCKET_ERROR)
{
Com_PrintError(1, "LiveRadiant: Failed to bind socket\n");
closesocket(udpSocket);
return 0;
}

Com_Printf(1, "LiveRadiant: Socket bound on port 3700\n");

while (true)
{
char recvBuf[2048];
memset(recvBuf, 0, sizeof(recvBuf));

int fromSize = sizeof(sockaddr_in);
int recvSize = recvfrom(udpSocket, recvBuf, sizeof(recvBuf), 0, (SOCKADDR *)&addrSender, &fromSize);

if (recvSize == SOCKET_ERROR)
{
Com_PrintError(1, "LiveRadiant: Socket receive from failed\n");
break;
}

// Data received from network, now tell the game
Sys_EnterCriticalSection((CriticalSection)61);
{
RadiantCommand *c = (RadiantCommand *)&recvBuf;

if (c->type != RADIANT_COMMAND_CAMERA)
Com_Printf(1, "Command %d %d:\n%s\n", c->type, c->liveUpdateId, c->strCommand);

// Insert in global array
memcpy(&gCommands[gCommandCount++], c, sizeof(RadiantCommand));
}
Sys_LeaveCriticalSection((CriticalSection)61);
}

shutdown(udpSocket, 2 /*SD_BOTH*/);
closesocket(udpSocket);
return 0;
}
33 changes: 33 additions & 0 deletions components/game_mod/radiant_remote.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

enum RadiantCommandType
{
RADIANT_COMMAND_SELECT = 0x0,
RADIANT_COMMAND_DESELECT = 0x1,
RADIANT_COMMAND_UPDATE_SELECTED = 0x2,
RADIANT_COMMAND_UPDATE = 0x3,
RADIANT_COMMAND_CREATE = 0x4,
RADIANT_COMMAND_DELETE = 0x5,
RADIANT_COMMAND_CAMERA = 0x6,
};

struct RadiantCommand
{
RadiantCommandType type;
int liveUpdateId;
char strCommand[512];
};

struct RadaintToGameMapping
{
int fromRadiantId;
int liveUpdateId;
int gameId;
int cg_gameId;
};

static_assert(sizeof(RadiantCommand) == 520, "Size check");
static_assert(sizeof(RadaintToGameMapping) == 16, "Size check");

void RadiantRemoteInit();
DWORD WINAPI RadiantRemoteThread(LPVOID Arg);
4 changes: 4 additions & 0 deletions components/game_mod/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <intrin.h>
#include <Psapi.h>
#include <shellapi.h>
#include <winsock.h>

#pragma comment(lib, "ws2_32.lib")

//
// Shared files
Expand Down Expand Up @@ -35,6 +38,7 @@
#include "r_reflection_probe.h"
#include "r_material_load_obj.h"
#include "threads.h"
#include "radiant_remote.h"

#include "win_localize.h"
#include "win_exception.h"
Expand Down
2 changes: 1 addition & 1 deletion components/game_mod/ui_main_pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool __cdecl UI_LoadModArenas()
return false;
}

if (fileSize <= ARENA_FILE_MAX_SIZE)
if (fileSize > ARENA_FILE_MAX_SIZE)
{
Com_PrintWarning(13, "Customized arena file size is too big to load > %d: %s\n", ARENA_FILE_MAX_SIZE, "mod.arena");
FS_FCloseFile(fileHandle); //Fix for leaked handles
Expand Down
3 changes: 3 additions & 0 deletions components/game_mod/win_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ enum CriticalSection
typedef void(__cdecl* Sys_EnterCriticalSection_t)(CriticalSection critSect);
static Sys_EnterCriticalSection_t Sys_EnterCriticalSection = (Sys_EnterCriticalSection_t)0x005FEA60;

typedef void(__cdecl* Sys_LeaveCriticalSection_t)(CriticalSection critSect);
static Sys_LeaveCriticalSection_t Sys_LeaveCriticalSection = (Sys_LeaveCriticalSection_t)0x0056D400;

void __cdecl Sys_OutOfMemErrorInternal(const char *filename, int line);

0 comments on commit df3da49

Please sign in to comment.