Skip to content
This repository was archived by the owner on Oct 10, 2024. It is now read-only.

Commit e6a9aa8

Browse files
authored
Feature/aum chat (#446)
* Chat with other AUM users in your lobby/game - Added AUM chat functionality - Added Custom RPC for AUM chat - Added Keybinding for AUM chat * cleaning * - fixed timestamp formatting - timestamps are created locally now only * updated screenshot
1 parent ce9404d commit e6a9aa8

18 files changed

+197
-5
lines changed

AmongUsMenu.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<ClCompile Include="events\TaskCompletedEvent.cpp" />
3030
<ClCompile Include="events\VentEvent.cpp" />
3131
<ClCompile Include="events\WalkEvent.cpp" />
32+
<ClCompile Include="gui\aum-chat.cpp" />
3233
<ClCompile Include="gui\console.cpp" />
3334
<ClCompile Include="gui\esp.cpp" />
3435
<ClCompile Include="gui\gui-helpers.cpp" />
@@ -75,6 +76,7 @@
7576
<ClCompile Include="hooks\SaveManager.cpp" />
7677
<ClCompile Include="hooks\UnityDebug.cpp" />
7778
<ClCompile Include="rpc\CustomRpcHandler.cpp" />
79+
<ClCompile Include="rpc\RpcChatMessage.cpp" />
7880
<ClCompile Include="rpc\RpcPlayerAppearance.cpp" />
7981
<ClCompile Include="rpc\RpcSetRole.cpp" />
8082
<ClCompile Include="rpc\RpcUsePlatform.cpp" />
@@ -325,6 +327,7 @@
325327
<ClInclude Include="appdata\il2cpp-functions.h" />
326328
<ClInclude Include="appdata\il2cpp-translations.h" />
327329
<ClInclude Include="events\_events.h" />
330+
<ClInclude Include="gui\aum-chat.hpp" />
328331
<ClInclude Include="gui\console.hpp" />
329332
<ClInclude Include="gui\esp.hpp" />
330333
<ClInclude Include="gui\gui-helpers.hpp" />

AmongUsMenu.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@
295295
<ClCompile Include="hooks\PlayerStorageManager.cpp">
296296
<Filter>hooks</Filter>
297297
</ClCompile>
298+
<ClCompile Include="rpc\RpcChatMessage.cpp">
299+
<Filter>rpc</Filter>
300+
</ClCompile>
301+
<ClCompile Include="gui\aum-chat.cpp">
302+
<Filter>gui</Filter>
303+
</ClCompile>
298304
</ItemGroup>
299305
<ItemGroup>
300306
<ClInclude Include="appdata\il2cpp-api-functions.h">
@@ -474,6 +480,9 @@
474480
<ClInclude Include="user\profiler.h">
475481
<Filter>user</Filter>
476482
</ClInclude>
483+
<ClInclude Include="gui\aum-chat.hpp">
484+
<Filter>gui</Filter>
485+
</ClInclude>
477486
</ItemGroup>
478487
<ItemGroup>
479488
<Image Include="resources\mira_hq.png">

appdata/il2cpp-functions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ DO_APP_FUNC(Byte__Array*, MessageReader_ReadBytesAndSize, (MessageReader* __this
162162
DO_APP_FUNC(Byte__Array*, MessageReader_ReadBytes, (MessageReader* __this, int32_t length, MethodInfo* method), "Hazel, System.Byte[] Hazel.MessageReader::ReadBytes(System.Int32)");
163163
DO_APP_FUNC(void, MessageWriter_WriteBoolean, (MessageWriter* __this, bool value, MethodInfo* method), "Hazel, System.Void Hazel.MessageWriter::Write(System.Boolean)");
164164
DO_APP_FUNC(void, MessageWriter_WriteByte, (MessageWriter* __this, uint8_t value, MethodInfo* method), "Hazel, System.Void Hazel.MessageWriter::Write(System.Byte)");
165+
DO_APP_FUNC(void, MessageWriter_WriteUShort, (MessageWriter* __this, uint16_t value, MethodInfo* method), "Hazel, System.Void Hazel.MessageWriter::Write(System.UInt16)");
165166
DO_APP_FUNC(void, MessageWriter_WriteInt32, (MessageWriter* __this, int32_t value, MethodInfo* method), "Hazel, System.Void Hazel.MessageWriter::Write(System.Int32)");
166167
DO_APP_FUNC(void, MessageWriter_WriteSingle, (MessageWriter* __this, float value, MethodInfo* method), "Hazel, System.Void Hazel.MessageWriter::Write(System.Single)");
167168
DO_APP_FUNC(void, MessageWriter_WriteString, (MessageWriter* __this, String* value, MethodInfo* method), "Hazel, System.Void Hazel.MessageWriter::Write(System.String)");

gui/aum-chat.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "pch-il2cpp.h"
2+
#include "aum-chat.hpp"
3+
#include "imgui/imgui.h"
4+
#include "gui-helpers.hpp"
5+
#include "state.hpp"
6+
#include "logger.h"
7+
8+
namespace ChatGui
9+
{
10+
char inputBuffer[250]{ "" };
11+
12+
void SendChatMessage(std::string message) {
13+
if (message.length() == 0) return;
14+
15+
auto gPlayerInfo = GetPlayerDataById((*Game::pLocalPlayer)->fields.PlayerId);
16+
auto outfit = GetPlayerOutfit(gPlayerInfo);
17+
auto name = convert_from_string(GameData_PlayerOutfit_get_PlayerName(outfit, nullptr));
18+
State.chatMessages.emplace_back(std::make_unique<RpcChatMessage>(name, message, (uint32_t)outfit->fields.ColorId, std::chrono::system_clock::now()));
19+
if (IsInGame()) State.rpcQueue.push(new RpcChatMessage(name, message, (uint32_t)outfit->fields.ColorId, std::chrono::system_clock::now()));
20+
else if (IsInLobby()) State.lobbyRpcQueue.push(new RpcChatMessage(name, message, (uint32_t)outfit->fields.ColorId, std::chrono::system_clock::now()));
21+
State.newChatMessage = true;
22+
23+
for (int i = 0; i < sizeof(inputBuffer); i++) {
24+
inputBuffer[i] = (char)0;
25+
}
26+
}
27+
28+
void Init() {
29+
ImGui::SetNextWindowSize(ImVec2(520, 320) * State.dpiScale, ImGuiCond_None);
30+
ImGui::SetNextWindowBgAlpha(1.F);
31+
}
32+
33+
void Render() {
34+
ChatGui::Init();
35+
36+
ImGui::Begin("Chat", &State.ShowChat, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar);
37+
ImGui::BeginChild("chat#scroll", ImVec2(511, 270) * State.dpiScale, true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
38+
39+
size_t i = 0;
40+
for (auto it = State.chatMessages.begin(); it != State.chatMessages.end(); ++it, ++i) {
41+
RpcChatMessage* cMsg = (*it).get();
42+
if (cMsg == NULL)
43+
{
44+
STREAM_ERROR("State.chatMessages[" << i << "] was NULL (chatMessages.size(): " << State.chatMessages.size() << ")");
45+
continue;
46+
}
47+
48+
cMsg->PrintUser();
49+
ImGui::SameLine();
50+
cMsg->PrintMessage();
51+
}
52+
if (State.newChatMessage) {
53+
State.newChatMessage = false;
54+
ImGui::SetScrollY(ImGui::GetScrollMaxY() + 50);
55+
}
56+
ImGui::EndChild();
57+
58+
ImGui::Separator();
59+
60+
ImGui::Dummy(ImVec2(1.0f, 2.0f) * State.dpiScale);
61+
62+
ImGui::BeginChild("chat#input", ImVec2(520, 20)* State.dpiScale, true);
63+
64+
if (ImGui::InputText("", inputBuffer, IM_ARRAYSIZE(inputBuffer), ImGuiInputTextFlags_EnterReturnsTrue)) {
65+
SendChatMessage(std::string(inputBuffer));
66+
}
67+
68+
ImGui::SameLine(340.f * State.dpiScale);
69+
70+
if (ImGui::Button("Send")) {
71+
SendChatMessage(std::string(inputBuffer));
72+
}
73+
74+
ImGui::EndChild();
75+
ImGui::End();
76+
}
77+
}

gui/aum-chat.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
namespace ChatGui {
4+
void Init();
5+
void Render();
6+
};

gui/menu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace Menu {
2222
void Init() {
23-
ImGui::SetNextWindowSize(ImVec2(520, 320) * State.dpiScale, ImGuiCond_None);
23+
ImGui::SetNextWindowSize(ImVec2(520, 330) * State.dpiScale, ImGuiCond_None);
2424
ImGui::SetNextWindowBgAlpha(1.F);
2525
}
2626

gui/tabs/game_tab.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ namespace GameTab {
7676

7777
ImGui::Dummy(ImVec2(4, 4) * State.dpiScale);
7878

79+
if (ImGui::Checkbox("AUM Chat", &State.ShowChat)) {
80+
State.Save();
81+
}
82+
83+
ImGui::SameLine();
84+
85+
ImGui::SameLine();
86+
if (HotKey(State.KeyBinds.Toggle_Chat)) {
87+
State.Save();
88+
}
89+
90+
ImGui::Dummy(ImVec2(4, 4) * State.dpiScale);
91+
7992
if ((State.mapType == Settings::MapType::Airship) && IsHost() && IsInGame() && ImGui::Button("Switch Moving Platform Side"))
8093
{
8194
State.rpcQueue.push(new RpcUsePlatform());

hooks/DirectX.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "resource_data.h"
2020
#include "game.h"
2121
#include "console.hpp"
22+
#include "aum-chat.hpp"
2223
#include "profiler.h"
2324

2425
#include <future>
@@ -70,6 +71,11 @@ static bool CanDrawRadar()
7071
return IsInGame() && State.ShowRadar && (!State.InMeeting || !State.HideRadar_During_Meetings);
7172
}
7273

74+
static bool CanDrawChat()
75+
{
76+
return (IsInGame() || IsInLobby()) && State.ShowChat;
77+
}
78+
7379
static bool CanDrawReplay()
7480
{
7581
return IsInGame() && State.ShowReplay;
@@ -111,6 +117,7 @@ LRESULT __stdcall dWndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
111117
if (KeyBinds::IsKeyPressed(State.KeyBinds.Toggle_Freecam) && IsInGame()) State.FreeCam = !State.FreeCam;
112118
if (KeyBinds::IsKeyPressed(State.KeyBinds.Close_Current_Room_Door) && IsInGame()) State.rpcQueue.push(new RpcCloseDoorsOfType(GetSystemTypes(GetTrueAdjustedPosition(*Game::pLocalPlayer)), false));
113119
if (KeyBinds::IsKeyPressed(State.KeyBinds.Toggle_Replay)) State.ShowReplay = !State.ShowReplay;
120+
if (KeyBinds::IsKeyPressed(State.KeyBinds.Toggle_Chat)) State.ShowChat = !State.ShowChat;
114121

115122
return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam);
116123
}
@@ -310,6 +317,11 @@ HRESULT __stdcall dPresent(IDXGISwapChain* __this, UINT SyncInterval, UINT Flags
310317
ImGuiRenderer::Submit([]() { ConsoleGui::Render(); });
311318
}
312319

320+
if (CanDrawChat())
321+
{
322+
ImGuiRenderer::Submit([]() { ChatGui::Render(); });
323+
}
324+
313325
if (CanDrawEsp())
314326
{
315327
ImGuiRenderer::Submit([&]()

hooks/InnerNetClient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ static void onGameEnd() {
209209
LOG_DEBUG("Reset All");
210210
Replay::Reset();
211211
State.aumUsers.clear();
212+
State.chatMessages.clear();
212213
State.MatchEnd = std::chrono::system_clock::now();
213214

214215
drawing_t& instance = Esp::GetDrawing();

hooks/PlayerControl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void dPlayerControl_FixedUpdate(PlayerControl* __this, MethodInfo* method) {
2929
if (__this == *Game::pLocalPlayer) {
3030
if (State.rpcCooldown == 0) {
3131
MessageWriter* rpcMessage = InnerNetClient_StartRpc((InnerNetClient*)(*Game::pAmongUsClient), __this->fields._.NetId, (uint8_t)42069, (SendOption__Enum)1, NULL);
32-
MessageWriter_WriteInt32(rpcMessage, __this->fields.PlayerId, NULL);
32+
MessageWriter_WriteByte(rpcMessage, __this->fields.PlayerId, NULL);
3333
MessageWriter_EndMessage(rpcMessage, NULL);
3434
State.rpcCooldown = 15;
3535
}

0 commit comments

Comments
 (0)