Skip to content

Commit 30a33b2

Browse files
committed
Add AllowChat options in RA2MD.INI (#16)
RA2MD.INI->[Options]->AllowChat = true
1 parent 06eda53 commit 30a33b2

File tree

7 files changed

+113
-17
lines changed

7 files changed

+113
-17
lines changed

Spawner.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<ClCompile Include="$(ThisDir)\src\Misc\SkipScoreScreen.cpp" />
4141
<ClCompile Include="$(ThisDir)\src\Misc\SavedGamesInSubdir.cpp" />
4242
<ClCompile Include="$(ThisDir)\src\Misc\DisableEdgeScrolling.cpp" />
43+
<ClCompile Include="$(ThisDir)\src\Misc\InGameChat.cpp" />
4344
<!-- Spawner -->
4445
<ClCompile Include="$(ThisDir)\src\Spawner\Spawner.cpp" />
4546
<ClCompile Include="$(ThisDir)\src\Spawner\Spawner.Hook.cpp" />

YRpp

Submodule YRpp updated 1 file

src/Main.Config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void MainConfig::LoadFromINIFile()
4141
this->DDrawHandlesClose = pINI->ReadBool(pOptionsSection, "DDrawHandlesClose", this->DDrawHandlesClose);
4242
this->SpeedControl = pINI->ReadBool(pOptionsSection, "SpeedControl", this->SpeedControl);
4343
this->AllowTaunts = pINI->ReadBool(pOptionsSection, "AllowTaunts", this->AllowTaunts);
44+
this->AllowChat = pINI->ReadBool(pOptionsSection, "AllowChat", this->AllowChat);
4445
}
4546

4647
const char* pVideoSection = "Video";

src/Main.Config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class MainConfig
3737
int DDrawTargetFPS;
3838

3939
bool AllowTaunts;
40+
bool AllowChat;
4041

4142
void LoadFromINIFile();
4243
void ApplyStaticOptions();
@@ -57,5 +58,6 @@ class MainConfig
5758
, DDrawTargetFPS { -1 }
5859

5960
, AllowTaunts { true }
61+
, AllowChat { true }
6062
{ }
6163
};

src/Misc/InGameChat.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* yrpp-spawner
3+
*
4+
* Copyright(C) 2022-present CnCNet
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program.If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <Spawner/Spawner.h>
21+
#include <Utilities/Macro.h>
22+
#include <HouseClass.h>
23+
24+
// This corrects the processing of Unicode player names
25+
// and prohibits incoming messages from players with whom chat is disabled
26+
27+
#pragma pack(push, 1)
28+
struct GlobalPacket_NetMessage
29+
{
30+
static constexpr reference<GlobalPacket_NetMessage, 0xA8D638u> const Instance {};
31+
32+
int Command;
33+
wchar_t PlayerName[21];
34+
byte HouseIndex;
35+
byte ChatID;
36+
wchar_t Message[112];
37+
byte Color;
38+
byte CRC;
39+
};
40+
#pragma pack(pop)
41+
42+
DEFINE_HOOK(0x48D92B, NetworkCallBack_NetMessage_Print, 0x5)
43+
{
44+
if (!Spawner::Enabled)
45+
return 0;
46+
47+
enum { SkipMessage = 0x48DAD3, PrintMessage = 0x48D937 };
48+
49+
const int houseIndex = GlobalPacket_NetMessage::Instance->HouseIndex;
50+
51+
if (houseIndex < 8 && Game::ChatMask[houseIndex])
52+
{
53+
if (HouseClass::Array->ValidIndex(houseIndex))
54+
{
55+
HouseClass* pHouse = HouseClass::Array->GetItem(houseIndex);
56+
57+
GlobalPacket_NetMessage::Instance->Color = (byte)pHouse->ColorSchemeIndex;
58+
R->ESI(pHouse->UIName);
59+
return PrintMessage;
60+
}
61+
}
62+
63+
return SkipMessage;
64+
}
65+
66+
DEFINE_HOOK(0x48D95B, NetworkCallBack_NetMessage_SetColor, 0x6)
67+
{
68+
if (!Spawner::Enabled)
69+
return 0;
70+
71+
R->EAX(R->ECX());
72+
return 0x48D966;
73+
}
74+
75+
DEFINE_HOOK(0x55EDD2, MessageInput_Write, 0x5)
76+
{
77+
if (!Spawner::Enabled)
78+
return 0;
79+
80+
HouseClass* pHouse = HouseClass::CurrentPlayer;
81+
wcscpy_s(GlobalPacket_NetMessage::Instance->PlayerName, pHouse->UIName);
82+
GlobalPacket_NetMessage::Instance->HouseIndex = (byte)pHouse->ArrayIndex;
83+
84+
return 0x55EE00;
85+
}
86+
87+
DEFINE_HOOK(0x55F0A8, MessageInput_Print, 0x5)
88+
{
89+
if (!Spawner::Enabled)
90+
return 0;
91+
92+
R->EAX(GlobalPacket_NetMessage::Instance->PlayerName);
93+
return 0x55F0B2;
94+
}

