Skip to content

Commit

Permalink
Anchor Build 12 (alpha 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjoecox committed Oct 7, 2023
1 parent 30d9b4a commit 6665319
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 87 deletions.
198 changes: 137 additions & 61 deletions soh/soh/Enhancements/game-interactor/GameInteractor_Anchor.cpp

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions soh/soh/Enhancements/game-interactor/GameInteractor_Anchor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ typedef struct {
std::string clientVersion;
std::string name;
Color_RGB8 color;
std::string seed;
uint32_t seed;
uint8_t fileNum;
bool gameComplete;
uint8_t scene;
uint8_t sceneNum;
uint8_t roomIndex;
uint32_t entranceIndex;
PosRot posRot;
Expand All @@ -28,9 +29,8 @@ class GameInteractorAnchor {
public:
static GameInteractorAnchor* Instance;
static std::map<uint32_t, AnchorClient> AnchorClients;
static std::vector<uint32_t> FairyIndexToClientId;
static std::vector<uint32_t> ActorIndexToClientId;
static std::string clientVersion;
static std::string seed;

void Enable();
void Disable();
Expand Down Expand Up @@ -82,7 +82,7 @@ uint8_t Anchor_GetClientScene(uint32_t fairyIndex);
PosRot Anchor_GetClientPosition(uint32_t fairyIndex);
uint8_t Anchor_GetClientRoomIndex(uint32_t fairyIndex);
Color_RGB8 Anchor_GetClientColor(uint32_t fairyIndex);
void Anchor_SpawnClientFairies();
void Anchor_RefreshClientActors();
void Anchor_SkipLocation(uint32_t locationIndex, bool skipped);
void Anchor_UpdateBeansBought(uint8_t amount);
void Anchor_UpdateBeansCount(uint8_t amount);
Expand Down
11 changes: 7 additions & 4 deletions soh/soh/Enhancements/game-interactor/GameInteractor_Remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ void GameInteractor::DisableRemoteInteractor() {
}

void GameInteractor::TransmitDataToRemote(const char* payload) {
SDLNet_TCP_Send(remoteSocket, payload, strlen(payload) + 1);
SDLNet_TCP_Send(remoteSocket, payload, strlen(payload));
}

// Appends a newline character to the end of the json payload and sends it to the remote
void GameInteractor::TransmitJsonToRemote(nlohmann::json payload) {
TransmitDataToRemote(payload.dump().c_str());
// TODO: Migrate anchor server to use null terminators instead of newlines
std::string payloadString = payload.dump() + '\n';
TransmitDataToRemote(payloadString.c_str());
}

// MARK: - Private
Expand Down Expand Up @@ -134,15 +136,16 @@ void GameInteractor::ReceiveFromServer() {
receivedData.append(remoteDataReceived, len);

// Proess all complete packets
size_t delimiterPos = receivedData.find('\0');
// TODO: Migrate anchor server to use null terminators instead of newlines
size_t delimiterPos = receivedData.find('\n');
while (delimiterPos != std::string::npos) {
// Extract the complete packet until the delimiter
std::string packet = receivedData.substr(0, delimiterPos);
// Remove the packet (including the delimiter) from the received data
receivedData.erase(0, delimiterPos + 1);
HandleRemoteJson(packet);
// Find the next delimiter
delimiterPos = receivedData.find('\0');
delimiterPos = receivedData.find('\n');
}
}

Expand Down
4 changes: 2 additions & 2 deletions soh/soh/SohMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,12 +1604,12 @@ void DrawRemoteControlMenu() {
ImGui::EndTooltip();
}
}
if (client.seed != GameInteractorAnchor::seed) {
if (client.seed != gSaveContext.finalSeed && client.fileNum != 0xFF && gSaveContext.fileNum != 0xFF) {
ImGui::SameLine();
ImGui::TextColored(ImVec4(1, 0, 0, 1), ICON_FA_EXCLAMATION_TRIANGLE);
if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::Text("Seed mismatch (%s)", client.seed.c_str());
ImGui::Text("Seed mismatch (%u != %u)", client.seed, gSaveContext.finalSeed);
ImGui::EndTooltip();
}
}
Expand Down
4 changes: 3 additions & 1 deletion soh/soh/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ std::map<uint32_t, const char*> itemIcons = {
ITEM_ICON(ITEM_DUNGEON_MAP),
ITEM_ICON(ITEM_KEY_SMALL),
ITEM_ICON(ITEM_MAGIC_SMALL),
ITEM_ICON(ITEM_MAGIC_LARGE)
ITEM_ICON(ITEM_MAGIC_LARGE),
ITEM_ICON(RG_TRIFORCE_PIECE),
};

std::map<int32_t, int32_t> randomizerGetToItemIdIcon = {
Expand Down Expand Up @@ -626,6 +627,7 @@ std::map<int32_t, int32_t> randomizerGetToItemIdIcon = {
{ RG_BUY_RED_POTION_40, ITEM_POTION_RED },
{ RG_BUY_RED_POTION_50, ITEM_POTION_RED },
{ RG_TYCOON_WALLET, ITEM_WALLET_GIANT },
{ RG_TRIFORCE_PIECE, RG_TRIFORCE_PIECE },
};

int32_t SohUtils::GetItemIdIconFromRandomizerGet(int32_t randomizerGet) {
Expand Down
10 changes: 6 additions & 4 deletions soh/src/code/z_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2200,10 +2200,12 @@ u8 Item_Give(PlayState* play, u8 item) {
gSaveContext.sohStats.heartPieces++;
if (CVarGetInteger("gFromGI", 0)) {
gSaveContext.healthAccumulator = 0x140;
if ((s32)(gSaveContext.inventory.questItems & 0xF0000000) == 0x40000000) {
gSaveContext.inventory.questItems ^= 0x40000000;
gSaveContext.healthCapacity += 0x10;
gSaveContext.health += 0x10;
s32 heartPieces = (s32)(gSaveContext.inventory.questItems & 0xF0000000) >> (QUEST_HEART_PIECE + 4);
if (heartPieces >= 4) {
gSaveContext.inventory.questItems &= ~0xF0000000;
gSaveContext.inventory.questItems += (heartPieces % 4) << (QUEST_HEART_PIECE + 4);
gSaveContext.healthCapacity += 0x10 * (heartPieces / 4);
gSaveContext.health += 0x10 * (heartPieces / 4);
}
}
return Return_Item(item, MOD_NONE, ITEM_NONE);
Expand Down
10 changes: 0 additions & 10 deletions soh/src/code/z_play.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include <overlays/actors/ovl_En_Niw/z_en_niw.h>
#include "soh/Enhancements/enhancementTypes.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#ifdef ENABLE_REMOTE_CONTROL
#include "soh/Enhancements/game-interactor/GameInteractor_Anchor.h"
#endif

#include <libultraship/libultraship.h>

Expand Down Expand Up @@ -748,13 +745,6 @@ void Play_Init(GameState* thisx) {
GET_PLAYER(play)->actor.world.pos.y + Player_GetHeight(GET_PLAYER(play)) + 5.0f,
GET_PLAYER(play)->actor.world.pos.z, 0, 0, 0, 1, true);
}
#ifdef ENABLE_REMOTE_CONTROL
// #region SOH [Co-op]
if (CVarGetInteger("gRemote.Scheme", 0) == GI_SCHEME_ANCHOR) {
Anchor_SpawnClientFairies();
}
// #endregion
#endif
}

void Play_Update(PlayState* play) {
Expand Down

0 comments on commit 6665319

Please sign in to comment.