Skip to content

Commit

Permalink
Merge branch 'anchor-player-models' into anchor-player-models-purple
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpleHato authored Sep 6, 2023
2 parents c24fe89 + 907a9ef commit afe13ed
Show file tree
Hide file tree
Showing 12 changed files with 328 additions and 74 deletions.
4 changes: 4 additions & 0 deletions soh/include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1143,9 +1143,13 @@ s32 Player_ActionToExplosive(Player* player, s32 actionParam);
s32 Player_GetExplosiveHeld(Player* player);
s32 func_8008F2BC(Player* player, s32 actionParam);
s32 func_8008F2F8(PlayState* play);
void DrawAnchorPuppet(PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount, s32 lod, s32 tunic,
s32 boots, s32 face, OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw,
void* this, PlayerData playerData);
void func_8008F470(PlayState* play, void** skeleton, Vec3s* jointTable, s32 dListCount, s32 lod, s32 tunic,
s32 boots, s32 face, OverrideLimbDrawOpa overrideLimbDraw, PostLimbDrawOpa postLimbDraw, void* this);
s32 func_8008FCC8(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* data);
s32 PuppetOverrideDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* data);
s32 func_80090014(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* data);
s32 func_800902F0(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* data);
s32 func_80090440(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* data);
Expand Down
8 changes: 8 additions & 0 deletions soh/include/z64player.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,14 @@ typedef struct Player {
// #endregion
u8 ivanFloating;
u8 ivanDamageMultiplier;
// #region SOH [Network]
// Upstream TODO: Rename this to make it more obvious it is apart of an enhancement
/* */ s16 unk_00;
/* */ s16 unk_02;
/* */ s16 unk_04;
/* */ s16 unk_06;
/* */ s16 unk_08;
// #endregion
} Player; // size = 0xA94

