Skip to content

Commit

Permalink
Merge branch 'salinecitrine-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
planqi committed Nov 2, 2018
2 parents 78e05a5 + 4579c44 commit 448ed89
Show file tree
Hide file tree
Showing 7 changed files with 101 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 @@ -129,6 +129,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 @@ -200,6 +201,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 @@ -252,6 +252,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 @@ -419,5 +422,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 @@ -11,4 +11,5 @@
#include "Modules\ItemMover\ItemMover.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"
69 changes: 69 additions & 0 deletions BH/Modules/ChatColor/ChatColor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#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();

BH::config->ReadAssoc("Whisper Color", whisperColors);
}

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 448ed89

Please sign in to comment.