From 7dca97469a6412e2940cc900b93419e3dd006019 Mon Sep 17 00:00:00 2001 From: void* Date: Tue, 23 Nov 2021 13:22:25 +0100 Subject: [PATCH] added new event for players leaving the lobby --- AmongUsMenu.vcxproj | 1 + AmongUsMenu.vcxproj.filters | 3 +++ events/DisconnectEvent.cpp | 24 ++++++++++++++++++++++++ events/_events.h | 12 ++++++++++-- gui/console.hpp | 2 +- hooks/InnerNetClient.cpp | 3 +++ user/gitparams.h | 2 +- 7 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 events/DisconnectEvent.cpp diff --git a/AmongUsMenu.vcxproj b/AmongUsMenu.vcxproj index ed02f408..5a7a983b 100644 --- a/AmongUsMenu.vcxproj +++ b/AmongUsMenu.vcxproj @@ -21,6 +21,7 @@ + diff --git a/AmongUsMenu.vcxproj.filters b/AmongUsMenu.vcxproj.filters index 27be697d..1b21b400 100644 --- a/AmongUsMenu.vcxproj.filters +++ b/AmongUsMenu.vcxproj.filters @@ -265,6 +265,9 @@ events + + events + diff --git a/events/DisconnectEvent.cpp b/events/DisconnectEvent.cpp new file mode 100644 index 00000000..e8dee8c8 --- /dev/null +++ b/events/DisconnectEvent.cpp @@ -0,0 +1,24 @@ +#include "pch-il2cpp.h" +#include "_events.h" +#include "utility.h" + +DisconnectEvent::DisconnectEvent(EVENT_PLAYER source) : EventInterface(source, EVENT_DISCONNECT) { } + +void DisconnectEvent::Output() { + ImGui::TextColored(AmongUsColorToImVec4(GetPlayerColor(source.colorId)), source.playerName.c_str()); + ImGui::SameLine(); + ImGui::Text("has left the game"); + ImGui::SameLine(); + auto sec = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() - std::chrono::duration_cast(this->timestamp.time_since_epoch()).count(); + auto min = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() - std::chrono::duration_cast(this->timestamp.time_since_epoch()).count(); + if (sec < 60) ImGui::Text(" [%ds ago]", sec); + else ImGui::Text(" [%dm ago]", min); +} + +void DisconnectEvent::ColoredEventOutput() { + ImGui::Text("["); + ImGui::SameLine(); + ImGui::TextColored(ImVec4(1.f, 1.f, 1.f, 1.f), "DISCONNECT"); + ImGui::SameLine(); + ImGui::Text("]"); +} \ No newline at end of file diff --git a/events/_events.h b/events/_events.h index 445e4876..09500e88 100644 --- a/events/_events.h +++ b/events/_events.h @@ -14,8 +14,9 @@ enum EVENT_TYPES { EVENT_MEETING = 0x5, EVENT_VOTE = 0x6, EVENT_CHEAT = 0x7, - EVENT_WALK = 0x8, - EVENT_TYPES_SIZE = 9 + EVENT_DISCONNECT = 0x8, + EVENT_WALK = 0x9, + EVENT_TYPES_SIZE = 10 }; enum VENT_ACTION { @@ -149,6 +150,13 @@ class CheatDetectedEvent : public EventInterface { virtual void ColoredEventOutput() override; }; +class DisconnectEvent : public EventInterface { +public: + DisconnectEvent(EVENT_PLAYER source); + virtual void Output() override; + virtual void ColoredEventOutput() override; +}; + class WalkEvent : public EventInterface { private: Vector2 position; diff --git a/gui/console.hpp b/gui/console.hpp index 9e17ce43..cb6cecbe 100644 --- a/gui/console.hpp +++ b/gui/console.hpp @@ -2,7 +2,7 @@ #include namespace ConsoleGui { - const std::vector BY_TYPE = { "", "Kill", "Vent", "Task", "Report", "Meeting", "Vote", "Cheat" }; + const std::vector BY_TYPE = { "All", "Kill", "Vent", "Task", "Report", "Meeting", "Vote", "Cheat", "Disconnect" }; extern int selectedType; void Init(); diff --git a/hooks/InnerNetClient.cpp b/hooks/InnerNetClient.cpp index 8bb5eaa0..23330b19 100644 --- a/hooks/InnerNetClient.cpp +++ b/hooks/InnerNetClient.cpp @@ -115,6 +115,9 @@ void dAmongUsClient_OnPlayerLeft(AmongUsClient* __this, ClientData* data, Discon auto it = std::find(State.aumUsers.begin(), State.aumUsers.end(), data->fields.Character->fields.PlayerId); if (it != State.aumUsers.end()) State.aumUsers.erase(it); + + State.events[data->fields.Character->fields.PlayerId][EVENT_DISCONNECT].push_back(new DisconnectEvent(GetEventPlayer(data->fields.Character->fields._cachedData).value())); + State.consoleEvents.push_back(new DisconnectEvent(GetEventPlayer(data->fields.Character->fields._cachedData).value())); } AmongUsClient_OnPlayerLeft(__this, data, reason, method); diff --git a/user/gitparams.h b/user/gitparams.h index 77ae3cb9..3a76f110 100644 --- a/user/gitparams.h +++ b/user/gitparams.h @@ -1,2 +1,2 @@ -#define GIT_CUR_COMMIT 9c1b3553fa9d5ce5471b61c88699736db773ed77 +#define GIT_CUR_COMMIT 68a2089d212e5058138387a4202ead7f92350570 #define GIT_BRANCH main