Skip to content

Commit

Permalink
Add AllowChat options in RA2MD.INI (#16)
Browse files Browse the repository at this point in the history
RA2MD.INI->[Options]->AllowChat = true
  • Loading branch information
Belonit committed Feb 17, 2024
1 parent 06eda53 commit c74ded9
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 17 deletions.
1 change: 1 addition & 0 deletions Spawner.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<ClCompile Include="$(ThisDir)\src\Misc\SkipScoreScreen.cpp" />
<ClCompile Include="$(ThisDir)\src\Misc\SavedGamesInSubdir.cpp" />
<ClCompile Include="$(ThisDir)\src\Misc\DisableEdgeScrolling.cpp" />
<ClCompile Include="$(ThisDir)\src\Misc\InGameChat.cpp" />
<!-- Spawner -->
<ClCompile Include="$(ThisDir)\src\Spawner\Spawner.cpp" />
<ClCompile Include="$(ThisDir)\src\Spawner\Spawner.Hook.cpp" />
Expand Down
2 changes: 1 addition & 1 deletion YRpp
Submodule YRpp updated 1 files
+1 −0 Unsorted.h
1 change: 1 addition & 0 deletions src/Main.Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void MainConfig::LoadFromINIFile()
this->DDrawHandlesClose = pINI->ReadBool(pOptionsSection, "DDrawHandlesClose", this->DDrawHandlesClose);
this->SpeedControl = pINI->ReadBool(pOptionsSection, "SpeedControl", this->SpeedControl);
this->AllowTaunts = pINI->ReadBool(pOptionsSection, "AllowTaunts", this->AllowTaunts);
this->AllowChat = pINI->ReadBool(pOptionsSection, "AllowChat", this->AllowChat);
}

const char* pVideoSection = "Video";
Expand Down
2 changes: 2 additions & 0 deletions src/Main.Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MainConfig
int DDrawTargetFPS;

bool AllowTaunts;
bool AllowChat;

void LoadFromINIFile();
void ApplyStaticOptions();
Expand All @@ -57,5 +58,6 @@ class MainConfig
, DDrawTargetFPS { -1 }

, AllowTaunts { true }
, AllowChat { true }
{ }
};
94 changes: 94 additions & 0 deletions src/Misc/InGameChat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* yrpp-spawner
*
* Copyright(C) 2022-present CnCNet
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.If not, see <http://www.gnu.org/licenses/>.
*/

#include <Spawner/Spawner.h>
#include <Utilities/Macro.h>
#include <HouseClass.h>

// This corrects the processing of Unicode player names
// and prohibits incoming messages from players with whom chat is disabled

#pragma pack(push, 1)
struct GlobalPacket_NetMessage
{
static constexpr reference<GlobalPacket_NetMessage, 0xA8D638u> const Instance {};

int Command;
wchar_t PlayerName[21];
byte HouseIndex;
byte ChatID;
wchar_t Message[112];
byte Color;
byte CRC;
};
#pragma pack(pop)

DEFINE_HOOK(0x48D92B, NetworkCallBack_NetMessage_Print, 0x5)
{
if (!Spawner::Enabled)
return 0;

enum { SkipMessage = 0x48DAD3, PrintMessage = 0x48D937 };

const int houseIndex = GlobalPacket_NetMessage::Instance->HouseIndex;

if (houseIndex < 8 && Game::ChatMask[houseIndex])
{
if (HouseClass::Array->ValidIndex(houseIndex))
{
HouseClass* pHouse = HouseClass::Array->GetItem(houseIndex);

GlobalPacket_NetMessage::Instance->Color = (byte)pHouse->ColorSchemeIndex;
R->ESI(pHouse->UIName);
return PrintMessage;
}
}

return SkipMessage;
}

DEFINE_HOOK(0x48D95B, NetworkCallBack_NetMessage_SetColor, 0x6)
{
if (!Spawner::Enabled)
return 0;

R->EAX(R->ECX());
return 0x48D966;
}

DEFINE_HOOK(0x55EDD2, MessageInput_Write, 0x5)
{
if (!Spawner::Enabled)
return 0;

HouseClass* pHouse = HouseClass::CurrentPlayer;
wcscpy_s(GlobalPacket_NetMessage::Instance->PlayerName, pHouse->UIName);
GlobalPacket_NetMessage::Instance->HouseIndex = (byte)pHouse->ArrayIndex;

return 0x55EE00;
}

DEFINE_HOOK(0x55F0A8, MessageInput_Print, 0x5)
{
if (!Spawner::Enabled)
return 0;

R->EAX(GlobalPacket_NetMessage::Instance->PlayerName);
return 0x55F0B2;
}
15 changes: 0 additions & 15 deletions src/Spawner/Spawner.Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ DEFINE_HOOK(0x6BD7CB, WinMain_SpawnerInit, 0x5)
// Set ConnTimeout
Patch::Apply_TYPED<int>(0x6843C7, { Spawner::GetConfig()->ConnTimeout }); // Scenario_Load_Wait

{ // Add support unicode player name in ingame chat
Patch::Apply_RAW(0x48D930, { 0x8B, 0xC1, 0x90, 0x90, 0x90 }); // mov eax, ecx
Patch::Apply_RAW(0x55F0AD, { 0x8B, 0xC1, 0x90, 0x90, 0x90 }); // mov eax, ecx
}

// Show GameMode in DiplomacyDialog in Skirmish
Patch::Apply_LJMP(0x658117, 0x658126); // RadarClass_DiplomacyDialog

Expand All @@ -82,16 +77,6 @@ DEFINE_HOOK(0x6BD7CB, WinMain_SpawnerInit, 0x5)
return 0;
}

// Add support unicode player name in ingame chat
DEFINE_HOOK(0x55EDD2, MessageInput_UnicodePlayerName, 0x5)
{
if (!Spawner::Enabled)
return 0;

wcscpy(reinterpret_cast<wchar_t*>(0xA8D63C), NodeNameType::Array->GetItem(0)->Name);
return 0x55EE00;
}

// Display UIGameMode if is set
// Otherwise use mode name from MPModesMD.ini
DEFINE_HOOK(0x65812E, RadarClass__DiplomacyDialog_UIGameMode, 0x6)
Expand Down
15 changes: 14 additions & 1 deletion src/Spawner/Spawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,27 @@ bool Spawner::StartNewScenario(const char* pScenarioName)
{
return ScenarioClass::StartScenario(pScenarioName, 0, -1);
}
else
else /* if (SessionClass::IsMultiplayer()) */
{
Spawner::InitNetwork();
if (!ScenarioClass::StartScenario(pScenarioName, 0, -1))
return false;

pSession->GameMode = GameMode::LAN;
pSession->CreateConnections();

if (Main::GetConfig()->DDrawHandlesClose)
{
Game::ChatMask[0] = false;
Game::ChatMask[1] = false;
Game::ChatMask[2] = false;
Game::ChatMask[3] = false;
Game::ChatMask[4] = false;
Game::ChatMask[5] = false;
Game::ChatMask[6] = false;
Game::ChatMask[7] = false;
}

return true;
}
}
Expand Down

0 comments on commit c74ded9

Please sign in to comment.