#endif
13 changes: 13 additions & 0 deletions soh/include/z64save.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ typedef struct {
u8 damageValue;
s16 playerHealth;
s16 playerHealthCapacity;
s32 strengthValue;
f32 yOffset;
u8 currentMask;
u8 swordEquipped;
u32 playerStateFlags1;
u8 moveFlags;
f32 unk_6C4;
s16 unk_00;
s16 unk_02;
s16 unk_04;
s16 unk_06;
s16 unk_08;
f32 speedXZ;
} PlayerData;

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion soh/soh/ActorDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ static ActorDBInit EnLinkPuppetInit = {
"En_Link_Puppet",
"Puppet",
ACTORCAT_ITEMACTION,
(ACTOR_FLAG_UPDATE_WHILE_CULLED | ACTOR_FLAG_DRAW_WHILE_CULLED),
(ACTOR_FLAG_TARGETABLE | ACTOR_FLAG_UPDATE_WHILE_CULLED | ACTOR_FLAG_DRAW_WHILE_CULLED),
OBJECT_LINK_BOY,
sizeof(LinkPuppet),
(ActorFunc)LinkPuppet_Init,
Expand Down
64 changes: 55 additions & 9 deletions soh/soh/Enhancements/game-interactor/GameInteractor_Anchor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <soh/Enhancements/item-tables/ItemTableManager.h>
#include <soh/Enhancements/randomizer/randomizerTypes.h>
#include <soh/Enhancements/randomizer/adult_trade_shuffle.h>
#include <overlays/actors/ovl_Link_Puppet/z_link_puppet.h>
#include <soh/Enhancements/nametag.h>
#include <soh/util.h>
#include <nlohmann/json.hpp>
Expand All @@ -15,6 +16,7 @@ extern "C" {
#include "z64scene.h"
#include "z64actor.h"
#include "functions.h"

extern "C" s16 gEnLinkPuppetId;
extern PlayState* gPlayState;
extern SaveContext gSaveContext;
Expand Down Expand Up @@ -51,6 +53,19 @@ void from_json(const json& j, PlayerData& playerData) {
j.at("damageValue").get_to(playerData.damageValue);
j.at("playerHealth").get_to(playerData.playerHealth);
j.at("playerHealthCapacity").get_to(playerData.playerHealthCapacity);
j.at("strengthValue").get_to(playerData.strengthValue);
j.at("yOffset").get_to(playerData.yOffset);
j.at("currentMask").get_to(playerData.currentMask);
j.at("swordEquipped").get_to(playerData.swordEquipped);
j.at("playerStateFlags1").get_to(playerData.playerStateFlags1);
j.at("moveFlags").get_to(playerData.moveFlags);
j.at("unk_6C4").get_to(playerData.unk_6C4);
j.at("unk_00").get_to(playerData.unk_00);
j.at("unk_02").get_to(playerData.unk_02);
j.at("unk_04").get_to(playerData.unk_04);
j.at("unk_06").get_to(playerData.unk_06);
j.at("unk_08").get_to(playerData.unk_08);
j.at("speedXZ").get_to(playerData.speedXZ);
}

void to_json(json& j, const PlayerData& playerData) {
Expand All @@ -69,8 +84,20 @@ void to_json(json& j, const PlayerData& playerData) {
{ "damageValue", playerData.damageValue },
{ "playerHealth", playerData.playerHealth },
{ "playerHealthCapacity", playerData.playerHealthCapacity },
{ "strengthValue", playerData.strengthValue },
{ "yOffset", playerData.yOffset },
{ "currentMask", playerData.currentMask },
{ "swordEquipped", playerData.swordEquipped },
{ "playerStateFlags1", playerData.playerStateFlags1 },
{ "moveFlags", playerData.moveFlags },
{ "unk_6C4", playerData.unk_6C4 },
{ "unk_00", playerData.unk_00 },
{ "unk_02", playerData.unk_02 },
{ "unk_04", playerData.unk_04 },
{ "unk_06", playerData.unk_06 },
{ "unk_08", playerData.unk_08 },
{ "speedXZ", playerData.speedXZ },
};

}

void to_json(json& j, const Vec3f& vec) {
Expand Down Expand Up @@ -225,7 +252,7 @@ void from_json(const json& j, SaveContext& saveContext) {

std::map<uint32_t, AnchorClient> GameInteractorAnchor::AnchorClients = {};
std::vector<uint32_t> GameInteractorAnchor::FairyIndexToClientId = {};
std::string GameInteractorAnchor::clientVersion = "Anchor + Player Models 1";
std::string GameInteractorAnchor::clientVersion = "Anchor + Player Models 2";
std::string GameInteractorAnchor::seed = "00000";
std::vector<std::pair<uint16_t, int16_t>> receivedItems = {};
std::vector<AnchorMessage> anchorMessages = {};
Expand Down Expand Up @@ -618,6 +645,15 @@ Vec3s* Anchor_GetClientJointTable(uint32_t puppetIndex) {
return GameInteractorAnchor::AnchorClients[clientId].jointTable;
}

const char* Anchor_GetClientName(uint32_t fairyIndex) {
uint32_t clientId = GameInteractorAnchor::FairyIndexToClientId[fairyIndex];
if (GameInteractorAnchor::AnchorClients.find(clientId) == GameInteractorAnchor::AnchorClients.end()) {
return "";
}

return GameInteractorAnchor::AnchorClients[clientId].name.c_str();
}

uint8_t Anchor_GetClientRoomIndex(uint32_t fairyIndex) {
uint32_t clientId = GameInteractorAnchor::FairyIndexToClientId[fairyIndex];
if (GameInteractorAnchor::AnchorClients.find(clientId) == GameInteractorAnchor::AnchorClients.end()) {
Expand Down Expand Up @@ -651,13 +687,10 @@ void Anchor_SpawnClientFairies() {
uint32_t i = 0;
for (auto [clientId, client] : GameInteractorAnchor::AnchorClients) {
GameInteractorAnchor::FairyIndexToClientId.push_back(clientId);
auto fairy = Actor_Spawn(&gPlayState->actorCtx, gPlayState, gEnLinkPuppetId, -9999.0, -9999.0, -9999.0, 0, 0, 0, 3 + i, false);

PlayerData playerData = Anchor_GetClientPlayerData(i);
Actor_Spawn(&gPlayState->actorCtx, gPlayState, gEnLinkPuppetId, -9999.0, -9999.0, -9999.0, 0, 0, 0, 3 + i,
false);

NameTagOptions options = NameTagOptions();
options.yOffset = playerData.playerAge == LINK_AGE_ADULT ? 50.0f : 26.0f;
NameTag_RegisterForActorWithOptions(fairy, client.name.c_str(), options);
i++;
}
}
Expand Down Expand Up @@ -765,6 +798,21 @@ void Anchor_RegisterHooks() {
gSaveContext.playerData.playerAge = gSaveContext.linkAge;
gSaveContext.playerData.playerHealth = gSaveContext.health;
gSaveContext.playerData.playerHealthCapacity = gSaveContext.healthCapacity;
gSaveContext.playerData.strengthValue = CUR_UPG_VALUE(UPG_STRENGTH);
gSaveContext.playerData.yOffset = player->actor.shape.yOffset;
gSaveContext.playerData.currentMask = player->currentMask;
gSaveContext.playerData.swordEquipped = gSaveContext.equips.buttonItems[0];
gSaveContext.playerData.playerStateFlags1 = player->stateFlags1;
gSaveContext.playerData.moveFlags = player->skelAnime.moveFlags;
gSaveContext.playerData.unk_6C4 = player->unk_6C4;
gSaveContext.playerData.unk_00 = player->unk_00;
gSaveContext.playerData.unk_02 = player->unk_02;
gSaveContext.playerData.unk_04 = player->unk_04;
gSaveContext.playerData.unk_06 = player->unk_06;
gSaveContext.playerData.unk_08 = player->unk_08;
gSaveContext.playerData.speedXZ = player->actor.speedXZ;

payload["playerData"] = gSaveContext.playerData;

payload["type"] = "CLIENT_UPDATE";
payload["sceneNum"] = gPlayState->sceneNum;
Expand All @@ -776,8 +824,6 @@ void Anchor_RegisterHooks() {
playerPosRot.rot = player->actor.shape.rot;
payload["posRot"] = playerPosRot;

payload["playerData"] = gSaveContext.playerData;

std::vector<Vec3s> jointTable = {};
for (int i = 0; i < 23; i++) {
jointTable.push_back(player->skelAnime.jointTable[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void Anchor_PushSaveStateToRemote();
void Anchor_RequestSaveStateFromRemote();
uint8_t Anchor_GetClientScene(uint32_t fairyIndex);
PosRot Anchor_GetClientPosition(uint32_t fairyIndex);
const char* Anchor_GetClientName(uint32_t fairyIndex);
uint8_t Anchor_GetClientRoomIndex(uint32_t fairyIndex);
Vec3s* Anchor_GetClientJointTable(uint32_t puppetIndex);
PlayerData Anchor_GetClientPlayerData(uint32_t puppetIndex);
Expand Down
2 changes: 1 addition & 1 deletion soh/soh/Enhancements/nametag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void DrawNameTag(PlayState* play, const NameTag* nameTag) {
alpha = (200000.0f - nameTag->actor->xyzDistToPlayerSq) / 40000.0f;
}

float scale = 75.0f / 100.f;
float scale = 75.0f / 150.f;

size_t numChar = nameTag->processedText.length();
// No text to render
Expand Down
4 changes: 3 additions & 1 deletion soh/src/code/z_map_exp.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,9 @@ void Minimap_DrawCompassIcons(PlayState* play) {
// Other Anchor Players Arrow
Actor* actor = gPlayState->actorCtx.actorLists[ACTORCAT_ITEMACTION].head;
while (actor != NULL) {
if (gEnLinkPuppetId == actor->id && Anchor_GetClientRoomIndex(actor->params - 3) == gPlayState->roomCtx.curRoom.num) {
if (gEnLinkPuppetId == actor->id &&
(Anchor_GetClientRoomIndex(actor->params - 3) == gPlayState->roomCtx.curRoom.num ||
(play->sceneNum >= SCENE_HYRULE_FIELD && play->sceneNum <= SCENE_OUTSIDE_GANONS_CASTLE))) {
if (actor->world.pos.x != -9999.0 && Anchor_GetClientScene(actor->params - 3) == gPlayState->sceneNum) {
Color_RGB8 playerColor = Anchor_GetClientColor(actor->params - 3);

Expand Down
Loading

0 comments on commit afe13ed

Please sign in to comment.