Skip to content

Commit

Permalink
Merge branch 'bs-stuff' of https://github.com/hkAlice/Sapphire into b…
Browse files Browse the repository at this point in the history
…s-stuff-rebase2
  • Loading branch information
takhlaq committed Jun 25, 2024
2 parents b38afc0 + 34fc49f commit e794df5
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
63 changes: 63 additions & 0 deletions src/world/Manager/DebugCommandMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Network/PacketWrappers/ServerNoticePacket.h"
#include "Network/PacketWrappers/ActorControlPacket.h"
#include "Network/PacketWrappers/ActorControlSelfPacket.h"
#include "Network/CommonActorControl.h"
#include "Network/PacketWrappers/MoveActorPacket.h"
#include "Network/PacketWrappers/PlayerSetupPacket.h"
#include "Network/PacketWrappers/PlayerSpawnPacket.h"
Expand Down Expand Up @@ -83,6 +84,7 @@ DebugCommandMgr::DebugCommandMgr()
registerCommand( "cf", &DebugCommandMgr::contentFinder, "Content-Finder", 1 );
registerCommand( "ew", &DebugCommandMgr::easyWarp, "Easy warping", 1 );
registerCommand( "reload", &DebugCommandMgr::hotReload, "Reloads a resource", 1 );
registerCommand( "cbt", &DebugCommandMgr::cbt, "Create, bind and teleport to an instance", 1 );
}

// clear all loaded commands
Expand Down Expand Up @@ -854,6 +856,7 @@ void DebugCommandMgr::script( char* data, Entity::Player& player, std::shared_pt

void DebugCommandMgr::instance( char* data, Entity::Player& player, std::shared_ptr< DebugCommand > command )
{
auto& server = Common::Service< World::WorldServer >::ref();
auto& terriMgr = Common::Service< TerritoryMgr >::ref();
auto pCurrentZone = terriMgr.getTerritoryByGuId( player.getTerritoryId() );

Expand Down Expand Up @@ -1114,6 +1117,14 @@ void DebugCommandMgr::instance( char* data, Entity::Player& player, std::shared_
if( auto instance = pCurrentZone->getAsInstanceContent() )
instance->setCurrentBGM( bgmId );
}
else if( subCommand == "dir_update" ) {
uint32_t dirType;
uint32_t param;
sscanf( params.c_str(), "%x %d", &dirType, &param );
if( auto instance = pCurrentZone->getAsInstanceContent() )
server.queueForPlayer( player.getCharacterId(), makeActorControlSelf( player.getId(), Network::ActorControl::DirectorUpdate, instance->getDirectorId(),
dirType, param ) );
}
else
{
PlayerMgr::sendDebug( player, "Unknown sub command." );
Expand Down Expand Up @@ -1441,6 +1452,58 @@ void DebugCommandMgr::contentFinder( char *data, Sapphire::Entity::Player &playe

}

void DebugCommandMgr::cbt( char* data, Sapphire::Entity::Player& player, std::shared_ptr< DebugCommand > command )
{
std::string subCommand;
std::string params = "";

// check if the command has parameters
std::string tmpCommand = std::string( data + command->getName().length() + 1 );

std::size_t pos = tmpCommand.find_first_of( ' ' );

if( pos != std::string::npos )
// command has parameters, grab the first part
subCommand = tmpCommand.substr( 0, pos );
else
// no subcommand given
subCommand = tmpCommand;

if( command->getName().length() + 1 + pos + 1 < strlen( data ) )
params = std::string( data + command->getName().length() + 1 + pos + 1 );

auto& terriMgr = Common::Service< TerritoryMgr >::ref();
auto& warpMgr = Common::Service< WarpMgr >::ref();

uint32_t contentFinderConditionId;
sscanf( params.c_str(), "%d", &contentFinderConditionId );

auto instance = terriMgr.createInstanceContent( contentFinderConditionId );
if( instance )
PlayerMgr::sendDebug( player, "Created instance with id#{0} -> {1}", instance->getGuId(), instance->getName() );
else
return PlayerMgr::sendDebug( player, "Failed to create instance with id#{0}", contentFinderConditionId );


auto terri = terriMgr.getTerritoryByGuId( instance->getGuId() );
if( terri )
{
auto pInstanceContent = terri->getAsInstanceContent();
if( !pInstanceContent )
{
PlayerMgr::sendDebug( player, "Instance id#{} is not an InstanceContent territory.", pInstanceContent->getGuId() );
return;
}

pInstanceContent->bindPlayer( player.getId() );
PlayerMgr::sendDebug( player,
"Now bound to instance with id: " + std::to_string( pInstanceContent->getGuId() ) +
" -> " + pInstanceContent->getName() );

warpMgr.requestMoveTerritory( player, Common::WarpType::WARP_TYPE_INSTANCE_CONTENT, instance->getGuId(), { 0.f, 0.f, 0.f }, 0.f );
}
}

void DebugCommandMgr::easyWarp( char* data, Sapphire::Entity::Player& player, std::shared_ptr< DebugCommand > command )
{
std::string subCommand;
Expand Down
2 changes: 2 additions & 0 deletions src/world/Manager/DebugCommandMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace Sapphire::World::Manager

void contentFinder( char* data, Entity::Player& player, std::shared_ptr< DebugCommand > command );

void cbt( char* data, Entity::Player& player, std::shared_ptr< DebugCommand > command );

void easyWarp( char* data, Entity::Player& player, std::shared_ptr< DebugCommand > command );

void hotReload( char* data, Sapphire::Entity::Player& player, std::shared_ptr< DebugCommand > command );
Expand Down
4 changes: 2 additions & 2 deletions src/world/Territory/InstanceContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,15 +661,15 @@ void Sapphire::InstanceContent::setCurrentBGM( uint16_t bgmIndex )
auto player = playerIt.second;
server.queueForPlayer( player->getCharacterId(),
makeActorControlSelf( player->getId(), DirectorUpdate, getDirectorId(),
DirectorEventId::BattleGroundMusic, bgmIndex ) );
DirectorEventId::BGM, bgmIndex ) );
}
}

