Skip to content

Commit

Permalink
#321: Fix report/meeting event missing (#349)
Browse files Browse the repository at this point in the history
* multi-combo displays the number of selected items

* #321: Fix report/meeting event missing

In some cases, 'PlayerControl_ReportDeadBody' will not be triggered. So I changed to hook the 'PlayerControl_CoStartMeeting' function to make sure the event is logged
  • Loading branch information
cddjr committed Apr 15, 2022
1 parent 9345ac1 commit 6eb2c11
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 23 deletions.
1 change: 1 addition & 0 deletions appdata/il2cpp-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ DO_APP_FUNC(void, PlayerControl_CmdReportDeadBody, (PlayerControl* __this, GameD
DO_APP_FUNC(void, PlayerControl_MurderPlayer, (PlayerControl* __this, PlayerControl* target, MethodInfo* method), "Assembly-CSharp, System.Void PlayerControl::MurderPlayer(PlayerControl)");
DO_APP_FUNC(void, PlayerControl_RpcMurderPlayer, (PlayerControl* __this, PlayerControl* target, MethodInfo* method), "Assembly-CSharp, System.Void PlayerControl::RpcMurderPlayer(PlayerControl)");
DO_APP_FUNC(void, PlayerControl_ReportDeadBody, (PlayerControl* __this, GameData_PlayerInfo* target, MethodInfo* method), "Assembly-CSharp, System.Void PlayerControl::ReportDeadBody(GameData.PlayerInfo)");
DO_APP_FUNC(void*, PlayerControl_CoStartMeeting, (PlayerControl* __this, GameData_PlayerInfo* target, MethodInfo* method), "Assembly-CSharp, System.Collections.IEnumerator PlayerControl::CoStartMeeting(GameData.PlayerInfo)");
DO_APP_FUNC(void, PlayerControl_RpcSetRole, (PlayerControl* __this, RoleTypes__Enum roleType, MethodInfo* method), "Assembly-CSharp, System.Void PlayerControl::RpcSetRole(RoleTypes)");
DO_APP_FUNC(void, PlayerControl_RpcSetScanner, (PlayerControl* __this, bool value, MethodInfo* method), "Assembly-CSharp, System.Void PlayerControl::RpcSetScanner(System.Boolean)");
DO_APP_FUNC(void, PlayerControl_CmdCheckColor, (PlayerControl* __this, uint8_t bodyColor, MethodInfo* method), "Assembly-CSharp, System.Void PlayerControl::CmdCheckColor(System.Byte)");
Expand Down
60 changes: 43 additions & 17 deletions gui/gui-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,31 @@ bool CustomListBoxIntMultiple(const char* label, std::vector<std::pair<const cha
ImGuiStyle& style = GetStyle();
float spacing = style.ItemInnerSpacing.x;
PushItemWidth(width);
bool response = BeginCombo(comboLabel.c_str(), label, flags);
size_t countSelected = 0;
for (auto& pair : *list) {
if (pair.second) {
countSelected++;
}
}
std::string preview;
if (countSelected > 0) {
char buf[32] = { 0 };
sprintf_s(buf, "%zu item(s) selected", countSelected);
preview = buf;
}
else
preview = label;
bool response = BeginCombo(comboLabel.c_str(), preview.c_str(), flags);
if (response) {
response = false;
for (size_t i = 0; i < list->size(); i++) {
if (strcmp(list->at(i).first, "") == 0) // ignore all entries with empty labels so we can create padding
for (auto& pair : *list) {
if (strcmp(pair.first, "") == 0) // ignore all entries with empty labels so we can create padding
continue;
if (Selectable(list->at(i).first, list->at(i).second)) {
list->at(i).second ^= 1;
if (Selectable(pair.first, pair.second)) {
pair.second ^= 1;
response = true;
}
if (list->at(i).second)
if (pair.second)
SetItemDefaultFocus();
}
EndCombo();
Expand All @@ -83,8 +97,8 @@ bool CustomListBoxIntMultiple(const char* label, std::vector<std::pair<const cha
SameLine(0, spacing);
const bool resetResponse = Button(buttonLabel.c_str());
if (resetResponse) {
for (size_t i = 0; i < list->size(); i++)
list->at(i).second = false;
for (auto& pair : *list)
pair.second = false;
return resetResponse;
}
}
Expand All @@ -100,7 +114,21 @@ bool CustomListBoxPlayerSelectionMultiple(const char* label, std::vector<std::pa
ImGuiStyle& style = GetStyle();
float spacing = style.ItemInnerSpacing.x;
PushItemWidth(width);
bool response = BeginCombo(comboLabel.c_str(), label, flags);
size_t countSelected = 0;
for (auto& pair : *list) {
if (pair.second) {
countSelected++;
}
}
std::string preview;
if (countSelected > 0) {
char buf[32] = { 0 };
sprintf_s(buf, "%zu player(s) selected", countSelected);
preview = buf;
}
else
preview = label;
bool response = BeginCombo(comboLabel.c_str(), preview.c_str(), flags);
if (response) {
response = false;
auto localData = GetPlayerData(*Game::pLocalPlayer);
Expand All @@ -110,22 +138,20 @@ bool CustomListBoxPlayerSelectionMultiple(const char* label, std::vector<std::pa

app::GameData_PlayerOutfit* outfit = GetPlayerOutfit(playerData);
if (outfit == NULL) return false;
auto& item = list->at(playerData->fields.PlayerId);
std::string playerName = convert_from_string(outfit->fields._playerName);
PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0) * State.dpiScale);
PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0) * State.dpiScale);
if (Selectable(std::string("##" + playerName + "_ConsoleName").c_str(), list->at(playerData->fields.PlayerId).second))
if (Selectable(std::string("##" + playerName + "_ConsoleName").c_str(), item.second))
{
list->at(playerData->fields.PlayerId).second ^= 1;
if (list->at(playerData->fields.PlayerId).second
&& (!list->at(playerData->fields.PlayerId).first.has_value()
|| (list->at(playerData->fields.PlayerId).first.has_value()
&& list->at(playerData->fields.PlayerId).first.is_Disconnected())))
item.second ^= 1;
if (item.second && (!item.first.has_value() || item.first.is_Disconnected()))
{
list->at(playerData->fields.PlayerId).first = PlayerSelection(playerData);
item.first = PlayerSelection(playerData);
}
response = true;
}
if (list->at(playerData->fields.PlayerId).second)
if (item.second)
SetItemDefaultFocus();
SameLine();
ColorButton(std::string("##" + playerName + "_ConsoleColorButton").c_str(), AmongUsColorToImVec4(GetPlayerColor(outfit->fields.ColorId)), ImGuiColorEditFlags_NoBorder | ImGuiColorEditFlags_NoTooltip);
Expand Down
11 changes: 11 additions & 0 deletions hooks/PlayerControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ void dPlayerControl_MurderPlayer(PlayerControl* __this, PlayerControl* target, M
PlayerControl_MurderPlayer(__this, target, method);
}

/* Use dPlayerControl_CoStartMeeting instead
void dPlayerControl_CmdReportDeadBody(PlayerControl* __this, GameData_PlayerInfo* target, MethodInfo* method)
{
std::lock_guard<std::mutex> replayLock(Replay::replayEventMutex);
Expand All @@ -272,6 +273,16 @@ void dPlayerControl_ReportDeadBody(PlayerControl*__this, GameData_PlayerInfo* ta
State.liveReplayEvents.push_back(std::make_unique<ReportDeadBodyEvent>(GetEventPlayerControl(__this).value(), GetEventPlayer(target), PlayerControl_GetTruePosition(__this, NULL), GetTargetPosition(target)));
}
PlayerControl_ReportDeadBody(__this, target, method);
}*/

void* dPlayerControl_CoStartMeeting(PlayerControl* __this, GameData_PlayerInfo* target, MethodInfo* method)
{
do {
std::lock_guard<std::mutex> replayLock(Replay::replayEventMutex);
State.rawEvents.push_back(std::make_unique<ReportDeadBodyEvent>(GetEventPlayerControl(__this).value(), GetEventPlayer(target), PlayerControl_GetTruePosition(__this, NULL), GetTargetPosition(target)));
State.liveReplayEvents.push_back(std::make_unique<ReportDeadBodyEvent>(GetEventPlayerControl(__this).value(), GetEventPlayer(target), PlayerControl_GetTruePosition(__this, NULL), GetTargetPosition(target)));
} while (0);
return PlayerControl_CoStartMeeting(__this, target, method);
}

void dPlayerControl_HandleRpc(PlayerControl* __this, uint8_t callId, MessageReader* reader, MethodInfo* method) {
Expand Down
10 changes: 6 additions & 4 deletions hooks/_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ void DetourInitilization() {
HOOKFUNC(GameOptionsData_Deserialize_1);
HOOKFUNC(PlayerControl_MurderPlayer);
HOOKFUNC(PlayerControl_CompleteTask);
HOOKFUNC(PlayerControl_CmdReportDeadBody);
HOOKFUNC(PlayerControl_ReportDeadBody);
//HOOKFUNC(PlayerControl_CmdReportDeadBody);
//HOOKFUNC(PlayerControl_ReportDeadBody);
HOOKFUNC(PlayerControl_CoStartMeeting);
HOOKFUNC(RoleManager_SelectRoles);
HOOKFUNC(RoleManager_AssignRolesForTeam);
HOOKFUNC(RoleManager_AssignRolesFromList);
Expand Down Expand Up @@ -201,8 +202,9 @@ void DetourUninitialization()
UNHOOKFUNC(GameOptionsData_Deserialize_1);
UNHOOKFUNC(PlayerControl_MurderPlayer);
UNHOOKFUNC(PlayerControl_CompleteTask);
UNHOOKFUNC(PlayerControl_CmdReportDeadBody);
UNHOOKFUNC(PlayerControl_ReportDeadBody);
//UNHOOKFUNC(PlayerControl_CmdReportDeadBody);
//UNHOOKFUNC(PlayerControl_ReportDeadBody);
UNHOOKFUNC(PlayerControl_CoStartMeeting);
UNHOOKFUNC(RoleManager_SelectRoles);
UNHOOKFUNC(RoleManager_AssignRolesForTeam);
UNHOOKFUNC(RoleManager_AssignRolesFromList);
Expand Down
5 changes: 3 additions & 2 deletions hooks/_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ void dPlainDoor_SetDoorway(PlainDoor* __this, bool open, MethodInfo* method);
void dPlayerControl_CompleteTask(PlayerControl* __this, uint32_t idx, MethodInfo* method);
void dPlayerControl_FixedUpdate(PlayerControl* __this, MethodInfo* method);
void dPlayerControl_MurderPlayer(PlayerControl* __this, PlayerControl* target, MethodInfo* method);
void dPlayerControl_CmdReportDeadBody(PlayerControl* __this, GameData_PlayerInfo* target, MethodInfo* method);
void dPlayerControl_ReportDeadBody(PlayerControl*__this, GameData_PlayerInfo* target, MethodInfo *method);
void* dPlayerControl_CoStartMeeting(PlayerControl* __this, GameData_PlayerInfo* target, MethodInfo* method);
//void dPlayerControl_CmdReportDeadBody(PlayerControl* __this, GameData_PlayerInfo* target, MethodInfo* method);
//void dPlayerControl_ReportDeadBody(PlayerControl*__this, GameData_PlayerInfo* target, MethodInfo *method);
void dPlayerControl_RpcSyncSettings(PlayerControl* __this, GameOptionsData* gameOptions, MethodInfo* method);
void dPlayerControl_HandleRpc(PlayerControl* __this, uint8_t callId, MessageReader* reader, MethodInfo* method);
void dPlayerControl_Shapeshift(PlayerControl* __this, PlayerControl* target, bool animate, MethodInfo* method);
Expand Down

0 comments on commit 6eb2c11

Please sign in to comment.