src/Spawner/Spawner.Hook.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ DEFINE_HOOK(0x6BD7CB, WinMain_SpawnerInit, 0x5)
6767
// Set ConnTimeout
6868
Patch::Apply_TYPED<int>(0x6843C7, { Spawner::GetConfig()->ConnTimeout }); // Scenario_Load_Wait
6969

70-
{ // Add support unicode player name in ingame chat
71-
Patch::Apply_RAW(0x48D930, { 0x8B, 0xC1, 0x90, 0x90, 0x90 }); // mov eax, ecx
72-
Patch::Apply_RAW(0x55F0AD, { 0x8B, 0xC1, 0x90, 0x90, 0x90 }); // mov eax, ecx
73-
}
74-
7570
// Show GameMode in DiplomacyDialog in Skirmish
7671
Patch::Apply_LJMP(0x658117, 0x658126); // RadarClass_DiplomacyDialog
7772

@@ -82,16 +77,6 @@ DEFINE_HOOK(0x6BD7CB, WinMain_SpawnerInit, 0x5)
8277
return 0;
8378
}
8479

85-
// Add support unicode player name in ingame chat
86-
DEFINE_HOOK(0x55EDD2, MessageInput_UnicodePlayerName, 0x5)
87-
{
88-
if (!Spawner::Enabled)
89-
return 0;
90-
91-
wcscpy(reinterpret_cast<wchar_t*>(0xA8D63C), NodeNameType::Array->GetItem(0)->Name);
92-
return 0x55EE00;
93-
}
94-
9580
// Display UIGameMode if is set
9681
// Otherwise use mode name from MPModesMD.ini
9782
DEFINE_HOOK(0x65812E, RadarClass__DiplomacyDialog_UIGameMode, 0x6)

src/Spawner/Spawner.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,27 @@ bool Spawner::StartNewScenario(const char* pScenarioName)
300300
{
301301
return ScenarioClass::StartScenario(pScenarioName, 0, -1);
302302
}
303-
else
303+
else /* if (SessionClass::IsMultiplayer()) */
304304
{
305305
Spawner::InitNetwork();
306306
if (!ScenarioClass::StartScenario(pScenarioName, 0, -1))
307307
return false;
308308

309309
pSession->GameMode = GameMode::LAN;
310310
pSession->CreateConnections();
311+
312+
if (Main::GetConfig()->AllowChat)
313+
{
314+
Game::ChatMask[0] = false;
315+
Game::ChatMask[1] = false;
316+
Game::ChatMask[2] = false;
317+
Game::ChatMask[3] = false;
318+
Game::ChatMask[4] = false;
319+
Game::ChatMask[5] = false;
320+
Game::ChatMask[6] = false;
321+
Game::ChatMask[7] = false;
322+
}
323+
311324
return true;
312325
}
313326
}

0 commit comments

Comments
 (0)