Skip to content

Commit

Permalink
Adds DisableChat feature
Browse files Browse the repository at this point in the history
  • Loading branch information
shmocz committed Jul 29, 2024
1 parent ba4d9f0 commit 3c8f851
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ SPAWNER_OBJS = \
src/custom_connection_timeout.o \
src/Hook_Main_Loop.o \
src/spawner/add_player_node.o \
src/spawner/chat_ignore.o \
src/spawner/coop.o \
src/spawner/load_spawn.o \
src/spawner/predetermined_alliances.o \
Expand Down
5 changes: 5 additions & 0 deletions inc/HouseClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ typedef struct HouseTypeClass_vtable {
int (__thiscall *Read_INI)(HouseType *houseType, INIClass *ini);
} HouseTypeClass_vtable;

// Size = 0x160b8
#pragma pack(push, 1)
typedef struct HouseClass {
char gap[0x30];
int ArrayIndex;
char gap2[0x15ff6];
wchar_t UIName[21];
} HouseClass;
#pragma pack(pop)

extern HouseClass *PlayerPtr;
HouseType **HouseTypeClassArray;
Expand Down
5 changes: 3 additions & 2 deletions inc/RA.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern bool QuickMatch;
extern bool RunAutoSS;
extern bool DoingAutoSS;
extern bool UsePNG;
extern bool DisableChat;

void *new(int32_t size);
void __thiscall ScenarioClass_ReadLightingAndBasic(void *this, void *ini);
Expand All @@ -43,5 +44,5 @@ void __thiscall ScreenCaptureCommandClass_Execute();
typedef void MessageListClass;
extern MessageListClass *MessageListClass_this;
void __thiscall MessageListClass__Manage(MessageListClass *message_list);
void __thiscall MessageListClass__Add_Message(MessageListClass *this, const wchar_t *Name, int ID,
const wchar_t *message, int color, int32_t PrintType, int32_t duration, bool SinglePlayer);
void* __thiscall MessageListClass__Add_Message(MessageListClass *this, const wchar_t *Name, int ID,
const wchar_t *message, int color, int32_t PrintType, int32_t duration, bool SinglePlayer);
1 change: 1 addition & 0 deletions inc/SessionClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ typedef struct SessionClass {
} SessionClass;

extern SessionClass SessionClass_this;
extern bool SessionClass_ChatEnabled[8];

void __thiscall SessionClass__Read_Scenario_Descriptions(SessionClass *this);
void __thiscall SessionClass__Create_Connections(SessionClass *this);
Expand Down
1 change: 1 addition & 0 deletions inc/macros/helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define countof(x) sizeof(x)/sizeof(*x)
10 changes: 9 additions & 1 deletion src/Hook_Main_Loop.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "macros/patch.h"
#include "macros/helpers.h"
#include "RA.h"
#include "SessionClass.h"
#include "network.h"
Expand Down Expand Up @@ -41,6 +42,13 @@ MainLoop_AfterRender(void *message_list)
ResponseTimeFrame = Frame + ResponseTimeInterval;
Send_Response_Time();
}
}

if (DisableChat)
{
for (int i = 0; i < countof(SessionClass_ChatEnabled); i++)
{
SessionClass_ChatEnabled[i] = false;
}
}
}
}
2 changes: 2 additions & 0 deletions src/loading.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern bool DisableEdgeScrolling;

bool UsingTSDDRAW = false;
bool UsePNG = true;
bool DisableChat = false;

void SetSingleProcAffinity();

Expand All @@ -64,6 +65,7 @@ read_extra_options(INIClass *old_INI, const char *section, const char *key, bool
Win8Compat = INIClass__GetBool(&RA2md_INI, "Options", "Win8Compat", false);

SingleProcAffinity = INIClass__GetBool(&RA2md_INI, "Options", "SingleProcAffinity", true);
DisableChat = INIClass__GetBool(&RA2md_INI, "Options", "DisableChat", false);
SetSingleProcAffinity();

HMODULE hDDraw = LoadLibraryA("ddraw.dll");
Expand Down
31 changes: 31 additions & 0 deletions src/spawner/chat_ignore.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <wchar.h>

#include "HouseClass.h"
#include "RA.h"
#include "macros/patch.h"

CALL(0x48d979, _fake_MessageListClass__Add_Message);
CALL(0x55f0f5, _fake_MessageListClass__Add_Message);

void *__thiscall fake_MessageListClass__Add_Message(MessageListClass *this,
const wchar_t *Name,
int ID,
const wchar_t *message,
int color,
int32_t PrintType,
int32_t duration,
bool SinglePlayer)
{
if (!DisableChat || Name == NULL)
{
return MessageListClass__Add_Message(this, Name, ID, message, color, PrintType, duration, SinglePlayer);
}

if (wcsicmp(Name, PlayerPtr->UIName) == 0)
{
return MessageListClass__Add_Message(this, 0, 0, L"Chat is disabled. Message not sent.", 4, 0x4096, 270, 1);
}

/* Base case. Don't display incoming player messages. */
return NULL;
}
2 changes: 2 additions & 0 deletions src/spawner/load_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ signed int Initialize_Spawn()
RunAutoSS = INIClass__GetBool(&INIClass_SPAWN, "Settings", "RunAutoSS", false);
ConnTimeout = INIClass__GetInt(&INIClass_SPAWN, "Settings", "ConnTimeout", 3600);
ReconnectTimeout=INIClass__GetInt(&INIClass_SPAWN, "Settings", "ReconnectTimeout", 2400);
if (!DisableChat)
DisableChat = INIClass__GetBool(&INIClass_SPAWN, "Settings", "DisableChat", false);

INIClass__GetString(&INIClass_SPAWN, "Settings", "MapHash", "", MapHash, 255);
INIClass__GetString(&INIClass_SPAWN, "Settings", "UIMapName", "", UIMapName, 255);
Expand Down
2 changes: 2 additions & 0 deletions sym.asm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ setcglob 0x007E1280, _imp__GetCommandLineA
setcglob 0x007E1460, _imp__MessageBoxA
setcglob 0x004C8FE0, PrintException
setcglob 0x007CA489, wcscpy
setcglob 0x007DD0F8, wcsicmp
setcglob 0x007E11F0, _imp__Sleep
setcglob 0x007E13EC, _imp__GetSystemMetrics

Expand Down Expand Up @@ -159,6 +160,7 @@ setcglob 0x00A8B26C, MultiEngineer
setcglob 0x00A8B394, PlayerColor
setcglob 0x00A8B23C, GameMode
setcglob 0x008871E0, RulesData
setcglob 0x00A8D108, SessionClass_ChatEnabled

setcglob 0x0061f210, Game_LoadPCXFiles
setcglob 0x00600560, InitCommonDialogStuff
Expand Down

0 comments on commit 3c8f851

Please sign in to comment.