void Sapphire::InstanceContent::setPlayerBGM( Sapphire::Entity::Player& player, uint16_t bgmId )
{
auto& server = Common::Service< World::WorldServer >::ref();
server.queueForPlayer( player.getCharacterId(), makeActorControlSelf( player.getId(), DirectorUpdate, getDirectorId(),
DirectorEventId::BattleGroundMusic, bgmId ) );
DirectorEventId::BGM, bgmId ) );
}

uint16_t Sapphire::InstanceContent::getCurrentBGM() const
Expand Down
11 changes: 10 additions & 1 deletion src/world/Territory/InstanceContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ namespace Sapphire
0x4000000E - INSTANCE_CONTENT_ORDER_SYSTEM_Unknown - no args - some timer set */
enum DirectorEventId : uint32_t
{
// 2.3
DEBUG_TimeSync = 0xC0000001,
DutyCommence = 0x40000001,
DutyComplete = 0x40000002,
SetStringendoMode = 0x40000003,
SetDutyTime = 0x40000004,
LoadingScreen = 0x40000005,
Forward = 0x40000006,
BattleGroundMusic = 0x40000007,
//BattleGroundMusic = 0x40000007,
InvalidateTodoList = 0x40000008,
VoteState = 0x40000009,
VoteStart = 0x4000000A,
Expand All @@ -53,6 +54,14 @@ namespace Sapphire
FirstTimeNotify = 0x4000000D,
TreasureVoteRefresh = 0x4000000E,
SetSharedGroupId = 0x4000000F,
// 3.3x onwards
Sync = 0x80000000,
BGM = 0x80000001,
SyncDutyTimer = 0x80000003,
// some vote stuff here
StartEventCutscene = 0x80000008,
EndEventCutscene = 0x80000009,
StartQTE = 0x8000000A
};

enum EventHandlerOrderId : uint32_t
Expand Down

0 comments on commit e794df5

Please sign in to comment.