Skip to content

Commit

Permalink
Add Chat Colors module to color messages from users
Browse files Browse the repository at this point in the history
The primary purpose of this module is to change the color of messages from *chat and *trade, to make them easier to distinguish from normal whispers
  • Loading branch information
salinecitrine committed Aug 13, 2018
1 parent d756b26 commit 393ccb6
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions BH/BH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void BH::Initialize()
new ItemMover();
new StashExport();
new Maphack();
new ChatColor();

moduleManager->LoadModules();

Expand Down
2 changes: 2 additions & 0 deletions BH/BH.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<ClCompile Include="JSONObject.cpp" />
<ClCompile Include="Modules\AutoTele\AutoTele.cpp" />
<ClCompile Include="Modules\Bnet\Bnet.cpp" />
<ClCompile Include="Modules\ChatColor\ChatColor.cpp" />
<ClCompile Include="Modules\Gamefilter\Gamefilter.cpp" />
<ClCompile Include="Modules\Item\Item.cpp" />
<ClCompile Include="Modules\Item\ItemDisplay.cpp" />
Expand Down Expand Up @@ -202,6 +203,7 @@
<ClInclude Include="Modules\AutoTele\ATIncludes\Vectors.h" />
<ClInclude Include="Modules\AutoTele\AutoTele.h" />
<ClInclude Include="Modules\Bnet\Bnet.h" />
<ClInclude Include="Modules\ChatColor\ChatColor.h" />
<ClInclude Include="Modules\Gamefilter\Gamefilter.h" />
<ClInclude Include="Modules\Item\Item.h" />
<ClInclude Include="Modules\Item\ItemDisplay.h" />
Expand Down
6 changes: 6 additions & 0 deletions BH/BH.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@
<ClCompile Include="D2Version.cpp">
<Filter>Diablo II\Version</Filter>
</ClCompile>
<ClCompile Include="Modules\ChatColor\ChatColor.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="D2Structs.h">
Expand Down Expand Up @@ -434,5 +437,8 @@
<ClInclude Include="D2Version.h">
<Filter>Diablo II\Version</Filter>
</ClInclude>
<ClInclude Include="Modules\ChatColor\ChatColor.h">
<Filter>Diablo II</Filter>
</ClInclude>
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion BH/Modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
#include "Modules\SpamFilter\SpamFilter.h"
#include "Modules\AutoTele\AutoTele.h"
#include "Modules\Party\Party.h"
#include "Modules\StashExport\StashExport.h"
#include "Modules\StashExport\StashExport.h"
#include "Modules\ChatColor\ChatColor.h"
73 changes: 73 additions & 0 deletions BH/Modules/ChatColor/ChatColor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "ChatColor.h"
#include "../../BH.h"
#include "../../D2Ptrs.h"
#include "../../D2Stubs.h"

void ChatColor::Init() {

}

void Print(DWORD color, char* format, ...) {
va_list vaArgs;
va_start(vaArgs, format);
int len = _vscprintf(format, vaArgs) + 1;
char* str = new char[len];
vsprintf_s(str, len, format, vaArgs);
va_end(vaArgs);

wchar_t* wstr = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, str, -1, wstr, len);
D2CLIENT_PrintGameString(wstr, color);
delete[] wstr;

delete[] str;
}

void ChatColor::OnGameJoin(const string& name, const string& pass, int diff) {
inGame = true;
}

void ChatColor::OnGameExit() {
inGame = false;
}

void ChatColor::OnLoad() {
LoadConfig();
}

void ChatColor::LoadConfig() {
whisperColors.clear();

auto whisperColorConfig = BH::config->ReadAssoc("Whisper Color");
for (auto it = whisperColorConfig.cbegin(); it != whisperColorConfig.cend(); it++) {
int color = StringToNumber(it->second);
whisperColors[it->first] = color;
}
}

void ChatColor::OnChatPacketRecv(BYTE* packet, bool* block) {
if (packet[1] == 0x0F && inGame) {
unsigned int event_id = *(unsigned short int*)&packet[4];

if (event_id == 4) {
const char* from = (const char*)&packet[28];
unsigned int fromLen = strlen(from);

const char* message = (const char*)&packet[28 + fromLen + 1];
unsigned int messageLen = strlen(message);

bool replace = false;
int color = 0;
if (whisperColors.find(from) != whisperColors.end()) {
replace = true;
color = whisperColors[from];
}

if (replace) {
*block = true;

Print(color, "%s | %s", from, message);
}
}
}
}
21 changes: 21 additions & 0 deletions BH/Modules/ChatColor/ChatColor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include "../../D2Structs.h"
#include "../Module.h"
#include "../../Config.h"
#include "../../Common.h"

class ChatColor : public Module {
private:
bool inGame;
std::map<string, unsigned int> whisperColors;
public:
ChatColor() : Module("Chat Color") {};

void Init();

void OnLoad();
void LoadConfig();
void OnGameJoin(const string& name, const string& pass, int diff);
void OnGameExit();
void OnChatPacketRecv(BYTE* packet, bool *block);
};
Binary file modified Release/BH.dll
Binary file not shown.

0 comments on commit 393ccb6

Please sign in to comment.