Skip to content

Commit

Permalink
Some tweaks to WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjoecox committed Dec 17, 2024
1 parent d725125 commit 5451ede
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 1 deletion.
9 changes: 9 additions & 0 deletions soh/soh/Network/Anchor/Anchor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,15 @@ void Anchor::DrawMenu() {
ImGui::EndMenu();
}
}

if (ImGui::Button("Request Team State", ImVec2(ImGui::GetContentRegionAvail().x - 25.0f, 0.0f))) {
SendPacket_RequestTeamState();
}
ImGui::SameLine();
if (ImGui::Button(ICON_FA_TRASH)) {
SendPacket_ClearTeamState();
}
UIWidgets::Tooltip("Clear Team State");
} else {
ImGui::Text("Connecting...");
}
Expand Down
1 change: 1 addition & 0 deletions soh/soh/Network/Anchor/Anchor.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Anchor : public Network {
void SendJsonToRemote(nlohmann::json packet);
bool IsSaveLoaded();

void SendPacket_ClearTeamState();
void SendPacket_ConsumeAdultTradeItem(u8 itemId);
void SendPacket_DamagePlayer(u32 clientId, u8 damageEffect, u8 damage);
void SendPacket_EntranceDiscovered(u16 entranceIndex);
Expand Down
4 changes: 4 additions & 0 deletions soh/soh/Network/Anchor/AnchorRoomWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void AnchorRoomWindow::Draw() {
continue;
}

ImGui::PushID(clientId);

if (client.clientId == Anchor::Instance->roomState.ownerClientId) {
ImGui::TextColored(ImVec4(1, 1, 0, 1), "%s", ICON_FA_GAVEL);
ImGui::SameLine();
Expand All @@ -58,6 +60,7 @@ void AnchorRoomWindow::Draw() {
ImGui::TextColored(ImVec4(0.8f, 1.0f, 0.8f, 1.0f), "%s", CVarGetString(CVAR_REMOTE_ANCHOR("Name"), ""));
} else if (!client.online) {
ImGui::TextColored(ImVec4(1, 1, 1, 0.3f), "%s - offline", client.name.c_str());
ImGui::PopID();
continue;
} else {
ImGui::Text("%s", client.name.c_str());
Expand Down Expand Up @@ -105,6 +108,7 @@ void AnchorRoomWindow::Draw() {
ImGui::EndTooltip();
}
}
ImGui::PopID();
}
}

Expand Down
6 changes: 5 additions & 1 deletion soh/soh/Network/Anchor/Packets/EntranceDiscovered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include "soh/Enhancements/randomizer/randomizer_entrance.h"
#include "soh/OTRGlobals.h"

static bool isResultOfHandling = false;

/**
* ENTRANCE_DISCOVERED
*/

void Anchor::SendPacket_EntranceDiscovered(u16 entranceIndex) {
if (!IsSaveLoaded()) {
if (!IsSaveLoaded() || isResultOfHandling) {
return;
}

Expand All @@ -30,8 +32,10 @@ void Anchor::HandlePacket_EntranceDiscovered(nlohmann::json payload) {
return;
}

isResultOfHandling = true;
u16 entranceIndex = payload["entranceIndex"].get<u16>();
Entrance_SetEntranceDiscovered(entranceIndex, 1);
isResultOfHandling = false;
}

#endif // ENABLE_REMOTE_CONTROL
4 changes: 4 additions & 0 deletions soh/soh/Network/Anchor/Packets/RequestTeamState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
*/

void Anchor::SendPacket_RequestTeamState() {
if (!IsSaveLoaded()) {
return;
}

nlohmann::json payload;
payload["type"] = REQUEST_TEAM_STATE;
payload["targetTeamId"] = CVarGetString(CVAR_REMOTE_ANCHOR("TeamId"), "default");
Expand Down
4 changes: 4 additions & 0 deletions soh/soh/Network/Anchor/Packets/SetFlag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
*/

void Anchor::SendPacket_SetFlag(s16 sceneNum, s16 flagType, s16 flag) {
if (!IsSaveLoaded()) {
return;
}

nlohmann::json payload;
payload["type"] = SET_FLAG;
payload["targetTeamId"] = CVarGetString(CVAR_REMOTE_ANCHOR("TeamId"), "default");
Expand Down
4 changes: 4 additions & 0 deletions soh/soh/Network/Anchor/Packets/UnsetFlag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
*/

void Anchor::SendPacket_UnsetFlag(s16 sceneNum, s16 flagType, s16 flag) {
if (!IsSaveLoaded()) {
return;
}

nlohmann::json payload;
payload["type"] = UNSET_FLAG;
payload["targetTeamId"] = CVarGetString(CVAR_REMOTE_ANCHOR("TeamId"), "default");
Expand Down
14 changes: 14 additions & 0 deletions soh/soh/Network/Anchor/Packets/UpdateTeamState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ void Anchor::SendPacket_UpdateTeamState() {
SendJsonToRemote(payload);
}

void Anchor::SendPacket_ClearTeamState() {
if (!IsSaveLoaded()) {
return;
}

json payload;
payload["type"] = UPDATE_TEAM_STATE;
payload["targetTeamId"] = CVarGetString(CVAR_REMOTE_ANCHOR("TeamId"), "default");

payload["queue"] = json::array();
payload["state"] = json::object();
SendJsonToRemote(payload);
}

void Anchor::HandlePacket_UpdateTeamState(nlohmann::json payload) {
isHandlingUpdateTeamState = true;
// This can happen in between file select and the game starting, so we cant use this check, but we need to ensure we
Expand Down

0 comments on commit 5451ede

Please sign in to comment.