Compare commits

..

2 Commits

Author SHA1 Message Date
jadebenn
24dae98ec8 LTO only on release 2024-04-08 22:29:56 -05:00
jadebenn
7e72febc80 add lto support 2024-04-05 21:06:10 -05:00
53 changed files with 2266 additions and 3441 deletions

View File

@@ -9,6 +9,18 @@ set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # Set CMAKE visibility policy to NEW on p
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) # Set C and C++ symbol visibility to hide inlined functions
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# Check if link-time-optimization is supported and apply it if possible in release builds
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if(supported)
message(STATUS "IPO / LTO enabled")
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
else()
message(STATUS "IPO / LTO not supported: <${error}>")
endif()
# Read variables from file
FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables)
@@ -73,8 +85,7 @@ if(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -O2 -fPIC")
elseif(MSVC)
# Skip warning for invalid conversion from size_t to uint32_t for all targets below for now
# Also disable non-portable MSVC volatile behavior
add_compile_options("/wd4267" "/utf-8" "/volatile:iso")
add_compile_options("/wd4267" "/utf-8")
elseif(WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()

View File

@@ -120,8 +120,6 @@ void CatchUnhandled(int sig) {
if (eptr) std::rethrow_exception(eptr);
} catch(const std::exception& e) {
LOG("Caught exception: '%s'", e.what());
} catch (...) {
LOG("Caught unknown exception.");
}
#ifndef INCLUDE_BACKTRACE

View File

@@ -156,9 +156,8 @@ namespace GeneralUtils {
* @returns An std::optional containing the desired value if it is equivalent to the string
*/
template <Numeric T>
[[nodiscard]] std::optional<T> TryParse(std::string_view str) {
[[nodiscard]] std::optional<T> TryParse(const std::string_view str) {
numeric_parse_t<T> result;
while (!str.empty() && std::isspace(str.front())) str.remove_prefix(1);
const char* const strEnd = str.data() + str.size();
const auto [parseEnd, ec] = std::from_chars(str.data(), strEnd, result);
@@ -182,10 +181,8 @@ namespace GeneralUtils {
* @returns An std::optional containing the desired value if it is equivalent to the string
*/
template <std::floating_point T>
[[nodiscard]] std::optional<T> TryParse(std::string_view str) noexcept
[[nodiscard]] std::optional<T> TryParse(const std::string_view str) noexcept
try {
while (!str.empty() && std::isspace(str.front())) str.remove_prefix(1);
size_t parseNum;
const T result = details::_parse<T>(str, parseNum);
const bool isParsed = str.length() == parseNum;

View File

@@ -790,10 +790,9 @@ enum class eGameMessageType : uint16_t {
GET_MISSION_TYPE_STATES = 853,
GET_TIME_PLAYED = 854,
SET_MISSION_VIEWED = 855,
HKX_VEHICLE_LOADED = 856,
SLASH_COMMAND_TEXT_FEEDBACK = 857,
SLASH_COMMAND_TEXT_FEEDBACK = 856,
HANDLE_SLASH_COMMAND_KORE_DEBUGGER = 857,
BROADCAST_TEXT_TO_CHATBOX = 858,
HANDLE_SLASH_COMMAND_KORE_DEBUGGER = 859,
OPEN_PROPERTY_MANAGEMENT = 860,
OPEN_PROPERTY_VENDOR = 861,
VOTE_ON_PROPERTY = 862,

View File

@@ -27,9 +27,12 @@ Character::Character(uint32_t id, User* parentUser) {
m_ID = id;
m_ParentUser = parentUser;
m_OurEntity = nullptr;
m_Doc = nullptr;
}
Character::~Character() {
if (m_Doc) delete m_Doc;
m_Doc = nullptr;
m_OurEntity = nullptr;
m_ParentUser = nullptr;
}
@@ -52,6 +55,8 @@ void Character::UpdateInfoFromDatabase() {
m_ZoneInstanceID = 0; //These values don't really matter, these are only used on the char select screen and seem unused.
m_ZoneCloneID = 0;
m_Doc = nullptr;
//Quickly and dirtly parse the xmlData to get the info we need:
DoQuickXMLDataParse();
@@ -65,13 +70,18 @@ void Character::UpdateInfoFromDatabase() {
}
void Character::UpdateFromDatabase() {
if (m_Doc) delete m_Doc;
UpdateInfoFromDatabase();
}
void Character::DoQuickXMLDataParse() {
if (m_XMLData.size() == 0) return;
if (m_Doc.Parse(m_XMLData.c_str(), m_XMLData.size()) == 0) {
delete m_Doc;
m_Doc = new tinyxml2::XMLDocument();
if (!m_Doc) return;
if (m_Doc->Parse(m_XMLData.c_str(), m_XMLData.size()) == 0) {
LOG("Loaded xmlData for character %s (%i)!", m_Name.c_str(), m_ID);
} else {
LOG("Failed to load xmlData!");
@@ -79,7 +89,7 @@ void Character::DoQuickXMLDataParse() {
return;
}
tinyxml2::XMLElement* mf = m_Doc.FirstChildElement("obj")->FirstChildElement("mf");
tinyxml2::XMLElement* mf = m_Doc->FirstChildElement("obj")->FirstChildElement("mf");
if (!mf) {
LOG("Failed to find mf tag!");
return;
@@ -98,7 +108,7 @@ void Character::DoQuickXMLDataParse() {
mf->QueryAttribute("ess", &m_Eyes);
mf->QueryAttribute("ms", &m_Mouth);
tinyxml2::XMLElement* inv = m_Doc.FirstChildElement("obj")->FirstChildElement("inv");
tinyxml2::XMLElement* inv = m_Doc->FirstChildElement("obj")->FirstChildElement("inv");
if (!inv) {
LOG("Char has no inv!");
return;
@@ -131,7 +141,7 @@ void Character::DoQuickXMLDataParse() {
}
tinyxml2::XMLElement* character = m_Doc.FirstChildElement("obj")->FirstChildElement("char");
tinyxml2::XMLElement* character = m_Doc->FirstChildElement("obj")->FirstChildElement("char");
if (character) {
character->QueryAttribute("cc", &m_Coins);
int32_t gm_level = 0;
@@ -195,7 +205,7 @@ void Character::DoQuickXMLDataParse() {
character->QueryAttribute("lzrw", &m_OriginalRotation.w);
}
auto* flags = m_Doc.FirstChildElement("obj")->FirstChildElement("flag");
auto* flags = m_Doc->FirstChildElement("obj")->FirstChildElement("flag");
if (flags) {
auto* currentChild = flags->FirstChildElement();
while (currentChild) {
@@ -229,10 +239,12 @@ void Character::SetBuildMode(bool buildMode) {
}
void Character::SaveXMLToDatabase() {
if (!m_Doc) return;
//For metrics, we'll record the time it took to save:
auto start = std::chrono::system_clock::now();
tinyxml2::XMLElement* character = m_Doc.FirstChildElement("obj")->FirstChildElement("char");
tinyxml2::XMLElement* character = m_Doc->FirstChildElement("obj")->FirstChildElement("char");
if (character) {
character->SetAttribute("gm", static_cast<uint32_t>(m_GMLevel));
character->SetAttribute("cc", m_Coins);
@@ -254,11 +266,11 @@ void Character::SaveXMLToDatabase() {
}
auto emotes = character->FirstChildElement("ue");
if (!emotes) emotes = m_Doc.NewElement("ue");
if (!emotes) emotes = m_Doc->NewElement("ue");
emotes->DeleteChildren();
for (int emoteID : m_UnlockedEmotes) {
auto emote = m_Doc.NewElement("e");
auto emote = m_Doc->NewElement("e");
emote->SetAttribute("id", emoteID);
emotes->LinkEndChild(emote);
@@ -268,15 +280,15 @@ void Character::SaveXMLToDatabase() {
}
//Export our flags:
auto* flags = m_Doc.FirstChildElement("obj")->FirstChildElement("flag");
auto* flags = m_Doc->FirstChildElement("obj")->FirstChildElement("flag");
if (!flags) {
flags = m_Doc.NewElement("flag"); //Create a flags tag if we don't have one
m_Doc.FirstChildElement("obj")->LinkEndChild(flags); //Link it to the obj tag so we can find next time
flags = m_Doc->NewElement("flag"); //Create a flags tag if we don't have one
m_Doc->FirstChildElement("obj")->LinkEndChild(flags); //Link it to the obj tag so we can find next time
}
flags->DeleteChildren(); //Clear it if we have anything, so that we can fill it up again without dupes
for (std::pair<uint32_t, uint64_t> flag : m_PlayerFlags) {
auto* f = m_Doc.NewElement("f");
auto* f = m_Doc->NewElement("f");
f->SetAttribute("id", flag.first);
//Because of the joy that is tinyxml2, it doesn't offer a function to set a uint64 as an attribute.
@@ -289,7 +301,7 @@ void Character::SaveXMLToDatabase() {
// Prevents the news feed from showing up on world transfers
if (GetPlayerFlag(ePlayerFlag::IS_NEWS_SCREEN_VISIBLE)) {
auto* s = m_Doc.NewElement("s");
auto* s = m_Doc->NewElement("s");
s->SetAttribute("si", ePlayerFlag::IS_NEWS_SCREEN_VISIBLE);
flags->LinkEndChild(s);
}
@@ -314,7 +326,7 @@ void Character::SaveXMLToDatabase() {
void Character::SetIsNewLogin() {
// If we dont have a flag element, then we cannot have a s element as a child of flag.
auto* flags = m_Doc.FirstChildElement("obj")->FirstChildElement("flag");
auto* flags = m_Doc->FirstChildElement("obj")->FirstChildElement("flag");
if (!flags) return;
auto* currentChild = flags->FirstChildElement();
@@ -332,7 +344,7 @@ void Character::SetIsNewLogin() {
void Character::WriteToDatabase() {
//Dump our xml into m_XMLData:
tinyxml2::XMLPrinter printer(0, true, 0);
m_Doc.Print(&printer);
m_Doc->Print(&printer);
//Finally, save to db:
Database::Get()->UpdateCharacterXml(m_ID, printer.CStr());
@@ -409,15 +421,15 @@ void Character::SetRetroactiveFlags() {
void Character::SaveXmlRespawnCheckpoints() {
//Export our respawn points:
auto* points = m_Doc.FirstChildElement("obj")->FirstChildElement("res");
auto* points = m_Doc->FirstChildElement("obj")->FirstChildElement("res");
if (!points) {
points = m_Doc.NewElement("res");
m_Doc.FirstChildElement("obj")->LinkEndChild(points);
points = m_Doc->NewElement("res");
m_Doc->FirstChildElement("obj")->LinkEndChild(points);
}
points->DeleteChildren();
for (const auto& point : m_WorldRespawnCheckpoints) {
auto* r = m_Doc.NewElement("r");
auto* r = m_Doc->NewElement("r");
r->SetAttribute("w", point.first);
r->SetAttribute("x", point.second.x);
@@ -431,7 +443,7 @@ void Character::SaveXmlRespawnCheckpoints() {
void Character::LoadXmlRespawnCheckpoints() {
m_WorldRespawnCheckpoints.clear();
auto* points = m_Doc.FirstChildElement("obj")->FirstChildElement("res");
auto* points = m_Doc->FirstChildElement("obj")->FirstChildElement("res");
if (!points) {
return;
}

View File

@@ -37,7 +37,7 @@ public:
void LoadXmlRespawnCheckpoints();
const std::string& GetXMLData() const { return m_XMLData; }
const tinyxml2::XMLDocument& GetXMLDoc() const { return m_Doc; }
tinyxml2::XMLDocument* GetXMLDoc() const { return m_Doc; }
/**
* Out of abundance of safety and clarity of what this saves, this is its own function.
@@ -623,7 +623,7 @@ private:
/**
* The character XML belonging to this character
*/
tinyxml2::XMLDocument m_Doc;
tinyxml2::XMLDocument* m_Doc;
/**
* Title of an announcement this character made (reserved for GMs)

View File

@@ -254,7 +254,7 @@ void Entity::Initialize() {
}
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MINI_GAME_CONTROL) > 0) {
AddComponent<MiniGameControlComponent>(m_TemplateID);
AddComponent<MiniGameControlComponent>();
}
uint32_t possessableComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::POSSESSABLE);
@@ -476,7 +476,8 @@ void Entity::Initialize() {
}
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::INVENTORY) > 0 || m_Character) {
AddComponent<InventoryComponent>();
auto* xmlDoc = m_Character ? m_Character->GetXMLDoc() : nullptr;
AddComponent<InventoryComponent>(xmlDoc);
}
// if this component exists, then we initialize it. it's value is always 0
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::MULTI_ZONE_ENTRANCE, -1) != -1) {
@@ -666,7 +667,7 @@ void Entity::Initialize() {
// Shooting gallery component
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::SHOOTING_GALLERY) > 0) {
AddComponent<ShootingGalleryComponent>(m_TemplateID);
AddComponent<ShootingGalleryComponent>();
}
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PROPERTY, -1) != -1) {
@@ -1243,7 +1244,7 @@ void Entity::WriteComponents(RakNet::BitStream& outBitStream, eReplicaPacketType
outBitStream.Write0();
}
void Entity::UpdateXMLDoc(tinyxml2::XMLDocument& doc) {
void Entity::UpdateXMLDoc(tinyxml2::XMLDocument* doc) {
//This function should only ever be called from within Character, meaning doc should always exist when this is called.
//Naturally, we don't include any non-player components in this update function.
@@ -1634,8 +1635,10 @@ void Entity::PickupItem(const LWOOBJID& objectID) {
CDObjectSkillsTable* skillsTable = CDClientManager::GetTable<CDObjectSkillsTable>();
std::vector<CDObjectSkills> skills = skillsTable->Query([=](CDObjectSkills entry) {return (entry.objectTemplate == p.second.lot); });
for (CDObjectSkills skill : skills) {
CDSkillBehaviorTable* skillBehTable = CDClientManager::GetTable<CDSkillBehaviorTable>();
auto* skillComponent = GetComponent<SkillComponent>();
if (skillComponent) skillComponent->CastSkill(skill.skillID, GetObjectID(), GetObjectID(), skill.castOnType, NiQuaternion(0, 0, 0, 0));
if (skillComponent) skillComponent->CastSkill(skill.skillID, GetObjectID(), GetObjectID());
auto* missionComponent = GetComponent<MissionComponent>();

View File

@@ -174,7 +174,7 @@ public:
void WriteBaseReplicaData(RakNet::BitStream& outBitStream, eReplicaPacketType packetType);
void WriteComponents(RakNet::BitStream& outBitStream, eReplicaPacketType packetType);
void UpdateXMLDoc(tinyxml2::XMLDocument& doc);
void UpdateXMLDoc(tinyxml2::XMLDocument* doc);
void Update(float deltaTime);
// Events

View File

@@ -326,9 +326,9 @@ Entity* BuffComponent::GetParent() const {
return m_Parent;
}
void BuffComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
void BuffComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
// Load buffs
auto* dest = doc.FirstChildElement("obj")->FirstChildElement("dest");
auto* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
// Make sure we have a clean buff element.
auto* buffElement = dest->FirstChildElement("buff");
@@ -386,15 +386,15 @@ void BuffComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
}
}
void BuffComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
void BuffComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
// Save buffs
auto* dest = doc.FirstChildElement("obj")->FirstChildElement("dest");
auto* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
// Make sure we have a clean buff element.
auto* buffElement = dest->FirstChildElement("buff");
if (buffElement == nullptr) {
buffElement = doc.NewElement("buff");
buffElement = doc->NewElement("buff");
dest->LinkEndChild(buffElement);
} else {
@@ -402,7 +402,7 @@ void BuffComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
}
for (const auto& [id, buff] : m_Buffs) {
auto* buffEntry = doc.NewElement("b");
auto* buffEntry = doc->NewElement("b");
// TODO: change this if to if (buff.cancelOnZone || buff.cancelOnLogout) handling at some point. No current way to differentiate between zone transfer and logout.
if (buff.cancelOnZone) continue;

View File

@@ -57,9 +57,9 @@ public:
Entity* GetParent() const;
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
void UpdateXml(tinyxml2::XMLDocument& doc) override;
void UpdateXml(tinyxml2::XMLDocument* doc) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;

View File

@@ -47,6 +47,7 @@ set(DGAME_DCOMPONENTS_SOURCES
"TriggerComponent.cpp"
"HavokVehiclePhysicsComponent.cpp"
"VendorComponent.cpp"
"MiniGameControlComponent.cpp"
"ScriptComponent.cpp"
)

View File

@@ -186,9 +186,9 @@ void CharacterComponent::SetGMLevel(eGameMasterLevel gmlevel) {
m_GMLevel = gmlevel;
}
void CharacterComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
void CharacterComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
auto* character = doc.FirstChildElement("obj")->FirstChildElement("char");
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
if (!character) {
LOG("Failed to find char tag while loading XML!");
return;
@@ -299,8 +299,8 @@ void CharacterComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
}
}
void CharacterComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
tinyxml2::XMLElement* minifig = doc.FirstChildElement("obj")->FirstChildElement("mf");
void CharacterComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
tinyxml2::XMLElement* minifig = doc->FirstChildElement("obj")->FirstChildElement("mf");
if (!minifig) {
LOG("Failed to find mf tag while updating XML!");
return;
@@ -320,7 +320,7 @@ void CharacterComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
// done with minifig
tinyxml2::XMLElement* character = doc.FirstChildElement("obj")->FirstChildElement("char");
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
if (!character) {
LOG("Failed to find char tag while updating XML!");
return;
@@ -338,11 +338,11 @@ void CharacterComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
// Set the zone statistics of the form <zs><s/> ... <s/></zs>
auto zoneStatistics = character->FirstChildElement("zs");
if (!zoneStatistics) zoneStatistics = doc.NewElement("zs");
if (!zoneStatistics) zoneStatistics = doc->NewElement("zs");
zoneStatistics->DeleteChildren();
for (auto pair : m_ZoneStatistics) {
auto zoneStatistic = doc.NewElement("s");
auto zoneStatistic = doc->NewElement("s");
zoneStatistic->SetAttribute("map", pair.first);
zoneStatistic->SetAttribute("ac", pair.second.m_AchievementsCollected);

View File

@@ -70,8 +70,8 @@ public:
CharacterComponent(Entity* parent, Character* character, const SystemAddress& systemAddress);
~CharacterComponent() override;
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
void UpdateXml(tinyxml2::XMLDocument& doc) override;
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
void UpdateXml(tinyxml2::XMLDocument* doc) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;

View File

@@ -21,11 +21,11 @@ void Component::OnUse(Entity* originator) {
}
void Component::UpdateXml(tinyxml2::XMLDocument& doc) {
void Component::UpdateXml(tinyxml2::XMLDocument* doc) {
}
void Component::LoadFromXml(const tinyxml2::XMLDocument& doc) {
void Component::LoadFromXml(tinyxml2::XMLDocument* doc) {
}

View File

@@ -34,13 +34,13 @@ public:
* Save data from this componennt to character XML
* @param doc the document to write data to
*/
virtual void UpdateXml(tinyxml2::XMLDocument& doc);
virtual void UpdateXml(tinyxml2::XMLDocument* doc);
/**
* Load base data for this component from character XML
* @param doc the document to read data from
*/
virtual void LoadFromXml(const tinyxml2::XMLDocument& doc);
virtual void LoadFromXml(tinyxml2::XMLDocument* doc);
virtual void Serialize(RakNet::BitStream& outBitStream, bool isConstruction);

View File

@@ -158,8 +158,8 @@ void ControllablePhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bo
}
}
void ControllablePhysicsComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
auto* character = doc.FirstChildElement("obj")->FirstChildElement("char");
void ControllablePhysicsComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
if (!character) {
LOG("Failed to find char tag!");
return;
@@ -178,8 +178,8 @@ void ControllablePhysicsComponent::LoadFromXml(const tinyxml2::XMLDocument& doc)
m_DirtyPosition = true;
}
void ControllablePhysicsComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
tinyxml2::XMLElement* character = doc.FirstChildElement("obj")->FirstChildElement("char");
void ControllablePhysicsComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
if (!character) {
LOG("Failed to find char tag while updating XML!");
return;

View File

@@ -28,8 +28,8 @@ public:
void Update(float deltaTime) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
void UpdateXml(tinyxml2::XMLDocument& doc) override;
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
void UpdateXml(tinyxml2::XMLDocument* doc) override;
/**
* Sets the position of this entity, also ensures this update is serialized next tick.

View File

@@ -185,8 +185,8 @@ void DestroyableComponent::Update(float deltaTime) {
m_DamageCooldownTimer -= deltaTime;
}
void DestroyableComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
auto* dest = doc.FirstChildElement("obj")->FirstChildElement("dest");
void DestroyableComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
tinyxml2::XMLElement* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
if (!dest) {
LOG("Failed to find dest tag!");
return;
@@ -207,8 +207,8 @@ void DestroyableComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
m_DirtyHealth = true;
}
void DestroyableComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
tinyxml2::XMLElement* dest = doc.FirstChildElement("obj")->FirstChildElement("dest");
void DestroyableComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
tinyxml2::XMLElement* dest = doc->FirstChildElement("obj")->FirstChildElement("dest");
if (!dest) {
LOG("Failed to find dest tag!");
return;

View File

@@ -26,8 +26,8 @@ public:
void Update(float deltaTime) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
void UpdateXml(tinyxml2::XMLDocument& doc) override;
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
void UpdateXml(tinyxml2::XMLDocument* doc) override;
/**
* Initializes the component using a different LOT

View File

@@ -38,7 +38,7 @@
#include "CDObjectSkillsTable.h"
#include "CDSkillBehaviorTable.h"
InventoryComponent::InventoryComponent(Entity* parent) : Component(parent) {
InventoryComponent::InventoryComponent(Entity* parent, tinyxml2::XMLDocument* document) : Component(parent) {
this->m_Dirty = true;
this->m_Equipped = {};
this->m_Pushed = {};
@@ -48,8 +48,7 @@ InventoryComponent::InventoryComponent(Entity* parent) : Component(parent) {
const auto lot = parent->GetLOT();
if (lot == 1) {
auto* character = m_Parent->GetCharacter();
if (character) LoadXml(character->GetXMLDoc());
LoadXml(document);
CheckProxyIntegrity();
@@ -473,10 +472,10 @@ bool InventoryComponent::HasSpaceForLoot(const std::unordered_map<LOT, int32_t>&
return true;
}
void InventoryComponent::LoadXml(const tinyxml2::XMLDocument& document) {
void InventoryComponent::LoadXml(tinyxml2::XMLDocument* document) {
LoadPetXml(document);
auto* inventoryElement = document.FirstChildElement("obj")->FirstChildElement("inv");
auto* inventoryElement = document->FirstChildElement("obj")->FirstChildElement("inv");
if (inventoryElement == nullptr) {
LOG("Failed to find 'inv' xml element!");
@@ -595,10 +594,10 @@ void InventoryComponent::LoadXml(const tinyxml2::XMLDocument& document) {
}
}
void InventoryComponent::UpdateXml(tinyxml2::XMLDocument& document) {
void InventoryComponent::UpdateXml(tinyxml2::XMLDocument* document) {
UpdatePetXml(document);
auto* inventoryElement = document.FirstChildElement("obj")->FirstChildElement("inv");
auto* inventoryElement = document->FirstChildElement("obj")->FirstChildElement("inv");
if (inventoryElement == nullptr) {
LOG("Failed to find 'inv' xml element!");
@@ -632,7 +631,7 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument& document) {
bags->DeleteChildren();
for (const auto* inventory : inventoriesToSave) {
auto* bag = document.NewElement("b");
auto* bag = document->NewElement("b");
bag->SetAttribute("t", inventory->GetType());
bag->SetAttribute("m", static_cast<unsigned int>(inventory->GetSize()));
@@ -655,14 +654,14 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument& document) {
continue;
}
auto* bagElement = document.NewElement("in");
auto* bagElement = document->NewElement("in");
bagElement->SetAttribute("t", inventory->GetType());
for (const auto& pair : inventory->GetItems()) {
auto* item = pair.second;
auto* itemElement = document.NewElement("i");
auto* itemElement = document->NewElement("i");
itemElement->SetAttribute("l", item->GetLot());
itemElement->SetAttribute("id", item->GetId());
@@ -681,7 +680,7 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument& document) {
continue;
}
auto* extraInfo = document.NewElement("x");
auto* extraInfo = document->NewElement("x");
extraInfo->SetAttribute("ma", data->GetString(false).c_str());
@@ -696,20 +695,22 @@ void InventoryComponent::UpdateXml(tinyxml2::XMLDocument& document) {
}
void InventoryComponent::Serialize(RakNet::BitStream& outBitStream, const bool bIsInitialUpdate) {
// LWOInventoryComponent_EquippedItem
outBitStream.Write(bIsInitialUpdate || m_Dirty);
if (bIsInitialUpdate || m_Dirty) {
outBitStream.Write(true);
outBitStream.Write<uint32_t>(m_Equipped.size());
for (const auto& pair : m_Equipped) {
const auto item = pair.second;
if (bIsInitialUpdate) AddItemSkills(item.lot);
if (bIsInitialUpdate) {
AddItemSkills(item.lot);
}
outBitStream.Write(item.id);
outBitStream.Write(item.lot);
outBitStream.Write0(); // subkey
outBitStream.Write0();
outBitStream.Write(item.count > 0);
if (item.count > 0) outBitStream.Write(item.count);
@@ -717,7 +718,7 @@ void InventoryComponent::Serialize(RakNet::BitStream& outBitStream, const bool b
outBitStream.Write(item.slot != 0);
if (item.slot != 0) outBitStream.Write<uint16_t>(item.slot);
outBitStream.Write0(); // inventory type
outBitStream.Write0();
bool flag = !item.config.empty();
outBitStream.Write(flag);
@@ -744,21 +745,11 @@ void InventoryComponent::Serialize(RakNet::BitStream& outBitStream, const bool b
}
m_Dirty = false;
} else {
outBitStream.Write(false);
}
// EquippedModelTransform
outBitStream.Write(false);
/*
outBitStream.Write(bIsInitialUpdate || m_Dirty); // Same dirty or different?
if (bIsInitialUpdate || m_Dirty) {
outBitStream.Write<uint32_t>(m_Equipped.size()); // Equiped models?
for (const auto& [location, item] : m_Equipped) {
outBitStream.Write(item.id);
outBitStream.Write(item.pos);
outBitStream.Write(item.rot);
}
}
*/
}
void InventoryComponent::Update(float deltaTime) {
@@ -1551,8 +1542,8 @@ void InventoryComponent::PurgeProxies(Item* item) {
}
}
void InventoryComponent::LoadPetXml(const tinyxml2::XMLDocument& document) {
auto* petInventoryElement = document.FirstChildElement("obj")->FirstChildElement("pet");
void InventoryComponent::LoadPetXml(tinyxml2::XMLDocument* document) {
auto* petInventoryElement = document->FirstChildElement("obj")->FirstChildElement("pet");
if (petInventoryElement == nullptr) {
m_Pets.clear();
@@ -1583,19 +1574,19 @@ void InventoryComponent::LoadPetXml(const tinyxml2::XMLDocument& document) {
}
}
void InventoryComponent::UpdatePetXml(tinyxml2::XMLDocument& document) {
auto* petInventoryElement = document.FirstChildElement("obj")->FirstChildElement("pet");
void InventoryComponent::UpdatePetXml(tinyxml2::XMLDocument* document) {
auto* petInventoryElement = document->FirstChildElement("obj")->FirstChildElement("pet");
if (petInventoryElement == nullptr) {
petInventoryElement = document.NewElement("pet");
petInventoryElement = document->NewElement("pet");
document.FirstChildElement("obj")->LinkEndChild(petInventoryElement);
document->FirstChildElement("obj")->LinkEndChild(petInventoryElement);
}
petInventoryElement->DeleteChildren();
for (const auto& pet : m_Pets) {
auto* petElement = document.NewElement("p");
auto* petElement = document->NewElement("p");
petElement->SetAttribute("id", pet.first);
petElement->SetAttribute("l", pet.second.lot);

View File

@@ -38,12 +38,12 @@ enum class eItemType : int32_t;
class InventoryComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::INVENTORY;
InventoryComponent(Entity* parent);
explicit InventoryComponent(Entity* parent, tinyxml2::XMLDocument* document = nullptr);
void Update(float deltaTime) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
void LoadXml(const tinyxml2::XMLDocument& document);
void UpdateXml(tinyxml2::XMLDocument& document) override;
void LoadXml(tinyxml2::XMLDocument* document);
void UpdateXml(tinyxml2::XMLDocument* document) override;
/**
* Returns an inventory of the specified type, if it exists
@@ -470,13 +470,13 @@ private:
* Saves all the pet information stored in inventory items to the database
* @param document the xml doc to save to
*/
void LoadPetXml(const tinyxml2::XMLDocument& document);
void LoadPetXml(tinyxml2::XMLDocument* document);
/**
* Loads all the pet information from an xml doc into items
* @param document the xml doc to load from
*/
void UpdatePetXml(tinyxml2::XMLDocument& document);
void UpdatePetXml(tinyxml2::XMLDocument* document);
};
#endif

View File

@@ -2,16 +2,4 @@
void ItemComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
outBitStream.Write0();
/*
outBitStream.Write(isConstruction || m_Dirty); // Same dirty or different?
if (isConstruction || m_Dirty) {
outBitStream.Write(m_parent->GetObjectID());
outBitStream.Write(moderationStatus);
outBitStream.Write(!description.empty());
if (!description.empty()) {
outBitStream.Write<uint32_t>(description.size());
outBitStream.Write(description) // u16string
}
}
*/
}

View File

@@ -13,8 +13,8 @@ LevelProgressionComponent::LevelProgressionComponent(Entity* parent) : Component
m_CharacterVersion = eCharacterVersion::LIVE;
}
void LevelProgressionComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
tinyxml2::XMLElement* level = doc.FirstChildElement("obj")->FirstChildElement("lvl");
void LevelProgressionComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
tinyxml2::XMLElement* level = doc->FirstChildElement("obj")->FirstChildElement("lvl");
if (!level) {
LOG("Failed to find lvl tag while updating XML!");
return;
@@ -24,8 +24,8 @@ void LevelProgressionComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
level->SetAttribute("cv", static_cast<uint32_t>(m_CharacterVersion));
}
void LevelProgressionComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
auto* level = doc.FirstChildElement("obj")->FirstChildElement("lvl");
void LevelProgressionComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
tinyxml2::XMLElement* level = doc->FirstChildElement("obj")->FirstChildElement("lvl");
if (!level) {
LOG("Failed to find lvl tag while loading XML!");
return;

View File

@@ -27,13 +27,13 @@ public:
* Save data from this componennt to character XML
* @param doc the document to write data to
*/
void UpdateXml(tinyxml2::XMLDocument& doc) override;
void UpdateXml(tinyxml2::XMLDocument* doc) override;
/**
* Load base data for this component from character XML
* @param doc the document to read data from
*/
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
/**
* Gets the current level of the entity

View File

@@ -0,0 +1,5 @@
#include "MiniGameControlComponent.h"
void MiniGameControlComponent::Serialize(RakNet::BitStream& outBitStream, bool isConstruction) {
outBitStream.Write<uint32_t>(0x40000000);
}

View File

@@ -1,13 +1,15 @@
#ifndef __MINIGAMECONTROLCOMPONENT__H__
#define __MINIGAMECONTROLCOMPONENT__H__
#include "ActivityComponent.h"
#include "Component.h"
#include "eReplicaComponentType.h"
class MiniGameControlComponent final : public ActivityComponent {
class MiniGameControlComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::MINI_GAME_CONTROL;
MiniGameControlComponent(Entity* parent, LOT lot) : ActivityComponent(parent, lot) {}
MiniGameControlComponent(Entity* parent) : Component(parent) {}
void Serialize(RakNet::BitStream& outBitStream, bool isConstruction);
};
#endif //!__MINIGAMECONTROLCOMPONENT__H__

View File

@@ -504,8 +504,10 @@ bool MissionComponent::RequiresItem(const LOT lot) {
}
void MissionComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
auto* mis = doc.FirstChildElement("obj")->FirstChildElement("mis");
void MissionComponent::LoadFromXml(tinyxml2::XMLDocument* doc) {
if (doc == nullptr) return;
auto* mis = doc->FirstChildElement("obj")->FirstChildElement("mis");
if (mis == nullptr) return;
@@ -521,7 +523,7 @@ void MissionComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
auto* mission = new Mission(this, missionId);
mission->LoadFromXml(*doneM);
mission->LoadFromXml(doneM);
doneM = doneM->NextSiblingElement();
@@ -538,7 +540,7 @@ void MissionComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
auto* mission = new Mission(this, missionId);
mission->LoadFromXml(*currentM);
mission->LoadFromXml(currentM);
if (currentM->QueryAttribute("o", &missionOrder) == tinyxml2::XML_SUCCESS && mission->IsMission()) {
mission->SetUniqueMissionOrderID(missionOrder);
@@ -552,23 +554,25 @@ void MissionComponent::LoadFromXml(const tinyxml2::XMLDocument& doc) {
}
void MissionComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
void MissionComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
if (doc == nullptr) return;
auto shouldInsertMis = false;
auto* obj = doc.FirstChildElement("obj");
auto* obj = doc->FirstChildElement("obj");
auto* mis = obj->FirstChildElement("mis");
if (mis == nullptr) {
mis = doc.NewElement("mis");
mis = doc->NewElement("mis");
shouldInsertMis = true;
}
mis->DeleteChildren();
auto* done = doc.NewElement("done");
auto* cur = doc.NewElement("cur");
auto* done = doc->NewElement("done");
auto* cur = doc->NewElement("cur");
for (const auto& pair : m_Missions) {
auto* mission = pair.second;
@@ -576,10 +580,10 @@ void MissionComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
if (mission) {
const auto complete = mission->IsComplete();
auto* m = doc.NewElement("m");
auto* m = doc->NewElement("m");
if (complete) {
mission->UpdateXml(*m);
mission->UpdateXml(m);
done->LinkEndChild(m);
@@ -587,7 +591,7 @@ void MissionComponent::UpdateXml(tinyxml2::XMLDocument& doc) {
}
if (mission->IsMission()) m->SetAttribute("o", mission->GetUniqueMissionOrderID());
mission->UpdateXml(*m);
mission->UpdateXml(m);
cur->LinkEndChild(m);
}

View File

@@ -31,8 +31,8 @@ public:
explicit MissionComponent(Entity* parent);
~MissionComponent() override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate, unsigned int& flags);
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
void UpdateXml(tinyxml2::XMLDocument& doc) override;
void LoadFromXml(tinyxml2::XMLDocument* doc) override;
void UpdateXml(tinyxml2::XMLDocument* doc) override;
/**
* Returns all the missions for this entity, mapped by mission ID

View File

@@ -2,6 +2,11 @@
#include "EntityManager.h"
#include "ScriptedActivityComponent.h"
ShootingGalleryComponent::ShootingGalleryComponent(Entity* parent) : Component(parent) {
}
ShootingGalleryComponent::~ShootingGalleryComponent() = default;
void ShootingGalleryComponent::SetStaticParams(const StaticShootingGalleryParams& params) {
m_StaticParams = params;
}
@@ -12,15 +17,20 @@ void ShootingGalleryComponent::SetDynamicParams(const DynamicShootingGalleryPara
Game::entityManager->SerializeEntity(m_Parent);
}
void ShootingGalleryComponent::SetCurrentPlayerID(LWOOBJID playerID) {
m_CurrentPlayerID = playerID;
m_Dirty = true;
AddActivityPlayerData(playerID);
};
void ShootingGalleryComponent::Serialize(RakNet::BitStream& outBitStream, bool isInitialUpdate) {
ActivityComponent::Serialize(outBitStream, isInitialUpdate);
// Start ScriptedActivityComponent
outBitStream.Write<bool>(true);
if (m_CurrentPlayerID == LWOOBJID_EMPTY) {
outBitStream.Write<uint32_t>(0);
} else {
outBitStream.Write<uint32_t>(1);
outBitStream.Write<LWOOBJID>(m_CurrentPlayerID);
for (size_t i = 0; i < 10; i++) {
outBitStream.Write<float_t>(0.0f);
}
}
// End ScriptedActivityComponent
if (isInitialUpdate) {
outBitStream.Write<float_t>(m_StaticParams.cameraPosition.GetX());

View File

@@ -2,7 +2,7 @@
#include "dCommonVars.h"
#include "NiPoint3.h"
#include "Entity.h"
#include "ActivityComponent.h"
#include "Component.h"
#include "eReplicaComponentType.h"
/**
@@ -71,11 +71,12 @@ struct StaticShootingGalleryParams {
* A very ancient component that was used to guide shooting galleries, it's still kind of used but a lot of logic is
* also in the related scripts.
*/
class ShootingGalleryComponent final : public ActivityComponent {
class ShootingGalleryComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SHOOTING_GALLERY;
explicit ShootingGalleryComponent(Entity* parent, LOT lot) : ActivityComponent(parent, lot) {}
explicit ShootingGalleryComponent(Entity* parent);
~ShootingGalleryComponent();
void Serialize(RakNet::BitStream& outBitStream, bool isInitialUpdate) override;
/**
@@ -106,8 +107,13 @@ public:
* Sets the entity that's currently playing the shooting gallery
* @param playerID the entity to set
*/
void SetCurrentPlayerID(LWOOBJID playerID);
void SetCurrentPlayerID(LWOOBJID playerID) { m_CurrentPlayerID = playerID; m_Dirty = true; };
/**
* Returns the player that's currently playing the shooting gallery
* @return the player that's currently playing the shooting gallery
*/
LWOOBJID GetCurrentPlayerID() const { return m_CurrentPlayerID; };
private:
/**

View File

@@ -227,7 +227,7 @@ void SkillComponent::RegisterCalculatedProjectile(const LWOOBJID projectileId, B
this->m_managedProjectiles.push_back(entry);
}
bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LWOOBJID optionalOriginatorID, const int32_t castType, const NiQuaternion rotationOverride) {
bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LWOOBJID optionalOriginatorID) {
uint32_t behaviorId = -1;
// try to find it via the cache
const auto& pair = m_skillBehaviorCache.find(skillId);
@@ -247,19 +247,11 @@ bool SkillComponent::CastSkill(const uint32_t skillId, LWOOBJID target, const LW
return false;
}
return CalculateBehavior(skillId, behaviorId, target, false, false, optionalOriginatorID, castType, rotationOverride).success;
return CalculateBehavior(skillId, behaviorId, target, false, false, optionalOriginatorID).success;
}
SkillExecutionResult SkillComponent::CalculateBehavior(
const uint32_t skillId,
const uint32_t behaviorId,
const LWOOBJID target,
const bool ignoreTarget,
const bool clientInitalized,
const LWOOBJID originatorOverride,
const int32_t castType,
const NiQuaternion rotationOverride) {
SkillExecutionResult SkillComponent::CalculateBehavior(const uint32_t skillId, const uint32_t behaviorId, const LWOOBJID target, const bool ignoreTarget, const bool clientInitalized, const LWOOBJID originatorOverride) {
RakNet::BitStream bitStream{};
auto* behavior = Behavior::CreateBehavior(behaviorId);
@@ -291,7 +283,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior(
// Echo start skill
EchoStartSkill start;
start.iCastType = castType;
start.iCastType = 0;
start.skillID = skillId;
start.uiSkillHandle = context->skillUId;
start.optionalOriginatorID = context->originator;
@@ -302,10 +294,6 @@ SkillExecutionResult SkillComponent::CalculateBehavior(
if (originator != nullptr) {
start.originatorRot = originator->GetRotation();
}
if (rotationOverride != NiQuaternionConstant::IDENTITY) {
start.originatorRot = rotationOverride;
}
//start.optionalTargetID = target;
start.sBitStream.assign(reinterpret_cast<char*>(bitStream.GetData()), bitStream.GetNumberOfBytesUsed());
@@ -476,7 +464,7 @@ void SkillComponent::HandleUnCast(const uint32_t behaviorId, const LWOOBJID targ
behavior->UnCast(&context, { target });
}
SkillComponent::SkillComponent(Entity* parent) : Component(parent) {
SkillComponent::SkillComponent(Entity* parent): Component(parent) {
this->m_skillUid = 0;
}
@@ -486,32 +474,6 @@ SkillComponent::~SkillComponent() {
void SkillComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
if (bIsInitialUpdate) outBitStream.Write0();
/*
outBitStream.Write(bIsInitialUpdate && !m_managedBehaviors.empty());
if (bIsInitialUpdate && !m_managedBehaviors.empty()) {
outBitStream.Write<uint32_t>(m_managedBehaviors.size());
for (const auto& [id, skill] : m_managedBehaviors) {
outBitStream.Write(skill.skillUID);
outBitStream.Write(skill.skillID);
outBitStream.Write(skill.cast_type);
outBitStream.Write(skill.cancel_type);
outBitStream.Write(skill.behavior_count);
for (auto& index : skill.behavior_count) {
outBitStream.Write<uint32_t>(behaviorUID); // Maybe
outBitStream.Write<uint32_t>(action);
outBitStream.Write<uint32_t>(wait_time_ms);
outBitStream.Write<uint32_t>(template_id);
outBitStream.Write(casterObjId);
outBitStream.Write(originatorObjId);
outBitStream.Write(targetObjId);
outBitStream.Write<bool>(usedMouse);
outBitStream.Write(cooldown);
outBitStream.Write(charge_time);
outBitStream.Write(imagination_cost);
}
}
}
*/
}
/// <summary>

View File

@@ -127,7 +127,7 @@ public:
* @param optionalOriginatorID change the originator of the skill
* @return if the case succeeded
*/
bool CastSkill(const uint32_t skillId, LWOOBJID target = LWOOBJID_EMPTY, const LWOOBJID optionalOriginatorID = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = NiQuaternionConstant::IDENTITY);
bool CastSkill(const uint32_t skillId, LWOOBJID target = LWOOBJID_EMPTY, const LWOOBJID optionalOriginatorID = LWOOBJID_EMPTY);
/**
* Initializes a server-side skill calculation.
@@ -139,7 +139,7 @@ public:
* @param originatorOverride an override for the originator of the skill calculation
* @return the result of the skill calculation
*/
SkillExecutionResult CalculateBehavior(uint32_t skillId, uint32_t behaviorId, LWOOBJID target, bool ignoreTarget = false, bool clientInitalized = false, LWOOBJID originatorOverride = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = NiQuaternionConstant::IDENTITY);
SkillExecutionResult CalculateBehavior(uint32_t skillId, uint32_t behaviorId, LWOOBJID target, bool ignoreTarget = false, bool clientInitalized = false, LWOOBJID originatorOverride = LWOOBJID_EMPTY);
/**
* Register a server-side projectile.

View File

@@ -4660,7 +4660,7 @@ void GameMessages::HandleBuyFromVendor(RakNet::BitStream& inStream, Entity* enti
if (!user) return;
Entity* player = Game::entityManager->GetEntity(user->GetLoggedInChar());
if (!player) return;
// handle buying normal items
auto* vendorComponent = entity->GetComponent<VendorComponent>();
if (vendorComponent) {
@@ -5290,7 +5290,7 @@ void GameMessages::HandleRemoveItemFromInventory(RakNet::BitStream& inStream, En
bool iLootTypeSourceIsDefault = false;
LWOOBJID iLootTypeSource = LWOOBJID_EMPTY;
bool iObjIDIsDefault = false;
LWOOBJID iObjID = LWOOBJID_EMPTY;
LWOOBJID iObjID;
bool iObjTemplateIsDefault = false;
LOT iObjTemplate = LOT_NULL;
bool iRequestingObjIDIsDefault = false;
@@ -6197,15 +6197,3 @@ void GameMessages::HandleCancelDonationOnPlayer(RakNet::BitStream& inStream, Ent
if (!characterComponent) return;
characterComponent->SetCurrentInteracting(LWOOBJID_EMPTY);
}
void GameMessages::SendSlashCommandFeedbackText(Entity* entity, std::u16string text) {
CBITSTREAM;
CMSGHEADER;
bitStream.Write(entity->GetObjectID());
bitStream.Write(eGameMessageType::SLASH_COMMAND_TEXT_FEEDBACK);
bitStream.Write<uint32_t>(text.size());
bitStream.Write(text);
auto sysAddr = entity->GetSystemAddress();
SEND_PACKET;
}

View File

@@ -664,8 +664,6 @@ namespace GameMessages {
void HandleRemoveDonationItem(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
void HandleConfirmDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity);
void HandleCancelDonationOnPlayer(RakNet::BitStream& inStream, Entity* entity);
void SendSlashCommandFeedbackText(Entity* entity, std::u16string text);
};
#endif // GAMEMESSAGES_H

View File

@@ -65,24 +65,24 @@ Mission::Mission(MissionComponent* missionComponent, const uint32_t missionId) {
}
}
void Mission::LoadFromXml(const tinyxml2::XMLElement& element) {
void Mission::LoadFromXml(tinyxml2::XMLElement* element) {
// Start custom XML
if (element.Attribute("state") != nullptr) {
m_State = static_cast<eMissionState>(std::stoul(element.Attribute("state")));
if (element->Attribute("state") != nullptr) {
m_State = static_cast<eMissionState>(std::stoul(element->Attribute("state")));
}
// End custom XML
if (element.Attribute("cct") != nullptr) {
m_Completions = std::stoul(element.Attribute("cct"));
if (element->Attribute("cct") != nullptr) {
m_Completions = std::stoul(element->Attribute("cct"));
m_Timestamp = std::stoul(element.Attribute("cts"));
m_Timestamp = std::stoul(element->Attribute("cts"));
if (IsComplete()) {
return;
}
}
auto* task = element.FirstChildElement();
auto* task = element->FirstChildElement();
auto index = 0U;
@@ -132,19 +132,19 @@ void Mission::LoadFromXml(const tinyxml2::XMLElement& element) {
}
}
void Mission::UpdateXml(tinyxml2::XMLElement& element) {
void Mission::UpdateXml(tinyxml2::XMLElement* element) {
// Start custom XML
element.SetAttribute("state", static_cast<unsigned int>(m_State));
element->SetAttribute("state", static_cast<unsigned int>(m_State));
// End custom XML
element.DeleteChildren();
element->DeleteChildren();
element.SetAttribute("id", static_cast<unsigned int>(info.id));
element->SetAttribute("id", static_cast<unsigned int>(info.id));
if (m_Completions > 0) {
element.SetAttribute("cct", static_cast<unsigned int>(m_Completions));
element->SetAttribute("cct", static_cast<unsigned int>(m_Completions));
element.SetAttribute("cts", static_cast<unsigned int>(m_Timestamp));
element->SetAttribute("cts", static_cast<unsigned int>(m_Timestamp));
if (IsComplete()) {
return;
@@ -155,27 +155,27 @@ void Mission::UpdateXml(tinyxml2::XMLElement& element) {
if (task->GetType() == eMissionTaskType::COLLECTION ||
task->GetType() == eMissionTaskType::VISIT_PROPERTY) {
auto* child = element.GetDocument()->NewElement("sv");
auto* child = element->GetDocument()->NewElement("sv");
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
element.LinkEndChild(child);
element->LinkEndChild(child);
for (auto unique : task->GetUnique()) {
auto* uniqueElement = element.GetDocument()->NewElement("sv");
auto* uniqueElement = element->GetDocument()->NewElement("sv");
uniqueElement->SetAttribute("v", static_cast<unsigned int>(unique));
element.LinkEndChild(uniqueElement);
element->LinkEndChild(uniqueElement);
}
break;
}
auto* child = element.GetDocument()->NewElement("sv");
auto* child = element->GetDocument()->NewElement("sv");
child->SetAttribute("v", static_cast<unsigned int>(task->GetProgress()));
element.LinkEndChild(child);
element->LinkEndChild(child);
}
}

View File

@@ -28,8 +28,8 @@ public:
Mission(MissionComponent* missionComponent, uint32_t missionId);
~Mission();
void LoadFromXml(const tinyxml2::XMLElement& element);
void UpdateXml(tinyxml2::XMLElement& element);
void LoadFromXml(tinyxml2::XMLElement* element);
void UpdateXml(tinyxml2::XMLElement* element);
/**
* Returns the ID of this mission

View File

@@ -29,14 +29,15 @@ const BrickList& BrickDatabase::GetBricks(const LxfmlPath& lxfmlPath) {
return emptyCache;
}
tinyxml2::XMLDocument doc;
if (doc.Parse(data.str().c_str(), data.str().size()) != 0) {
auto* doc = new tinyxml2::XMLDocument();
if (doc->Parse(data.str().c_str(), data.str().size()) != 0) {
delete doc;
return emptyCache;
}
BrickList parts;
auto* lxfml = doc.FirstChildElement("LXFML");
auto* lxfml = doc->FirstChildElement("LXFML");
auto* bricks = lxfml->FirstChildElement("Bricks");
std::string searchTerm = "Brick";
@@ -85,5 +86,7 @@ const BrickList& BrickDatabase::GetBricks(const LxfmlPath& lxfmlPath) {
m_Cache[lxfmlPath] = parts;
delete doc;
return m_Cache[lxfmlPath];
}

View File

@@ -8,15 +8,9 @@ set(DGAME_DUTILITIES_SOURCES "BrickDatabase.cpp"
"SlashCommandHandler.cpp"
"VanityUtilities.cpp")
add_subdirectory(SlashCommands)
foreach(file ${DGAME_DUTILITIES_SLASHCOMMANDS})
set(DGAME_DUTILITIES_SOURCES ${DGAME_DUTILITIES_SOURCES} "SlashCommands/${file}")
endforeach()
add_library(dUtilities OBJECT ${DGAME_DUTILITIES_SOURCES})
target_precompile_headers(dUtilities REUSE_FROM dGameBase)
target_include_directories(dUtilities PUBLIC "." "SlashCommands"
target_include_directories(dUtilities PUBLIC "."
PRIVATE
"${PROJECT_SOURCE_DIR}/dGame/dComponents"
"${PROJECT_SOURCE_DIR}/dGame/dInventory" # transitive via PossessableComponent.h

File diff suppressed because it is too large Load Diff

View File

@@ -7,28 +7,13 @@
#define SLASHCOMMANDHANDLER_H
#include "RakNetTypes.h"
#include "eGameMasterLevel.h"
#include <string>
class Entity;
struct Command {
std::string help;
std::string info;
std::vector<std::string> aliases;
std::function<void(Entity*, const SystemAddress&,const std::string)> handle;
eGameMasterLevel requiredLevel = eGameMasterLevel::OPERATOR;
};
namespace SlashCommandHandler {
void HandleChatCommand(const std::u16string& command, Entity* entity, const SystemAddress& sysAddr);
void SendAnnouncement(const std::string& title, const std::string& message);
void RegisterCommand(Command info);
void Startup();
};
namespace GMZeroCommands {
void Help(Entity* entity, const SystemAddress& sysAddr, const std::string args);
}
#endif // SLASHCOMMANDHANDLER_H

View File

@@ -1,6 +0,0 @@
set(DGAME_DUTILITIES_SLASHCOMMANDS
"DEVGMCommands.cpp"
"GMGreaterThanZeroCommands.cpp"
"GMZeroCommands.cpp"
PARENT_SCOPE
)

File diff suppressed because it is too large Load Diff

View File

@@ -1,73 +0,0 @@
namespace DEVGMCommands {
void SetGMLevel(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ToggleNameplate(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ToggleSkipCinematics(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Kill(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Metrics(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Announce(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetAnnTitle(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetAnnMsg(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ShutdownUniverse(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetMinifig(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void TestMap(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ReportProxPhys(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SpawnPhysicsVerts(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Teleport(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ActivateSpawner(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void AddMission(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Boost(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Unboost(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Buff(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void BuffMe(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void BuffMed(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ClearFlag(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void CompleteMission(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void CreatePrivate(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void DebugUi(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Dismount(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ReloadConfig(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ForceSave(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Freecam(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void FreeMoney(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GetNavmeshHeight(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GiveUScore(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GmAddItem(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Inspect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ListSpawns(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void LocRow(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Lookup(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void PlayAnimation(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void PlayEffect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void PlayLvlFx(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void PlayRebuildFx(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Pos(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void RefillStats(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Reforge(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ResetMission(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Rot(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void RunMacro(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetControlScheme(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetCurrency(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetFlag(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetInventorySize(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetUiState(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Spawn(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SpawnGroup(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SpeedBoost(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void StartCelebration(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void StopEffect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Toggle(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void TpAll(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void TriggerSpawner(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void UnlockEmote(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetLevel(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetSkillSlot(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetFaction(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void AddFaction(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GetFactions(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetRewardCode(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Crash(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void RollLoot(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void CastSkill(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void DeleteInven(Entity* entity, const SystemAddress& sysAddr, const std::string args);
}

View File

@@ -1,290 +0,0 @@
#include "GMGreaterThanZeroCommands.h"
// Classes
#include "Character.h"
#include "ChatPackets.h"
#include "dServer.h"
#include "PlayerManager.h"
#include "User.h"
// Database
#include "Database.h"
// Components
#include "DestroyableComponent.h"
#include "PropertyManagementComponent.h"
// Enums
#include "eChatMessageType.h"
#include "eServerDisconnectIdentifiers.h"
#include "eObjectBits.h"
namespace GMGreaterThanZeroCommands {
void Kick(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
if (splitArgs.size() == 1) {
auto* player = PlayerManager::GetPlayer(splitArgs[0]);
std::u16string username = GeneralUtils::UTF8ToUTF16(splitArgs[0]);
if (player == nullptr) {
ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + username);
return;
}
Game::server->Disconnect(player->GetSystemAddress(), eServerDisconnectIdentifiers::KICK);
ChatPackets::SendSystemMessage(sysAddr, u"Kicked: " + username);
} else {
ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /kick <username>");
}
}
void Ban(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
if (splitArgs.size() == 1) {
auto* player = PlayerManager::GetPlayer(splitArgs[0]);
uint32_t accountId = 0;
if (player == nullptr) {
auto characterInfo = Database::Get()->GetCharacterInfo(splitArgs[0]);
if (characterInfo) {
accountId = characterInfo->accountId;
}
if (accountId == 0) {
ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + GeneralUtils::UTF8ToUTF16(splitArgs[0]));
return;
}
} else {
auto* character = player->GetCharacter();
auto* user = character != nullptr ? character->GetParentUser() : nullptr;
if (user) accountId = user->GetAccountID();
}
if (accountId != 0) Database::Get()->UpdateAccountBan(accountId, true);
if (player != nullptr) {
Game::server->Disconnect(player->GetSystemAddress(), eServerDisconnectIdentifiers::FREE_TRIAL_EXPIRED);
}
ChatPackets::SendSystemMessage(sysAddr, u"Banned: " + GeneralUtils::ASCIIToUTF16(splitArgs[0]));
} else {
ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /ban <username>");
}
}
void MailItem(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
if (splitArgs.size() < 2) return;
const auto& playerName = splitArgs[0];
auto playerInfo = Database::Get()->GetCharacterInfo(playerName);
uint32_t receiverID = 0;
if (!playerInfo) {
ChatPackets::SendSystemMessage(sysAddr, u"Failed to find that player");
return;
}
receiverID = playerInfo->id;
const auto lot = GeneralUtils::TryParse<LOT>(splitArgs.at(1));
if (!lot) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid item lot.");
return;
}
IMail::MailInfo mailInsert;
mailInsert.senderId = entity->GetObjectID();
mailInsert.senderUsername = "Darkflame Universe";
mailInsert.receiverId = receiverID;
mailInsert.recipient = playerName;
mailInsert.subject = "Lost item";
mailInsert.body = "This is a replacement item for one you lost.";
mailInsert.itemID = LWOOBJID_EMPTY;
mailInsert.itemLOT = lot.value();
mailInsert.itemSubkey = LWOOBJID_EMPTY;
mailInsert.itemCount = 1;
Database::Get()->InsertNewMail(mailInsert);
ChatPackets::SendSystemMessage(sysAddr, u"Mail sent");
}
void ApproveProperty(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
if (PropertyManagementComponent::Instance() != nullptr) {
PropertyManagementComponent::Instance()->UpdateApprovedStatus(true);
}
}
void Mute(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
if (splitArgs.size() >= 1) {
auto* player = PlayerManager::GetPlayer(splitArgs[0]);
uint32_t accountId = 0;
LWOOBJID characterId = 0;
if (player == nullptr) {
auto characterInfo = Database::Get()->GetCharacterInfo(splitArgs[0]);
if (characterInfo) {
accountId = characterInfo->accountId;
characterId = characterInfo->id;
GeneralUtils::SetBit(characterId, eObjectBits::CHARACTER);
GeneralUtils::SetBit(characterId, eObjectBits::PERSISTENT);
}
if (accountId == 0) {
ChatPackets::SendSystemMessage(sysAddr, u"Count not find player of name: " + GeneralUtils::UTF8ToUTF16(splitArgs[0]));
return;
}
} else {
auto* character = player->GetCharacter();
auto* user = character != nullptr ? character->GetParentUser() : nullptr;
if (user) accountId = user->GetAccountID();
characterId = player->GetObjectID();
}
time_t expire = 1; // Default to indefinate mute
if (splitArgs.size() >= 2) {
const auto days = GeneralUtils::TryParse<uint32_t>(splitArgs[1]);
if (!days) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid days.");
return;
}
std::optional<uint32_t> hours;
if (splitArgs.size() >= 3) {
hours = GeneralUtils::TryParse<uint32_t>(splitArgs[2]);
if (!hours) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid hours.");
return;
}
}
expire = time(NULL);
expire += 24 * 60 * 60 * days.value();
expire += 60 * 60 * hours.value_or(0);
}
if (accountId != 0) Database::Get()->UpdateAccountUnmuteTime(accountId, expire);
char buffer[32] = "brought up for review.\0";
if (expire != 1) {
std::tm* ptm = std::localtime(&expire);
// Format: Mo, 15.06.2009 20:20:00
std::strftime(buffer, 32, "%a, %d.%m.%Y %H:%M:%S", ptm);
}
const auto timeStr = GeneralUtils::ASCIIToUTF16(std::string(buffer));
ChatPackets::SendSystemMessage(sysAddr, u"Muted: " + GeneralUtils::UTF8ToUTF16(splitArgs[0]) + u" until " + timeStr);
//Notify chat about it
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, eChatMessageType::GM_MUTE);
bitStream.Write(characterId);
bitStream.Write(expire);
Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false);
} else {
ChatPackets::SendSystemMessage(sysAddr, u"Correct usage: /mute <username> <days (optional)> <hours (optional)>");
}
}
void Fly(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
auto* character = entity->GetCharacter();
if (character) {
bool isFlying = character->GetIsFlying();
if (isFlying) {
GameMessages::SendSetJetPackMode(entity, false);
character->SetIsFlying(false);
} else {
float speedScale = 1.0f;
if (splitArgs.size() >= 1) {
const auto tempScaleStore = GeneralUtils::TryParse<float>(splitArgs.at(0));
if (tempScaleStore) {
speedScale = tempScaleStore.value();
} else {
ChatPackets::SendSystemMessage(sysAddr, u"Failed to parse speed scale argument.");
}
}
float airSpeed = 20 * speedScale;
float maxAirSpeed = 30 * speedScale;
float verticalVelocity = 1.5 * speedScale;
GameMessages::SendSetJetPackMode(entity, true, true, false, 167, airSpeed, maxAirSpeed, verticalVelocity);
character->SetIsFlying(true);
}
}
}
void AttackImmune(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
if (splitArgs.empty()) return;
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
const auto state = GeneralUtils::TryParse<int32_t>(splitArgs[0]);
if (!state) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid state.");
return;
}
if (destroyableComponent) destroyableComponent->SetIsImmune(state.value());
}
void GmImmune(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto splitArgs = GeneralUtils::SplitString(args, ' ');
if (splitArgs.empty()) return;
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
const auto state = GeneralUtils::TryParse<int32_t>(splitArgs[0]);
if (!state) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid state.");
return;
}
if (destroyableComponent) destroyableComponent->SetIsGMImmune(state.value());
}
void GmInvis(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
GameMessages::SendToggleGMInvis(entity->GetObjectID(), true, UNASSIGNED_SYSTEM_ADDRESS);
}
void SetName(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
GameMessages::SendSetName(entity->GetObjectID(), GeneralUtils::UTF8ToUTF16(args), UNASSIGNED_SYSTEM_ADDRESS);
}
void Title(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
std::string name = entity->GetCharacter()->GetName() + " - " + args;
GameMessages::SendSetName(entity->GetObjectID(), GeneralUtils::UTF8ToUTF16(name), UNASSIGNED_SYSTEM_ADDRESS);
}
}

View File

@@ -1,13 +0,0 @@
namespace GMGreaterThanZeroCommands {
void Kick(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void MailItem(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Ban(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void ApproveProperty(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Mute(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Fly(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void AttackImmune(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GmImmune(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void GmInvis(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void SetName(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Title(Entity* entity, const SystemAddress& sysAddr, const std::string args);
}

View File

@@ -1,228 +0,0 @@
#include "GMZeroCommands.h"
// Classes
#include "Amf3.h"
#include "BinaryPathFinder.h"
#include "ChatPackets.h"
#include "dServer.h"
#include "dZoneManager.h"
#include "Mail.h"
#include "PlayerManager.h"
#include "SlashCommandHandler.h"
#include "VanityUtilities.h"
#include "WorldPackets.h"
#include "ZoneInstanceManager.h"
// Components
#include "BuffComponent.h"
#include "CharacterComponent.h"
#include "DestroyableComponent.h"
#include "ScriptedActivityComponent.h"
#include "SkillComponent.h"
// Emuns
#include "eGameMasterLevel.h"
namespace GMZeroCommands {
void Pvp(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
auto* character = entity->GetComponent<CharacterComponent>();
if (character == nullptr) {
LOG("Failed to find character component!");
return;
}
character->SetPvpEnabled(!character->GetPvpEnabled());
Game::entityManager->SerializeEntity(entity);
std::stringstream message;
message << character->GetName() << " changed their PVP flag to " << std::to_string(character->GetPvpEnabled()) << "!";
ChatPackets::SendSystemMessage(UNASSIGNED_SYSTEM_ADDRESS, GeneralUtils::UTF8ToUTF16(message.str()), true);
}
void Who(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
ChatPackets::SendSystemMessage(
sysAddr,
u"Players in this instance: (" + GeneralUtils::to_u16string(PlayerManager::GetAllPlayers().size()) + u")"
);
for (auto* player : PlayerManager::GetAllPlayers()) {
const auto& name = player->GetCharacter()->GetName();
ChatPackets::SendSystemMessage(
sysAddr,
GeneralUtils::UTF8ToUTF16(player == entity ? name + " (you)" : name)
);
}
}
void Ping(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
if (!args.empty() && args.starts_with("-l")) {
std::stringstream message;
message << "Your latest ping: " << std::to_string(Game::server->GetLatestPing(sysAddr)) << "ms";
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(message.str()));
} else {
std::stringstream message;
message << "Your average ping: " << std::to_string(Game::server->GetPing(sysAddr)) << "ms";
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(message.str()));
}
}
void FixStats(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
// Reset skill component and buff component
auto* skillComponent = entity->GetComponent<SkillComponent>();
auto* buffComponent = entity->GetComponent<BuffComponent>();
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
// If any of the components are nullptr, return
if (skillComponent == nullptr || buffComponent == nullptr || destroyableComponent == nullptr) {
return;
}
// Reset skill component
skillComponent->Reset();
// Reset buff component
buffComponent->Reset();
// Fix the destroyable component
destroyableComponent->FixStats();
}
void Credits(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto& customText = VanityUtilities::ParseMarkdown((BinaryPathFinder::GetBinaryDir() / "vanity/CREDITS.md").string());
{
AMFArrayValue args;
args.Insert("state", "Story");
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
}
entity->AddCallbackTimer(0.5f, [customText, entity]() {
AMFArrayValue args;
args.Insert("visible", true);
args.Insert("text", customText);
LOG("Sending %s", customText.c_str());
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "ToggleStoryBox", args);
});
}
void Info(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto& customText = VanityUtilities::ParseMarkdown((BinaryPathFinder::GetBinaryDir() / "vanity/INFO.md").string());
{
AMFArrayValue args;
args.Insert("state", "Story");
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "pushGameState", args);
}
entity->AddCallbackTimer(0.5f, [customText, entity]() {
AMFArrayValue args;
args.Insert("visible", true);
args.Insert("text", customText);
LOG("Sending %s", customText.c_str());
GameMessages::SendUIMessageServerToSingleClient(entity, entity->GetSystemAddress(), "ToggleStoryBox", args);
});
}
void LeaveZone(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto currentZone = Game::zoneManager->GetZone()->GetZoneID().GetMapID();
LWOMAPID newZone = 0;
if (currentZone == 1001 || currentZone % 100 == 0) {
ChatPackets::SendSystemMessage(sysAddr, u"You are not in an instanced zone.");
return;
} else {
newZone = (currentZone / 100) * 100;
}
// If new zone would be inaccessible, then default to Avant Gardens.
if (!Game::zoneManager->CheckIfAccessibleZone(newZone)) newZone = 1100;
ChatPackets::SendSystemMessage(sysAddr, u"Leaving zone...");
const auto objid = entity->GetObjectID();
ZoneInstanceManager::Instance()->RequestZoneTransfer(Game::server, newZone, 0, false, [objid](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
auto* entity = Game::entityManager->GetEntity(objid);
if (entity == nullptr) {
return;
}
const auto sysAddr = entity->GetSystemAddress();
LOG("Transferring %s to Zone %i (Instance %i | Clone %i | Mythran Shift: %s) with IP %s and Port %i", entity->GetCharacter()->GetName().c_str(), zoneID, zoneInstance, zoneClone, mythranShift == true ? "true" : "false", serverIP.c_str(), serverPort);
if (entity->GetCharacter()) {
entity->GetCharacter()->SetZoneID(zoneID);
entity->GetCharacter()->SetZoneInstance(zoneInstance);
entity->GetCharacter()->SetZoneClone(zoneClone);
}
entity->GetCharacter()->SaveXMLToDatabase();
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift);
});
}
void Join(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
auto splitArgs = GeneralUtils::SplitString(args, ' ');
if (splitArgs.empty()) return;
ChatPackets::SendSystemMessage(sysAddr, u"Requesting private map...");
const auto& password = splitArgs[0];
ZoneInstanceManager::Instance()->RequestPrivateZone(Game::server, false, password, [=](bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, std::string serverIP, uint16_t serverPort) {
LOG("Transferring %s to Zone %i (Instance %i | Clone %i | Mythran Shift: %s) with IP %s and Port %i", sysAddr.ToString(), zoneID, zoneInstance, zoneClone, mythranShift == true ? "true" : "false", serverIP.c_str(), serverPort);
if (entity->GetCharacter()) {
entity->GetCharacter()->SetZoneID(zoneID);
entity->GetCharacter()->SetZoneInstance(zoneInstance);
entity->GetCharacter()->SetZoneClone(zoneClone);
}
entity->GetCharacter()->SaveXMLToDatabase();
WorldPackets::SendTransferToWorld(sysAddr, serverIP, serverPort, mythranShift);
});
}
void Die(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
entity->Smash(entity->GetObjectID());
}
void Resurrect(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
ScriptedActivityComponent* scriptedActivityComponent = Game::zoneManager->GetZoneControlObject()->GetComponent<ScriptedActivityComponent>();
if (scriptedActivityComponent) { // check if user is in activity world and if so, they can't resurrect
ChatPackets::SendSystemMessage(sysAddr, u"You cannot resurrect in an activity world.");
return;
}
GameMessages::SendResurrect(entity);
}
void RequestMailCount(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
Mail::HandleNotificationRequest(entity->GetSystemAddress(), entity->GetObjectID());
}
void InstanceInfo(Entity* entity, const SystemAddress& sysAddr, const std::string args) {
const auto zoneId = Game::zoneManager->GetZone()->GetZoneID();
ChatPackets::SendSystemMessage(sysAddr, u"Map: " + (GeneralUtils::to_u16string(zoneId.GetMapID())) + u"\nClone: " + (GeneralUtils::to_u16string(zoneId.GetCloneID())) + u"\nInstance: " + (GeneralUtils::to_u16string(zoneId.GetInstanceID())));
}
};

View File

@@ -1,15 +0,0 @@
namespace GMZeroCommands {
void Help(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Credits(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Info(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Die(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Ping(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Pvp(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void RequestMailCount(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Who(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void FixStats(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Join(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void LeaveZone(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void Resurrect(Entity* entity, const SystemAddress& sysAddr, const std::string args);
void InstanceInfo(Entity* entity, const SystemAddress& sysAddr, const std::string args);
}

View File

@@ -17,9 +17,7 @@ void TokenConsoleServer::OnUse(Entity* self, Entity* user) {
inv->RemoveItem(6194, bricksToTake);
//play sound
if (self->HasVar(u"sound1")) {
GameMessages::SendPlayNDAudioEmitter(self, user->GetSystemAddress(), self->GetVarAsString(u"sound1"));
}
GameMessages::SendPlayNDAudioEmitter(self, user->GetSystemAddress(), "947d0d52-c7f8-4516-8dee-e1593a7fd1d1");
//figure out which faction the player belongs to:
auto character = user->GetCharacter();

View File

@@ -39,7 +39,7 @@ void NsTokenConsoleServer::OnUse(Entity* self, Entity* user) {
const auto useSound = self->GetVar<std::string>(u"sound1");
if (!useSound.empty()) {
GameMessages::SendPlayNDAudioEmitter(self, user->GetSystemAddress(), useSound);
GameMessages::SendPlayNDAudioEmitter(self, UNASSIGNED_SYSTEM_ADDRESS, useSound);
}
// Player must be in faction to interact with this entity.

View File

@@ -90,7 +90,7 @@ void SGCannon::OnActivityStateChangeRequest(Entity* self, LWOOBJID senderID, int
auto* shootingGalleryComponent = self->GetComponent<ShootingGalleryComponent>();
if (shootingGalleryComponent != nullptr) {
shootingGalleryComponent->AddActivityPlayerData(player->GetObjectID());
shootingGalleryComponent->SetCurrentPlayerID(player->GetObjectID());
LOG("Setting player ID");

View File

@@ -79,7 +79,6 @@
#include "PositionUpdate.h"
#include "PlayerManager.h"
#include "eLoginResponse.h"
#include "SlashCommandHandler.h"
namespace Game {
Logger* logger = nullptr;
@@ -314,9 +313,6 @@ int main(int argc, char** argv) {
uint32_t sqlPingTime = 10 * 60 * currentFramerate; // 10 minutes in frames
uint32_t emptyShutdownTime = (cloneID == 0 ? 30 : 5) * 60 * currentFramerate; // 30 minutes for main worlds, 5 for all others.
// Register slash commands if not in zone 0
if (zoneID != 0) SlashCommandHandler::Startup();
Game::logger->Flush(); // once immediately before the main loop
while (true) {
Metrics::StartMeasurement(MetricVariable::Frame);

View File

@@ -121,7 +121,7 @@ TEST(MagicEnumTest, eGameMessageTypeTest) {
namespace {
template <typename T>
void AssertEnumArraySorted(const T& eArray) {
for (int i = 0; i < eArray->size() - 1; ++i) {
for (int i = 0; i < eArray->size(); ++i) {
const auto entryCurr = eArray->at(i).first;
LOG_EARRAY(eArray, i, entryCurr);
const auto entryNext = eArray->at(++i).first;

View File

@@ -36,11 +36,10 @@
#include "sqlite3.h"
#include <cstdio>
#include <cstring>
#include <exception>
#define CPPSQLITE_ERROR 1000
class CppSQLite3Exception : public std::exception
class CppSQLite3Exception
{
public:
@@ -55,8 +54,6 @@ public:
const int errorCode() { return mnErrCode; }
const char* errorMessage() { return mpszErrMess; }
const char* what() const noexcept override { return mpszErrMess; }
static const char* errorCodeAsString(int nErrCode);